public abstract class AbstractDownloadLicensesMojo extends AbstractLicensesXmlMojo implements MavenProjectDependenciesConfigurator
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractDownloadLicensesMojo.ErrorRemedy
What to do in case of a license download error.
|
| Modifier and Type | Field and Description |
|---|---|
protected AbstractDownloadLicensesMojo.ErrorRemedy |
errorRemedy
What to do on any license download related error.
|
protected File |
licensesConfigFile
A file containing the license data (most notably license names and license URLs) missing in
pom.xml files of the dependencies. |
protected File |
licensesOutputDirectory
The directory to which the dependency licenses should be written.
|
protected Map<String,String> |
licenseUrlFileNames
A map that helps to select local files names for the content downloaded from license URLs.
|
protected List<LicenseUrlReplacement> |
licenseUrlFileNameSanitizers
A list of regexp:replacement pairs that should be applied to file names for storing licenses.
|
protected List<LicenseUrlReplacement> |
licenseUrlReplacements
List of regexps/replacements applied to the license urls prior to download.
|
protected org.apache.maven.artifact.repository.ArtifactRepository |
localRepository
Location of the local repository.
|
protected boolean |
organizeLicensesByDependencies
A flag to organize the licenses by dependencies.
|
protected org.apache.maven.project.MavenProject |
project
The Maven Project Object
|
protected List<org.apache.maven.artifact.repository.ArtifactRepository> |
remoteRepositories
List of Remote Repositories used by the resolver
|
protected boolean |
useDefaultUrlReplacements
If
true the default license URL replacements be added to the internal Map of URL replacements
before adding licenseUrlReplacements by their id; otherwise the default license URL replacements
will not be added to the internal Map of URL replacements. |
dependenciesTool, licensesOutputFile, licensesOutputFileEol| Constructor and Description |
|---|
AbstractDownloadLicensesMojo() |
| Modifier and Type | Method and Description |
|---|---|
void |
execute() |
ArtifactFilters |
getArtifactFilters() |
protected Path[] |
getAutodetectEolFiles() |
protected abstract Map<String,LicensedArtifact> |
getDependencies() |
protected org.apache.maven.project.MavenProject |
getProject() |
boolean |
isExcludeTransitiveDependencies() |
boolean |
isIncludeTransitiveDependencies() |
protected abstract boolean |
isSkip() |
boolean |
isVerbose() |
getEncoding, writeLicenseSummary@Parameter(defaultValue="${localRepository}",
readonly=true)
protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
@Parameter(defaultValue="${project.remoteArtifactRepositories}",
readonly=true)
protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories
@Parameter(property="licensesConfigFile",
defaultValue="${project.basedir}/src/license/licenses.xml")
protected File licensesConfigFile
pom.xml files of the dependencies.
Note that since 1.18, if you set errorRemedy to xmlOutput the format of
licensesErrorsFile is the same as the one of licensesConfigFile. So you can use
licensesErrorsFile as a base for licensesConfigFile.
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:
licensesConfigFile is applied before
licenseUrlReplacementslicenseUrlReplacements are applied before licenseUrlFileNameslicenseUrlFileNames have higher precedence than <file> elements in
licensesConfigFilelicenseUrlFileNames are ignored when organizeLicensesByDependencies is true@Parameter(property="licensesOutputDirectory",
defaultValue="${project.build.directory}/generated-resources/licenses")
protected File licensesOutputDirectory
@Parameter(property="license.errorRemedy",
defaultValue="warn")
protected AbstractDownloadLicensesMojo.ErrorRemedy errorRemedy
AbstractDownloadLicensesMojo.ErrorRemedy.ignore: all errors are ignoredAbstractDownloadLicensesMojo.ErrorRemedy.warn: all errors are output to the log as warningsAbstractDownloadLicensesMojo.ErrorRemedy.failFast: a MojoFailureException is thrown on the first download related
errorAbstractDownloadLicensesMojo.ErrorRemedy.xmlOutput: error messages are added as <downloaderMessages> to
licensesErrorsFile; in case there are error messages, the build will
fail after processing all dependencies@Parameter(property="license.organizeLicensesByDependencies",
defaultValue="false")
protected boolean organizeLicensesByDependencies
@Parameter(defaultValue="${project}",
readonly=true)
protected org.apache.maven.project.MavenProject project
@Parameter protected List<LicenseUrlReplacement> licenseUrlReplacements
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 to
licenseUrlReplacements
The id field of LicenseUrlReplacement 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:
useDefaultUrlReplacements to true.licensesConfigFile is applied before
licenseUrlReplacementslicenseUrlReplacements are applied before licenseUrlFileNameslicenseUrlFileNames have higher precedence than <file> elements in
licensesConfigFilelicenseUrlFileNames are ignored when organizeLicensesByDependencies is true@Parameter(property="license.useDefaultUrlReplacements",
defaultValue="false")
protected boolean useDefaultUrlReplacements
true the default license URL replacements be added to the internal Map of URL replacements
before adding licenseUrlReplacements by their id; otherwise the default license URL replacements
will not be added to the internal Map of URL replacements.
Any individual URL replacement from the set of default URL replacements can be overriden via
licenseUrlReplacements if the same id is used in licenseUrlReplacements.
To view the list of default URL replacements, set useDefaultUrlReplacements to true 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.
licenseUrlReplacements@Parameter protected Map<String,String> licenseUrlFileNames
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 using Pattern.CASE_INSENSITIVE. Note that various
characters that commonly occur in URLs have special meanings in regular extensions. Therefore, consider using
regex quoting as described in Pattern - 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 is true. 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:
licensesConfigFile is applied before
licenseUrlReplacementslicenseUrlReplacements are applied before licenseUrlFileNameslicenseUrlFileNames have higher precedence than <file> elements in
licensesConfigFilelicenseUrlFileNames are ignored when organizeLicensesByDependencies is true@Parameter protected List<LicenseUrlReplacement> licenseUrlFileNameSanitizers
Note that these patterns are not applied to file names defined in licenseUrlFileNames.
protected abstract boolean isSkip()
protected org.apache.maven.project.MavenProject getProject()
protected abstract Map<String,LicensedArtifact> getDependencies()
public void execute()
throws org.apache.maven.plugin.MojoExecutionException,
org.apache.maven.plugin.MojoFailureException
execute in interface org.apache.maven.plugin.Mojoorg.apache.maven.plugin.MojoFailureExceptionorg.apache.maven.plugin.MojoExecutionExceptionpublic boolean isIncludeTransitiveDependencies()
isIncludeTransitiveDependencies in interface MavenProjectDependenciesConfiguratortrue if should include transitive dependencies, false to include only direct
dependencies.public boolean isExcludeTransitiveDependencies()
isExcludeTransitiveDependencies in interface MavenProjectDependenciesConfiguratortrue if should exclude transitive dependencies from excluded artifacts, else false.public ArtifactFilters getArtifactFilters()
getArtifactFilters in interface MavenProjectDependenciesConfiguratorArtifactFilters to apply when processing dependenciespublic boolean isVerbose()
isVerbose in interface MavenProjectDependenciesConfiguratortrue if verbose mode is on, false otherwise.protected Path[] getAutodetectEolFiles()
getAutodetectEolFiles in class AbstractLicensesXmlMojoCopyright © 2010–2019 MojoHaus. All rights reserved.