Class AbstractAddThirdPartyMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AddThirdPartyMojo
,AggregatorAddThirdPartyMojo
- Since:
- 1.0
- Author:
- tchemit dev@tchemit.fr
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Class to fill theexcludedLicenses
parameter, from a simple string to split, or a list of string.static class
Class to fill theincludedLicenses
parameter, from a simple string to split, or a list of string. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Iftrue
the mojo will be executed for reactor projects having any packaging (includingpom
); otherwise the mojo will be executed only for projects that do not have packagingpom
.protected String
A URL returning a plain text file that contains include/exclude artifact filters in the following format:protected String
The path of the bundled third party file to produce whengenerateBundle
is on.protected Set
<org.apache.maven.artifact.Artifact> The set of dependencies for the current project, used to locate license databases.protected boolean
Attach the 'missing' file as an additional artifact so that it is deployed in the deploy phase.protected boolean
Flag computed in theinit()
method to know if there is something has to be generated.protected boolean
Flag computed in theinit()
method to know if a bundle version has to be generated.protected String
A regular expression (not glob pattern) used as filter to exclude artifacts that have matching artifactId.protected String
A regular expression (not glob pattern) used as filter to exclude artifacts that have matching groupId.To specify some licenses to exclude.protected String
A comma separated list of scopes to exclude: e.g.protected String
A comma separated list of types to exclude: e.g.protected boolean
Deprecated.protected boolean
A flag to fail the build if at least one dependency was blacklisted.protected boolean
A flag to fail the build if at least one dependency was detected without a license.protected String
Template used to build the third-party file.protected boolean
To force generation of the third-party file even if everything is up to date.protected boolean
A flag to copy a bundled version of the third-party file.protected String
A regular expression (not glob pattern) used as filter to include only artifacts that have matching artifactId.protected String
A regular expression (not glob pattern) used as filter to include only artifacts that have matching groupId.To specify some licenses to include.protected String
A comma separated list of scopes to include: e.g.protected String
A comma separated list of types to include.protected LicenseMap
To merge licenses in final file.protected String
Deprecated.prefer use nowlicenseMergesUrl
protected String
Location of file with the merge licenses in order to be used by command line.protected File
The file to write with a license information template for dependencies with unknown license.protected String
The Url that holds the missing license dependency entries.protected String
To resolve third party licenses from an artifact.protected File
Directory where to generate files.protected String
A URL prepared either our ofoverrideFile
oroverrideUrl
or the default value.protected boolean
A flag to sort artifact by name in the generated third-party file.protected String
File where to write the third-party file.protected SortedSet
<org.apache.maven.project.MavenProject> protected SortedProperties
protected boolean
A flag to use the missing licenses file to consolidate the THID-PARTY file.protected boolean
Load files supplying information for missing third party licenses from repositories.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractAddThirdPartyMojo
(ThirdPartyTool thirdPartyTool, DependenciesTool dependenciesTool) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract SortedProperties
Creates the unsafe mapping (says dependencies with no license given by their pom).protected ThirdPartyHelper
protected void
init()
Method to initialize the mojo before doing any concrete actions.Loads the dependencies of the project (asMavenProject
, indexed by their gav.void
setExcludedLicenses
(String excludedLicenses) Fill theexcludedLicenses
parameter from a simple string to split.void
setIncludedLicenses
(String includedLicenses) Fill theincludedLicenses
parameter from a simple string to split.Methods inherited from class org.codehaus.mojo.license.AbstractLicenseMojo
acceptPackaging, addResourceDir, afterExecute, checkEncoding, checkPackaging, doAction, execute, getEncoding, getProject, hasClassPath, isSkip, isVerbose, rejectPackaging, setEncoding, setVerbose, shouldSkip
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
outputDirectory
@Parameter(property="license.outputDirectory", defaultValue="${project.build.directory}/generated-sources/license", required=true) protected File outputDirectoryDirectory where to generate files.- Since:
- 1.0
-
deployMissingFile
@Parameter(property="license.deployMissingFile", defaultValue="true") protected boolean deployMissingFileAttach the 'missing' file as an additional artifact so that it is deployed in the deploy phase.- Since:
- 1.0
-
useRepositoryMissingFiles
@Parameter(property="license.useRepositoryMissingFiles", defaultValue="true") protected boolean useRepositoryMissingFilesLoad files supplying information for missing third party licenses from repositories. The plugin looks for Maven artifacts with coordinates of the form G:A:V:properties:third-party, where the group, artifact, and version are those for dependencies of your project, while the type is 'properties' and the classifier is 'third-party'.- Since:
- 1.0
-
acceptPomPackaging
@Parameter(property="license.acceptPomPackaging", defaultValue="false") protected boolean acceptPomPackagingIftrue
the mojo will be executed for reactor projects having any packaging (includingpom
); otherwise the mojo will be executed only for projects that do not have packagingpom
.Since 1.18, when
acceptPomPackaging
istrue
,aggregate-add-third-party
mojo is executed also for the Maven session root project - i.e. the one out whose directory the mojo was executed. Before 1.18, whenacceptPomPackaging
wastrue
,aggregate-add-third-party
mojo was iterating over all modules in the reactor but the Maven session root project was skipped.- Since:
- 1.1
-
excludedScopes
@Parameter(property="license.excludedScopes", defaultValue="system") protected String excludedScopesA comma separated list of scopes to exclude: e.g.<excludedScopes>test,provided</excludedScopes>
or-Dlicense.excludedScopes=test,provided
.This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is excluded its transitive dependencies are not automatically excluded. To enforce this behavior refer to
excludeTransitiveDependencies
.- Since:
- 1.1
-
includedScopes
A comma separated list of scopes to include: e.g.<includedScopes>test,provided</includedScopes>
or-Dlicense.includedScopes=test,provided
.This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is included also its transitive dependencies are included. To suppress this behavior refer to
includeTransitiveDependencies
.- Since:
- 1.1
-
excludedTypes
A comma separated list of types to exclude: e.g.<excludedTypes>war,pom</excludedTypes>
or-Dlicense.excludedTypes=was,pom
.This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is excluded its transitive dependencies are not automatically excluded. To enforce this behavior refer to
excludeTransitiveDependencies
.- Since:
- 1.15
-
includedTypes
A comma separated list of types to include.This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is included also its transitive dependencies are included. To suppress this behavior refer to
includeTransitiveDependencies
.- Since:
- 1.15
-
excludedGroups
A regular expression (not glob pattern) used as filter to exclude artifacts that have matching groupId. Match could be also partial for example^org\.
This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is excluded its transitive dependencies are not automatically excluded. To enforce this behavior refer to
excludeTransitiveDependencies
.- Since:
- 1.1
-
includedGroups
A regular expression (not glob pattern) used as filter to include only artifacts that have matching groupId.This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is included also its transitive dependencies are included. To suppress this behavior refer to
includeTransitiveDependencies
.- Since:
- 1.1
-
excludedArtifacts
A regular expression (not glob pattern) used as filter to exclude artifacts that have matching artifactId. Match could be also partial for example^org\.
This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is excluded its transitive dependencies are not automatically excluded. To enforce this behavior refer to
excludeTransitiveDependencies
.- Since:
- 1.1
-
includedArtifacts
A regular expression (not glob pattern) used as filter to include only artifacts that have matching artifactId.This filter is applied on the list of direct dependencies (and their transitive dependencies) of the projects in the reactor.
By default if an artifact is included also its transitive dependencies are included. To suppress this behavior refer to
includeTransitiveDependencies
.- Since:
- 1.1
-
thirdPartyFilename
@Parameter(property="license.thirdPartyFilename", defaultValue="THIRD-PARTY.txt", required=true) protected String thirdPartyFilenameFile where to write the third-party file.- Since:
- 1.0
-
useMissingFile
@Parameter(property="license.useMissingFile", defaultValue="false") protected boolean useMissingFileA flag to use the missing licenses file to consolidate the THID-PARTY file.- Since:
- 1.0
-
missingFile
@Parameter(property="license.missingFile", defaultValue="src/license/THIRD-PARTY.properties") protected File missingFileThe file to write with a license information template for dependencies with unknown license.- Since:
- 1.0
-
missingFileUrl
The Url that holds the missing license dependency entries. This is an extension tomissingFile
. 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!- Since:
- 1.15
-
missingLicensesFileArtifact
@Parameter(property="license.missingLicensesFileArtifact") protected String missingLicensesFileArtifactTo resolve third party licenses from an artifact.- Since:
- 1.14
-
resolvedOverrideUrl
A URL prepared either our ofoverrideFile
oroverrideUrl
or the default value.- See Also:
-
licenseMerges
To merge licenses in final file.Each entry represents a merge (first license is main license to keep), licenses are separated by
|
.Example :
<licenseMerges> <licenseMerge>The Apache Software License|Version 2.0,Apache License, Version 2.0</licenseMerge> </licenseMerges> </pre> Note: This option will be overridden by
licenseMergesUrl
if it is used by command line.- Since:
- 1.0
-
licenseMergesFile
Deprecated.prefer use nowlicenseMergesUrl
The file with the merge licenses in order to be used by command line. Note: This option overrideslicenseMerges
.- Since:
- 1.15
-
licenseMergesUrl
Location of file with the merge licenses in order to be used by command line. Note: This option overrideslicenseMerges
.- Since:
- 1.17
-
includedLicenses
@Parameter(property="license.includedLicenses") protected AbstractAddThirdPartyMojo.IncludedLicenses includedLicensesTo specify some licenses to include.If this parameter is filled and a license is not in this
whitelist
then build will fail when propertyfailOnBlacklist
is true.Since version
1.4
, there are three ways to fill this parameter :- A simple string (separated by
|
), the way to use by property configuration:<includedLicenses>licenseA|licenseB</includedLicenses>
or-Dlicense.includedLicenses=licenseA|licenseB
- A list of string (can only be used in plugin configuration, not via property configuration)
<includedLicenses> <includedLicense>licenseA</includedLicense> <includedLicenses>licenseB</includedLicense> </includedLicenses>
- Since version
1.15
a URL that contains a set of license names at the target source (only a single URL is accepted as parameter)<includedLicenses>http://my.license.host.com/my-whitelist</includedLicenses>
the license-list on the given URL is expected to be list with a line-break after every entry e.g.:- The Apache Software License, Version 2.0
- Apache License, Version 2.0
- Bouncy Castle Licence
- MIT License
- Since:
- 1.1
- A simple string (separated by
-
excludedLicenses
@Parameter(property="license.excludedLicenses") protected AbstractAddThirdPartyMojo.ExcludedLicenses excludedLicensesTo specify some licenses to exclude.If a such license is found then build will fail when property
failOnBlacklist
is true.Since version
1.4
, there are three ways to fill this parameter :- A simple string (separated by
|
), the way to use by property configuration:<excludedLicenses>licenseA|licenseB</excludedLicenses>
or-Dlicense.excludedLicenses=licenseA|licenseB
- A list of string (can only be used in plugin configuration, not via property configuration)
<excludedLicenses> <excludedLicense>licenseA</excludedLicense> <excludedLicense>licenseB</excludedLicense> </excludedLicenses>
- Since version
1.15
a URL that contains a set of license names at the target source (only a single URL is accepted as parameter)<includedLicenses>http://my.license.host.com/my-blacklist</includedLicenses>
the license-list on the given URL is expected to be list with a line-break after every entry e.g.:- The Apache Software License, Version 2.0
- Apache License, Version 2.0
- Bouncy Castle Licence
- MIT License
- Since:
- 1.1
- A simple string (separated by
-
bundleThirdPartyPath
@Parameter(property="license.bundleThirdPartyPath", defaultValue="META-INF/${project.artifactId}-THIRD-PARTY.txt") protected String bundleThirdPartyPathThe path of the bundled third party file to produce whengenerateBundle
is on.Note: This option is not available for
pom
module types.- Since:
- 1.0
-
generateBundle
@Parameter(property="license.generateBundle", defaultValue="false") protected boolean generateBundleA flag to copy a bundled version of the third-party file. This is useful to avoid for a final application collision name of third party file.The file will be copied at the
bundleThirdPartyPath
location.- Since:
- 1.0
-
force
@Parameter(property="license.force", defaultValue="false") protected boolean forceTo force generation of the third-party file even if everything is up to date.- Since:
- 1.0
-
failIfWarning
@Deprecated @Parameter(property="license.failIfWarning", defaultValue="false") protected boolean failIfWarningDeprecated.since 1.14, use nowfailOnMissing
orfailOnBlacklist
.A flag to fail the build if at least one dependency was detected without a license.- Since:
- 1.0
-
failOnMissing
@Parameter(property="license.failOnMissing", defaultValue="false") protected boolean failOnMissingA flag to fail the build if at least one dependency was detected without a license.- Since:
- 1.14
-
failOnBlacklist
@Parameter(property="license.failOnBlacklist", defaultValue="false") protected boolean failOnBlacklistA flag to fail the build if at least one dependency was blacklisted.- Since:
- 1.14
-
sortArtifactByName
@Parameter(property="license.sortArtifactByName", defaultValue="false") protected boolean sortArtifactByNameA flag to sort artifact by name in the generated third-party file.If not then artifacts are sorted by
groupId:artifactId:version
- Since:
- 1.6
-
fileTemplate
@Parameter(property="license.fileTemplate", defaultValue="/org/codehaus/mojo/license/third-party-file.ftl") protected String fileTemplateTemplate used to build the third-party file.(This template uses freemarker).
Note: This property can either point to a file or a resource on the classpath. In case it points to a file and this plugin is used within a sub-module as part of a multi-module build, you need to make this path resolvable, e.g. by prepending
basedir
.- Since:
- 1.1
-
dependencies
@Parameter(property="project.artifacts", required=true, readonly=true) protected Set<org.apache.maven.artifact.Artifact> dependenciesThe set of dependencies for the current project, used to locate license databases. -
projectDependencies
-
licenseMap
-
unsafeDependencies
-
unsafeMappings
-
doGenerate
protected boolean doGenerateFlag computed in theinit()
method to know if there is something has to be generated. -
doGenerateBundle
protected boolean doGenerateBundleFlag computed in theinit()
method to know if a bundle version has to be generated. -
artifactFiltersUrl
A URL returning a plain text file that contains include/exclude artifact filters in the following format:# 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
- Since:
- 1.18
-
-
Constructor Details
-
AbstractAddThirdPartyMojo
protected AbstractAddThirdPartyMojo(ThirdPartyTool thirdPartyTool, DependenciesTool dependenciesTool)
-
-
Method Details
-
loadDependencies
protected abstract SortedMap<String,org.apache.maven.project.MavenProject> loadDependencies() throws DependenciesToolExceptionLoads the dependencies of the project (asMavenProject
, indexed by their gav.- Returns:
- the map of dependencies of the maven project indexed by their gav.
- Throws:
DependenciesToolException
- if the dependencies could not be loaded
-
createUnsafeMapping
protected abstract SortedProperties createUnsafeMapping() throws org.apache.maven.project.ProjectBuildingException, IOException, ThirdPartyToolException, org.apache.maven.plugin.MojoExecutionException, DependenciesToolExceptionCreates the unsafe mapping (says dependencies with no license given by their pom).Can come from loaded missing file or from dependencies with no license at all.
- Returns:
- the map of usafe mapping indexed by their gav.
- Throws:
org.apache.maven.project.ProjectBuildingException
- if could not create maven project for some dependenciesIOException
- if could not load missing fileThirdPartyToolException
- for third party tool errorDependenciesToolException
- if the dependencies could not be loadedorg.apache.maven.plugin.MojoExecutionException
-
init
Method to initialize the mojo before doing any concrete actions. Note: The method is invoked before theAbstractLicenseMojo.doAction()
method.- Specified by:
init
in classAbstractLicenseMojo
- Throws:
Exception
- if any
-
setIncludedLicenses
public void setIncludedLicenses(String includedLicenses) throws org.apache.maven.plugin.MojoExecutionException Fill theincludedLicenses
parameter from a simple string to split.- Parameters:
includedLicenses
- license to excludes separated by a|
.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
setExcludedLicenses
public void setExcludedLicenses(String excludedLicenses) throws org.apache.maven.plugin.MojoExecutionException Fill theexcludedLicenses
parameter from a simple string to split.- Parameters:
excludedLicenses
- license to excludes separated by a|
.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getHelper
-
failOnMissing
orfailOnBlacklist
.