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..284928ced
--- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java
+++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java
@@ -22,6 +22,19 @@
* #L%
*/
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -41,6 +54,7 @@
import org.codehaus.mojo.license.api.DependenciesTool;
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.ThirdPartyDetails;
import org.codehaus.mojo.license.api.ThirdPartyHelper;
import org.codehaus.mojo.license.api.ThirdPartyTool;
@@ -52,20 +66,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-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.
*
@@ -73,9 +73,9 @@
* @since 1.1
*/
public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
- implements MavenProjectDependenciesConfigurator
+ implements MavenProjectDependenciesConfigurator
{
- private static final Logger LOG = LoggerFactory.getLogger( AbstractThirdPartyReportMojo.class );
+ private static final Logger LOG = LoggerFactory.getLogger ( AbstractThirdPartyReportMojo.class );
// ----------------------------------------------------------------------
// Mojo Parameters
@@ -86,15 +86,16 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( property = "license.excludedScopes", defaultValue = "system" )
+ @Parameter ( property = "license.excludedScopes", defaultValue = "system" )
private String excludedScopes;
/**
- * A filter to include only some scopes, if let empty then all scopes will be used (no filter).
+ * A filter to include only some scopes, if let empty then all scopes will be
+ * used (no filter).
*
* @since 1.1
*/
- @Parameter( property = "license.includedScopes" )
+ @Parameter ( property = "license.includedScopes" )
private String includedScopes;
/**
@@ -102,15 +103,16 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.15
*/
- @Parameter( property = "license.excludedTypes" )
+ @Parameter ( property = "license.excludedTypes" )
private String excludedTypes;
/**
- * A filter to include only some types, if let empty then all types will be used (no filter).
+ * A filter to include only some types, if let empty then all types will be used
+ * (no filter).
*
* @since 1.15
*/
- @Parameter( property = "license.includedTypes" )
+ @Parameter ( property = "license.includedTypes" )
private String includedTypes;
/**
@@ -118,7 +120,7 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( property = "license.excludedGroups" )
+ @Parameter ( property = "license.excludedGroups" )
private String excludedGroups;
/**
@@ -126,7 +128,7 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( property = "license.includedGroups" )
+ @Parameter ( property = "license.includedGroups" )
private String includedGroups;
/**
@@ -134,7 +136,7 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( property = "license.excludedArtifacts" )
+ @Parameter ( property = "license.excludedArtifacts" )
private String excludedArtifacts;
/**
@@ -142,15 +144,16 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( property = "license.includedArtifacts" )
+ @Parameter ( property = "license.includedArtifacts" )
private String includedArtifacts;
/**
- * Include transitive dependencies when looking for missing licenses and downloading license files.
+ * Include transitive dependencies when looking for missing licenses and
+ * downloading license files.
*
* @since 1.1
*/
- @Parameter( property = "license.includeTransitiveDependencies", defaultValue = "true" )
+ @Parameter ( property = "license.includeTransitiveDependencies", defaultValue = "true" )
private boolean includeTransitiveDependencies;
/**
@@ -158,16 +161,17 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.13
*/
- @Parameter( property = "license.excludeTransitiveDependencies", defaultValue = "false" )
+ @Parameter ( property = "license.excludeTransitiveDependencies", defaultValue = "false" )
private boolean excludeTransitiveDependencies;
/**
- * If {@code true} both optional and non-optional dependencies will be included in the list of artifacts for
- * creating the license report; otherwise only non-optional dependencies will be considered.
+ * If {@code true} both optional and non-optional dependencies will be included
+ * in the list of artifacts for creating the license report; otherwise only
+ * non-optional dependencies will be considered.
*
* @since 1.19
*/
- @Parameter( property = "license.includeOptional", defaultValue = "true" )
+ @Parameter ( property = "license.includeOptional", defaultValue = "true" )
boolean includeOptional;
/**
@@ -175,7 +179,7 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( property = "license.useMissingFile", defaultValue = "false" )
+ @Parameter ( property = "license.useMissingFile", defaultValue = "false" )
private boolean useMissingFile;
/**
@@ -183,53 +187,59 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( property = "license.missingFile", defaultValue = "src/license/THIRD-PARTY.properties" )
+ @Parameter ( property = "license.missingFile", defaultValue = "src/license/THIRD-PARTY.properties" )
private File missingFile;
/**
- * The Url that holds the missing license dependency entries. This is an extension to {@link #missingFile}.
- * If set then the entries that will be found at this URL will be added additionally to the entries of the
- * missing file.
+ * The Url that holds the missing license dependency entries. This is an
+ * extension to {@link #missingFile}. If set then the entries that will be found
+ * at this URL will be added additionally to the entries of the missing
+ * file.
*
* NOTE:
- * the response of the URL endpoint must return content that matches the THIRD-PARTY.properties file!
+ * the response of the URL endpoint must return content that matches the
+ * THIRD-PARTY.properties file!
*
* @since 1.15
*/
- @Parameter( property = "license.missingFileUrl" )
+ @Parameter ( property = "license.missingFileUrl" )
String missingFileUrl;
/**
* A file containing the override license information for dependencies.
- * Note: Specify either {@link #overrideUrl} (preferred) or {@link #overrideFile}.
- * If none of these is specified, then {@value LicenseMojoUtils#DEFAULT_OVERRIDE_THIRD_PARTY} resolved against
+ * Note: Specify either {@link #overrideUrl} (preferred) or
+ * {@link #overrideFile}. If none of these is specified, then
+ * {@value LicenseMojoUtils#DEFAULT_OVERRIDE_THIRD_PARTY} resolved against
* ${basedir}
will be used if it exists.
*
* @since 1.11
* @deprecated Use {@link #overrideUrl} instead
*/
@Deprecated
- @Parameter( property = "license.overrideFile" )
+ @Parameter ( property = "license.overrideFile" )
private File overrideFile;
/**
- * A URL pointing at a property file with the override license information for dependencies.
- * Note: Specify either {@link #overrideUrl} (preferred) or {@link #overrideFile}.
- * If none of these is specified, then {@value LicenseMojoUtils#DEFAULT_OVERRIDE_THIRD_PARTY} resolved against
+ * A URL pointing at a property file with the override license information for
+ * dependencies. Note: Specify either {@link #overrideUrl} (preferred) or
+ * {@link #overrideFile}. If none of these is specified, then
+ * {@value LicenseMojoUtils#DEFAULT_OVERRIDE_THIRD_PARTY} resolved against
* ${basedir}
will be used if it exists.
*
* An example of the file content:
+ *
*
* org.jboss.xnio--xnio-api--3.3.6.Final=The Apache Software License, Version 2.0
*
*
* @since 1.17
*/
- @Parameter( property = "license.overrideUrl" )
+ @Parameter ( property = "license.overrideUrl" )
private String overrideUrl;
/**
- * A {@link URL} prepared either our of {@link #overrideFile} or {@link #overrideUrl} or the default value.
+ * A {@link URL} prepared either our of {@link #overrideFile} or
+ * {@link #overrideUrl} or the default value.
*
* @see LicenseMojoUtils#prepareThirdPartyOverrideUrl(URL, File, String, File)
*/
@@ -240,45 +250,49 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.0
*/
- @Parameter( property = "license.useRepositoryMissingFiles", defaultValue = "true" )
+ @Parameter ( property = "license.useRepositoryMissingFiles", defaultValue = "true" )
private boolean useRepositoryMissingFiles;
/**
* To merge licenses in final file.
*
- * Each entry represents a merge (first license is main license to keep), licenses are separated by {@code |}.
+ * Each entry represents a merge (first license is main license to keep),
+ * licenses are separated by {@code |}.
*
* Example :
*
+ *
*
- * <licenseMerges>
- * <licenseMerge>The Apache Software License|Version 2.0,Apache License, Version 2.0</licenseMerge>
- * </licenseMerges>
+ * <licenseMerges> <licenseMerge>The Apache Software License|Version
+ * 2.0,Apache License, Version 2.0</licenseMerge> </licenseMerges>
* </pre>
*
- * Note: This option will be overridden by {@link #licenseMergesUrl} if it is used by command line.
+ * Note: This option will be overridden by {@link #licenseMergesUrl} if
+ * it is used by command line.
+ *
* @since 1.0
*/
@Parameter
private List licenseMerges;
/**
- * Location of file with the merge licenses in order to be used by command line.
- * Note: This option overrides {@link #licenseMerges}.
- *
- * @since 1.18
- */
- @Parameter( property = "license.licenseMergesUrl" )
- protected String licenseMergesUrl;
+ * Location of file with the merge licenses in order to be used by command line.
+ * Note: This option overrides {@link #licenseMerges}.
+ *
+ * @since 1.18
+ */
+ @Parameter ( property = "license.licenseMergesUrl" )
+ protected String licenseMergesUrl;
/**
- * The output directory for the report. Note that this parameter is only evaluated if the goal is run directly from
- * the command line. If the goal is run indirectly as part of a site generation, the output directory configured in
- * the Maven Site Plugin is used instead.
+ * The output directory for the report. Note that this parameter is only
+ * evaluated if the goal is run directly from the command line. If the goal is
+ * run indirectly as part of a site generation, the output directory configured
+ * in the Maven Site Plugin is used instead.
*
* @since 1.1
*/
- @Parameter( defaultValue = "${project.reporting.outputDirectory}", required = true )
+ @Parameter ( defaultValue = "${project.reporting.outputDirectory}", required = true )
private File outputDirectory;
/**
@@ -289,18 +303,18 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.0
*/
- @Parameter( property = "license.verbose", defaultValue = "${maven.verbose}" )
+ @Parameter ( property = "license.verbose", defaultValue = "${maven.verbose}" )
private boolean verbose;
/**
* Encoding used to read and writes files.
*
- * Note: If nothing is filled here, we will use the system
- * property {@code file.encoding}.
+ * Note: If nothing is filled here, we will use the system property
+ * {@code file.encoding}.
*
* @since 1.0
*/
- @Parameter( property = "license.encoding", defaultValue = "${project.build.sourceEncoding}" )
+ @Parameter ( property = "license.encoding", defaultValue = "${project.build.sourceEncoding}" )
private String encoding;
/**
@@ -308,7 +322,7 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
*
* @since 1.1
*/
- @Parameter( defaultValue = "${project}", readonly = true )
+ @Parameter ( defaultValue = "${project}", readonly = true )
private MavenProject project;
// ----------------------------------------------------------------------
@@ -348,7 +362,9 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
private ThirdPartyTool thirdPartyTool;
/**
- * A URL returning a plain text file that contains include/exclude artifact filters in the following format:
+ * A URL returning a plain text file that contains include/exclude artifact
+ * filters in the following format:
+ *
*
* {@code
* # this is a comment
@@ -360,11 +376,12 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
* exclude scope system
* include type jar
* exclude type war
- * }
+ * }
+ *
*
* @since 1.18
*/
- @Parameter( property = "license.artifactFiltersUrl" )
+ @Parameter ( property = "license.artifactFiltersUrl" )
private String artifactFiltersUrl;
private ArtifactFilters artifactFilters;
@@ -373,10 +390,9 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
// Protected Abstract Methods
// ----------------------------------------------------------------------
- protected abstract Collection createThirdPartyDetails()
- throws IOException, ThirdPartyToolException, ProjectBuildingException, MojoFailureException,
- InvalidDependencyVersionException, ArtifactNotFoundException, ArtifactResolutionException,
- DependenciesToolException, MojoExecutionException;
+ protected abstract Collection createThirdPartyDetails () throws IOException,
+ ThirdPartyToolException, ProjectBuildingException, MojoFailureException, InvalidDependencyVersionException,
+ ArtifactNotFoundException, ArtifactResolutionException, DependenciesToolException, MojoExecutionException;
// ----------------------------------------------------------------------
// AbstractMavenReport Implementation
@@ -385,20 +401,21 @@ protected abstract Collection createThirdPartyDetails()
/**
* Method to initialize the mojo before doing any concrete actions.
*
- * Note: The method is invoked before the {@link #executeReport()} method.
+ * Note: The method is invoked before the {@link #executeReport()}
+ * method.
+ *
* @throws IOException
*/
- protected void init()
- throws IOException
+ protected void init () throws IOException
{
if ( licenseMergesUrl != null )
{
- LOG.warn( "" );
- LOG.warn( "licenseMerges will be overridden by licenseMergesUrl." );
- LOG.warn( "" );
- if ( UrlRequester.isStringUrl( licenseMergesUrl ) )
+ LOG.warn ( "" );
+ LOG.warn ( "licenseMerges will be overridden by licenseMergesUrl." );
+ LOG.warn ( "" );
+ if ( UrlRequester.isStringUrl ( licenseMergesUrl ) )
{
- licenseMerges = Arrays.asList( UrlRequester.getFromUrl( licenseMergesUrl ).split( "[\n\r]+" ) );
+ licenseMerges = Arrays.asList ( UrlRequester.getFromUrl ( licenseMergesUrl ).split ( "[\n\r]+" ) );
}
}
}
@@ -406,62 +423,61 @@ protected void init()
/**
* {@inheritDoc}
*/
- protected void executeReport( Locale locale )
- throws MavenReportException
+ protected void executeReport ( Locale locale ) throws MavenReportException
{
- resolvedOverrideUrl = LicenseMojoUtils.prepareThirdPartyOverrideUrl( resolvedOverrideUrl, overrideFile,
- overrideUrl, project.getBasedir() );
+ resolvedOverrideUrl = LicenseMojoUtils.prepareThirdPartyOverrideUrl ( resolvedOverrideUrl, overrideFile,
+ overrideUrl, project.getBasedir () );
Collection details;
try
{
- init();
- details = createThirdPartyDetails();
+ init ();
+ details = createThirdPartyDetails ();
}
catch ( IOException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
catch ( ThirdPartyToolException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
catch ( ProjectBuildingException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
catch ( ArtifactNotFoundException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
catch ( ArtifactResolutionException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
catch ( MojoFailureException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
catch ( DependenciesToolException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
catch ( MojoExecutionException e )
{
- throw new MavenReportException( e.getMessage(), e );
+ throw new MavenReportException ( e.getMessage (), e );
}
- ThirdPartyReportRenderer renderer =
- new ThirdPartyReportRenderer( getSink(), i18n, getOutputName(), locale, details );
- renderer.render();
+ ThirdPartyReportRenderer renderer = new ThirdPartyReportRenderer ( getSink (), i18n, getOutputName (), locale,
+ details );
+ renderer.render ();
}
/**
* {@inheritDoc}
*/
- protected MavenProject getProject()
+ protected MavenProject getProject ()
{
return project;
}
@@ -469,20 +485,20 @@ protected MavenProject getProject()
/**
* {@inheritDoc}
*/
- protected String getOutputDirectory()
+ protected String getOutputDirectory ()
{
- if ( !outputDirectory.isAbsolute() )
+ if ( !outputDirectory.isAbsolute () )
{
- outputDirectory = new File( project.getBasedir(), outputDirectory.getPath() );
+ outputDirectory = new File ( project.getBasedir (), outputDirectory.getPath () );
}
- return outputDirectory.getAbsolutePath();
+ return outputDirectory.getAbsolutePath ();
}
/**
* {@inheritDoc}
*/
- protected Renderer getSiteRenderer()
+ protected Renderer getSiteRenderer ()
{
return siteRenderer;
}
@@ -490,17 +506,17 @@ protected Renderer getSiteRenderer()
/**
* {@inheritDoc}
*/
- public String getDescription( Locale locale )
+ public String getDescription ( Locale locale )
{
- return i18n.getString( getOutputName(), locale, "report.description" );
+ return i18n.getString ( getOutputName (), locale, "report.description" );
}
/**
* {@inheritDoc}
*/
- public String getName( Locale locale )
+ public String getName ( Locale locale )
{
- return i18n.getString( getOutputName(), locale, "report.title" );
+ return i18n.getString ( getOutputName (), locale, "report.title" );
}
// ----------------------------------------------------------------------
@@ -510,7 +526,7 @@ public String getName( Locale locale )
/**
* {@inheritDoc}
*/
- public boolean isIncludeTransitiveDependencies()
+ public boolean isIncludeTransitiveDependencies ()
{
return includeTransitiveDependencies;
}
@@ -518,19 +534,19 @@ public boolean isIncludeTransitiveDependencies()
/**
* {@inheritDoc}
*/
- public boolean isExcludeTransitiveDependencies()
+ public boolean isExcludeTransitiveDependencies ()
{
return excludeTransitiveDependencies;
}
/** {@inheritDoc} */
- public ArtifactFilters getArtifactFilters()
+ public ArtifactFilters getArtifactFilters ()
{
if ( artifactFilters == null )
{
- artifactFilters = ArtifactFilters.of( includedGroups, excludedGroups, includedArtifacts, excludedArtifacts,
- includedScopes, excludedScopes, includedTypes, excludedTypes,
- includeOptional, artifactFiltersUrl , getEncoding() );
+ artifactFilters = ArtifactFilters.of ( includedGroups, excludedGroups, includedArtifacts, excludedArtifacts,
+ includedScopes, excludedScopes, includedTypes, excludedTypes, includeOptional, artifactFiltersUrl,
+ getEncoding () );
}
return artifactFilters;
}
@@ -538,7 +554,7 @@ public ArtifactFilters getArtifactFilters()
/**
* {@inheritDoc}
*/
- public boolean isVerbose()
+ public boolean isVerbose ()
{
return verbose;
}
@@ -547,95 +563,93 @@ public boolean isVerbose()
// Protected Methods
// ----------------------------------------------------------------------
- Collection createThirdPartyDetails( MavenProject project, boolean loadArtifacts )
- throws IOException, ThirdPartyToolException, ProjectBuildingException, MojoFailureException,
- DependenciesToolException, MojoExecutionException
+ Collection createThirdPartyDetails ( MavenProject project, boolean loadArtifacts )
+ throws IOException, ThirdPartyToolException, ProjectBuildingException, MojoFailureException,
+ DependenciesToolException, MojoExecutionException
{
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() );
+ loadedDependencies = new ResolvedProjectDependencies ( getProject ().getArtifacts (),
+ MojoHelper.getDependencyArtifacts ( project ) );
}
- ThirdPartyHelper thirdPartyHelper =
- new DefaultThirdPartyHelper( project, encoding, verbose,
- dependenciesTool, thirdPartyTool,
- project.getRemoteArtifactRepositories(), project.getRemoteProjectRepositories() );
+ ThirdPartyHelper thirdPartyHelper = new DefaultThirdPartyHelper ( project, encoding, verbose, dependenciesTool,
+ thirdPartyTool, project.getRemoteArtifactRepositories (), project.getRemoteProjectRepositories () );
// 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 );
+ LicenseMap licenseMap = thirdPartyHelper.createLicenseMap ( projectDependencies );
// Get unsafe dependencies (dependencies with no license in pom)
- SortedSet dependenciesWithNoLicense = thirdPartyHelper.getProjectsWithNoLicense( licenseMap );
+ SortedSet dependenciesWithNoLicense = thirdPartyHelper.getProjectsWithNoLicense ( licenseMap );
// compute safe dependencies (with pom licenses)
- Set dependenciesWithPomLicense =
- new TreeSet<>( MojoHelper.newMavenProjectComparator() );
- dependenciesWithPomLicense.addAll( projectDependencies.values() );
+ Set dependenciesWithPomLicense = new TreeSet<> ( MojoHelper.newMavenProjectComparator () );
+ dependenciesWithPomLicense.addAll ( projectDependencies.values () );
- if ( CollectionUtils.isNotEmpty( dependenciesWithNoLicense ) )
+ if ( CollectionUtils.isNotEmpty ( dependenciesWithNoLicense ) )
{
// there is some unsafe dependencies, remove them from safe dependencies
- dependenciesWithPomLicense.removeAll( dependenciesWithNoLicense );
+ dependenciesWithPomLicense.removeAll ( dependenciesWithNoLicense );
if ( useMissingFile )
{
- // Resolve unsafe dependencies using missing files, this will update licenseMap and unsafeDependencies
- thirdPartyHelper.createUnsafeMapping( licenseMap, missingFile, missingFileUrl,
- useRepositoryMissingFiles, dependenciesWithNoLicense,
- projectDependencies, loadedDependencies.getAllDependencies() );
+ // Resolve unsafe dependencies using missing files, this will update licenseMap
+ // and unsafeDependencies
+ thirdPartyHelper.createUnsafeMapping ( licenseMap, missingFile, missingFileUrl,
+ useRepositoryMissingFiles, dependenciesWithNoLicense, projectDependencies,
+ loadedDependencies.getAllDependencies () );
}
}
// LicenseMap is now complete, let's merge licenses if necessary
- thirdPartyHelper.mergeLicenses( licenseMerges, licenseMap );
+ thirdPartyHelper.mergeLicenses ( licenseMerges, licenseMap );
// Add override licenses
- thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, encoding, resolvedOverrideUrl );
+ thirdPartyTool.overrideLicenses ( licenseMap, projectDependencies, encoding, resolvedOverrideUrl );
// let's build third party details for each dependencies
- Collection details = new ArrayList<>();
+ Collection details = new ArrayList<> ();
- for ( Map.Entry entry : licenseMap.toDependencyMap().entrySet() )
+ for ( Map.Entry entry : licenseMap.toDependencyMap ().entrySet () )
{
- MavenProject dependency = entry.getKey();
- String[] licenses = entry.getValue();
- ThirdPartyDetails detail = new DefaultThirdPartyDetails( dependency );
- details.add( detail );
- if ( dependenciesWithPomLicense.contains( dependency ) )
+ MavenProject dependency = entry.getKey ();
+ String[] licenses = entry.getValue ();
+ ThirdPartyDetails detail = new DefaultThirdPartyDetails ( dependency );
+ details.add ( detail );
+ if ( dependenciesWithPomLicense.contains ( dependency ) )
{
// this is a pom licenses
- detail.setPomLicenses( licenses );
+ detail.setPomLicenses ( licenses );
}
- else if ( !dependenciesWithNoLicense.contains( dependency ) )
+ else if ( !dependenciesWithNoLicense.contains ( dependency ) )
{
// this is a third-party licenses
- detail.setThirdPartyLicenses( licenses );
+ detail.setThirdPartyLicenses ( licenses );
}
}
return details;
}
/** {@inheritDoc} */
- public String getArtifactFiltersUrl()
+ public String getArtifactFiltersUrl ()
{
return artifactFiltersUrl;
}
/** {@inheritDoc} */
- public String getEncoding()
+ public String getEncoding ()
{
return encoding;
}
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..a6b5d6804
--- 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;
@@ -140,8 +141,9 @@ public ArtifactFilters getArtifactFilters()
};
final Map resolvedDeps = new TreeMap();
licensedArtifactResolver.loadProjectDependencies(
- new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ),
- config, remoteRepositories, resolvedDeps );
+ 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..a0b79f509
--- 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.
@@ -51,10 +56,10 @@ public class MojoHelper
* @param includes the includes of the resource
* @return {@code true} if the resources was added (not already existing)
*/
- public static boolean addResourceDir( File dir, MavenProject project, String... includes )
+ public static boolean addResourceDir ( File dir, MavenProject project, String... includes )
{
- List> resources = project.getResources();
- return addResourceDir( dir, project, resources, includes );
+ List> resources = project.getResources ();
+ return addResourceDir ( dir, project, resources, includes );
}
/**
@@ -66,23 +71,23 @@ public static boolean addResourceDir( File dir, MavenProject project, String...
* @param includes includes of the new resources
* @return {@code true} if the resource was added (not already existing)
*/
- public static boolean addResourceDir( File dir, MavenProject project, List> resources, String... includes )
+ public static boolean addResourceDir ( File dir, MavenProject project, List> resources, String... includes )
{
- String newresourceDir = dir.getAbsolutePath();
+ String newresourceDir = dir.getAbsolutePath ();
boolean shouldAdd = true;
for ( Object o : resources )
{
Resource r = (Resource) o;
- if ( !r.getDirectory().equals( newresourceDir ) )
+ if ( !r.getDirectory ().equals ( newresourceDir ) )
{
continue;
}
for ( String i : includes )
{
- if ( !r.getIncludes().contains( i ) )
+ if ( !r.getIncludes ().contains ( i ) )
{
- r.addInclude( i );
+ r.addInclude ( i );
}
}
shouldAdd = false;
@@ -90,70 +95,72 @@ public static boolean addResourceDir( File dir, MavenProject project, List> re
}
if ( shouldAdd )
{
- Resource r = new Resource();
- r.setDirectory( newresourceDir );
+ Resource r = new Resource ();
+ r.setDirectory ( newresourceDir );
for ( String i : includes )
{
- if ( !r.getIncludes().contains( i ) )
+ if ( !r.getIncludes ().contains ( i ) )
{
- r.addInclude( i );
+ r.addInclude ( i );
}
}
- project.addResource( r );
+ project.addResource ( r );
}
return shouldAdd;
}
- public static Comparator newMavenProjectComparator()
+ public static Comparator newMavenProjectComparator ()
{
- return new Comparator()
+ return new Comparator ()
{
/**
* {@inheritDoc}
*/
- public int compare( MavenProject o1, MavenProject o2 )
+ public int compare ( MavenProject o1, MavenProject o2 )
{
- String id1 = getArtifactId( o1.getArtifact() );
- String id2 = getArtifactId( o2.getArtifact() );
- return id1.compareTo( id2 );
+ String id1 = getArtifactId ( o1.getArtifact () );
+ String id2 = getArtifactId ( o2.getArtifact () );
+ return id1.compareTo ( id2 );
}
};
}
- public static Comparator newMavenProjectComparatorByName()
+ public static Comparator newMavenProjectComparatorByName ()
{
- return new Comparator()
+ return new Comparator ()
{
/**
* {@inheritDoc}
*/
- public int compare( MavenProject o1, MavenProject o2 )
+ public int compare ( MavenProject o1, MavenProject o2 )
{
- String id1 = getProjectName( o1 );
- String id2 = getProjectName( o2 );
- return id1.compareToIgnoreCase( id2 );
+ String id1 = getProjectName ( o1 );
+ String id2 = getProjectName ( o2 );
+ return id1.compareToIgnoreCase ( id2 );
}
};
}
- protected static final double[] TIME_FACTORS = { 1000000, 1000, 60, 60, 24 };
+ protected static final double[] TIME_FACTORS =
+ { 1000000, 1000, 60, 60, 24 };
- protected static final String[] TIME_UNITES = { "ns", "ms", "s", "m", "h", "d" };
+ protected static final String[] TIME_UNITES =
+ { "ns", "ms", "s", "m", "h", "d" };
- public static String convertTime( long value )
+ public static String convertTime ( long value )
{
- return convert( value, TIME_FACTORS, TIME_UNITES );
+ return convert ( value, TIME_FACTORS, TIME_UNITES );
}
- public static String convert( long value, double[] factors, String[] unites )
+ public static String convert ( long value, double[] factors, String[] unites )
{
- long sign = value == 0 ? 1 : value / Math.abs( value );
+ long sign = value == 0 ? 1 : value / Math.abs ( value );
int i = 0;
- double tmp = Math.abs( value );
+ double tmp = Math.abs ( value );
while ( i < factors.length && i < unites.length && tmp > factors[i] )
{
tmp = tmp / factors[i++];
@@ -161,7 +168,7 @@ public static String convert( long value, double[] factors, String[] unites )
tmp *= sign;
String result;
- result = MessageFormat.format( "{0,number,0.###}{1}", tmp, unites[i] );
+ result = MessageFormat.format ( "{0,number,0.###}{1}", tmp, unites[i] );
return result;
}
@@ -172,77 +179,102 @@ public static String convert( long value, double[] factors, String[] unites )
* @param suffix suffix to add
* @return the new url
*/
- public static URL getUrl( URL baseUrl, String suffix )
+ public static URL getUrl ( URL baseUrl, String suffix )
{
- String url = baseUrl.toString() + "/" + suffix;
+ String url = baseUrl.toString () + "/" + suffix;
try
{
- return new URL( url );
+ return new URL ( url );
}
catch ( MalformedURLException ex )
{
- throw new IllegalArgumentException( "could not obtain url " + url, ex );
+ throw new IllegalArgumentException ( "could not obtain url " + url, ex );
}
}
- public static String getArtifactId( Artifact artifact )
+ public static String getArtifactId ( Artifact artifact )
{
- StringBuilder sb = new StringBuilder();
- sb.append( artifact.getGroupId() );
- sb.append( "--" );
- sb.append( artifact.getArtifactId() );
- sb.append( "--" );
- sb.append( artifact.getVersion() );
- return sb.toString();
+ StringBuilder sb = new StringBuilder ();
+ sb.append ( artifact.getGroupId () );
+ sb.append ( "--" );
+ sb.append ( artifact.getArtifactId () );
+ sb.append ( "--" );
+ sb.append ( artifact.getVersion () );
+ return sb.toString ();
}
- public static String getArtifactName( MavenProject project )
+ public static String getArtifactName ( MavenProject project )
{
- StringBuilder sb = new StringBuilder();
- if ( project.getName().startsWith( "Unnamed -" ) )
+ StringBuilder sb = new StringBuilder ();
+ if ( project.getName ().startsWith ( "Unnamed -" ) )
{
// as in Maven 3, let's use the artifact id
- sb.append( project.getArtifactId() );
+ sb.append ( project.getArtifactId () );
}
else
{
- sb.append( project.getName() );
+ sb.append ( project.getName () );
}
- sb.append( " (" );
- sb.append( project.getGroupId() );
- sb.append( ":" );
- sb.append( project.getArtifactId() );
- sb.append( ":" );
- sb.append( project.getVersion() );
- sb.append( " - " );
- String url = project.getUrl();
- sb.append( url == null ? "no url defined" : url );
- sb.append( ")" );
-
- return sb.toString();
+ sb.append ( " (" );
+ sb.append ( project.getGroupId () );
+ sb.append ( ":" );
+ sb.append ( project.getArtifactId () );
+ sb.append ( ":" );
+ sb.append ( project.getVersion () );
+ sb.append ( " - " );
+ String url = project.getUrl ();
+ sb.append ( url == null ? "no url defined" : url );
+ sb.append ( ")" );
+
+ return sb.toString ();
}
- public static String getProjectName( MavenProject project )
+ public static String getProjectName ( MavenProject project )
{
String sb;
- if ( project.getName().startsWith( "Unnamed" ) )
+ if ( project.getName ().startsWith ( "Unnamed" ) )
{
// as in Maven 3, let's use the artifact id
- sb = project.getArtifactId();
+ sb = project.getArtifactId ();
}
else
{
- sb = project.getName();
+ sb = project.getName ();
}
return sb;
}
- public static List getParams( String params )
+ public static List getParams ( String params )
{
- String[] split = params == null ? new String[0] : params.split( "," );
- return Arrays.asList( split );
+ 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 ();
+ }
+
}