Class AbstractDownloadLicensesMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.license.AbstractLicensesXmlMojo
org.codehaus.mojo.license.AbstractDownloadLicensesMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo, MavenProjectDependenciesConfigurator
Direct Known Subclasses:
AggregateDownloadLicensesMojo, DownloadLicensesMojo

public abstract class AbstractDownloadLicensesMojo extends AbstractLicensesXmlMojo implements MavenProjectDependenciesConfigurator
Created on 23/05/16.
Author:
Tony Chemit - chemit@codelutin.com
  • Field Details

    • remoteRepositories

      @Parameter(defaultValue="${project.remoteArtifactRepositories}", readonly=true) protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories
      List of Remote Repositories used by the resolver
      Since:
      1.0
    • licensesConfigFile

      @Parameter(property="licensesConfigFile", defaultValue="${project.basedir}/src/license/licenses.xml") protected File licensesConfigFile
      A file containing the license data (most notably license names and license URLs) missing in 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:

      Since:
      1.0
    • licensesOutputDirectory

      @Parameter(property="licensesOutputDirectory", defaultValue="${project.build.directory}/generated-resources/licenses") protected File licensesOutputDirectory
      The directory to which the dependency licenses should be written.
      Since:
      1.0
    • errorRemedy

      @Parameter(property="license.errorRemedy", defaultValue="warn") protected AbstractDownloadLicensesMojo.ErrorRemedy errorRemedy
      What to do on any license download related error. The possible values are:
    • Since:
      1.18
    • organizeLicensesByDependencies

      @Parameter(property="license.organizeLicensesByDependencies", defaultValue="false") protected boolean organizeLicensesByDependencies
      A 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 project
      The Maven Project Object
      Since:
      1.0
    • licenseUrlReplacements

      @Parameter protected List<LicenseUrlReplacement> 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 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:

      Since:
      1.17
    • useDefaultUrlReplacements

      @Parameter(property="license.useDefaultUrlReplacements", defaultValue="false") 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.

      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.

      Since:
      1.20
      See Also:
    • licenseUrlFileNames

      @Parameter protected Map<String,String> 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 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:

      Since:
      1.18
    • licenseUrlFileNameSanitizers

      @Parameter protected List<LicenseUrlReplacement> 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 licensesExcelOutputFile
      The Excel output file used if writeExcelFile is true, containing a mapping between each dependency and its license information. With extended information, if available.
      Since:
      2.4.0
      See Also:
      • writeExcelFile
      • AggregateDownloadLicensesMojo.extendedInfo
    • licensesCalcOutputFile

      @Parameter(property="license.licensesCalcOutputFile", defaultValue="${project.build.directory}/generated-resources/licenses.ods") protected File licensesCalcOutputFile
      The Calc output file used if writeCalcFile is true, containing a mapping between each dependency and its license information. With extended information, if available.
      Since:
      2.4.0
      See Also:
      • writeCalcFile
      • AggregateDownloadLicensesMojo.extendedInfo
  • Constructor Details

    • AbstractDownloadLicensesMojo

      public AbstractDownloadLicensesMojo()
  • Method Details