Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #358, #352 NPE on site generation caused by null returned by deprecated MavenProject.getDependencyArtifacts() #373

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/it/ISSUE-358/child-1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.tomred</groupId>
<artifactId>ISSUE-358</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>child-1</artifactId>
</project>
1 change: 1 addition & 0 deletions src/it/ISSUE-358/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean site
44 changes: 44 additions & 0 deletions src/it/ISSUE-358/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.tomred</groupId>
<artifactId>ISSUE-358</artifactId>
<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<modules>
<module>child-1</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>@maven-site-plugin.version@</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>@maven-project-info-reports-plugin.version@</version>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
</reporting>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ Collection<ThirdPartyDetails> createThirdPartyDetails(MavenProject project, bool
ResolvedProjectDependencies loadedDependencies;
if (loadArtifacts) {
loadedDependencies =
new ResolvedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts());
new ResolvedProjectDependencies(project.getArtifacts(), MojoHelper.getDependencyArtifacts(project));
} else {
loadedDependencies = new ResolvedProjectDependencies(
getProject().getArtifacts(), getProject().getDependencyArtifacts());
getProject().getArtifacts(), MojoHelper.getDependencyArtifacts(project));
}

ThirdPartyHelper thirdPartyHelper = new DefaultThirdPartyHelper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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;
Expand Down Expand Up @@ -225,10 +226,10 @@ protected ResolvedProjectDependencies resolveDependencyArtifacts() throws Depend
}
if (isAggregatorBuild) {
dependencyArtifacts =
new ResolvedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts());
new ResolvedProjectDependencies(project.getArtifacts(), MojoHelper.getDependencyArtifacts(project));
} else {
dependencyArtifacts =
new ResolvedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts());
new ResolvedProjectDependencies(project.getArtifacts(), MojoHelper.getDependencyArtifacts(project));
}
return dependencyArtifacts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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;

/**
* Download the license files of all aggregated dependencies of the current project, and generate a summary file
Expand Down Expand Up @@ -116,7 +117,7 @@ protected Map<String, LicensedArtifact> getDependencies() {

for (MavenProject p : reactorProjects) {
licensedArtifactResolver.loadProjectDependencies(
new ResolvedProjectDependencies(p.getArtifacts(), p.getDependencyArtifacts()),
new ResolvedProjectDependencies(p.getArtifacts(), MojoHelper.getDependencyArtifacts(p)),
this,
remoteRepositories,
result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,7 +85,7 @@ protected boolean isSkip() {
protected Map<String, LicensedArtifact> getDependencies() {
final Map<String, LicensedArtifact> result = new TreeMap<>();
licensedArtifactResolver.loadProjectDependencies(
new ResolvedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts()),
new ResolvedProjectDependencies(project.getArtifacts(), MojoHelper.getDependencyArtifacts(project)),
this,
remoteRepositories,
result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -129,7 +130,7 @@ public ArtifactFilters getArtifactFilters() {
};
final Map<String, LicensedArtifact> resolvedDeps = new TreeMap<String, LicensedArtifact>();
licensedArtifactResolver.loadProjectDependencies(
new ResolvedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts()),
new ResolvedProjectDependencies(project.getArtifacts(), MojoHelper.getDependencyArtifacts(project)),
config,
remoteRepositories,
resolvedDeps);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/codehaus/mojo/license/utils/MojoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
import java.net.URL;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import org.apache.commons.collections.comparators.ComparatorChain;
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;

/**
* Mojo helper methods.
Expand All @@ -42,6 +46,7 @@
* @since 1.0
*/
public class MojoHelper {
private static final Logger LOG = LoggerFactory.getLogger(MojoHelper.class);

/**
* Add the directory as a resource of the given project.
Expand Down Expand Up @@ -215,4 +220,25 @@ public static List<String> getParams(String params) {
String[] split = params == null ? new String[0] : params.split(",");
return Arrays.asList(split);
}

/**
* {@link MavenProject#getDependencyArtifacts()} is deprecated.
*
* <p>
* 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}.
* </p>
*
* @param project the MavenProject to retrieve artifacts from
* @return a HashSet of dependencies or an empty set
*/
public static Set<Artifact> getDependencyArtifacts(MavenProject project) {
if (project == null || project.getDependencyArtifacts() == null) {
LOG.warn("");
LOG.warn("Non-transitive dependencies cannot be found. ");
LOG.warn("");
return Collections.emptySet();
}
return project.getDependencyArtifacts();
}
}