diff --git a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java index e8bdef313..3432746cf 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java @@ -32,6 +32,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Proxy; +import org.codehaus.mojo.license.api.ArtifactFilters; import org.codehaus.mojo.license.api.MavenProjectDependenciesConfigurator; import org.codehaus.mojo.license.api.ResolvedProjectDependencies; import org.codehaus.mojo.license.download.Cache; @@ -43,7 +44,6 @@ import org.codehaus.mojo.license.download.LicenseDownloader.LicenseDownloadResult; import org.codehaus.mojo.license.download.LicenseMatchers; import org.codehaus.mojo.license.utils.FileUtil; -import org.codehaus.mojo.license.utils.MojoHelper; import java.io.File; import java.io.FileNotFoundException; @@ -579,6 +579,8 @@ public abstract class AbstractDownloadLicensesMojo private int downloadErrorCount = 0; + private ArtifactFilters artifactFilters; + protected abstract boolean isSkip(); protected MavenProject getProject() @@ -773,92 +775,15 @@ public boolean isExcludeTransitiveDependencies() } /** {@inheritDoc} */ - public boolean isIncludeOptional() - { - return includeOptional; - } - - /** - * {@inheritDoc} - */ - public List getExcludedScopes() - { - return MojoHelper.getParams( excludedScopes ); - } - - public void setExcludedScopes( String excludedScopes ) - { - this.excludedScopes = excludedScopes; - } - - /** - * {@inheritDoc} - */ - public List getIncludedScopes() - { - return MojoHelper.getParams( includedScopes ); - } - - /** - * {@inheritDoc} - */ - public List getExcludedTypes() - { - return MojoHelper.getParams( excludedTypes ); - } - - /** - * {@inheritDoc} - */ - public List getIncludedTypes() - { - return MojoHelper.getParams( includedTypes ); - } - - // not used at the moment - - /** - * {@inheritDoc} - */ - public String getIncludedArtifacts() - { - return includedArtifacts; - } - - // not used at the moment - - /** - * {@inheritDoc} - */ - public String getIncludedGroups() - { - return includedGroups; - } - - // not used at the moment - - /** - * {@inheritDoc} - */ - public String getExcludedGroups() - { - return excludedGroups; - } - - // not used at the moment - - /** - * {@inheritDoc} - */ - public String getExcludedArtifacts() - { - return excludedArtifacts; - } - - /** {@inheritDoc} */ - public String getArtifactFiltersUrl() + public ArtifactFilters getArtifactFilters() { - return artifactFiltersUrl; + if ( artifactFilters == null ) + { + artifactFilters = ArtifactFilters.of( includedGroups, excludedGroups, includedArtifacts, excludedArtifacts, + includedScopes, excludedScopes, includedTypes, excludedTypes, + includeOptional, artifactFiltersUrl , getEncoding() ); + } + return artifactFilters; } /** diff --git a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java index 02cd904ee..6c95c5889 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java @@ -36,6 +36,7 @@ import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.reporting.AbstractMavenReport; import org.apache.maven.reporting.MavenReportException; +import org.codehaus.mojo.license.api.ArtifactFilters; import org.codehaus.mojo.license.api.DefaultThirdPartyDetails; import org.codehaus.mojo.license.api.DefaultThirdPartyHelper; import org.codehaus.mojo.license.api.DependenciesTool; @@ -372,6 +373,8 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport @Parameter( property = "license.artifactFiltersUrl" ) private String artifactFiltersUrl; + private ArtifactFilters artifactFilters; + // ---------------------------------------------------------------------- // Protected Abstract Methods // ---------------------------------------------------------------------- @@ -514,70 +517,6 @@ public String getName( Locale locale ) // MavenProjectDependenciesConfigurator Implementation // ---------------------------------------------------------------------- - /** - * {@inheritDoc} - */ - public List getExcludedScopes() - { - return MojoHelper.getParams( excludedScopes ); - } - - /** - * {@inheritDoc} - */ - public List getIncludedScopes() - { - return MojoHelper.getParams( includedScopes ); - } - - /** - * {@inheritDoc} - */ - public List getExcludedTypes() - { - return MojoHelper.getParams( excludedTypes ); - } - - /** - * {@inheritDoc} - */ - public List getIncludedTypes() - { - return MojoHelper.getParams( includedTypes ); - } - - /** - * {@inheritDoc} - */ - public String getExcludedGroups() - { - return excludedGroups; - } - - /** - * {@inheritDoc} - */ - public String getIncludedGroups() - { - return includedGroups; - } - - /** - * {@inheritDoc} - */ - public String getExcludedArtifacts() - { - return excludedArtifacts; - } - - /** - * {@inheritDoc} - */ - public String getIncludedArtifacts() - { - return includedArtifacts; - } - /** * {@inheritDoc} */ @@ -595,9 +534,15 @@ public boolean isExcludeTransitiveDependencies() } /** {@inheritDoc} */ - public boolean isIncludeOptional() + public ArtifactFilters getArtifactFilters() { - return includeOptional; + if ( artifactFilters == null ) + { + artifactFilters = ArtifactFilters.of( includedGroups, excludedGroups, includedArtifacts, excludedArtifacts, + includedScopes, excludedScopes, includedTypes, excludedTypes, + includeOptional, artifactFiltersUrl , getEncoding() ); + } + return artifactFilters; } /** diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java index f65c42985..18b802554 100644 --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -41,13 +41,13 @@ 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.ArtifactFilters; 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; -import org.codehaus.mojo.license.utils.MojoHelper; import org.codehaus.mojo.license.utils.SortedProperties; // CHECKSTYLE_OFF: LineLength @@ -117,6 +117,8 @@ public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo implements Mave */ private ResolvedProjectDependencies dependencyArtifacts; + private ArtifactFilters artifactFilters; + // ---------------------------------------------------------------------- // AbstractLicenseMojo Implementaton // ---------------------------------------------------------------------- @@ -297,76 +299,6 @@ protected SortedProperties createUnsafeMapping() // MavenProjectDependenciesConfigurator Implementaton // ---------------------------------------------------------------------- - /** - * {@inheritDoc} - */ - public String getExcludedGroups() - { - return excludedGroups; - } - - /** - * {@inheritDoc} - */ - public String getIncludedGroups() - { - return includedGroups; - } - - /** - * {@inheritDoc} - */ - public List getExcludedScopes() - { - return MojoHelper.getParams( excludedScopes ); - } - - /** - * {@inheritDoc} - */ - public List getIncludedScopes() - { - return MojoHelper.getParams( includedScopes ); - } - - /** - * {@inheritDoc} - */ - public List getExcludedTypes() - { - return MojoHelper.getParams( excludedTypes ); - } - - /** - * {@inheritDoc} - */ - public List getIncludedTypes() - { - return MojoHelper.getParams( includedTypes ); - } - - /** - * {@inheritDoc} - */ - public String getExcludedArtifacts() - { - return excludedArtifacts; - } - - /** - * {@inheritDoc} - */ - public String getIncludedArtifacts() - { - return includedArtifacts; - } - - /** {@inheritDoc} */ - public String getArtifactFiltersUrl() - { - return artifactFiltersUrl; - } - /** * {@inheritDoc} */ @@ -384,9 +316,15 @@ public boolean isExcludeTransitiveDependencies() } /** {@inheritDoc} */ - public boolean isIncludeOptional() + public ArtifactFilters getArtifactFilters() { - return includeOptional; + if ( artifactFilters == null ) + { + artifactFilters = ArtifactFilters.of( includedGroups, excludedGroups, includedArtifacts, excludedArtifacts, + includedScopes, excludedScopes, includedTypes, excludedTypes, + includeOptional, artifactFiltersUrl , getEncoding() ); + } + return artifactFilters; } // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/api/ArtifactFilters.java b/src/main/java/org/codehaus/mojo/license/api/ArtifactFilters.java index f237c5a35..db5a490df 100644 --- a/src/main/java/org/codehaus/mojo/license/api/ArtifactFilters.java +++ b/src/main/java/org/codehaus/mojo/license/api/ArtifactFilters.java @@ -30,6 +30,7 @@ import java.util.regex.Pattern; import org.apache.maven.artifact.Artifact; +import org.codehaus.mojo.license.utils.MojoHelper; import org.codehaus.mojo.license.utils.UrlRequester; /** @@ -51,31 +52,36 @@ public static Builder buidler() return new Builder(); } - public static ArtifactFilters of( MavenProjectDependenciesConfigurator config ) + // CHECKSTYLE_OFF: ParameterNumber + + public static ArtifactFilters of( String includedGroups, String excludedGroups, String includedArtifacts, + String excludedArtifacts, String includedScopes, String excludedScopes, + String includedTypes, String excludedTypes, boolean includeOptional, + String artifactFiltersUrl, String encoding ) + // CHECKSTYLE_ON: ParameterNumber { Builder builder = new Builder(); - builder.includeGa( toGaPattern( config.getIncludedGroups(), true ) ); - builder.excludeGa( toGaPattern( config.getExcludedGroups(), true ) ); + builder.includeGa( toGaPattern( includedGroups, true ) ); + builder.excludeGa( toGaPattern( excludedGroups, true ) ); - builder.includeGa( toGaPattern( config.getIncludedArtifacts(), false ) ); - builder.excludeGa( toGaPattern( config.getExcludedArtifacts(), false ) ); + builder.includeGa( toGaPattern( includedArtifacts, false ) ); + builder.excludeGa( toGaPattern( excludedArtifacts, false ) ); - builder.includeScopes( config.getIncludedScopes() ); - builder.excludeScopes( config.getExcludedScopes() ); - builder.includeTypes( config.getIncludedTypes() ); - builder.excludeTypes( config.getExcludedTypes() ); - builder.includeOptional( config.isIncludeOptional() ); + builder.includeScopes( MojoHelper.getParams( includedScopes ) ); + builder.excludeScopes( MojoHelper.getParams( excludedScopes ) ); + builder.includeTypes( MojoHelper.getParams( includedTypes ) ); + builder.excludeTypes( MojoHelper.getParams( excludedTypes ) ); + builder.includeOptional( includeOptional ); - final String url = config.getArtifactFiltersUrl(); - if ( url != null ) + if ( artifactFiltersUrl != null ) { try { - final String content = UrlRequester.getFromUrl( url, config.getEncoding() ); + final String content = UrlRequester.getFromUrl( artifactFiltersUrl, encoding ); if ( content != null ) { - builder.script( url, content ); + builder.script( artifactFiltersUrl, content ); } } catch ( IOException e ) 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 3d9c41049..7beaecb30 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DependenciesTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DependenciesTool.java @@ -109,7 +109,7 @@ public SortedMap loadProjectDependencies( ResolvedProjectD SortedMap cache ) { - final ArtifactFilters artifactFilters = ArtifactFilters.of( configuration ); + final ArtifactFilters artifactFilters = configuration.getArtifactFilters(); final boolean excludeTransitiveDependencies = configuration.isExcludeTransitiveDependencies(); diff --git a/src/main/java/org/codehaus/mojo/license/api/MavenProjectDependenciesConfigurator.java b/src/main/java/org/codehaus/mojo/license/api/MavenProjectDependenciesConfigurator.java index c65fbacea..c58251c94 100644 --- a/src/main/java/org/codehaus/mojo/license/api/MavenProjectDependenciesConfigurator.java +++ b/src/main/java/org/codehaus/mojo/license/api/MavenProjectDependenciesConfigurator.java @@ -22,8 +22,6 @@ * #L% */ -import java.util.List; - /** * Contract to configure which dependencies will be loaded by the dependency tool via the method * {@link DependenciesTool#loadProjectDependencies(org.apache.maven.project.MavenProject, @@ -49,83 +47,12 @@ public interface MavenProjectDependenciesConfigurator boolean isExcludeTransitiveDependencies(); /** - * @return list of scopes to include while loading dependencies, if {@code null} is setted, then include all scopes. - */ - List getIncludedScopes(); - - /** - * @return list of scopes to exclude while loading dependencies, if {@code null} is setted, then include all scopes. - */ - List getExcludedScopes(); - - /** - * @return list of types to include while loading dependencies, if {@code null} is setted, then include all types. - */ - List getIncludedTypes(); - - /** - * @return list of types to exclude while loading dependencies, if {@code null} is setted, then include all types. - */ - List getExcludedTypes(); - - /** - * @return a pattern to include dependencies by thier {@code artificatId}, if {@code null} is setted then include - * all artifacts. - */ - String getIncludedArtifacts(); - - /** - * @return a pattern to include dependencies by their {@code groupId}, if {@code null} is setted then include - * all artifacts. + * @return {@link ArtifactFilters} to apply when processing dependencies */ - String getIncludedGroups(); - - /** - * @return a pattern to exclude dependencies by their {@code artifactId}, if {@code null} is setted the no exclude - * is done on artifactId. - */ - String getExcludedGroups(); - - /** - * @return a pattern to exclude dependencies by their {@code groupId}, if {@code null} is setted then no exclude - * is done on groupId. - */ - String getExcludedArtifacts(); - - /** - * Returns a URL returning a plain text file that contains include/exclude artifact filters in the following format: - *
-     * {@code
-     * # this is a comment
-     * include gaPattern org\.my-org:my-artifact
-     * include gaPattern org\.other-org:other-artifact
-     * exclude gaPattern org\.yet-anther-org:.*
-     * include scope compile
-     * include scope test
-     * exclude scope system
-     * include type jar
-     * exclude type war
-     * }
- * - * @return a URL returning a plain text file - * @since 1.18 - */ - String getArtifactFiltersUrl(); - - /** - * @return the encoding to use when reading {@link #getArtifactFiltersUrl()} unless it is an HTTP URL returning a - * valid charset in the {@code Content-Type} response header. - */ - String getEncoding(); + ArtifactFilters getArtifactFilters(); /** * @return {@code true} if verbose mode is on, {@code false} otherwise. */ boolean isVerbose(); - - /** - * @return {@code true} if optional dependencies should be included, {@code false} otherwise. - * @since 1.19 - */ - boolean isIncludeOptional(); }