Class AbstractAddThirdPartyMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.license.AbstractLicenseMojo
org.codehaus.mojo.license.AbstractAddThirdPartyMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
AddThirdPartyMojo, AggregatorAddThirdPartyMojo

public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo
Abstract mojo for all third-party mojos.
Since:
1.0
Author:
tchemit dev@tchemit.fr
  • Field Details

    • outputDirectory

      @Parameter(property="license.outputDirectory", defaultValue="${project.build.directory}/generated-sources/license", required=true) protected File outputDirectory
      Directory where to generate files.
      Since:
      1.0
    • deployMissingFile

      @Parameter(property="license.deployMissingFile", defaultValue="true") protected boolean deployMissingFile
      Attach 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 useRepositoryMissingFiles
      Load 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 acceptPomPackaging
      If true the mojo will be executed for reactor projects having any packaging (including pom); otherwise the mojo will be executed only for projects that do not have packaging pom.

      Since 1.18, when acceptPomPackaging is true, 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, when acceptPomPackaging was true, 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 excludedScopes
      A 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

      @Parameter(property="license.includedScopes") protected String 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

      @Parameter(property="license.excludedTypes") protected String 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

      @Parameter(property="license.includedTypes") protected String 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

      @Parameter(property="license.excludedGroups") protected String 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

      @Parameter(property="license.includedGroups") protected String 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

      @Parameter(property="license.excludedArtifacts") protected String 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

      @Parameter(property="license.includedArtifacts") protected String 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 thirdPartyFilename
      File where to write the third-party file.
      Since:
      1.0
    • useMissingFile

      @Parameter(property="license.useMissingFile", defaultValue="false") protected boolean useMissingFile
      A 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 missingFile
      The file to write with a license information template for dependencies with unknown license.
      Since:
      1.0
    • missingFileUrl

      @Parameter(property="license.missingFileUrl") protected String missingFileUrl
      The Url that holds the missing license dependency entries. This is an extension to missingFile. 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 missingLicensesFileArtifact
      To resolve third party licenses from an artifact.
      Since:
      1.14
    • resolvedOverrideUrl

      protected String resolvedOverrideUrl
      A URL prepared either our of overrideFile or overrideUrl or the default value.
      See Also:
    • licenseMerges

      @Parameter protected List<String> 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 @Parameter(property="license.licenseMergesFile") protected String licenseMergesFile
      Deprecated.
      prefer use now licenseMergesUrl
      The file with the merge licenses in order to be used by command line. Note: This option overrides licenseMerges.
      Since:
      1.15
    • licenseMergesUrl

      @Parameter(property="license.licenseMergesUrl") protected String licenseMergesUrl
      Location of file with the merge licenses in order to be used by command line. Note: This option overrides licenseMerges.
      Since:
      1.17
    • includedLicenses

      @Parameter(property="license.includedLicenses") protected AbstractAddThirdPartyMojo.IncludedLicenses includedLicenses
      To specify some licenses to include.

      If this parameter is filled and a license is not in this whitelist 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:
         <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
        empty lines will be ignored.
      Since:
      1.1
    • excludedLicenses

      @Parameter(property="license.excludedLicenses") protected AbstractAddThirdPartyMojo.ExcludedLicenses excludedLicenses
      To 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
        empty lines will be ignored.
      Since:
      1.1
    • bundleThirdPartyPath

      @Parameter(property="license.bundleThirdPartyPath", defaultValue="META-INF/${project.artifactId}-THIRD-PARTY.txt") protected String bundleThirdPartyPath
      The path of the bundled third party file to produce when generateBundle is on.

      Note: This option is not available for pom module types.

      Since:
      1.0
    • generateBundle

      @Parameter(property="license.generateBundle", defaultValue="false") protected boolean generateBundle
      A 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 force
      To 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 failIfWarning
      Deprecated.
      since 1.14, use now failOnMissing or failOnBlacklist.
      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 failOnMissing
      A 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 failOnBlacklist
      A flag to fail the build if at least one dependency was blacklisted.
      Since:
      1.14
    • sortArtifactByName

      @Parameter(property="license.sortArtifactByName", defaultValue="false") protected boolean sortArtifactByName
      A 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 fileTemplate
      Template 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> dependencies
      The set of dependencies for the current project, used to locate license databases.
    • projectDependencies

      protected SortedMap<String,org.apache.maven.project.MavenProject> projectDependencies
    • licenseMap

      protected LicenseMap licenseMap
    • unsafeDependencies

      protected SortedSet<org.apache.maven.project.MavenProject> unsafeDependencies
    • unsafeMappings

      protected SortedProperties unsafeMappings
    • doGenerate

      protected boolean doGenerate
      Flag computed in the init() method to know if there is something has to be generated.
    • doGenerateBundle

      protected boolean doGenerateBundle
      Flag computed in the init() method to know if a bundle version has to be generated.
    • artifactFiltersUrl

      @Parameter(property="license.artifactFiltersUrl") protected String 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

      public AbstractAddThirdPartyMojo()
  • Method Details

    • loadDependencies

      protected abstract SortedMap<String,org.apache.maven.project.MavenProject> loadDependencies() throws DependenciesToolException
      Loads the dependencies of the project (as MavenProject, 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, DependenciesToolException
      Creates 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 dependencies
      IOException - if could not load missing file
      ThirdPartyToolException - for third party tool error
      DependenciesToolException - if the dependencies could not be loaded
      org.apache.maven.plugin.MojoExecutionException
    • init

      protected void init() throws Exception
      Method to initialize the mojo before doing any concrete actions. Note: The method is invoked before the AbstractLicenseMojo.doAction() method.
      Specified by:
      init in class AbstractLicenseMojo
      Throws:
      Exception - if any
    • setIncludedLicenses

      public void setIncludedLicenses(String includedLicenses) throws org.apache.maven.plugin.MojoExecutionException
      Fill the includedLicenses 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 the excludedLicenses parameter from a simple string to split.
      Parameters:
      excludedLicenses - license to excludes separated by a |.
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • getHelper

      protected ThirdPartyHelper getHelper()