diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 diff --git a/src/it/ISSUE-358/child-1/pom.xml b/src/it/ISSUE-358/child-1/pom.xml new file mode 100755 index 000000000..6a94c1b55 --- /dev/null +++ b/src/it/ISSUE-358/child-1/pom.xml @@ -0,0 +1,11 @@ + + 4.0.0 + + net.tomred + ISSUE-358 + 0.0.1-SNAPSHOT + + child-1 + \ No newline at end of file diff --git a/src/it/ISSUE-358/invoker.properties b/src/it/ISSUE-358/invoker.properties new file mode 100755 index 000000000..c586cbd63 --- /dev/null +++ b/src/it/ISSUE-358/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean site +invoker.failureBehavior=fail-fast \ No newline at end of file diff --git a/src/it/ISSUE-358/pom.xml b/src/it/ISSUE-358/pom.xml new file mode 100755 index 000000000..79b8b32f6 --- /dev/null +++ b/src/it/ISSUE-358/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + net.tomred + ISSUE-358 + 0.0.1-SNAPSHOT + + pom + + + child-1 + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + org.apache.maven.plugins + maven-site-plugin + 3.9.0 + + + org.apache.maven.doxia + doxia-site-renderer + 1.9.2 + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + + \ No newline at end of file diff --git a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java old mode 100644 new mode 100755 index 61c529c90..7c581c697 --- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java @@ -555,13 +555,13 @@ Collection createThirdPartyDetails( MavenProject project, boo ResolvedProjectDependencies loadedDependencies; if ( loadArtifacts ) { - loadedDependencies = - new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ); + loadedDependencies = new ResolvedProjectDependencies( project.getArtifacts(), + MojoHelper.getDependencyArtifacts( project ) ); } else { loadedDependencies = new ResolvedProjectDependencies( getProject().getArtifacts(), - getProject().getDependencyArtifacts() ); + MojoHelper.getDependencyArtifacts( project ) ); } ThirdPartyHelper thirdPartyHelper = diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java old mode 100644 new mode 100755 index 1e5bec0d5..367243bde --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -47,6 +47,7 @@ import org.codehaus.mojo.license.api.ThirdPartyToolException; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.FileUtil; +import org.codehaus.mojo.license.utils.MojoHelper; import org.codehaus.mojo.license.utils.SortedProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -240,13 +241,13 @@ protected ResolvedProjectDependencies resolveDependencyArtifacts() throws Depend } if ( isAggregatorBuild ) { - dependencyArtifacts = - new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ); + dependencyArtifacts = new ResolvedProjectDependencies( project.getArtifacts(), + MojoHelper.getDependencyArtifacts( project ) ); } else { dependencyArtifacts = new ResolvedProjectDependencies( project.getArtifacts(), - project.getDependencyArtifacts() ); + MojoHelper.getDependencyArtifacts( project ) ); } return dependencyArtifacts; } @@ -442,7 +443,7 @@ void initFromMojo( AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject, resolvedOverrideUrl = mojo.resolvedOverrideUrl; missingLicensesFileArtifact = mojo.missingLicensesFileArtifact; localRepository = mojo.localRepository; - dependencies = new HashSet<>( mavenProject.getDependencyArtifacts() ); + dependencies = new HashSet<>( MojoHelper.getDependencyArtifacts( mavenProject ) ); licenseMerges = mojo.licenseMerges; licenseMergesFile = mojo.licenseMergesFile; includedLicenses = mojo.includedLicenses; diff --git a/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java old mode 100644 new mode 100755 index fd44d576f..86bda94d0 --- a/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java @@ -29,6 +29,7 @@ import org.apache.maven.project.MavenProject; import org.codehaus.mojo.license.api.ResolvedProjectDependencies; import org.codehaus.mojo.license.download.LicensedArtifact; +import org.codehaus.mojo.license.utils.MojoHelper; import java.util.List; import java.util.Map; @@ -115,8 +116,7 @@ protected Map getDependencies() for ( MavenProject p : reactorProjects ) { licensedArtifactResolver.loadProjectDependencies( new ResolvedProjectDependencies( p.getArtifacts(), - p.getDependencyArtifacts() ), - this, remoteRepositories, result ); + MojoHelper.getDependencyArtifacts( p ) ), this, remoteRepositories, result ); } return result; } diff --git a/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java old mode 100644 new mode 100755 index b0a6bebed..6c7455f34 --- a/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java @@ -31,6 +31,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.codehaus.mojo.license.api.ResolvedProjectDependencies; import org.codehaus.mojo.license.download.LicensedArtifact; +import org.codehaus.mojo.license.utils.MojoHelper; /** * Download the license files of all the current project's dependencies, and generate a summary file containing a list @@ -86,7 +87,7 @@ protected Map getDependencies() { final Map result = new TreeMap<>(); licensedArtifactResolver.loadProjectDependencies( - new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ), + new ResolvedProjectDependencies( project.getArtifacts(), MojoHelper.getDependencyArtifacts( project ) ), this, remoteRepositories, result ); return result; } diff --git a/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java b/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java old mode 100644 new mode 100755 index fddcb50e9..bfc7a37b6 --- a/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java +++ b/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java @@ -42,6 +42,7 @@ import org.codehaus.mojo.license.download.LicensedArtifact; import org.codehaus.mojo.license.download.ProjectLicenseInfo; import org.codehaus.mojo.license.utils.FileUtil; +import org.codehaus.mojo.license.utils.MojoHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,9 +140,8 @@ public ArtifactFilters getArtifactFilters() } }; final Map resolvedDeps = new TreeMap(); - licensedArtifactResolver.loadProjectDependencies( - new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ), - config, remoteRepositories, resolvedDeps ); + licensedArtifactResolver.loadProjectDependencies( new ResolvedProjectDependencies( project.getArtifacts(), + MojoHelper.getDependencyArtifacts( project ) ), config, remoteRepositories, resolvedDeps ); final Map resolvedDepsMap = new HashMap<>( resolvedDeps.size() ); for ( LicensedArtifact dep : resolvedDeps.values() ) { diff --git a/src/main/java/org/codehaus/mojo/license/utils/MojoHelper.java b/src/main/java/org/codehaus/mojo/license/utils/MojoHelper.java old mode 100644 new mode 100755 index 112b6849d..3e6fd524f --- a/src/main/java/org/codehaus/mojo/license/utils/MojoHelper.java +++ b/src/main/java/org/codehaus/mojo/license/utils/MojoHelper.java @@ -25,6 +25,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Resource; import org.apache.maven.project.MavenProject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.net.MalformedURLException; @@ -32,7 +34,9 @@ import java.text.MessageFormat; import java.util.Arrays; import java.util.Comparator; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * Mojo helper methods. @@ -42,6 +46,7 @@ */ public class MojoHelper { + private static final Logger LOG = LoggerFactory.getLogger( MojoHelper.class ); /** * Add the directory as a resource of the given project. @@ -245,4 +250,27 @@ public static List getParams( String params ) String[] split = params == null ? new String[0] : params.split( "," ); return Arrays.asList( split ); } + + /** + * {@link MavenProject#getDependencyArtifacts()} is deprecated. + * + *

+ * This method checks if the dependency artifacts is {@code null} and returns an empty {@code HashSet} to avoid the + * {@code NullPointerException}s caused by the {@link MavenProject#getDependencyArtifacts()} returning {@code null}. + *

+ * + * @param project the MavenProject to retrieve artifacts from + * @return a HashSet of dependencies or an empty set + */ + public static Set getDependencyArtifacts( MavenProject project ) + { + if ( project == null || project.getDependencyArtifacts() == null ) + { + LOG.warn( "" ); + LOG.warn( "Non-transitive dependencies cannot be found. " ); + LOG.warn( "" ); + return new HashSet(); + } + return project.getDependencyArtifacts(); + } }