diff --git a/src/it/ISSUE-145/pom.xml b/src/it/ISSUE-145/pom.xml index 0e1340350..b08752cb9 100644 --- a/src/it/ISSUE-145/pom.xml +++ b/src/it/ISSUE-145/pom.xml @@ -35,6 +35,11 @@ org.codehaus.mojo license-maven-plugin + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + diff --git a/src/it/ISSUE-145/submodule1/pom.xml b/src/it/ISSUE-145/submodule1/pom.xml index d80c24501..284341d89 100644 --- a/src/it/ISSUE-145/submodule1/pom.xml +++ b/src/it/ISSUE-145/submodule1/pom.xml @@ -26,7 +26,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.0 + 3.2.1 package diff --git a/src/it/ISSUE-145/submodule1/src/main/java/org/codehaus/mojo/license/Application.java b/src/it/ISSUE-145/submodule1/src/main/java/org/codehaus/mojo/license/Application.java index 684828896..09ed10e55 100644 --- a/src/it/ISSUE-145/submodule1/src/main/java/org/codehaus/mojo/license/Application.java +++ b/src/it/ISSUE-145/submodule1/src/main/java/org/codehaus/mojo/license/Application.java @@ -1,5 +1,27 @@ package org.codehaus.mojo.license; +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2017 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 + * . + * #L% + */ + public class Application { public static void main(String[] args) { diff --git a/src/it/ISSUE-145/submodule2/src/main/java/org/codehaus/mojo/license/AnImportantDependency.java b/src/it/ISSUE-145/submodule2/src/main/java/org/codehaus/mojo/license/AnImportantDependency.java index b34469792..c1d0b0d61 100644 --- a/src/it/ISSUE-145/submodule2/src/main/java/org/codehaus/mojo/license/AnImportantDependency.java +++ b/src/it/ISSUE-145/submodule2/src/main/java/org/codehaus/mojo/license/AnImportantDependency.java @@ -1,6 +1,28 @@ package org.codehaus.mojo.license; +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2017 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 + * . + * #L% + */ + public class AnImportantDependency { } diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index 8effda010..27bf4e9b7 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -562,10 +562,32 @@ public abstract class AbstractAddThirdPartyMojo */ private Map globalKnownLicenses; - boolean isAggregatorBuild; + /** + * Whether this is an aggregate build, or a single-project goal. This setting determines which dependency artifacts + * will be examined by the plugin. AddThirdParty needs to load dependencies only for the single project it is run + * for, while AggregateAddThirdParty needs to load dependencies for the parent project, as well as all child + * projects in the reactor. + */ + boolean isAggregatorBuild = false; + /** + * Map from reactor project G/A to direct dependencies. When loading dependencies, the aggregator goal replaces all + * reactor projects with their direct dependencies, to avoid trying to load artifacts for projects that haven't been + * built/published yet. This field is used to keep track of which dependencies are also projects in the reactor. + */ Map> reactorProjectDependencies; + /** + * Copies of the project's dependency sets. AddThirdParty needs to load dependencies only for the single project it + * is run for, while AggregateAddThirdParty needs to load dependencies for the parent project, as well as all child + * projects in the reactor. + * + * The aggregator goal replaces all reactor projects with their direct dependencies, to avoid trying to load + * artifacts for projects that haven't been built/published yet. This is necessary in cases where one child project + * A in a reactor depends on another project B in the same reactor. Since B is not necessarily built/published, the + * plugin needs to replace B with its dependencies when processing A. This field stores that modified view of the + * project's dependencies. + */ LoadedProjectDependencies dependencyArtifacts; // ---------------------------------------------------------------------- @@ -643,10 +665,10 @@ protected void init() doGenerateBundle = false; } - if (isAggregatorBuild) { + if ( isAggregatorBuild ) { dependencyArtifacts = dependenciesTool.loadProjectArtifacts( localRepository, remoteRepositories, project, reactorProjectDependencies ); } else { - dependencyArtifacts = new LoadedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts()); + dependencyArtifacts = new LoadedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ); } projectDependencies = loadDependencies(); diff --git a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java index 70be2224e..d9e54ba4c 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java @@ -265,7 +265,7 @@ protected MavenProject getProject() protected SortedMap getDependencies( MavenProject project ) { return dependenciesTool.loadProjectDependencies( - new LoadedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts()), + new LoadedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ), this, localRepository, remoteRepositories, null ); } diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java index 41760e04c..0996de262 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java @@ -160,7 +160,7 @@ protected void init() throws Exception { isAggregatorBuild = true; reactorProjectDependencies = new TreeMap<>(); for (MavenProject reactorProject : this.reactorProjects) { - reactorProjectDependencies.put(String.format("%s:%s", reactorProject.getGroupId(), reactorProject.getArtifactId()), reactorProject.getDependencies()); + reactorProjectDependencies.put( String.format( "%s:%s", reactorProject.getGroupId(), reactorProject.getArtifactId() ), reactorProject.getDependencies() ); } super.init(); } diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultDependenciesTool.java b/src/main/java/org/codehaus/mojo/license/api/DefaultDependenciesTool.java index 6a1cab6be..9542df77e 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultDependenciesTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultDependenciesTool.java @@ -26,7 +26,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -137,12 +136,12 @@ public SortedMap loadProjectDependencies( LoadedProjectDep if ( configuration.isIncludeTransitiveDependencies() ) { // All project dependencies - depArtifacts = Collections.unmodifiableSet(artifacts.getAllDependencies()); + depArtifacts = artifacts.getAllDependencies(); } else { // Only direct project dependencies - depArtifacts = Collections.unmodifiableSet(artifacts.getDirectDependencies()); + depArtifacts = artifacts.getDirectDependencies(); } List includedScopes = configuration.getIncludedScopes(); diff --git a/src/main/java/org/codehaus/mojo/license/api/LoadedProjectDependencies.java b/src/main/java/org/codehaus/mojo/license/api/LoadedProjectDependencies.java index 859a0c677..68111d0d4 100644 --- a/src/main/java/org/codehaus/mojo/license/api/LoadedProjectDependencies.java +++ b/src/main/java/org/codehaus/mojo/license/api/LoadedProjectDependencies.java @@ -1,9 +1,44 @@ package org.codehaus.mojo.license.api; +import edu.emory.mathcs.backport.java.util.Collections; +import java.util.HashSet; import java.util.Set; import org.apache.maven.artifact.Artifact; +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2008 - 2012 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 + * . + * #L% + */ + +/** + * Copies of the project's dependency sets. AddThirdParty needs to load dependencies only for the single project it is + * run for, while AggregateAddThirdParty needs to load dependencies for the parent project, as well as all child + * projects in the reactor. + * + * The aggregator goal replaces all reactor projects with their direct dependencies, to avoid trying to load artifacts + * for projects that haven't been built/published yet. This is necessary in cases where one child project A in a reactor + * depends on another project B in the same reactor. Since B is not necessarily built/published, the plugin needs to + * replace B with its dependencies when processing A. This field stores that modified view of the project's + * dependencies. + */ public class LoadedProjectDependencies { private final Set allDependencies; @@ -11,18 +46,18 @@ public class LoadedProjectDependencies { public LoadedProjectDependencies( Set allDependencies, Set directDependencies ) { - this.allDependencies = allDependencies; - this.directDependencies = directDependencies; + this.allDependencies = new HashSet<>( allDependencies ); + this.directDependencies = new HashSet<>( directDependencies ); } public Set getAllDependencies() { - return allDependencies; + return Collections.unmodifiableSet( allDependencies ); } public Set getDirectDependencies() { - return directDependencies; + return Collections.unmodifiableSet( directDependencies ); } }