Skip to content

Commit ae3a443

Browse files
committed
Fix issue in DefaultDependenciesTool.loadProjectArtifacts causing direct dependencies within the same reactor to not be returned in the result
1 parent c251e04 commit ae3a443

19 files changed

+301
-59
lines changed

src/it/ISSUE-145-2/README.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Demonstrates that the aggregateAddThirdParty goal can handle long sibling project dependency chains in the same reactor.
2+
3+
The project has parent A and children B, C, D, E with B depending on C, C dependending on D and D depending on E. The E dependency has a certain license. When the plugin generates the license list, it should pick up the license for E.

src/it/ISSUE-145-2/invoker.properties

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
invoker.goals=clean package
23+
invoker.failureBehavior=fail-fast

src/it/ISSUE-145-2/pom.xml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.codehaus.mojo.license.test</groupId>
7+
<artifactId>test-ISSUE-145-2</artifactId>
8+
<version>@pom.version@</version>
9+
<name>License Test :: ISSUE-145-2</name>
10+
<packaging>pom</packaging>
11+
12+
<licenses>
13+
<license>
14+
<name>The GNU Lesser General Public License, Version 3.0</name>
15+
<url>http://www.gnu.org/licenses/lgpl-3.0.txt</url>
16+
<distribution>repo</distribution>
17+
</license>
18+
</licenses>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<license.verbose>true</license.verbose>
23+
<license.sortByGroupIdAndArtifactId>true</license.sortByGroupIdAndArtifactId>
24+
<licensesOutputFile>${project.build.directory}/licenses.xml</licensesOutputFile>
25+
</properties>
26+
27+
<modules>
28+
<module>submodule1</module>
29+
<module>submodule2</module>
30+
<module>submodule3</module>
31+
<module>submodule4</module>
32+
</modules>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.codehaus.mojo</groupId>
38+
<artifactId>license-maven-plugin</artifactId>
39+
</plugin>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-compiler-plugin</artifactId>
43+
<version>3.8.0</version>
44+
</plugin>
45+
</plugins>
46+
47+
<pluginManagement>
48+
<plugins>
49+
<plugin>
50+
<groupId>org.codehaus.mojo</groupId>
51+
<artifactId>license-maven-plugin</artifactId>
52+
<version>@pom.version@</version>
53+
<executions>
54+
<execution>
55+
<id>aggregate-add-third-party</id>
56+
<goals>
57+
<goal>aggregate-add-third-party</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</pluginManagement>
64+
</build>
65+
66+
</project>

src/it/ISSUE-145-2/postbuild.groovy

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
def assertExistsFile(file) {
24+
if (!file.exists() || file.isDirectory()) {
25+
println(file.getAbsolutePath() + " file is missing or a directory.")
26+
assert false
27+
}
28+
assert true
29+
}
30+
31+
def assertContains(file, content, expected) {
32+
if (!content.contains(expected)) {
33+
println(expected + " was not found in file [" + file + "]\n :" + content)
34+
return false
35+
}
36+
return true
37+
}
38+
39+
file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt');
40+
assertExistsFile(file);
41+
42+
content = file.text;
43+
assert assertContains(file, content, 'Custom ISSUE-145 license');
44+
45+
return true;

src/it/ISSUE-145-2/submodule1/pom.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.codehaus.mojo.license.test</groupId>
7+
<artifactId>test-ISSUE-145-2</artifactId>
8+
<version>@pom.version@</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<packaging>jar</packaging>
13+
14+
<artifactId>test-ISSUE-145-2-submodule1</artifactId>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.codehaus.mojo.license.test</groupId>
19+
<artifactId>test-ISSUE-145-2-submodule2</artifactId>
20+
<version>@pom.version@</version>
21+
</dependency>
22+
</dependencies>
23+
24+
</project>

src/it/ISSUE-145-2/submodule2/pom.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.codehaus.mojo.license.test</groupId>
7+
<artifactId>test-ISSUE-145-2</artifactId>
8+
<version>@pom.version@</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>test-ISSUE-145-2-submodule2</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.codehaus.mojo.license.test</groupId>
17+
<artifactId>test-ISSUE-145-2-submodule3</artifactId>
18+
<version>@pom.version@</version>
19+
</dependency>
20+
</dependencies>
21+
</project>

src/it/ISSUE-145-2/submodule3/pom.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.codehaus.mojo.license.test</groupId>
7+
<artifactId>test-ISSUE-145-2</artifactId>
8+
<version>@pom.version@</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>test-ISSUE-145-2-submodule3</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.codehaus.mojo.license.test</groupId>
17+
<artifactId>test-ISSUE-145-2-submodule4</artifactId>
18+
<version>@pom.version@</version>
19+
</dependency>
20+
</dependencies>
21+
</project>

src/it/ISSUE-145-2/submodule4/pom.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.codehaus.mojo.license.test</groupId>
7+
<artifactId>test-ISSUE-145-2</artifactId>
8+
<version>@pom.version@</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>test-ISSUE-145-2-submodule4</artifactId>
13+
14+
<licenses>
15+
<license>
16+
<name>Custom ISSUE-145 license</name>
17+
</license>
18+
</licenses>
19+
</project>

src/it/ISSUE-145/README.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Demonstrates that the aggregateAddThirdParty goal does not cause Maven to drop dependencies.
2+
3+
The project has parent A and children B and C with B depending on C. The bug in the plugin caused B to lose its dependency on C at build time, because the plugin modified Maven's list of dependencies for B. The test verifies that the dependency is preserved.

src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import java.util.SortedMap;
4141
import java.util.SortedSet;
4242
import org.apache.maven.model.Dependency;
43-
import org.codehaus.mojo.license.api.LoadedProjectDependencies;
43+
import org.codehaus.mojo.license.api.ResolvedProjectDependencies;
4444

4545
/*
4646
* #%L
@@ -588,7 +588,7 @@ public abstract class AbstractAddThirdPartyMojo
588588
* plugin needs to replace B with its dependencies when processing A. This field stores that modified view of the
589589
* project's dependencies.
590590
*/
591-
LoadedProjectDependencies dependencyArtifacts;
591+
ResolvedProjectDependencies dependencyArtifacts;
592592

593593
// ----------------------------------------------------------------------
594594
// Abstract Methods
@@ -668,7 +668,7 @@ protected void init()
668668
if ( isAggregatorBuild ) {
669669
dependencyArtifacts = dependenciesTool.loadProjectArtifacts( localRepository, remoteRepositories, project, reactorProjectDependencies );
670670
} else {
671-
dependencyArtifacts = new LoadedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() );
671+
dependencyArtifacts = new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() );
672672
}
673673

674674
projectDependencies = loadDependencies();

src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import java.util.Map;
3535
import java.util.Set;
3636
import java.util.SortedMap;
37-
import org.codehaus.mojo.license.api.LoadedProjectDependencies;
37+
import org.codehaus.mojo.license.api.ResolvedProjectDependencies;
3838

3939
/**
4040
* Created on 23/05/16.
@@ -264,8 +264,7 @@ protected MavenProject getProject()
264264

265265
protected SortedMap<String, MavenProject> getDependencies( MavenProject project )
266266
{
267-
return dependenciesTool.loadProjectDependencies(
268-
new LoadedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ),
267+
return dependenciesTool.loadProjectDependencies(new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ),
269268
this, localRepository, remoteRepositories, null );
270269
}
271270

src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
import java.util.SortedMap;
6161
import java.util.SortedSet;
6262
import java.util.TreeSet;
63-
import org.apache.maven.artifact.Artifact;
64-
import org.codehaus.mojo.license.api.LoadedProjectDependencies;
63+
import org.codehaus.mojo.license.api.ResolvedProjectDependencies;
6564

6665
/**
6766
* Base class for third-party reports.
@@ -518,12 +517,12 @@ Collection<ThirdPartyDetails> createThirdPartyDetails( MavenProject project, boo
518517
DependenciesToolException, MojoExecutionException
519518
{
520519

521-
LoadedProjectDependencies loadedDependencies;
520+
ResolvedProjectDependencies loadedDependencies;
522521
if ( loadArtifacts ) {
523522
loadedDependencies = dependenciesTool.loadProjectArtifacts( localRepository, licenseMerges, project, null );
524523
}
525524
else {
526-
loadedDependencies = new LoadedProjectDependencies(getProject().getArtifacts(), getProject().getDependencyArtifacts());
525+
loadedDependencies = new ResolvedProjectDependencies(getProject().getArtifacts(), getProject().getDependencyArtifacts());
527526
}
528527

529528
ThirdPartyHelper thirdPartyHelper =

src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java

-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
import java.util.HashSet;
88
import java.util.List;
99
import java.util.Map;
10-
import java.util.Set;
1110
import java.util.SortedMap;
1211
import java.util.SortedSet;
1312
import org.apache.commons.collections.CollectionUtils;
1413
import org.apache.commons.collections.MapUtils;
15-
import org.apache.maven.artifact.Artifact;
1614
import org.apache.maven.model.Dependency;
1715
import org.apache.maven.plugin.MojoExecutionException;
1816
import org.apache.maven.plugin.logging.Log;
@@ -22,7 +20,6 @@
2220
import org.apache.maven.plugins.annotations.ResolutionScope;
2321
import org.apache.maven.project.MavenProject;
2422
import org.apache.maven.project.ProjectBuildingException;
25-
import org.codehaus.mojo.license.api.LoadedProjectDependencies;
2623
import org.codehaus.mojo.license.api.MavenProjectDependenciesConfigurator;
2724
import org.codehaus.mojo.license.api.ThirdPartyToolException;
2825
import org.codehaus.mojo.license.model.LicenseMap;

src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java

-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
import java.io.IOException;
55
import java.util.List;
66
import java.util.Map;
7-
import java.util.Set;
87
import java.util.SortedMap;
98
import java.util.SortedSet;
109
import java.util.TreeMap;
1110
import org.apache.commons.collections.CollectionUtils;
1211
import org.apache.maven.artifact.Artifact;
13-
import org.apache.maven.model.Dependency;
1412
import org.apache.maven.model.Plugin;
1513
import org.apache.maven.plugin.MojoExecutionException;
1614
import org.apache.maven.plugin.logging.Log;
@@ -20,7 +18,6 @@
2018
import org.apache.maven.plugins.annotations.ResolutionScope;
2119
import org.apache.maven.project.MavenProject;
2220
import org.apache.maven.project.ProjectBuildingException;
23-
import org.codehaus.mojo.license.api.LoadedProjectDependencies;
2421
import org.codehaus.mojo.license.model.LicenseMap;
2522
import org.codehaus.mojo.license.utils.SortedProperties;
2623

0 commit comments

Comments
 (0)