Class AbstractDownloadLicensesMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
,MavenProjectDependenciesConfigurator
- Direct Known Subclasses:
AggregateDownloadLicensesMojo
,DownloadLicensesMojo
- Author:
- Tony Chemit - chemit@codelutin.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
What to do in case of a license download error. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractDownloadLicensesMojo.ErrorRemedy
What to do on any license download related error.protected File
The Calc output file used ifwriteCalcFile
is true, containing a mapping between each dependency and its license information.protected File
A file containing the license data (most notably license names and license URLs) missing inpom.xml
files of the dependencies.protected File
The Excel output file used ifwriteExcelFile
is true, containing a mapping between each dependency and its license information.protected File
The directory to which the dependency licenses should be written.A map that helps to select local files names for the content downloaded from license URLs.protected List
<LicenseUrlReplacement> A list of regexp:replacement pairs that should be applied to file names for storing licenses.protected List
<LicenseUrlReplacement> List of regexps/replacements applied to the license urls prior to download.protected boolean
A flag to organize the licenses by dependencies.protected org.apache.maven.project.MavenProject
The Maven Project Objectprotected List
<org.apache.maven.artifact.repository.ArtifactRepository> List of Remote Repositories used by the resolverprotected boolean
Iftrue
the default license URL replacements be added to the internalMap
of URL replacements before addinglicenseUrlReplacements
by theirid
; otherwise the default license URL replacements will not be added to the internalMap
of URL replacements.Fields inherited from class org.codehaus.mojo.license.AbstractLicensesXmlMojo
licensedArtifactResolver, licensesOutputFile, licensesOutputFileEol
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractDownloadLicensesMojo
(LicensedArtifactResolver licensedArtifactResolver) -
Method Summary
Methods inherited from class org.codehaus.mojo.license.AbstractLicensesXmlMojo
getEncoding, writeLicenseSummary
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
remoteRepositories
@Parameter(defaultValue="${project.remoteArtifactRepositories}", readonly=true) protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositoriesList of Remote Repositories used by the resolver- Since:
- 1.0
-
licensesConfigFile
@Parameter(property="licensesConfigFile", defaultValue="${project.basedir}/src/license/licenses.xml") protected File licensesConfigFileA file containing the license data (most notably license names and license URLs) missing inpom.xml
files of the dependencies.Note that since 1.18, if you set
errorRemedy
toxmlOutput
the format oflicensesErrorsFile
is the same as the one oflicensesConfigFile
. So you can uselicensesErrorsFile
as a base forlicensesConfigFile
.Since 1.18, the format of the file is as follows:
<licenseSummary> <dependencies> <dependency> <groupId>\Qaopalliance\E</groupId><!-- A regular expression --> <artifactId>\Qaopalliance\E</artifactId><!-- A regular expression --> <!-- <version>.*</version> A version pattern is optional, .* being the default. <matchLicenses> <!-- Match a list of licenses with a single entry having name "Public Domain" --> <license> <name>\QPublic Domain\E</name><!-- A regular expression --> </license> </matchLicenses> <licenses approved="true" /><!-- Leave the matched dependency as is. --> <!-- In this particular case we approve that code in the Public --> <!-- Domain does not need any license URL. --> </dependency> <dependency> <groupId>\Qasm\E</groupId> <artifactId>\Qasm\E</artifactId> <matchLicenses> <!-- Match an empty list of licenses --> </matchLicenses> <!-- Replace the list of licenses in all matching dependencies with the following licenses --> <licenses> <license> <name>BSD 3-Clause ASM</name> <url>https://gitlab.ow2.org/asm/asm/raw/ASM_3_1_MVN/LICENSE.txt</url> </license> </licenses> </dependency> <dependency> <groupId>\Qca.uhn.hapi\E</groupId> <artifactId>.*</artifactId> <matchLicenses> <!-- Match a list of licenses with the following three entries in order: --> <license> <name>\QHAPI is dual licensed (MPL, GPL)\E</name> <comments>\QHAPI is dual licensed under both the Mozilla Public License and the GNU General Public License.\E\s+\QWhat this means is that you may choose to use HAPI under the terms of either license.\E\s+\QYou are both permitted and encouraged to use HAPI, royalty-free, within your applications,\E\s+\Qwhether they are free/open-source or commercial/closed-source, provided you abide by the\E\s+\Qterms of one of the licenses below.\E\s+\QYou are under no obligations to inform the HAPI project about what you are doing with\E\s+\QHAPI, but we would love to hear about it anyway!\E</comments> </license> <license> <name>\QMozilla Public License 1.1\E</name> <url>\Qhttp://www.mozilla.org/MPL/MPL-1.1.txt\E</url> <file>\Qmozilla public license 1.1 - index.0c5913925d40.txt\E</file> </license> <license> <name>\QGNU General Public License\E</name> <url>\Qhttp://www.gnu.org/licenses/gpl.txt\E</url> <file>\Qgnu general public license - gpl.txt\E</file> </license> </matchLicenses> <licenses approved="true" /><!-- It is OK that the first entry has no URL --> </dependency> </dependencies> </licenseSummary>
Before 1.18 the format was the same as the one of
AbstractLicensesXmlMojo.licensesOutputFile
and the groupIds and artifactIds were matched as plain text rather than regular expressions. No other elements (incl. versions) were matched at all. Since 1.18 the backwards compatibility is achieved by falling back to plain text matching of groupIds and artifactIds if the given<dependency>
does not contain the<matchLicenses>
element.Relationship to other parameters:
- License names and license URLs
licensesConfigFile
is applied beforelicenseUrlReplacements
licenseUrlReplacements
are applied beforelicenseUrlFileNames
licenseUrlFileNames
have higher precedence than<file>
elements inlicensesConfigFile
licenseUrlFileNames
are ignored whenorganizeLicensesByDependencies
istrue
- Since:
- 1.0
- License names and license URLs
-
licensesOutputDirectory
@Parameter(property="licensesOutputDirectory", defaultValue="${project.build.directory}/generated-resources/licenses") protected File licensesOutputDirectoryThe directory to which the dependency licenses should be written.- Since:
- 1.0
-
errorRemedy
@Parameter(property="license.errorRemedy", defaultValue="warn") protected AbstractDownloadLicensesMojo.ErrorRemedy errorRemedyWhat to do on any license download related error. The possible values are:AbstractDownloadLicensesMojo.ErrorRemedy.ignore
: all errors are ignoredAbstractDownloadLicensesMojo.ErrorRemedy.warn
: all errors are output to the log as warningsAbstractDownloadLicensesMojo.ErrorRemedy.failFast
: aMojoFailureException
is thrown on the first download related errorAbstractDownloadLicensesMojo.ErrorRemedy.xmlOutput
: error messages are added as<downloaderMessages>
tolicensesErrorsFile
; in case there are error messages, the build will fail after processing all dependencies- Since:
- 1.18
-
organizeLicensesByDependencies
@Parameter(property="license.organizeLicensesByDependencies", defaultValue="false") protected boolean organizeLicensesByDependenciesA flag to organize the licenses by dependencies. When this is done, each dependency will get its full license file, even if already downloaded for another dependency.- Since:
- 1.9
-
project
@Parameter(defaultValue="${project}", readonly=true) protected org.apache.maven.project.MavenProject projectThe Maven Project Object- Since:
- 1.0
-
licenseUrlReplacements
List of regexps/replacements applied to the license urls prior to download.License urls that match a regular expression will be replaced by the corresponding replacement. Replacement is performed with
java.util.regex.Matcher#replaceAll(String)
so you can take advantage of capturing groups to facilitate flexible transformations.If the replacement element is omitted, this is equivalent to an empty replacement string.
The replacements are applied in the same order as they are present in the configuration. The default replacements (that can be activated via
useDefaultUrlReplacements
) are appended tolicenseUrlReplacements
The
id
field ofLicenseUrlReplacement
is optional and is useful only if you want to override some of the default replacements.<licenseUrlReplacements> <licenseUrlReplacement> <regexp>\Qhttps://glassfish.java.net/public/CDDL+GPL_1_1.html\E</regexp> <replacement>https://oss.oracle.com/licenses/CDDL+GPL-1.1</replacement> </licenseUrlReplacement> <licenseUrlReplacement> <regexp>https://(.*)</regexp><!-- replace https with http --> <replacement>http://$1</replacement> </licenseUrlReplacement> <licenseUrlReplacement> <id>github.com-0</id><!-- An optional id to override the default replacement with the same id --> <regexp>^https?://github\.com/([^/]+)/([^/]+)/blob/(.*)$</regexp><!-- replace GitHub web UI with raw --> <replacement>https://raw.githubusercontent.com/$1/$2/$3</replacement> </licenseUrlReplacement> </licenseUrlReplacements>
Relationship to other parameters:
- Default URL replacements can be unlocked by setting
useDefaultUrlReplacements
totrue
. - License names and license URLs
licensesConfigFile
is applied beforelicenseUrlReplacements
licenseUrlReplacements
are applied beforelicenseUrlFileNames
licenseUrlFileNames
have higher precedence than<file>
elements inlicensesConfigFile
licenseUrlFileNames
are ignored whenorganizeLicensesByDependencies
istrue
- Since:
- 1.17
- Default URL replacements can be unlocked by setting
-
useDefaultUrlReplacements
@Parameter(property="license.useDefaultUrlReplacements", defaultValue="false") protected boolean useDefaultUrlReplacementsIftrue
the default license URL replacements be added to the internalMap
of URL replacements before addinglicenseUrlReplacements
by theirid
; otherwise the default license URL replacements will not be added to the internalMap
of URL replacements.Any individual URL replacement from the set of default URL replacements can be overriden via
licenseUrlReplacements
if the sameid
is used inlicenseUrlReplacements
.To view the list of default URL replacements, set
useDefaultUrlReplacements
totrue
and run the mojo with debug log level, e.g. using-X
or {-Dorg.slf4j.simpleLogger.log.org.codehaus.mojo.license=debug} on the command line.- Since:
- 1.20
- See Also:
-
licenseUrlFileNames
A map that helps to select local files names for the content downloaded from license URLs.Keys in the map are the local file names. These files will be created under
licensesOutputDirectory
.Values are white space (
" \t\n\r"
) separated lists of regular expressions that will be used to match license URLs. The regular expressions are compiled usingPattern.CASE_INSENSITIVE
. Note that various characters that commonly occur in URLs have special meanings in regular extensions. Therefore, consider using regex quoting as described inPattern
- e.g.http://example\.com
or\Qhttp://example.com\E
In addition to URL patterns, the list can optionally contain a sha1 checksum of the expected content. This is to ensure that the content delivered by a URL does not change without notice. Note that strict checking of the checksum happens only when
forceDownload
istrue
. Otherwise the mojo assumes that the URL -> local name mapping is correct and downloads from the URL only if the local file does not exist.A special value-less entry
<spdx/>
can be used to activate built-in license names that are based on license IDs from https://spdx.org/licenses. The built-in SPDX mappings can be overridden by the subsequent entries. To see which SPDX mappings are built-in, add the<spdx/>
entry and run the mojo with debug log level, e.g. using-X
or {-Dorg.slf4j.simpleLogger.log.org.codehaus.mojo.license=debug} on the command line.An example:
<licenseUrlFileNames> <spdx/><!-- A special element to activate built-in file name entries based on spdx.org license IDs --> <bsd-antlr.html> sha1:81ffbd1712afe8cdf138b570c0fc9934742c33c1 https?://(www\.)?antlr\.org/license\.html </bsd-antlr.html> <cddl-gplv2-ce.txt> sha1:534a3fc9ae1076409bb00d01127dbba1e2620e92 \Qhttps://raw.githubusercontent.com/javaee/activation/master/LICENSE.txt\E </cddl-gplv2-ce.txt> </licenseUrlFileNames>
Relationship to other parameters:
- License names and license URLs
licensesConfigFile
is applied beforelicenseUrlReplacements
licenseUrlReplacements
are applied beforelicenseUrlFileNames
licenseUrlFileNames
have higher precedence than<file>
elements inlicensesConfigFile
licenseUrlFileNames
are ignored whenorganizeLicensesByDependencies
istrue
- Since:
- 1.18
- License names and license URLs
-
licenseUrlFileNameSanitizers
A list of regexp:replacement pairs that should be applied to file names for storing licenses.Note that these patterns are not applied to file names defined in
licenseUrlFileNames
.- Since:
- 1.18
-
licensesExcelOutputFile
@Parameter(property="license.licensesExcelOutputFile", defaultValue="${project.build.directory}/generated-resources/licenses.xlsx") protected File licensesExcelOutputFileThe Excel output file used ifwriteExcelFile
is true, containing a mapping between each dependency and its license information. With extended information, if available.- Since:
- 2.4.0
- See Also:
-
licensesCalcOutputFile
@Parameter(property="license.licensesCalcOutputFile", defaultValue="${project.build.directory}/generated-resources/licenses.ods") protected File licensesCalcOutputFileThe Calc output file used ifwriteCalcFile
is true, containing a mapping between each dependency and its license information. With extended information, if available.- Since:
- 2.4.0
- See Also:
-
-
Constructor Details
-
AbstractDownloadLicensesMojo
-
-
Method Details
-
isSkip
protected abstract boolean isSkip() -
getProject
protected org.apache.maven.project.MavenProject getProject() -
getDependencies
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Specified by:
execute
in interfaceorg.apache.maven.plugin.Mojo
- Throws:
org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
-
isIncludeTransitiveDependencies
public boolean isIncludeTransitiveDependencies()- Specified by:
isIncludeTransitiveDependencies
in interfaceMavenProjectDependenciesConfigurator
- Returns:
true
if should include transitive dependencies,false
to include only direct dependencies.
-
isExcludeTransitiveDependencies
public boolean isExcludeTransitiveDependencies()- Specified by:
isExcludeTransitiveDependencies
in interfaceMavenProjectDependenciesConfigurator
- Returns:
true
if should exclude transitive dependencies from excluded artifacts, elsefalse
.
-
getArtifactFilters
- Specified by:
getArtifactFilters
in interfaceMavenProjectDependenciesConfigurator
- Returns:
ArtifactFilters
to apply when processing dependencies
-
isVerbose
public boolean isVerbose()- Specified by:
isVerbose
in interfaceMavenProjectDependenciesConfigurator
- Returns:
true
if verbose mode is on,false
otherwise.
-
getAutodetectEolFiles
- Overrides:
getAutodetectEolFiles
in classAbstractLicensesXmlMojo
-