From d47178b5c58d74714bda202e358bf7927ec67788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Rohde=20D=C3=B8ssing?= Date: Thu, 4 Oct 2018 14:24:18 +0200 Subject: [PATCH] Fix #145 aggregate-add-third-party modifying project dependencies --- pom.xml | 5 + src/it/ISSUE-145-2/README.txt | 3 + src/it/ISSUE-145-2/invoker.properties | 25 +++ src/it/ISSUE-145-2/pom.xml | 66 ++++++ src/it/ISSUE-145-2/postbuild.groovy | 46 ++++ src/it/ISSUE-145-2/submodule1/pom.xml | 24 +++ src/it/ISSUE-145-2/submodule2/pom.xml | 21 ++ src/it/ISSUE-145-2/submodule3/pom.xml | 34 +++ src/it/ISSUE-145-2/submodule4/pom.xml | 19 ++ src/it/ISSUE-145/README.txt | 3 + src/it/ISSUE-145/invoker.properties | 23 ++ src/it/ISSUE-145/pom.xml | 64 ++++++ src/it/ISSUE-145/postbuild.groovy | 27 +++ src/it/ISSUE-145/submodule1/pom.xml | 49 +++++ .../codehaus/mojo/license/Application.java | 29 +++ src/it/ISSUE-145/submodule2/pom.xml | 13 ++ .../mojo/license/AnImportantDependency.java | 28 +++ src/it/ISSUE-80/pom.xml | 2 +- .../license/AbstractAddThirdPartyMojo.java | 13 +- .../license/AbstractDownloadLicensesMojo.java | 5 +- .../license/AbstractThirdPartyReportMojo.java | 19 +- .../mojo/license/AddThirdPartyMojo.java | 75 ++++++- .../license/AggregatorAddThirdPartyMojo.java | 14 +- .../license/api/DefaultDependenciesTool.java | 197 +++++++++++++----- .../license/api/DefaultThirdPartyHelper.java | 13 +- .../mojo/license/api/DependenciesTool.java | 16 +- .../api/ResolvedProjectDependencies.java | 63 ++++++ .../mojo/license/api/ThirdPartyHelper.java | 14 +- 28 files changed, 808 insertions(+), 102 deletions(-) create mode 100644 src/it/ISSUE-145-2/README.txt create mode 100644 src/it/ISSUE-145-2/invoker.properties create mode 100644 src/it/ISSUE-145-2/pom.xml create mode 100644 src/it/ISSUE-145-2/postbuild.groovy create mode 100644 src/it/ISSUE-145-2/submodule1/pom.xml create mode 100644 src/it/ISSUE-145-2/submodule2/pom.xml create mode 100644 src/it/ISSUE-145-2/submodule3/pom.xml create mode 100644 src/it/ISSUE-145-2/submodule4/pom.xml create mode 100644 src/it/ISSUE-145/README.txt create mode 100644 src/it/ISSUE-145/invoker.properties create mode 100644 src/it/ISSUE-145/pom.xml create mode 100644 src/it/ISSUE-145/postbuild.groovy create mode 100644 src/it/ISSUE-145/submodule1/pom.xml create mode 100644 src/it/ISSUE-145/submodule1/src/main/java/org/codehaus/mojo/license/Application.java create mode 100644 src/it/ISSUE-145/submodule2/pom.xml create mode 100644 src/it/ISSUE-145/submodule2/src/main/java/org/codehaus/mojo/license/AnImportantDependency.java create mode 100644 src/main/java/org/codehaus/mojo/license/api/ResolvedProjectDependencies.java diff --git a/pom.xml b/pom.xml index 1d5c04cf9..ea10bbd18 100644 --- a/pom.xml +++ b/pom.xml @@ -365,6 +365,11 @@ org.apache.maven.plugins maven-invoker-plugin 3.0.0 + + + ${project.version} + + org.ec4j.maven diff --git a/src/it/ISSUE-145-2/README.txt b/src/it/ISSUE-145-2/README.txt new file mode 100644 index 000000000..0cad7f2c7 --- /dev/null +++ b/src/it/ISSUE-145-2/README.txt @@ -0,0 +1,3 @@ +Demonstrates that the aggregateAddThirdParty goal can handle long sibling project dependency chains in the same reactor, and that it resolves dependencies based on the right remote repositories list. + +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 D dependency has a custom repository specified, and a dependency from that repo. When the plugin generates the license list, it should pick up the license for the dependency from the custom repo. E has a custom license specified, which should also be picked up. \ No newline at end of file diff --git a/src/it/ISSUE-145-2/invoker.properties b/src/it/ISSUE-145-2/invoker.properties new file mode 100644 index 000000000..8f321909c --- /dev/null +++ b/src/it/ISSUE-145-2/invoker.properties @@ -0,0 +1,25 @@ +### +# #%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 +# . +# #L% +### +invoker.goals=clean package +invoker.failureBehavior=fail-fast +#Disable the default settings.xml for integration tests. This test needs to always resolve dependencies from remote repositories, not from the local. +invoker.profiles=!it-repo \ No newline at end of file diff --git a/src/it/ISSUE-145-2/pom.xml b/src/it/ISSUE-145-2/pom.xml new file mode 100644 index 000000000..f521db16a --- /dev/null +++ b/src/it/ISSUE-145-2/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + org.codehaus.mojo.license.test + test-ISSUE-145-2 + @pom.version@ + License Test :: ISSUE-145-2 + pom + + + + The GNU Lesser General Public License, Version 3.0 + http://www.gnu.org/licenses/lgpl-3.0.txt + repo + + + + + UTF-8 + true + true + ${project.build.directory}/licenses.xml + + + + submodule1 + submodule2 + submodule3 + submodule4 + + + + + + org.codehaus.mojo + license-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + aggregate-add-third-party + + aggregate-add-third-party + + + + + + + + + diff --git a/src/it/ISSUE-145-2/postbuild.groovy b/src/it/ISSUE-145-2/postbuild.groovy new file mode 100644 index 000000000..06532dac1 --- /dev/null +++ b/src/it/ISSUE-145-2/postbuild.groovy @@ -0,0 +1,46 @@ +/* + * #%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 + * . + * #L% + */ + +def assertExistsFile(file) { + if (!file.exists() || file.isDirectory()) { + println(file.getAbsolutePath() + " file is missing or a directory.") + assert false + } + assert true +} + +def assertContains(file, content, expected) { + if (!content.contains(expected)) { + println(expected + " was not found in file [" + file + "]\n :" + content) + return false + } + return true +} + +file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt'); +assertExistsFile(file); + +content = file.text; +assert assertContains(file, content, 'Eclipse Public License 1.0'); +assert assertContains(file, content, 'Custom ISSUE-145 license'); + +return true; \ No newline at end of file diff --git a/src/it/ISSUE-145-2/submodule1/pom.xml b/src/it/ISSUE-145-2/submodule1/pom.xml new file mode 100644 index 000000000..55205928c --- /dev/null +++ b/src/it/ISSUE-145-2/submodule1/pom.xml @@ -0,0 +1,24 @@ + + + + org.codehaus.mojo.license.test + test-ISSUE-145-2 + @pom.version@ + + + 4.0.0 + jar + + test-ISSUE-145-2-submodule1 + + + + org.codehaus.mojo.license.test + test-ISSUE-145-2-submodule2 + @pom.version@ + + + + \ No newline at end of file diff --git a/src/it/ISSUE-145-2/submodule2/pom.xml b/src/it/ISSUE-145-2/submodule2/pom.xml new file mode 100644 index 000000000..facbe92fa --- /dev/null +++ b/src/it/ISSUE-145-2/submodule2/pom.xml @@ -0,0 +1,21 @@ + + + + org.codehaus.mojo.license.test + test-ISSUE-145-2 + @pom.version@ + + 4.0.0 + + test-ISSUE-145-2-submodule2 + + + + org.codehaus.mojo.license.test + test-ISSUE-145-2-submodule3 + @pom.version@ + + + \ No newline at end of file diff --git a/src/it/ISSUE-145-2/submodule3/pom.xml b/src/it/ISSUE-145-2/submodule3/pom.xml new file mode 100644 index 000000000..5fd6a3c7d --- /dev/null +++ b/src/it/ISSUE-145-2/submodule3/pom.xml @@ -0,0 +1,34 @@ + + + + org.codehaus.mojo.license.test + test-ISSUE-145-2 + @pom.version@ + + 4.0.0 + + test-ISSUE-145-2-submodule3 + + + + clojars.org + https://repo.clojars.org + + + + + + + org.clojure-android + tools.logging + 0.3.2 + + + org.codehaus.mojo.license.test + test-ISSUE-145-2-submodule4 + @pom.version@ + + + \ No newline at end of file diff --git a/src/it/ISSUE-145-2/submodule4/pom.xml b/src/it/ISSUE-145-2/submodule4/pom.xml new file mode 100644 index 000000000..7527b3a04 --- /dev/null +++ b/src/it/ISSUE-145-2/submodule4/pom.xml @@ -0,0 +1,19 @@ + + + + org.codehaus.mojo.license.test + test-ISSUE-145-2 + @pom.version@ + + 4.0.0 + + test-ISSUE-145-2-submodule4 + + + + Custom ISSUE-145 license + + + \ No newline at end of file diff --git a/src/it/ISSUE-145/README.txt b/src/it/ISSUE-145/README.txt new file mode 100644 index 000000000..7d185ddf6 --- /dev/null +++ b/src/it/ISSUE-145/README.txt @@ -0,0 +1,3 @@ +Demonstrates that the aggregateAddThirdParty goal does not cause Maven to drop dependencies. + +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. \ No newline at end of file diff --git a/src/it/ISSUE-145/invoker.properties b/src/it/ISSUE-145/invoker.properties new file mode 100644 index 000000000..d1250ecb1 --- /dev/null +++ b/src/it/ISSUE-145/invoker.properties @@ -0,0 +1,23 @@ +### +# #%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 +# . +# #L% +### +invoker.goals=clean package +invoker.failureBehavior=fail-fast \ No newline at end of file diff --git a/src/it/ISSUE-145/pom.xml b/src/it/ISSUE-145/pom.xml new file mode 100644 index 000000000..4241fddd7 --- /dev/null +++ b/src/it/ISSUE-145/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + org.codehaus.mojo.license.test + test-ISSUE-145 + @pom.version@ + License Test :: ISSUE-145 + pom + + + + The GNU Lesser General Public License, Version 3.0 + http://www.gnu.org/licenses/lgpl-3.0.txt + repo + + + + + UTF-8 + true + true + ${project.build.directory}/licenses.xml + + + + submodule1 + submodule2 + + + + + + org.codehaus.mojo + license-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + aggregate-add-third-party + + aggregate-add-third-party + + + + + + + + + diff --git a/src/it/ISSUE-145/postbuild.groovy b/src/it/ISSUE-145/postbuild.groovy new file mode 100644 index 000000000..327364294 --- /dev/null +++ b/src/it/ISSUE-145/postbuild.groovy @@ -0,0 +1,27 @@ +/* + * #%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 + * . + * #L% + */ +import java.util.jar.JarFile + +file = new JarFile(new File(basedir, 'submodule1/target/test-ISSUE-145-submodule1-' + projectVersion + '.jar')); +expectedLibPath = 'org/codehaus/mojo/license/AnImportantDependency.class'; +assert file.getJarEntry(expectedLibPath) != null; +return true; \ No newline at end of file diff --git a/src/it/ISSUE-145/submodule1/pom.xml b/src/it/ISSUE-145/submodule1/pom.xml new file mode 100644 index 000000000..559221a92 --- /dev/null +++ b/src/it/ISSUE-145/submodule1/pom.xml @@ -0,0 +1,49 @@ + + + + org.codehaus.mojo.license.test + test-ISSUE-145 + @pom.version@ + + + 4.0.0 + jar + + test-ISSUE-145-submodule1 + + + + org.codehaus.mojo.license.test + test-ISSUE-145-submodule2 + @pom.version@ + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + + + + src/main/resources + true + + + + + \ No newline at end of file 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 new file mode 100644 index 000000000..26d2c01eb --- /dev/null +++ b/src/it/ISSUE-145/submodule1/src/main/java/org/codehaus/mojo/license/Application.java @@ -0,0 +1,29 @@ +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/pom.xml b/src/it/ISSUE-145/submodule2/pom.xml new file mode 100644 index 000000000..31e0428f6 --- /dev/null +++ b/src/it/ISSUE-145/submodule2/pom.xml @@ -0,0 +1,13 @@ + + + + org.codehaus.mojo.license.test + test-ISSUE-145 + @pom.version@ + + 4.0.0 + + test-ISSUE-145-submodule2 + \ No newline at end of file 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 new file mode 100644 index 000000000..c1d0b0d61 --- /dev/null +++ b/src/it/ISSUE-145/submodule2/src/main/java/org/codehaus/mojo/license/AnImportantDependency.java @@ -0,0 +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/it/ISSUE-80/pom.xml b/src/it/ISSUE-80/pom.xml index 87f322196..4d8c406b7 100644 --- a/src/it/ISSUE-80/pom.xml +++ b/src/it/ISSUE-80/pom.xml @@ -31,7 +31,7 @@ test-ISSUE-59 @pom.version@ - License Test :: ISSUE-59 + License Test :: ISSUE-80 jar diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index 293fe8712..3ad316349 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -61,6 +61,7 @@ import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; +import org.codehaus.mojo.license.api.DependenciesToolException; /** * Abstract mojo for all third-party mojos. @@ -574,8 +575,9 @@ public abstract class AbstractAddThirdPartyMojo * Loads the dependencies of the project (as {@link MavenProject}, indexed by their gav. * * @return the map of dependencies of the maven project indexed by their gav. + * @throws DependenciesToolException if the dependencies could not be loaded */ - protected abstract SortedMap loadDependencies(); + protected abstract SortedMap loadDependencies() throws DependenciesToolException; /** * Creates the unsafe mapping (says dependencies with no license given by their pom). @@ -583,12 +585,14 @@ public abstract class AbstractAddThirdPartyMojo * Can come from loaded missing file or from dependencies with no license at all. * * @return the map of usafe mapping indexed by their gav. - * @throws ProjectBuildingException if could not create maven porject for some dependencies + * @throws ProjectBuildingException if could not create maven project for some dependencies * @throws IOException if could not load missing file * @throws ThirdPartyToolException for third party tool error + * @throws DependenciesToolException if the dependencies could not be loaded */ protected abstract SortedProperties createUnsafeMapping() - throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException; + throws ProjectBuildingException, IOException, ThirdPartyToolException, + MojoExecutionException, DependenciesToolException; // ---------------------------------------------------------------------- // AbstractLicenseMojo Implementaton @@ -674,7 +678,8 @@ else if ( licenseMergesUrl != null ) } void consolidate() throws IOException, ArtifactNotFoundException, ArtifactResolutionException, MojoFailureException, - ProjectBuildingException, ThirdPartyToolException, MojoExecutionException + ProjectBuildingException, ThirdPartyToolException, + MojoExecutionException, DependenciesToolException { unsafeDependencies = getHelper().getProjectsWithNoLicense( licenseMap ); diff --git a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java index 9024590f0..ed8b74d59 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java @@ -56,6 +56,7 @@ import java.util.Map; import java.util.Set; import java.util.SortedMap; +import org.codehaus.mojo.license.api.ResolvedProjectDependencies; /** * Created on 23/05/16. @@ -285,7 +286,9 @@ protected MavenProject getProject() protected SortedMap getDependencies( MavenProject project ) { - return dependenciesTool.loadProjectDependencies( project, this, localRepository, remoteRepositories, null ); + return dependenciesTool.loadProjectDependencies( + new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ), + this, localRepository, remoteRepositories, null ); } /** diff --git a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java index 630434aa3..d08b8c6a5 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java @@ -60,6 +60,7 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeSet; +import org.codehaus.mojo.license.api.ResolvedProjectDependencies; /** * Base class for third-party reports. @@ -517,17 +518,24 @@ Collection createThirdPartyDetails( MavenProject project, boo DependenciesToolException, MojoExecutionException { + ResolvedProjectDependencies loadedDependencies; if ( loadArtifacts ) { - dependenciesTool.loadProjectArtifacts( localRepository, project.getRemoteArtifactRepositories(), project, - null ); + loadedDependencies = dependenciesTool.loadProjectArtifacts( localRepository, licenseMerges, project, null ); + } + else + { + loadedDependencies = new ResolvedProjectDependencies( getProject().getArtifacts(), + getProject().getDependencyArtifacts() ); } ThirdPartyHelper thirdPartyHelper = - new DefaultThirdPartyHelper( project, encoding, verbose, dependenciesTool, thirdPartyTool, + new DefaultThirdPartyHelper( project, encoding, verbose, + dependenciesTool, thirdPartyTool, localRepository, project.getRemoteArtifactRepositories(), getLog() ); // load dependencies of the project - SortedMap projectDependencies = thirdPartyHelper.loadDependencies( this ); + SortedMap projectDependencies = thirdPartyHelper.loadDependencies( this, + loadedDependencies ); // create licenseMap from it LicenseMap licenseMap = thirdPartyHelper.createLicenseMap( projectDependencies ); @@ -549,7 +557,8 @@ Collection createThirdPartyDetails( MavenProject project, boo { // Resolve unsafe dependencies using missing files, this will update licenseMap and unsafeDependencies thirdPartyHelper.createUnsafeMapping( licenseMap, missingFile, missingFileUrl, - useRepositoryMissingFiles, dependenciesWithNoLicense, projectDependencies ); + useRepositoryMissingFiles, dependenciesWithNoLicense, + projectDependencies, loadedDependencies.getAllDependencies() ); } } diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java index ab2ab3e26..784ff240d 100644 --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -33,8 +33,6 @@ import java.util.SortedSet; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -43,7 +41,9 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.mojo.license.api.DependenciesToolException; import org.codehaus.mojo.license.api.MavenProjectDependenciesConfigurator; +import org.codehaus.mojo.license.api.ResolvedProjectDependencies; import org.codehaus.mojo.license.api.ThirdPartyToolException; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.FileUtil; @@ -91,6 +91,32 @@ public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo implements Mave */ private boolean doGenerateMissing; + /** + * 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. + */ + private boolean isAggregatorBuild = false; + + /** + * The reactor projects. When resolving dependencies, the aggregator goal needs to do custom handling + * of sibling dependencies for projects in the reactor, + * to avoid trying to load artifacts for projects that haven't been built/published yet. + */ + private List 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. + * + * In cases where one child project A in a reactor depends on another project B in the same reactor, + * B is not necessarily built/published. The plugin needs to resolve B's dependencies manually. + * This field stores the result of that manual resolution. + */ + private ResolvedProjectDependencies dependencyArtifacts; + // ---------------------------------------------------------------------- // AbstractLicenseMojo Implementaton // ---------------------------------------------------------------------- @@ -193,9 +219,34 @@ protected void doAction() * {@inheritDoc} */ @Override - protected SortedMap loadDependencies() + protected SortedMap loadDependencies() throws DependenciesToolException { - return getHelper().loadDependencies( this ); + return getHelper().loadDependencies( this, resolveDependencyArtifacts() ); + } + + /** + * Resolves the transitive and direct dependency sets for this project. + * + * @return The set of all dependencies, and the set of only direct dependency artifacts. + * @throws org.codehaus.mojo.license.api.DependenciesToolException if the dependencies could not be resolved + */ + protected ResolvedProjectDependencies resolveDependencyArtifacts() throws DependenciesToolException + { + if ( dependencyArtifacts != null ) + { + return dependencyArtifacts; + } + if ( isAggregatorBuild ) + { + dependencyArtifacts = dependenciesTool.loadProjectArtifacts( localRepository, remoteRepositories, + project, reactorProjectDependencies ); + } + else + { + dependencyArtifacts = new ResolvedProjectDependencies( project.getArtifacts(), + project.getDependencyArtifacts() ); + } + return dependencyArtifacts; } /** @@ -203,7 +254,8 @@ protected SortedMap loadDependencies() */ @Override protected SortedProperties createUnsafeMapping() - throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException + throws ProjectBuildingException, IOException, ThirdPartyToolException, + MojoExecutionException, DependenciesToolException { SortedSet unsafeDependencies = getUnsafeDependencies(); @@ -211,7 +263,8 @@ protected SortedProperties createUnsafeMapping() SortedProperties unsafeMappings = getHelper().createUnsafeMapping( getLicenseMap(), getMissingFile(), missingFileUrl, useRepositoryMissingFiles, unsafeDependencies, - getProjectDependencies() ); + getProjectDependencies(), + resolveDependencyArtifacts().getAllDependencies() ); if ( isVerbose() ) { getLog().info( "found " + unsafeMappings.size() + " unsafe mappings" ); @@ -425,7 +478,7 @@ private void writeMissingFile() } void initFromMojo( AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject, - Map> reactorProjects ) throws Exception + List reactorProjects ) throws Exception { project = mavenProject; deployMissingFile = mojo.deployMissingFile; @@ -449,8 +502,8 @@ void initFromMojo( AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject, mojo.overrideFile.getAbsolutePath().substring( absolutePath.length() ) ); missingLicensesFileArtifact = mojo.missingLicensesFileArtifact; localRepository = mojo.localRepository; - remoteRepositories = mojo.remoteRepositories; - dependencies = new HashSet( mavenProject.getDependencies() ); + remoteRepositories = mavenProject.getRemoteArtifactRepositories(); + dependencies = new HashSet<>( mavenProject.getDependencies() ); licenseMerges = mojo.licenseMerges; licenseMergesFile = mojo.licenseMergesFile; includedLicenses = mojo.includedLicenses; @@ -469,8 +522,8 @@ void initFromMojo( AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject, setLog( mojo.getLog() ); - dependenciesTool.loadProjectArtifacts( localRepository, project.getRemoteArtifactRepositories(), project, - reactorProjects ); + isAggregatorBuild = true; + reactorProjectDependencies = reactorProjects; init(); diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java index c0952c164..f6bb337cd 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java @@ -24,14 +24,13 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.SortedMap; import java.util.SortedSet; -import java.util.TreeMap; import org.apache.commons.collections.CollectionUtils; import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; @@ -208,14 +207,8 @@ protected void doAction() } String addThirdPartyRoleHint = groupId + ":" + artifactId + ":" + version + ":" + "add-third-party"; - Map> reactorProjectDependencies = new TreeMap<>(); - for ( MavenProject reactorProject : this.reactorProjects ) - { - reactorProjectDependencies.put( String.format( "%s:%s", reactorProject.getGroupId(), - reactorProject.getArtifactId() ), reactorProject.getDependencies() ); - } - for ( Object reactorProject : reactorProjects ) + for ( MavenProject reactorProject : reactorProjects ) { if ( getProject().equals( reactorProject ) ) { @@ -223,11 +216,10 @@ protected void doAction() continue; } - AddThirdPartyMojo mojo = (AddThirdPartyMojo) getSession() .lookup( AddThirdPartyMojo.ROLE, addThirdPartyRoleHint ); - mojo.initFromMojo( this, (MavenProject) reactorProject, reactorProjectDependencies ); + mojo.initFromMojo( this, reactorProject, new ArrayList<>( this.reactorProjects ) ); LicenseMap childLicenseMap = mojo.getLicenseMap(); if ( isVerbose() ) 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 d04c10a02..9f50a4eb3 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultDependenciesTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultDependenciesTool.java @@ -22,12 +22,14 @@ * #L% */ +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashSet; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Queue; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -36,6 +38,7 @@ import java.util.regex.PatternSyntaxException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; @@ -94,7 +97,7 @@ public class DefaultDependenciesTool /** * {@inheritDoc} */ - public SortedMap loadProjectDependencies( MavenProject project, + public SortedMap loadProjectDependencies( ResolvedProjectDependencies artifacts, MavenProjectDependenciesConfigurator configuration, ArtifactRepository localRepository, List remoteRepositories, @@ -136,12 +139,12 @@ public SortedMap loadProjectDependencies( MavenProject pro if ( configuration.isIncludeTransitiveDependencies() ) { // All project dependencies - depArtifacts = project.getArtifacts(); + depArtifacts = artifacts.getAllDependencies(); } else { // Only direct project dependencies - depArtifacts = project.getDependencyArtifacts(); + depArtifacts = artifacts.getDirectDependencies(); } List includedScopes = configuration.getIncludedScopes(); @@ -314,68 +317,168 @@ public SortedMap loadProjectDependencies( MavenProject pro /** * {@inheritDoc} */ - public void loadProjectArtifacts( ArtifactRepository localRepository, List remoteRepositories, - MavenProject project, Map> reactorProjectDependencies ) + public ResolvedProjectDependencies loadProjectArtifacts( ArtifactRepository localRepository, + List remoteRepositories, MavenProject project, List reactorProjects ) throws DependenciesToolException { - - if ( CollectionUtils.isEmpty( project.getDependencyArtifacts() ) ) + Map idToReactorProject = new HashMap<>(); + if ( reactorProjects != null ) { + for ( MavenProject reactorProject : reactorProjects ) + { + idToReactorProject.put( String.format( "%s:%s", reactorProject.getGroupId(), + reactorProject.getArtifactId() ), reactorProject ); + } + } - Set dependenciesArtifacts; - try + /* + * Find the list of dependencies to resolve transitively. Some projects may be in the reactor. + * Reactor projects can't be resolved by the artifact resolver yet. + * In order to still get the complete dependency tree for the project, we will add the transitive + * dependencies of the reactor project to the list of dependencies to resolve. + * Since the transitive dependencies could + * also be reactor projects, we need to repeat this check for each of those. + * Note that since the dependency reactor + * project may specify its own list of repositories, + * we need to keep track of which project the transitive dependency is declared in. + */ + List directDependencies = new ArrayList<>( project.getDependencies() ); + Map> reactorProjectToTransitiveDependencies = new HashMap<>(); + Queue> dependenciesToCheck = new ArrayDeque<>(); + for ( Dependency dependency : directDependencies ) + { + dependenciesToCheck.add( Pair.of( project, dependency ) ); + } + if ( reactorProjects != null ) + { + while ( !dependenciesToCheck.isEmpty() ) { - List dependencies = new ArrayList( project.getDependencies() ); - if ( reactorProjectDependencies != null ) + Pair pair = dependenciesToCheck.remove(); + Dependency dependency = pair.getRight(); + String id = String.format( "%s:%s", dependency.getGroupId(), dependency.getArtifactId() ); + MavenProject dependencyReactorProject = idToReactorProject.get( id ); + if ( dependencyReactorProject != null ) { - - for ( Dependency dependency : new ArrayList<>( dependencies ) ) + /* + * Since the project is in the reactor, the artifact resolver may not be able to resolve + * the artifact plus transitive dependencies yet. In order to still get the + * complete dependency tree for the project, we will add the transitive + * dependencies of the reactor project to the list of dependencies to resolve. + * Since the transitive dependencies could + * also be reactor projects, we need to repeat this check for each of those. + * Note that since the dependency reactor + * project may specify its own list of repositories, + * we need to keep track of which project the transitive dependency is + * declared in. + */ + for ( Dependency transitiveDependency + : ( List ) dependencyReactorProject.getDependencies() ) { - String id = String.format( "%s:%s", dependency.getGroupId(), dependency.getArtifactId() ); - List projectDependencies = reactorProjectDependencies.get( id ); - if ( projectDependencies != null ) - { - dependencies.remove( dependency ); - dependencies.addAll( projectDependencies ); - } + dependenciesToCheck.add( Pair.of( dependencyReactorProject, transitiveDependency ) ); } } - dependenciesArtifacts = - MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, project ); + if ( !directDependencies.contains( dependency ) ) + { + List transitiveForSameProject = + reactorProjectToTransitiveDependencies.get( pair.getLeft() ); + if ( transitiveForSameProject == null ) + { + transitiveForSameProject = new ArrayList<>(); + reactorProjectToTransitiveDependencies.put( pair.getLeft(), transitiveForSameProject ); + } + transitiveForSameProject.add( dependency ); + } } - catch ( InvalidDependencyVersionException e ) + } + + //Create artifacts for all dependencies, + //keep the transitive dependencies grouped by project they are declared in + Set directDependencyArtifacts = createDependencyArtifacts( project, directDependencies ); + Map> reactorProjectToDependencyArtifacts = new HashMap<>(); + for ( Entry> entry : reactorProjectToTransitiveDependencies.entrySet() ) + { + reactorProjectToDependencyArtifacts.put( entry.getKey(), + createDependencyArtifacts( entry.getKey(), entry.getValue() ) ); + } + + //Resolve artifacts. Transitive dependencies are resolved with the settings of the POM they are declared in. + //Skip reactor projects, since they can't necessarily be resolved yet. + //The transitive handling above ensures we still get a complete list of dependencies. + Set reactorArtifacts = new HashSet<>(); + Set directArtifactsToResolve = new HashSet<>(); + if ( reactorProjects == null ) + { + directArtifactsToResolve.addAll( directDependencyArtifacts ); + } + else + { + partitionByIsReactorProject( directDependencyArtifacts, reactorArtifacts, + directArtifactsToResolve, idToReactorProject.keySet() ); + for ( Entry> entry : reactorProjectToDependencyArtifacts.entrySet() ) { - throw new DependenciesToolException( e ); + Set nonReactorArtifacts = new HashSet<>(); + partitionByIsReactorProject( entry.getValue(), reactorArtifacts, + nonReactorArtifacts, idToReactorProject.keySet() ); + entry.setValue( nonReactorArtifacts ); } - project.setDependencyArtifacts( dependenciesArtifacts ); + } + Set allDependencies = new HashSet<>( reactorArtifacts ); + allDependencies.addAll( resolve( directArtifactsToResolve, project.getArtifact(), localRepository, + remoteRepositories ).getArtifacts() ); + for ( Entry> entry : reactorProjectToDependencyArtifacts.entrySet() ) + { + MavenProject reactorProject = entry.getKey(); + Set toResolve = entry.getValue(); + Artifact reactorProjectArtifact = reactorProject.getArtifact(); + List reactorRemoteRepositories = reactorProject.getRemoteArtifactRepositories(); + allDependencies.addAll( + resolve( toResolve, reactorProjectArtifact, localRepository, + reactorRemoteRepositories ).getArtifacts() ); + } + return new ResolvedProjectDependencies( allDependencies, directDependencyArtifacts ); + } + private Set createDependencyArtifacts( MavenProject project, List dependencies ) + throws DependenciesToolException + { + try + { + return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, project ); } + catch ( InvalidDependencyVersionException e ) + { + throw new DependenciesToolException( e ); + } + } - Artifact artifact = project.getArtifact(); - Set reactorArtifacts = new LinkedHashSet<>(); - if ( reactorProjectDependencies != null ) + private void partitionByIsReactorProject( Set artifacts, Set reactorArtifacts, + Set nonReactorArtifacts, Set reactorProjectIds ) + { + for ( Artifact dependencyArtifact : artifacts ) { - // let's not include sibling dependencies, since artifact files may not be generated - // (aggregate mode without forking mode) - Iterator artifacts = project.getDependencyArtifacts().iterator(); - while ( artifacts.hasNext() ) - { - Artifact artifact1 = (Artifact) artifacts.next(); - String artifactKey = artifact1.getGroupId() + ":" + artifact1.getArtifactId(); - if ( reactorProjectDependencies.containsKey( artifactKey ) ) + String artifactKey = String.format( "%s:%s", dependencyArtifact.getGroupId(), + dependencyArtifact.getArtifactId() ); + if ( reactorProjectIds.contains( artifactKey ) ) { - artifacts.remove(); - reactorArtifacts.add( artifact1 ); + reactorArtifacts.add( dependencyArtifact ); + } + else + { + nonReactorArtifacts.add( dependencyArtifact ); } } - } - ArtifactResolutionResult result; + } + + private ArtifactResolutionResult resolve( Set artifacts, Artifact projectArtifact, + ArtifactRepository localRepository, List remoteRepositories ) + throws DependenciesToolException + { try { - result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(), artifact, - remoteRepositories, localRepository, artifactMetadataSource ); + return artifactResolver.resolveTransitively( artifacts, projectArtifact, remoteRepositories, + localRepository, artifactMetadataSource ); } catch ( ArtifactResolutionException e ) { @@ -384,11 +487,7 @@ public void loadProjectArtifacts( ArtifactRepository localRepository, List remot catch ( ArtifactNotFoundException e ) { throw new DependenciesToolException( e ); - } - reactorArtifacts.addAll( result.getArtifacts() ); - - project.setArtifacts( reactorArtifacts ); - + } } /** diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java index 66c9a88b4..e5b0159a2 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java @@ -150,10 +150,11 @@ public SortedMap getArtifactCache() /** * {@inheritDoc} */ - public SortedMap loadDependencies( MavenProjectDependenciesConfigurator configuration ) + public SortedMap loadDependencies( MavenProjectDependenciesConfigurator configuration, + ResolvedProjectDependencies dependencyArtifacts ) { - return dependenciesTool.loadProjectDependencies( project, configuration, localRepository, remoteRepositories, - getArtifactCache() ); + return dependenciesTool.loadProjectDependencies( dependencyArtifacts, configuration, localRepository, + remoteRepositories, getArtifactCache() ); } /** @@ -217,11 +218,11 @@ public SortedSet getProjectsWithNoLicense( LicenseMap licenseMap ) /** * {@inheritDoc} */ - @SuppressWarnings( "unchecked" ) // project.getArtifacts() public SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, boolean useRepositoryMissingFiles, SortedSet unsafeDependencies, - SortedMap projectDependencies ) + SortedMap projectDependencies, + Set dependencyArtifacts ) throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException { @@ -243,7 +244,7 @@ public SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missing projects.removeAll( unsafeDependencies ); SortedProperties resolvedUnsafeMapping = - loadThirdPartyDescriptorForUnsafeMapping( project.getArtifacts(), unsafeDependencies, projects, + loadThirdPartyDescriptorForUnsafeMapping( dependencyArtifacts, unsafeDependencies, projects, licenseMap ); // push back resolved unsafe mappings (only for project dependencies) diff --git a/src/main/java/org/codehaus/mojo/license/api/DependenciesTool.java b/src/main/java/org/codehaus/mojo/license/api/DependenciesTool.java index ea521d221..972cdf608 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DependenciesTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DependenciesTool.java @@ -22,9 +22,7 @@ * #L% */ -import java.util.Map; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; import java.util.List; @@ -45,7 +43,7 @@ public interface DependenciesTool * * Result is given in a map where keys are unique artifact id * - * @param project the project to scann + * @param dependencies the project dependencies * @param configuration the configuration * @param localRepository local repository used to resolv dependencies * @param remoteRepositories remote repositories used to resolv dependencies @@ -53,7 +51,7 @@ public interface DependenciesTool * @return the map of resolved dependencies indexed by their unique id. * @see MavenProjectDependenciesConfigurator */ - SortedMap loadProjectDependencies( MavenProject project, + SortedMap loadProjectDependencies( ResolvedProjectDependencies dependencies, MavenProjectDependenciesConfigurator configuration, ArtifactRepository localRepository, List remoteRepositories, @@ -64,12 +62,12 @@ SortedMap loadProjectDependencies( MavenProject project, * * @param localRepository local repository used to resolv dependencies * @param remoteRepositories remote repositories used to resolv dependencies - * @param project the project to scann - * @param reactorProjectDependencies optional reactor projects dependencies indexed by their gav to resolve - * artifacts without fork mode (means artifacts may not exist) + * @param project the project to scan + * @param reactorProjectDependencies reactor projects. Optional, only relevant if there is more than one) + * @return the loaded project dependency artifacts * @throws DependenciesToolException if could not load project dependencies */ - void loadProjectArtifacts( ArtifactRepository localRepository, List remoteRepositories, MavenProject project , - Map> reactorProjectDependencies ) + ResolvedProjectDependencies loadProjectArtifacts( ArtifactRepository localRepository, List remoteRepositories, + MavenProject project, List reactorProjectDependencies ) throws DependenciesToolException; } diff --git a/src/main/java/org/codehaus/mojo/license/api/ResolvedProjectDependencies.java b/src/main/java/org/codehaus/mojo/license/api/ResolvedProjectDependencies.java new file mode 100644 index 000000000..3ba71f77d --- /dev/null +++ b/src/main/java/org/codehaus/mojo/license/api/ResolvedProjectDependencies.java @@ -0,0 +1,63 @@ +package org.codehaus.mojo.license.api; + +/* + * #%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% + */ + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import org.apache.maven.artifact.Artifact; + +/** + * 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 ResolvedProjectDependencies +{ + + private final Set allDependencies; + private final Set directDependencies; + + public ResolvedProjectDependencies( Set allDependencies, Set directDependencies ) + { + this.allDependencies = Collections.unmodifiableSet( new HashSet<>( allDependencies ) ); + this.directDependencies = Collections.unmodifiableSet( new HashSet<>( directDependencies ) ); + } + + public Set getAllDependencies() + { + return allDependencies; + } + + public Set getDirectDependencies() + { + return directDependencies; + } + +} diff --git a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java index f738b78ad..4f6c9ced2 100644 --- a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java +++ b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java @@ -50,10 +50,12 @@ public interface ThirdPartyHelper /** * Load all dependencies given the configuration as {@link MavenProject}. * - * @param configuration the configuration of the project and include/exclude to do on his dependencies + * @param configuration the configuration of the project and include/exclude to do on its dependencies + * @param dependencyArtifacts the dependency artifacts of the project * @return the dictionary of loaded dependencies as {@link MavenProject} indexed by their gav. */ - SortedMap loadDependencies( MavenProjectDependenciesConfigurator configuration ); + SortedMap loadDependencies( MavenProjectDependenciesConfigurator configuration, + ResolvedProjectDependencies dependencyArtifacts ); /** @@ -82,8 +84,8 @@ SortedProperties loadThirdPartyDescriptorForUnsafeMapping( Set topLeve * @param missingFile location of an optional missing fille (says where you fix missing license). * @param missingFileUrl location of an optional missing file extension that can be downloaded from some * resource hoster and that will be merged with the content of the missing file. - * @param projectDependencies project dependencies used to detect which dependencies in the missing file are unknown - * to the project. + * @param projectDependencies project dependencies used to detect which dependencies in the missing file + * are unknown to the project. * @return the map of all unsafe mapping * @throws IOException if could not load missing file */ @@ -144,6 +146,7 @@ SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, Str * maven repositories * @param unsafeDependencies all unsafe dependencies * @param projectDependencies all project dependencies + * @param dependencyArtifacts all project dependency artifacts * @return the loaded unsafe mapping * @throws ProjectBuildingException if could not build some dependencies maven project * @throws IOException if could not load missing file @@ -152,7 +155,8 @@ SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, Str SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, boolean useRepositoryMissingFiles, SortedSet unsafeDependencies, - SortedMap projectDependencies ) + SortedMap projectDependencies, + Set dependencyArtifacts ) throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException; /**