Package org.codehaus.mojo.license.api
Class DefaultThirdPartyHelper
java.lang.Object
org.codehaus.mojo.license.api.DefaultThirdPartyHelper
- All Implemented Interfaces:
ThirdPartyHelper
Default implementation of the
ThirdPartyHelper
.- Since:
- 1.1
- Author:
- tchemit dev@tchemit.fr
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultThirdPartyHelper
(org.apache.maven.project.MavenProject project, String encoding, boolean verbose, DependenciesTool dependenciesTool, ThirdPartyTool thirdPartyTool, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositoriesCoreApi, List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories) Constructor of the helper. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Attach the third-party descriptor to the build.createLicenseMap
(SortedMap<String, org.apache.maven.project.MavenProject> dependencies) Creates a license map from given dependencies.createUnsafeMapping
(LicenseMap licenseMap, File missingFile, String missingFileUrl, boolean useRepositoryMissingFiles, SortedSet<org.apache.maven.project.MavenProject> unsafeDependencies, SortedMap<String, org.apache.maven.project.MavenProject> projectDependencies, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts) Loads unsafe mappings.Obtains the cache of loaded dependencies indexed by their gav.SortedSet
<org.apache.maven.project.MavenProject> getProjectsWithNoLicense
(LicenseMap licenseMap) Obtains all dependencies with no license form the given license map.loadDependencies
(MavenProjectDependenciesConfigurator configuration, ResolvedProjectDependencies dependencyArtifacts) Load all dependencies given the configuration asMavenProject
.loadThirdPartyDescriptorForUnsafeMapping
(Set<org.apache.maven.artifact.Artifact> topLevelDependencies, SortedSet<org.apache.maven.project.MavenProject> unsafeDependencies, Collection<org.apache.maven.project.MavenProject> projects, LicenseMap licenseMap) Try to load maximum of unsafe license mapping using third-party descriptors (from maven repositories) and return it.loadUnsafeMapping
(LicenseMap licenseMap, File missingFile, String missingFileUrl, SortedMap<String, org.apache.maven.project.MavenProject> projectDependencies) Load unsafe mapping for all dependencies with no license in their pom, we will load the missing file if it exists and also add all dependencies from licenseMap with no license known.void
mergeLicenses
(List<String> licenseMerges, LicenseMap licenseMap) Merges licenses.
-
Constructor Details
-
DefaultThirdPartyHelper
public DefaultThirdPartyHelper(org.apache.maven.project.MavenProject project, String encoding, boolean verbose, DependenciesTool dependenciesTool, ThirdPartyTool thirdPartyTool, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositoriesCoreApi, List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories) Constructor of the helper.- Parameters:
project
- Current maven projectencoding
- Encoding used to read and write filesverbose
- Verbose flagdependenciesTool
- tool to load dependenciesthirdPartyTool
- tool to load third-parties descriptorsremoteRepositoriesCoreApi
- maven remote repositories, in the core api formatremoteRepositories
- maven remote repositories
-
-
Method Details
-
getArtifactCache
Obtains the cache of loaded dependencies indexed by their gav.- Specified by:
getArtifactCache
in interfaceThirdPartyHelper
- Returns:
- the cache of loaded dependencies indexed by their gav
-
loadDependencies
public SortedMap<String,org.apache.maven.project.MavenProject> loadDependencies(MavenProjectDependenciesConfigurator configuration, ResolvedProjectDependencies dependencyArtifacts) Load all dependencies given the configuration asMavenProject
.- Specified by:
loadDependencies
in interfaceThirdPartyHelper
- Parameters:
configuration
- the configuration of the project and include/exclude to do on its dependenciesdependencyArtifacts
- the dependency artifacts of the project- Returns:
- the dictionary of loaded dependencies as
MavenProject
indexed by their gav.
-
loadThirdPartyDescriptorForUnsafeMapping
public SortedProperties loadThirdPartyDescriptorForUnsafeMapping(Set<org.apache.maven.artifact.Artifact> topLevelDependencies, SortedSet<org.apache.maven.project.MavenProject> unsafeDependencies, Collection<org.apache.maven.project.MavenProject> projects, LicenseMap licenseMap) throws ThirdPartyToolException, IOException Try to load maximum of unsafe license mapping using third-party descriptors (from maven repositories) and return it.- Specified by:
loadThirdPartyDescriptorForUnsafeMapping
in interfaceThirdPartyHelper
- Parameters:
topLevelDependencies
- project dependencies to scan for .license.properties files.unsafeDependencies
- all unsafe dependenciesprojects
- all projects where to read third parties descriptorslicenseMap
- license map where to store new licenses- Returns:
- the map of loaded missing from the remote missing third party files
- Throws:
ThirdPartyToolException
- if anyIOException
- if any
-
loadUnsafeMapping
public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, SortedMap<String, org.apache.maven.project.MavenProject> projectDependencies) throws IOException, org.apache.maven.plugin.MojoExecutionExceptionLoad unsafe mapping for all dependencies with no license in their pom, we will load the missing file if it exists and also add all dependencies from licenseMap with no license known.- Specified by:
loadUnsafeMapping
in interfaceThirdPartyHelper
- Parameters:
licenseMap
- the license map of all dependencies.missingFile
- location of an optional missing fille (says where you fix missing license).missingFileUrl
- location of an optional missing file extension that can be downloaded from some resource hoster and that will be merged with the content of the missing file.projectDependencies
- project dependencies used to detect which dependencies in the missing file are unknown to the project.- Returns:
- the map of all unsafe mapping
- Throws:
IOException
- if could not load missing fileorg.apache.maven.plugin.MojoExecutionException
-
createLicenseMap
public LicenseMap createLicenseMap(SortedMap<String, org.apache.maven.project.MavenProject> dependencies) Creates a license map from given dependencies.- Specified by:
createLicenseMap
in interfaceThirdPartyHelper
- Parameters:
dependencies
- dependencies to store in the license map- Returns:
- the created license map fro the given dependencies
-
attachThirdPartyDescriptor
Attach the third-party descriptor to the build.- Specified by:
attachThirdPartyDescriptor
in interfaceThirdPartyHelper
- Parameters:
file
- location of the third-party descriptor
-
getProjectsWithNoLicense
public SortedSet<org.apache.maven.project.MavenProject> getProjectsWithNoLicense(LicenseMap licenseMap) Obtains all dependencies with no license form the given license map.- Specified by:
getProjectsWithNoLicense
in interfaceThirdPartyHelper
- Parameters:
licenseMap
- license map where to find- Returns:
- all dependencies with no license
-
createUnsafeMapping
public SortedProperties createUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, boolean useRepositoryMissingFiles, SortedSet<org.apache.maven.project.MavenProject> unsafeDependencies, SortedMap<String, org.apache.maven.project.MavenProject> projectDependencies, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts) throws org.apache.maven.project.ProjectBuildingException, IOException, ThirdPartyToolException, org.apache.maven.plugin.MojoExecutionExceptionLoads unsafe mappings. Unsafe mappings are files that supply license metadata for artifacts that lack it in their POM models. It's called 'unsafe' because its safer to see actual metadata.There are three sources of this data:
- the 'missing' file.
- additional property files attached to artifacts; these have classifier=third-party and are expected to contain the license information the base artifact's dependencies. These are controlled by a parameter,
- declared dependencies of type license.properties. These are in the same format, and provide global information.
- Specified by:
createUnsafeMapping
in interfaceThirdPartyHelper
- Parameters:
licenseMap
- license map to readmissingFile
- location of an optional missing filemissingFileUrl
- location of an optional missing file extension that can be downloaded from some resource hoster and that will be merged with the content of the missing file.useRepositoryMissingFiles
- flag to use or not third-party descriptors via the 'third-party' classifier from maven repositoriesunsafeDependencies
- all unsafe dependenciesprojectDependencies
- all project dependenciesdependencyArtifacts
- all project dependency artifacts- Returns:
- the loaded unsafe mapping
- Throws:
org.apache.maven.project.ProjectBuildingException
- if could not build some dependencies maven projectIOException
- if could not load missing fileThirdPartyToolException
- if pb with third-party toolorg.apache.maven.plugin.MojoExecutionException
-
mergeLicenses
public void mergeLicenses(List<String> licenseMerges, LicenseMap licenseMap) throws org.apache.maven.plugin.MojoFailureException Merges licenses.- Specified by:
mergeLicenses
in interfaceThirdPartyHelper
- Parameters:
licenseMerges
- list of license mergeables (each entry is a list of licenses separated by |, the first one is the license to use for all the others of the entry).licenseMap
- license map to merge- Throws:
org.apache.maven.plugin.MojoFailureException
- if there is a bad license merge definition (says for example two license with same name)
-