Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #423 Don't log warning for unused overrides in remote override file. #424

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/it/ISSUE-423/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=clean license:add-third-party
invoker.failureBehavior=fail-fast
64 changes: 64 additions & 0 deletions src/it/ISSUE-423/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
License Maven Plugin
%%
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Lesser Public License for more details.

You should have received a copy of the GNU General Lesser Public
License along with this program. If not, see
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>issue-423</artifactId>
<version>@pom.version@</version>

<name>License Test :: ISSUE-423</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.verbose>true</license.verbose>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@pom.version@</version>
</plugin>
</plugins>
</build>

<dependencies>
tpage-alfresco marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>

</project>
36 changes: 36 additions & 0 deletions src/it/ISSUE-423/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/

file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt')
assert file.exists()
content = file.text
// Check that the non-overridden dependency is present.
assert content.contains('(Apache License, Version 2.0) Apache Commons Lang (org.apache.commons:commons-lang3:3.8.1 - http://commons.apache.org/proper/commons-lang/)')
// Check that the license name for a dependency can be overridden.
assert content.contains('(Apache-2.0) Commons Logging (commons-logging:commons-logging:1.1.1 - http://commons.apache.org/logging)')
// Check that the unused override does not end up in the report.
assert !content.contains('antlr')

// Check that the log contains a warning for the unused override.
log = new File(basedir, 'build.log')
assert log.exists()
assert log.text.contains('dependency [org.antlr--antlr--3.5.2] does not exist in project.')
2 changes: 2 additions & 0 deletions src/it/ISSUE-423/src/license/override-THIRD-PARTY.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
commons-logging--commons-logging--1.1.1=Apache-2.0
org.antlr--antlr--3.5.2=BSD-3-Clause
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,16 @@ public void overrideLicenses( LicenseMap licenseMap, SortedMap<String, MavenProj
MavenProject project = artifactCache.get( id );
if ( project == null )
{
LOG.warn( "dependency [{}] does not exist in project.", id );
// Log at warn for local override files, but at debug for remote (presumably shared) override files.
String protocol = UrlRequester.findProtocol( overrideUrl );
if ( "http".equals( protocol ) || "https".equals( protocol ) )
{
LOG.debug( "dependency [{}] does not exist in project.", id );
}
else
{
LOG.warn( "dependency [{}] does not exist in project.", id );
}
continue;
}

Expand Down
18 changes: 15 additions & 3 deletions src/main/java/org/codehaus/mojo/license/utils/UrlRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public static String getFromUrl( String url ) throws IOException
return getFromUrl( url, "UTF-8" );
}

/**
* Returns the protocol of the given URL as a string.
*
* The RFC specifies that the url is composed by <protocol>:<schema-part>.
*
* @param url the URL as a string.
* @return the protocol from the URL.
*/
public static String findProtocol( String url )
{
// Here could not be used the URL parser because classpath does not have a registered Handler
return StringUtils.substringBefore( url, ":" ).toLowerCase();
}

/**
* Returns the content of the resource pointed by the given URL as a string.
*
Expand All @@ -100,9 +114,7 @@ public static String getFromUrl( String url ) throws IOException
*/
public static String getFromUrl( String url, String encoding ) throws IOException
{
// by RFC url is composed by <protocol>:<schema-part>.
// Here could not be used the URL parser because classpath does not have a registered Handler
String protocol = StringUtils.substringBefore( url, ":" ).toLowerCase();
String protocol = findProtocol( url );
Charset charset = Charset.forName( encoding );

String result = null;
Expand Down