![JAR search and dependency download from the Maven repository](/logo.png)
org.codehaus.mojo.license.AddThirdPartyMojo Maven / Gradle / Ivy
/**
* Copyright 2010-2012 The Kuali Foundation
*
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ecl2.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.mojo.license;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.mojo.license.model.LicenseMap;
/**
* Goal to generate the third-party license file.
*
* This file contains a list of the dependencies and their licenses. Each dependency and it's license is displayed on a
* single line in the format
*
*
* (<license-name>) <project-name> <groupId>:<artifactId>:<version> - <project-url>
*
*
* It will also copy it in the class-path (says add the generated directory as a resource of the build).
*
* @author tchemit
* @goal add-third-party
* @phase generate-resources
* @requiresDependencyResolution test
* @requiresProject true
* @since 1.0
*/
public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo implements MavenProjectDependenciesConfigurator {
/**
* Local Repository.
*
* @parameter expression="${localRepository}"
* @required
* @readonly
* @since 1.0.0
*/
protected ArtifactRepository localRepository;
/**
* Remote repositories used for the project.
*
* @parameter expression="${project.remoteArtifactRepositories}"
* @required
* @readonly
* @since 1.0.0
*/
protected List remoteRepositories;
/**
* Deploy the third party missing file in maven repository.
*
* @parameter expression="${license.deployMissingFile}" default-value="true"
* @since 1.0
*/
protected boolean deployMissingFile;
/**
* Load from repositories third party missing files.
*
* @parameter expression="${license.useRepositoryMissingFiles}" default-value="true"
* @since 1.0
*/
protected boolean useRepositoryMissingFiles;
/**
* dependencies tool.
*
* @component
* @readonly
* @since 1.0
*/
private DependenciesTool dependenciesTool;
/**
* Controls if THIRD-PARTY.properties gets created or not
*
* @parameter expression="${license.doGenerateMissing}" default-value="false"
*/
private boolean doGenerateMissing;
@Override
protected boolean checkPackaging() {
return rejectPackaging("pom");
}
@Override
protected SortedMap loadDependencies() {
return dependenciesTool.loadProjectDependencies(getProject(), this, localRepository, remoteRepositories,
getArtifactCache());
}
@Override
protected SortedProperties createUnsafeMapping() throws ProjectBuildingException, IOException,
ThirdPartyToolException {
SortedProperties unsafeMappings = getThridPartyTool().loadUnsafeMapping(getLicenseMap(), getArtifactCache(),
getEncoding(), getMissingFile());
SortedSet unsafeDependencies = getUnsafeDependencies();
getLog().debug("1.0");
if (CollectionUtils.isNotEmpty(unsafeDependencies)) {
// there is some unresolved license
getLog().debug("2.0");
if (isUseRepositoryMissingFiles()) {
// try to load missing third party files from dependencies
Collection projects = new ArrayList(getProjectDependencies().values());
projects.remove(getProject());
projects.removeAll(unsafeDependencies);
getLog().debug("2.1");
SortedProperties resolvedUnsafeMapping = new SortedProperties("UTF-8");
// The next few lines attempt to download groupid--artifactid--third-party.properties for every
// dependency in the tree
// getThridPartyTool().loadThirdPartyDescriptorsForUnsafeMapping(
// getEncoding(), projects, unsafeDependencies, getLicenseMap(), localRepository,
// remoteRepositories);
getLog().debug("2.2");
// push back resolved unsafe mappings
unsafeMappings.putAll(resolvedUnsafeMapping);
}
}
if (isVerbose()) {
getLog().info("found " + unsafeMappings.size() + " unsafe mappings");
}
// compute if missing file should be (re)-generate
boolean generateMissingfile = doGenerateMissing
&& computeDoGenerateMissingFile(unsafeMappings, unsafeDependencies);
setDoGenerateMissing(generateMissingfile);
if (generateMissingfile && isVerbose()) {
StringBuilder sb = new StringBuilder();
sb.append("Will use from missing file ");
sb.append(unsafeMappings.size());
sb.append(" dependencies :");
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy