Skip to content

Commit 6e1a124

Browse files
Fix mojohaus#423 Don't log warning for unused overrides in remote override file.
1 parent 4736bf6 commit 6e1a124

File tree

6 files changed

+119
-4
lines changed

6 files changed

+119
-4
lines changed

src/it/ISSUE-423/invoker.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals=clean install license:add-third-party
2+
invoker.failureBehavior=fail-fast

src/it/ISSUE-423/pom.xml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
#%L
4+
License Maven Plugin
5+
%%
6+
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
7+
%%
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as
10+
published by the Free Software Foundation, either version 3 of the
11+
License, or (at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Lesser Public License for more details.
17+
18+
You should have received a copy of the GNU General Lesser Public
19+
License along with this program. If not, see
20+
<http://www.gnu.org/licenses/lgpl-3.0.html>.
21+
#L%
22+
-->
23+
24+
<project xmlns="http://maven.apache.org/POM/4.0.0"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
28+
<modelVersion>4.0.0</modelVersion>
29+
30+
<groupId>org.codehaus.mojo.license.test</groupId>
31+
<artifactId>issue-423</artifactId>
32+
<version>@pom.version@</version>
33+
34+
<name>License Test :: ISSUE-423</name>
35+
36+
<properties>
37+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
<license.verbose>true</license.verbose>
39+
</properties>
40+
41+
<dependencies>
42+
<dependency>
43+
<groupId>commons-logging</groupId>
44+
<artifactId>commons-logging</artifactId>
45+
<version>1.1.1</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.commons</groupId>
49+
<artifactId>commons-lang3</artifactId>
50+
<version>3.8.1</version>
51+
</dependency>
52+
</dependencies>
53+
54+
</project>

src/it/ISSUE-423/postbuild.groovy

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* #%L
3+
* License Maven Plugin
4+
* %%
5+
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
20+
* #L%
21+
*/
22+
23+
file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt')
24+
assert file.exists()
25+
content = file.text
26+
// Check that the non-overridden dependency is present.
27+
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/)')
28+
// Check that the license name for a dependency can be overridden.
29+
assert content.contains('(Apache-2.0) Commons Logging (commons-logging:commons-logging:1.1.1 - http://commons.apache.org/logging)')
30+
// Check that the unused override does not end up in the report.
31+
assert !content.contains('antlr')
32+
33+
// Check that the log contains a warning for the unused override.
34+
log = new File(basedir, 'build.log')
35+
assert log.exists()
36+
assert log.text.contains('dependency [org.antlr--antlr--3.5.2] does not exist in project.')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
commons-logging--commons-logging--1.1.1=Apache-2.0
2+
org.antlr--antlr--3.5.2=BSD-3-Clause

src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,16 @@ public void overrideLicenses( LicenseMap licenseMap, SortedMap<String, MavenProj
614614
MavenProject project = artifactCache.get( id );
615615
if ( project == null )
616616
{
617-
LOG.warn( "dependency [{}] does not exist in project.", id );
617+
// Log at warn for local override files, but at debug for remote (presumably shared) override files.
618+
String protocol = UrlRequester.findProtocol( overrideUrl );
619+
if ( "http".equals( protocol ) || "https".equals( protocol ) )
620+
{
621+
LOG.debug( "dependency [{}] does not exist in project.", id );
622+
}
623+
else
624+
{
625+
LOG.warn( "dependency [{}] does not exist in project.", id );
626+
}
618627
continue;
619628
}
620629

src/main/java/org/codehaus/mojo/license/utils/UrlRequester.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ public static String getFromUrl( String url ) throws IOException
9090
return getFromUrl( url, "UTF-8" );
9191
}
9292

93+
/**
94+
* Returns the protocol of the given URL as a string.
95+
*
96+
* The RFC specifies that the url is composed by <protocol>:<schema-part>.
97+
*
98+
* @param url the URL as a string.
99+
* @return the protocol from the URL.
100+
*/
101+
public static String findProtocol( String url )
102+
{
103+
// Here could not be used the URL parser because classpath does not have a registered Handler
104+
return StringUtils.substringBefore( url, ":" ).toLowerCase();
105+
}
106+
93107
/**
94108
* Returns the content of the resource pointed by the given URL as a string.
95109
*
@@ -100,9 +114,7 @@ public static String getFromUrl( String url ) throws IOException
100114
*/
101115
public static String getFromUrl( String url, String encoding ) throws IOException
102116
{
103-
// by RFC url is composed by <protocol>:<schema-part>.
104-
// Here could not be used the URL parser because classpath does not have a registered Handler
105-
String protocol = StringUtils.substringBefore( url, ":" ).toLowerCase();
117+
String protocol = findProtocol( url );
106118
Charset charset = Charset.forName( encoding );
107119

108120
String result = null;

0 commit comments

Comments
 (0)