Maven-license-plugin-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
June 2010
- 1 participants
- 28 discussions
25 Jun '10
Author: tchemit
Date: 2010-06-25 15:30:21 +0200 (Fri, 25 Jun 2010)
New Revision: 1778
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1778
Log:
finalize the two add-third-party goals
Modified:
trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java
trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java
trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java
Modified: trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-06-25 11:51:13 UTC (rev 1777)
+++ trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-06-25 13:30:21 UTC (rev 1778)
@@ -36,15 +36,19 @@
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
/**
- * Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de
- * toutes les dependances du projet) dans le classpath (et le generer s'il
- * n'existe pas).
+ * Goal to generate the THIRD-PARTY.txt file which resumes all dependencies with
+ * their licenses.
+ * <p/>
+ * It also add it in class-path.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.3
@@ -73,10 +77,10 @@
/**
* A flag to use the missing licenses file to consolidate the THID-PARTY file.
*
- * @parameter expression="${license.useMissingfile}" default-value="false"
+ * @parameter expression="${license.useMissingFile}" default-value="false"
* @since 2.3
*/
- protected boolean useMissingfile;
+ protected boolean useMissingFile;
/**
* The file where to fill the license for dependencies with unknwon license.
@@ -107,6 +111,14 @@
protected boolean generateBundle;
/**
+ * Un flag pour forcer la generation.
+ *
+ * @parameter expression="${license.force}" default-value="false"
+ * @since 1.0.0
+ */
+ protected boolean force;
+
+ /**
* A flag to fail the build if at least one dependency was detected without a license.
*
* @parameter expression="${license.failIfWarning}" default-value="false"
@@ -135,6 +147,10 @@
private SortedProperties unsafeMappings;
+ private boolean doGenerate;
+
+ private boolean doGenerateBundle;
+
public static final String NO_DEPENDENCIES_MESSAGE = "the project has no dependencies.";
private static SortedMap<String, MavenProject> artifactCache;
@@ -151,6 +167,17 @@
protected abstract SortedProperties createUnsafeMapping() throws ProjectBuildingException, IOException;
@Override
+ protected boolean checkSkip() {
+ if (!isDoGenerate() &&
+ !isDoGenerateBundle()) {
+
+ getLog().info("All files are up to date, skip goal execution.");
+ return false;
+ }
+ return super.checkSkip();
+ }
+
+ @Override
protected void init() throws Exception {
Log log = getLog();
@@ -165,12 +192,31 @@
setThirdPartyFile(file);
+ setDoGenerate(isForce() || !file.exists() || !isFileNewerThanPomFile(file));
+
+ if (isGenerateBundle()) {
+
+ File bundleFile =
+ PluginHelper.getFile(getOutputDirectory(), getBundleThirdPartyPath());
+
+ setDoGenerateBundle(isForce() ||
+ !bundleFile.exists() ||
+ !isFileNewerThanPomFile(bundleFile) ||
+ file.lastModified() > bundleFile.lastModified());
+ } else {
+
+ // not generating bundled file
+ setDoGenerateBundle(false);
+ }
+
licenseMap = createLicenseMap();
licenseMap.setLog(log);
unsafeDependencies = licenseMap.getUnsafeDependencies();
- if (CollectionUtils.isEmpty(unsafeDependencies) || !isUseMissingfile()) {
+ if (CollectionUtils.isEmpty(unsafeDependencies) ||
+ !isUseMissingFile() ||
+ !isDoGenerate()) {
// no unsafe dependencies
// or user does not ask to generate missing file
@@ -182,82 +228,6 @@
unsafeMappings = createUnsafeMapping();
}
- public File getOutputDirectory() {
- return outputDirectory;
- }
-
- public String getThirdPartyFilename() {
- return thirdPartyFilename;
- }
-
- public String getBundleThirdPartyPath() {
- return bundleThirdPartyPath;
- }
-
- public boolean isGenerateBundle() {
- return generateBundle;
- }
-
- public boolean isFailIfWarning() {
- return failIfWarning;
- }
-
- public SortedSet<MavenProject> getUnsafeDependencies() {
- return unsafeDependencies;
- }
-
- public File getThirdPartyFile() {
- return thirdPartyFile;
- }
-
- public LicenseMap getLicenseMap() {
- return licenseMap;
- }
-
- public void setOutputDirectory(File outputDirectory) {
- this.outputDirectory = outputDirectory;
- }
-
- public void setThirdPartyFilename(String thirdPartyFilename) {
- this.thirdPartyFilename = thirdPartyFilename;
- }
-
- public void setBundleThirdPartyPath(String bundleThirdPartyPath) {
- this.bundleThirdPartyPath = bundleThirdPartyPath;
- }
-
- public void setGenerateBundle(boolean generateBundle) {
- this.generateBundle = generateBundle;
- }
-
- public void setThirdPartyFile(File thirdPartyFile) {
- this.thirdPartyFile = thirdPartyFile;
- }
-
- public boolean isUseMissingfile() {
- return useMissingfile;
- }
-
- public File getMissingFile() {
- return missingFile;
- }
-
- public void setUseMissingfile(boolean useMissingfile) {
- this.useMissingfile = useMissingfile;
- }
-
- public void setMissingFile(File missingFile) {
- this.missingFile = missingFile;
- }
-
- public void setFailIfWarning(boolean failIfWarning) {
- this.failIfWarning = failIfWarning;
- }
-
- public SortedProperties getUnsafeMappings() {
- return unsafeMappings;
- }
-
protected boolean checkUnsafeDependencies() {
SortedSet<MavenProject> unsafeDependencies = getUnsafeDependencies();
boolean unsafe = !CollectionUtils.isEmpty(unsafeDependencies);
@@ -304,13 +274,13 @@
return sb.toString();
}
- protected void writeThirdPartyFile(boolean generate, boolean generateBundle) throws IOException {
+ protected void writeThirdPartyFile() throws IOException {
Log log = getLog();
LicenseMap licenseMap = getLicenseMap();
File target = getThirdPartyFile();
- if (generate) {
+ if (isDoGenerate()) {
StringBuilder sb = new StringBuilder();
if (licenseMap.isEmpty()) {
sb.append(NO_DEPENDENCIES_MESSAGE);
@@ -336,19 +306,26 @@
// group by dependencies
SortedMap<MavenProject, String[]> map = licenseMap.toDependencyMap();
- sb.append("List of ").append(map.size()).append(" third-party dependencies.\n\n");
+ sb.append("List of ").append(map.size()).append(" third-party dependencies.\n");
- String format = "\n%1$s %2$s";
+ List<String> lines = new ArrayList<String>();
+
for (Map.Entry<MavenProject, String[]> entry : map.entrySet()) {
String artifact = getArtifactName(entry.getKey());
StringBuilder buffer = new StringBuilder();
for (String license : entry.getValue()) {
buffer.append(" (").append(license).append(")");
}
-
String licenses = buffer.toString();
- sb.append(String.format(format, licenses, artifact));
+ String line = licenses + " " + artifact;
+ lines.add(line);
}
+
+ Collections.sort(lines);
+ for (String line : lines) {
+ sb.append('\n').append(line);
+ }
+ lines.clear();
}
}
String content = sb.toString();
@@ -361,7 +338,7 @@
writeFile(target, content, getEncoding());
}
- if (generateBundle) {
+ if (isDoGenerateBundle()) {
// creates the bundled license file
File bundleTarget =
@@ -378,4 +355,104 @@
public void setGroupByLicense(boolean groupByLicense) {
this.groupByLicense = groupByLicense;
}
+
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ public String getThirdPartyFilename() {
+ return thirdPartyFilename;
+ }
+
+ public String getBundleThirdPartyPath() {
+ return bundleThirdPartyPath;
+ }
+
+ public boolean isGenerateBundle() {
+ return generateBundle;
+ }
+
+ public boolean isFailIfWarning() {
+ return failIfWarning;
+ }
+
+ public SortedSet<MavenProject> getUnsafeDependencies() {
+ return unsafeDependencies;
+ }
+
+ public File getThirdPartyFile() {
+ return thirdPartyFile;
+ }
+
+ public LicenseMap getLicenseMap() {
+ return licenseMap;
+ }
+
+ public void setOutputDirectory(File outputDirectory) {
+ this.outputDirectory = outputDirectory;
+ }
+
+ public void setThirdPartyFilename(String thirdPartyFilename) {
+ this.thirdPartyFilename = thirdPartyFilename;
+ }
+
+ public void setBundleThirdPartyPath(String bundleThirdPartyPath) {
+ this.bundleThirdPartyPath = bundleThirdPartyPath;
+ }
+
+ public void setGenerateBundle(boolean generateBundle) {
+ this.generateBundle = generateBundle;
+ }
+
+ public void setThirdPartyFile(File thirdPartyFile) {
+ this.thirdPartyFile = thirdPartyFile;
+ }
+
+ public boolean isUseMissingFile() {
+ return useMissingFile;
+ }
+
+ public File getMissingFile() {
+ return missingFile;
+ }
+
+ public void setUseMissingFile(boolean useMissingFile) {
+ this.useMissingFile = useMissingFile;
+ }
+
+ public void setMissingFile(File missingFile) {
+ this.missingFile = missingFile;
+ }
+
+ public void setFailIfWarning(boolean failIfWarning) {
+ this.failIfWarning = failIfWarning;
+ }
+
+ public SortedProperties getUnsafeMappings() {
+ return unsafeMappings;
+ }
+
+ public boolean isForce() {
+ return force;
+ }
+
+ public boolean isDoGenerate() {
+ return doGenerate;
+ }
+
+ public void setForce(boolean force) {
+ this.force = force;
+ }
+
+ public void setDoGenerate(boolean doGenerate) {
+ this.doGenerate = doGenerate;
+ }
+
+ public boolean isDoGenerateBundle() {
+ return doGenerateBundle;
+ }
+
+ public void setDoGenerateBundle(boolean doGenerateBundle) {
+ this.doGenerateBundle = doGenerateBundle;
+ }
}
\ No newline at end of file
Modified: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-25 11:51:13 UTC (rev 1777)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-25 13:30:21 UTC (rev 1778)
@@ -34,7 +34,6 @@
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.nuiton.io.SortedProperties;
-import org.nuiton.plugin.PluginHelper;
import java.io.File;
import java.io.FileWriter;
@@ -58,14 +57,6 @@
public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo {
/**
- * Un flag pour forcer la generation.
- *
- * @parameter expression="${license.force}" default-value="false"
- * @since 1.0.0
- */
- protected boolean force;
-
- /**
* Local Repository.
*
* @parameter expression="${localRepository}"
@@ -95,10 +86,6 @@
*/
protected MavenProjectBuilder mavenProjectBuilder;
- private boolean doGenerate;
-
- private boolean doGenerateBundle;
-
private boolean doGenerateMissing;
@Override
@@ -113,29 +100,6 @@
LicenseMap licenseMap = new LicenseMap();
licenseMap.setLog(log);
- File file = getThirdPartyFile();
-
- setDoGenerate(isForce() || !file.exists() || !isFileNewerThanPomFile(file));
-
- if (isGenerateBundle()) {
-
- File bundleFile =
- PluginHelper.getFile(getOutputDirectory(), getBundleThirdPartyPath());
-
- setDoGenerateBundle(isForce() ||
- !bundleFile.exists() ||
- !isFileNewerThanPomFile(bundleFile) ||
- file.lastModified() > bundleFile.lastModified());
- } else {
-
- // not generating bundled file
- setDoGenerateBundle(false);
- }
-
- if (!isDoGenerate() && !isDoGenerateBundle()) {
- return licenseMap;
- }
-
// build the license map for the dependencies of the project
for (Object o : getProject().getArtifacts()) {
@@ -153,28 +117,27 @@
licenseMap.addLicense(project, project.getLicenses());
}
-
return licenseMap;
}
-
@Override
protected SortedProperties createUnsafeMapping() throws ProjectBuildingException, IOException {
- SortedProperties unsafeMappings = getLicenseMap().loadUnsafeMapping(getEncoding(), getMissingFile());
+ SortedProperties unsafeMappings =
+ getLicenseMap().loadUnsafeMapping(getEncoding(),
+ getMissingFile());
+
SortedSet<MavenProject> unsafeDependencies = getUnsafeDependencies();
setDoGenerateMissing(!CollectionUtils.isEmpty(unsafeDependencies) &&
- isUseMissingfile());
+ isUseMissingFile());
return unsafeMappings;
}
@Override
protected boolean checkSkip() {
- if (!isDoGenerate() &&
- !isDoGenerateBundle() &&
- !isDoGenerateMissing()) {
+ if (!isDoGenerateMissing()) {
getLog().info("All files are up to date, skip goal execution.");
return false;
@@ -187,7 +150,7 @@
boolean unsafe = checkUnsafeDependencies();
- writeThirdPartyFile(isDoGenerate(), isDoGenerateBundle());
+ writeThirdPartyFile();
if (isDoGenerateMissing()) {
@@ -204,10 +167,9 @@
protected void writeMissingFile() throws IOException {
Log log = getLog();
-
-
LicenseMap licenseMap = getLicenseMap();
File file = getMissingFile();
+
createDirectoryIfNecessary(file.getParentFile());
if (isVerbose()) {
log.info("regenerate missing license file " + file);
@@ -236,54 +198,29 @@
protected MavenProject addArtifact(String id,
Artifact artifact) throws ProjectBuildingException {
- MavenProject project;
+ MavenProject project = getArtifactCache().get(id);
Log log = getLog();
- if (getArtifactCache().containsKey(id)) {
- project = getArtifactCache().get(id);
+ if (project != null) {
if (isVerbose()) {
log.info("add dependency [" + id + "] (from cache)");
}
- return project;
+ } else {
+ project = mavenProjectBuilder.buildFromRepository(
+ artifact,
+ remoteRepositories,
+ localRepository,
+ false
+ );
+ if (isVerbose()) {
+ log.info("add dependency [" + id + "]");
+ }
+ getArtifactCache().put(id, project);
}
- project = mavenProjectBuilder.buildFromRepository(
- artifact,
- remoteRepositories,
- localRepository,
- false
- );
- if (isVerbose()) {
- log.info("add dependency [" + id + "]");
- }
- getArtifactCache().put(id, project);
+
return project;
}
-
- public boolean isForce() {
- return force;
- }
-
- public boolean isDoGenerate() {
- return doGenerate;
- }
-
- public void setForce(boolean force) {
- this.force = force;
- }
-
- public void setDoGenerate(boolean doGenerate) {
- this.doGenerate = doGenerate;
- }
-
- public boolean isDoGenerateBundle() {
- return doGenerateBundle;
- }
-
- public void setDoGenerateBundle(boolean doGenerateBundle) {
- this.doGenerateBundle = doGenerateBundle;
- }
-
public boolean isDoGenerateMissing() {
return doGenerateMissing;
}
Modified: trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java 2010-06-25 11:51:13 UTC (rev 1777)
+++ trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java 2010-06-25 13:30:21 UTC (rev 1778)
@@ -61,7 +61,7 @@
* @required
* @since 2.3
*/
- protected List reactorProjects;
+ protected List<?> reactorProjects;
@Override
protected boolean checkPackaging() {
@@ -143,7 +143,7 @@
}
boolean unsafe = checkUnsafeDependencies();
- writeThirdPartyFile(true, isGenerateBundle());
+ writeThirdPartyFile();
if (unsafe && isFailIfWarning()) {
throw new MojoFailureException("There is some dependencies with no license, please review the modules.");
Modified: trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-06-25 11:51:13 UTC (rev 1777)
+++ trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-06-25 13:30:21 UTC (rev 1778)
@@ -131,6 +131,8 @@
// there is some unsafe dependencies
if (missingFile.exists()) {
+ getLog().info("Load missing file "+missingFile);
+
// load the missing file
unsafeMappings.load(missingFile);
}
1
0
25 Jun '10
Author: tchemit
Date: 2010-06-25 13:51:13 +0200 (Fri, 25 Jun 2010)
New Revision: 1777
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1777
Log:
- Evolution #709: aggregation of Third party in parent project & change format
- use back javadoc 2.6
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java
trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java
trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-25 10:31:27 UTC (rev 1776)
+++ trunk/pom.xml 2010-06-25 11:51:13 UTC (rev 1777)
@@ -332,6 +332,8 @@
<!-- documentation is in english then french -->
<locales>en,fr</locales>
+ <javadoc.version>2.6</javadoc.version>
+
</properties>
<build>
Modified: trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-06-25 10:31:27 UTC (rev 1776)
+++ trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-06-25 11:51:13 UTC (rev 1777)
@@ -36,6 +36,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
@@ -113,6 +114,17 @@
*/
protected boolean failIfWarning;
+ /**
+ * A flag to change the grouping of the generated THIRD-PARTY file.
+ * <p/>
+ * By default, group by dependecies.
+ * <p/>
+ * If sets to {@code true}, the it will group by license type.
+ *
+ * @parameter expression="${license.groupByLicense}" default-value="false"
+ * @since 2.3
+ */
+ protected boolean groupByLicense;
private LicenseMap licenseMap;
@@ -303,17 +315,40 @@
if (licenseMap.isEmpty()) {
sb.append(NO_DEPENDENCIES_MESSAGE);
} else {
- sb.append("List of third-party dependencies grouped by " +
- "their license type.");
- for (String licenseName : licenseMap.keySet()) {
- SortedSet<MavenProject> projects = licenseMap.get(licenseName);
- sb.append("\n\n").append(licenseName).append(" : ");
+ if (isGroupByLicense()) {
+ // group by license
+ sb.append("List of third-party dependencies grouped by " +
+ "their license type.");
+ for (String licenseName : licenseMap.keySet()) {
+ SortedSet<MavenProject> projects = licenseMap.get(licenseName);
+ sb.append("\n\n").append(licenseName).append(" : ");
- for (MavenProject mavenProject : projects) {
- String s = getArtifactName(mavenProject);
- sb.append("\n * ").append(s);
+
+ for (MavenProject mavenProject : projects) {
+ String s = getArtifactName(mavenProject);
+ sb.append("\n * ").append(s);
+ }
}
+
+ } else {
+
+ // group by dependencies
+ SortedMap<MavenProject, String[]> map = licenseMap.toDependencyMap();
+
+ sb.append("List of ").append(map.size()).append(" third-party dependencies.\n\n");
+
+ String format = "\n%1$s %2$s";
+ for (Map.Entry<MavenProject, String[]> entry : map.entrySet()) {
+ String artifact = getArtifactName(entry.getKey());
+ StringBuilder buffer = new StringBuilder();
+ for (String license : entry.getValue()) {
+ buffer.append(" (").append(license).append(")");
+ }
+
+ String licenses = buffer.toString();
+ sb.append(String.format(format, licenses, artifact));
+ }
}
}
String content = sb.toString();
@@ -335,4 +370,12 @@
copyFile(target, bundleTarget);
}
}
+
+ public boolean isGroupByLicense() {
+ return groupByLicense;
+ }
+
+ public void setGroupByLicense(boolean groupByLicense) {
+ this.groupByLicense = groupByLicense;
+ }
}
\ No newline at end of file
Modified: trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java 2010-06-25 10:31:27 UTC (rev 1776)
+++ trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java 2010-06-25 11:51:13 UTC (rev 1777)
@@ -47,7 +47,7 @@
* @goal aggregate-add-third-party
* @phase generate-resources
* @requiresProject true
- * @aggregator true
+ * @aggregator
* @execute goal="add-third-party"
* @since 2.3
*/
@@ -88,7 +88,7 @@
String path = getMissingFile().getAbsolutePath().substring(getProject().getBasedir().getAbsolutePath().length() + 1);
if (isVerbose()) {
- getLog().info("will use missing file path : " + path);
+ getLog().info("Use missing file path : " + path);
}
SortedProperties unsafeMappings = new SortedProperties(getEncoding());
@@ -102,9 +102,7 @@
if (file.exists()) {
- if (isVerbose()) {
- getLog().info("will load missing file : " + file);
- }
+ getLog().info("Load missing file : " + file);
SortedProperties tmp = licenseMap.loadUnsafeMapping(getEncoding(), file);
unsafeMappings.putAll(tmp);
@@ -112,6 +110,7 @@
SortedSet<MavenProject> unsafes = licenseMap.getUnsafeDependencies();
if (CollectionUtils.isEmpty(unsafes)) {
+
// no more unsafe dependencies, can break
break;
}
Modified: trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-06-25 10:31:27 UTC (rev 1776)
+++ trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-06-25 11:51:13 UTC (rev 1777)
@@ -35,9 +35,15 @@
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -178,15 +184,8 @@
// handle multiple values as a set to avoid duplicates
SortedSet<MavenProject> valueList = get(key);
if (valueList == null) {
- valueList = new TreeSet<MavenProject>(new Comparator<MavenProject>() {
- @Override
- public int compare(MavenProject o1, MavenProject o2) {
- String id1 = AbstractAddThirdPartyMojo.getArtifactId(o1.getArtifact());
- String id2 = AbstractAddThirdPartyMojo.getArtifactId(o2.getArtifact());
- return id1.compareTo(id2);
- }
- });
+ valueList = new TreeSet<MavenProject>(getProjectComparator());
}
if (getLog().isDebugEnabled()) {
getLog().debug("key:" + key + ",value: " + value);
@@ -195,7 +194,52 @@
return put(key, valueList);
}
+ public SortedMap<MavenProject, String[]> toDependencyMap() {
+ SortedMap<MavenProject, Set<String>> tmp =
+ new TreeMap<MavenProject, Set<String>>(getProjectComparator());
+
+ for (Map.Entry<String, SortedSet<MavenProject>> entry : entrySet()) {
+ String license = entry.getKey();
+ SortedSet<MavenProject> set = entry.getValue();
+ for (MavenProject p : set) {
+ Set<String> list = tmp.get(p);
+ if (list == null) {
+ list = new HashSet<String>();
+ tmp.put(p, list);
+ }
+ list.add(license);
+ }
+ }
+
+ SortedMap<MavenProject, String[]> result =
+ new TreeMap<MavenProject, String[]>(getProjectComparator());
+ for (Map.Entry<MavenProject, Set<String>> entry : tmp.entrySet()) {
+ List<String> value = new ArrayList<String>(entry.getValue());
+ Collections.sort(value);
+ result.put(entry.getKey(), value.toArray(new String[value.size()]));
+ }
+ tmp.clear();
+ return result;
+ }
+
public static String getUnknownLicenseMessage() {
return unknownLicenseMessage;
}
+
+ protected static transient Comparator<MavenProject> projectComparator;
+
+ public static Comparator<MavenProject> getProjectComparator() {
+ if (projectComparator == null) {
+ projectComparator = new Comparator<MavenProject>() {
+ @Override
+ public int compare(MavenProject o1, MavenProject o2) {
+
+ String id1 = AbstractAddThirdPartyMojo.getArtifactId(o1.getArtifact());
+ String id2 = AbstractAddThirdPartyMojo.getArtifactId(o2.getArtifact());
+ return id1.compareTo(id2);
+ }
+ };
+ }
+ return projectComparator;
+ }
}
1
0
r1776 - in trunk/src: main/java/org/nuiton/license/plugin site site/apt site/fr/apt
by tchemit@users.nuiton.org 25 Jun '10
by tchemit@users.nuiton.org 25 Jun '10
25 Jun '10
Author: tchemit
Date: 2010-06-25 12:31:27 +0200 (Fri, 25 Jun 2010)
New Revision: 1776
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1776
Log:
- Evolution #693: Improve Third-party generation (add a fallback file to push unknown license for dependencies)
- Evolution #715: Introduce the aggregate-add-third-party mojo
- Update docs
Added:
trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java
trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java
trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java
Modified:
trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
trunk/src/site/apt/index.apt
trunk/src/site/apt/usage.apt
trunk/src/site/fr/apt/index.apt
trunk/src/site/fr/apt/usage.apt
trunk/src/site/site_en.xml
trunk/src/site/site_fr.xml
Added: trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-06-25 10:31:27 UTC (rev 1776)
@@ -0,0 +1,338 @@
+/*
+ * #%L
+ * Maven License Plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.license.plugin;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
+import org.nuiton.io.SortedProperties;
+import org.nuiton.plugin.PluginHelper;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+
+/**
+ * Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de
+ * toutes les dependances du projet) dans le classpath (et le generer s'il
+ * n'existe pas).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.3
+ */
+public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo {
+
+ /**
+ * Repertoire de sortie des classes (classpath).
+ *
+ * @parameter expression="${license.outputDirectory}" default-value="target/generated-sources/license"
+ * @required
+ * @since 2.3
+ */
+ protected File outputDirectory;
+
+ /**
+ * Fichier ou ecrire les licences des dependances.
+ *
+ * @parameter expression="${license.thirdPartyFilename}"
+ * default-value="THIRD-PARTY.txt"
+ * @required
+ * @since 2.3
+ */
+ protected String thirdPartyFilename;
+
+ /**
+ * A flag to use the missing licenses file to consolidate the THID-PARTY file.
+ *
+ * @parameter expression="${license.useMissingfile}" default-value="false"
+ * @since 2.3
+ */
+ protected boolean useMissingfile;
+
+ /**
+ * The file where to fill the license for dependencies with unknwon license.
+ *
+ * @parameter expression="${license.missingFile}" default-value="src/license/THIRD-PARTY.properties"
+ * @since 1.0.0
+ */
+ protected File missingFile;
+
+ /**
+ * The path of the bundled third party file to produce when
+ * {@link #generateBundle} is on.
+ * <p/>
+ * <b>Note:</b> This option is not available for {@code pom} module types.
+ *
+ * @parameter expression="${license.bundleThirdPartyPath}" default-value="META-INF/${project.artifactId}-THIRD-PARTY.txt"
+ * @since 2.3
+ */
+ protected String bundleThirdPartyPath;
+
+ /**
+ * Un flag pour faire une copie nommé dans META-INF (prefixe avec le nom de
+ * l'artifact).
+ *
+ * @parameter expression="${license.generateBundle}" default-value="false"
+ * @since 2.3
+ */
+ protected boolean generateBundle;
+
+ /**
+ * A flag to fail the build if at least one dependency was detected without a license.
+ *
+ * @parameter expression="${license.failIfWarning}" default-value="false"
+ * @since 2.3
+ */
+ protected boolean failIfWarning;
+
+
+
+ private LicenseMap licenseMap;
+
+ private SortedSet<MavenProject> unsafeDependencies;
+
+ private File thirdPartyFile;
+
+ private SortedProperties unsafeMappings;
+
+ public static final String NO_DEPENDENCIES_MESSAGE = "the project has no dependencies.";
+
+ private static SortedMap<String, MavenProject> artifactCache;
+
+ public static SortedMap<String, MavenProject> getArtifactCache() {
+ if (artifactCache == null) {
+ artifactCache = new TreeMap<String, MavenProject>();
+ }
+ return artifactCache;
+ }
+
+ protected abstract LicenseMap createLicenseMap() throws ProjectBuildingException;
+
+ protected abstract SortedProperties createUnsafeMapping() throws ProjectBuildingException, IOException;
+
+ @Override
+ protected void init() throws Exception {
+
+ Log log = getLog();
+
+ if (log.isDebugEnabled()) {
+
+ // always be verbose in debug mode
+ setVerbose(true);
+ }
+
+ File file = new File(getOutputDirectory(), getThirdPartyFilename());
+
+ setThirdPartyFile(file);
+
+ licenseMap = createLicenseMap();
+ licenseMap.setLog(log);
+
+ unsafeDependencies = licenseMap.getUnsafeDependencies();
+
+ if (CollectionUtils.isEmpty(unsafeDependencies) || !isUseMissingfile()) {
+
+ // no unsafe dependencies
+ // or user does not ask to generate missing file
+ // so no more thing to do
+ return;
+ }
+
+ // load unsafeMapping
+ unsafeMappings = createUnsafeMapping();
+ }
+
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ public String getThirdPartyFilename() {
+ return thirdPartyFilename;
+ }
+
+ public String getBundleThirdPartyPath() {
+ return bundleThirdPartyPath;
+ }
+
+ public boolean isGenerateBundle() {
+ return generateBundle;
+ }
+
+ public boolean isFailIfWarning() {
+ return failIfWarning;
+ }
+
+ public SortedSet<MavenProject> getUnsafeDependencies() {
+ return unsafeDependencies;
+ }
+
+ public File getThirdPartyFile() {
+ return thirdPartyFile;
+ }
+
+ public LicenseMap getLicenseMap() {
+ return licenseMap;
+ }
+
+ public void setOutputDirectory(File outputDirectory) {
+ this.outputDirectory = outputDirectory;
+ }
+
+ public void setThirdPartyFilename(String thirdPartyFilename) {
+ this.thirdPartyFilename = thirdPartyFilename;
+ }
+
+ public void setBundleThirdPartyPath(String bundleThirdPartyPath) {
+ this.bundleThirdPartyPath = bundleThirdPartyPath;
+ }
+
+ public void setGenerateBundle(boolean generateBundle) {
+ this.generateBundle = generateBundle;
+ }
+
+ public void setThirdPartyFile(File thirdPartyFile) {
+ this.thirdPartyFile = thirdPartyFile;
+ }
+
+ public boolean isUseMissingfile() {
+ return useMissingfile;
+ }
+
+ public File getMissingFile() {
+ return missingFile;
+ }
+
+ public void setUseMissingfile(boolean useMissingfile) {
+ this.useMissingfile = useMissingfile;
+ }
+
+ public void setMissingFile(File missingFile) {
+ this.missingFile = missingFile;
+ }
+
+ public void setFailIfWarning(boolean failIfWarning) {
+ this.failIfWarning = failIfWarning;
+ }
+
+ public SortedProperties getUnsafeMappings() {
+ return unsafeMappings;
+ }
+
+ protected boolean checkUnsafeDependencies() {
+ SortedSet<MavenProject> unsafeDependencies = getUnsafeDependencies();
+ boolean unsafe = !CollectionUtils.isEmpty(unsafeDependencies);
+ if (unsafe) {
+ Log log = getLog();
+ log.warn("There is " + unsafeDependencies.size() + " dependencies with no license :");
+ for (MavenProject dep : unsafeDependencies) {
+
+ // no license found for the dependency
+ log.warn(" - " + getArtifactId(dep.getArtifact()));
+ }
+ }
+ return unsafe;
+ }
+
+ public static String getArtifactId(Artifact artifact) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(artifact.getGroupId());
+ sb.append("--");
+ sb.append(artifact.getArtifactId());
+ sb.append("--");
+ sb.append(artifact.getVersion());
+ if (!StringUtils.isEmpty(artifact.getClassifier())) {
+ sb.append("--");
+ sb.append(artifact.getClassifier());
+ }
+ return sb.toString();
+ }
+
+ public static String getArtifactName(MavenProject project) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(project.getName());
+ sb.append(" (");
+ sb.append(project.getGroupId());
+ sb.append(":");
+ sb.append(project.getArtifactId());
+ sb.append(":");
+ sb.append(project.getVersion());
+ sb.append(" - ");
+ String url = project.getUrl();
+ sb.append(url == null ? "no url defined" : url);
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ protected void writeThirdPartyFile(boolean generate, boolean generateBundle) throws IOException {
+
+ Log log = getLog();
+ LicenseMap licenseMap = getLicenseMap();
+ File target = getThirdPartyFile();
+
+ if (generate) {
+ StringBuilder sb = new StringBuilder();
+ if (licenseMap.isEmpty()) {
+ sb.append(NO_DEPENDENCIES_MESSAGE);
+ } else {
+ sb.append("List of third-party dependencies grouped by " +
+ "their license type.");
+ for (String licenseName : licenseMap.keySet()) {
+ SortedSet<MavenProject> projects = licenseMap.get(licenseName);
+ sb.append("\n\n").append(licenseName).append(" : ");
+
+
+ for (MavenProject mavenProject : projects) {
+ String s = getArtifactName(mavenProject);
+ sb.append("\n * ").append(s);
+ }
+ }
+ }
+ String content = sb.toString();
+
+ log.info("writing third-party file to " + target);
+ if (isVerbose()) {
+ log.info(content);
+ }
+
+ writeFile(target, content, getEncoding());
+ }
+
+ if (generateBundle) {
+
+ // creates the bundled license file
+ File bundleTarget =
+ PluginHelper.getFile(getOutputDirectory(), getBundleThirdPartyPath());
+ log.info("writing bundled third-party file to " + bundleTarget);
+ copyFile(target, bundleTarget);
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-20 21:41:45 UTC (rev 1775)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-25 10:31:27 UTC (rev 1776)
@@ -26,10 +26,8 @@
package org.nuiton.license.plugin;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.License;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
@@ -40,14 +38,10 @@
import java.io.File;
import java.io.FileWriter;
-import java.util.Arrays;
-import java.util.Comparator;
+import java.io.IOException;
import java.util.List;
import java.util.Set;
-import java.util.SortedMap;
import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
/**
* Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de
@@ -61,66 +55,9 @@
* @requiresProject true
* @since 2.2 (was previously {@code AddThirdPartyFileMojo}).
*/
-public class AddThirdPartyMojo extends AbstractLicenseMojo {
+public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo {
- private static final String unknownLicenseMessage = "Unknown license";
-
/**
- * Repertoire de sortie des classes (classpath).
- *
- * @parameter expression="${license.outputDirectory}" default-value="target/generated-sources/license"
- * @required
- * @since 1.0.0
- */
- protected File outputDirectory;
-
- /**
- * Fichier ou ecrire les licences des dependances.
- *
- * @parameter expression="${license.thirdPartyFilename}"
- * default-value="THIRD-PARTY.txt"
- * @required
- * @since 1.0.0
- */
- protected String thirdPartyFilename;
-
- /**
- * The path of the bundled third party file to produce when
- * {@link #generateBundle} is on.
- * <p/>
- * <b>Note:</b> This option is not available for {@code pom} module types.
- *
- * @parameter expression="${license.bundleThirdPartyPath}" default-value="META-INF/${project.artifactId}-THIRD-PARTY.txt"
- * @since 2.2
- */
- protected String bundleThirdPartyPath;
-
- /**
- * The file where to fill the license for dependencies with unknwon license.
- *
- * @parameter expression="${license.missingFile}" default-value="src/license/THIRD-PARTY.properties"
- * @since 1.0.0
- */
- protected File missingFile;
-
- /**
- * Un flag pour faire une copie nommé dans META-INF (prefixe avec le nom de
- * l'artifact).
- *
- * @parameter expression="${license.generateBundle}" default-value="false"
- * @since 1.0.0
- */
- protected boolean generateBundle;
-
- /**
- * A flag to generate or update the missing licenses file.
- *
- * @parameter expression="${license.generateMissing}" default-value="true"
- * @since 2.3
- */
- protected boolean generateMissing;
-
- /**
* Un flag pour forcer la generation.
*
* @parameter expression="${license.force}" default-value="false"
@@ -129,22 +66,6 @@
protected boolean force;
/**
- * A flag to fail the build if at least one dependency was detected without a license.
- *
- * @parameter expression="${license.failIfWarning}" default-value="false"
- * @since 2.3
- */
- protected boolean failIfWarning;
-
- /**
- * Un flag pour conserver un backup des fichiers modifies.
- *
- * @parameter expression="${license.keepBackup}" default-value="false"
- * @since 1.0.0
- */
- protected boolean keepBackup;
-
- /**
* Local Repository.
*
* @parameter expression="${localRepository}"
@@ -174,51 +95,26 @@
*/
protected MavenProjectBuilder mavenProjectBuilder;
- private File thirdPartyFile;
-
- private LicenseMap licenseMap;
-
- private SortedSet<MavenProject> unsafeDependencies;
-
- private SortedProperties unsafeMappings;
-
private boolean doGenerate;
private boolean doGenerateBundle;
private boolean doGenerateMissing;
- private static SortedMap<String, MavenProject> artifactCache;
-
- public static SortedMap<String, MavenProject> getArtifactCache() {
- if (artifactCache == null) {
- artifactCache = new TreeMap<String, MavenProject>();
- }
- return artifactCache;
- }
-
- public static final String NO_DEPENDENCIES_MESSAGE = "the project has no dependencies.";
-
@Override
protected boolean checkPackaging() {
return rejectPackaging(Packaging.pom);
}
@Override
- protected void init() throws Exception {
+ protected LicenseMap createLicenseMap() throws ProjectBuildingException {
Log log = getLog();
- if (log.isDebugEnabled()) {
- // always be verbose in debug mode
- setVerbose(true);
- }
+ LicenseMap licenseMap = new LicenseMap();
+ licenseMap.setLog(log);
- licenseMap = new LicenseMap();
+ File file = getThirdPartyFile();
- File file = new File(getOutputDirectory(), getThirdPartyFilename());
-
- setThirdPartyFile(file);
-
setDoGenerate(isForce() || !file.exists() || !isFileNewerThanPomFile(file));
if (isGenerateBundle()) {
@@ -237,9 +133,7 @@
}
if (!isDoGenerate() && !isDoGenerateBundle()) {
-
- // nothing to do
- return;
+ return licenseMap;
}
// build the license map for the dependencies of the project
@@ -257,90 +151,23 @@
MavenProject project = addArtifact(id, artifact);
- addLicense(project, project.getLicenses());
+ licenseMap.addLicense(project, project.getLicenses());
}
- // get unsafe dependencies (says with no license)
- unsafeDependencies = licenseMap.get(getUnknownLicenseMessage());
+ return licenseMap;
+ }
- if (CollectionUtils.isEmpty(unsafeDependencies)) {
- // no unsafe dependencies, so no need to generate missing file
- setDoGenerateMissing(false);
- return;
- }
+ @Override
+ protected SortedProperties createUnsafeMapping() throws ProjectBuildingException, IOException {
+ SortedProperties unsafeMappings = getLicenseMap().loadUnsafeMapping(getEncoding(), getMissingFile());
- if (log.isDebugEnabled()) {
- log.debug("There is " + unsafeDependencies.size() + " dependencies with no license from poms : ");
- for (MavenProject dep : unsafeDependencies) {
+ SortedSet<MavenProject> unsafeDependencies = getUnsafeDependencies();
- // no license found for the dependency
- log.debug(" - " + getArtifactId(dep.getArtifact()));
- }
- }
+ setDoGenerateMissing(!CollectionUtils.isEmpty(unsafeDependencies) &&
+ isUseMissingfile());
- if (!isGenerateMissing()) {
-
- // user does not ask to generate missing file
- // so no more thing to do
- return;
- }
-
- unsafeMappings = new SortedProperties(getEncoding());
-
- // there is some unsafe dependencies
- if (missingFile.exists()) {
-
- // load the missing file
- unsafeMappings.load(missingFile);
- }
-
- // push back loaded dependencies
- for (Object o : unsafeMappings.keySet()) {
- String id = (String) o;
-
- MavenProject project = getArtifactCache().get(id);
- if (project == null) {
- log.warn("dependency [" + id + "] does not exists in project.");
- continue;
- }
-
- String license = (String) unsafeMappings.get(id);
- if (StringUtils.isEmpty(license)) {
-
- // empty license means not fill, skip it
- continue;
- }
-
- // add license in map
- License l = new License();
- l.setName(license.trim());
- l.setUrl(license.trim());
-
- // add license
- addLicense(project, Arrays.asList(l));
-
- // remove unknown license
- unsafeDependencies.remove(project);
- }
-
- if (unsafeDependencies.isEmpty()) {
-
- // no unsafe dependencies, so no need to generate missing file
- setDoGenerateMissing(false);
-
- // no more unknown license in map
- licenseMap.remove(getUnknownLicenseMessage());
- return;
- }
-
- // mark to regenerate the file (if anything has changed)
- setDoGenerateMissing(true);
-
- for (MavenProject project : unsafeDependencies) {
- String id = getArtifactId(project.getArtifact());
- unsafeMappings.setProperty(id, "");
- }
+ return unsafeMappings;
}
@Override
@@ -358,111 +185,51 @@
@Override
protected void doAction() throws Exception {
- Log log = getLog();
+ boolean unsafe = checkUnsafeDependencies();
- File target = getThirdPartyFile();
- File output = getOutputDirectory();
+ writeThirdPartyFile(isDoGenerate(), isDoGenerateBundle());
- boolean unsafe = !CollectionUtils.isEmpty(unsafeDependencies);
- if (unsafe) {
-
- log.warn("There is " + unsafeDependencies.size() + " dependencies with no license :");
- for (MavenProject dep : unsafeDependencies) {
-
- // no license found for the dependency
- log.warn(" - " + getArtifactId(dep.getArtifact()));
- }
- }
- if (isDoGenerate()) {
-
- // build thirdPartyFileContent
- String content = buildThirdPartyFilecontent();
-
- if (isVerbose()) {
- log.info("writing third-party file : " + target + "\n" + content);
- }
-
- if (isKeepBackup() && target.exists()) {
- if (isVerbose()) {
- log.info("backup " + target);
- }
- backupFile(target);
- }
- writeFile(target, content, getEncoding());
- }
-
- if (isDoGenerateBundle()) {
-
- // creates the bundled license file
- File bundleTarget =
- PluginHelper.getFile(output, getBundleThirdPartyPath());
- copyFile(target, bundleTarget);
- }
-
if (isDoGenerateMissing()) {
- File file = getMissingFile();
- createDirectoryIfNecessary(file.getParentFile());
- if (isVerbose()) {
- log.info("regenerate missing license file " + file);
- }
- FileWriter writer = new FileWriter(file);
- try {
- StringBuilder sb = new StringBuilder(" Generated by " + getClass().getName());
- Set<String> licenses = licenseMap.keySet();
- if (!licenses.isEmpty()) {
- sb.append("\n-------------------------------------------------------------------------------");
- sb.append("\n Already used licenses in project :");
- for (String license : licenses) {
- if (getUnknownLicenseMessage().equals(license)) {
- continue;
- }
- sb.append("\n - ").append(license);
- }
- }
- sb.append("\n-------------------------------------------------------------------------------");
- sb.append("\n Please fill the missing licenses for dependencies :\n\n");
- unsafeMappings.store(writer, sb.toString());
- } finally {
- writer.close();
- }
+ writeMissingFile();
}
if (unsafe && isFailIfWarning()) {
throw new MojoFailureException("There is some dependencies with no license, please fill the file " + getMissingFile());
}
- addResourceDir(output, "**/*.txt");
+ addResourceDir(getOutputDirectory(), "**/*.txt");
}
+ protected void writeMissingFile() throws IOException {
- protected void addLicense(MavenProject project,
- List<?> licenses) throws ProjectBuildingException {
+ Log log = getLog();
- if (Artifact.SCOPE_SYSTEM.equals(project.getArtifact().getScope())) {
- // do NOT treate system dependency
- return;
+ LicenseMap licenseMap = getLicenseMap();
+ File file = getMissingFile();
+ createDirectoryIfNecessary(file.getParentFile());
+ if (isVerbose()) {
+ log.info("regenerate missing license file " + file);
}
-
- if (CollectionUtils.isEmpty(licenses)) {
-
- // no license found for the dependency
- licenseMap.put(getUnknownLicenseMessage(), project);
- return;
- }
-
- for (Object o : licenses) {
- if (o == null) {
- getLog().warn("could not acquire the license for " + getArtifactId(project.getArtifact()));
- continue;
+ FileWriter writer = new FileWriter(file);
+ try {
+ StringBuilder sb = new StringBuilder(" Generated by " + getClass().getName());
+ Set<String> licenses = licenseMap.keySet();
+ if (!licenses.isEmpty()) {
+ sb.append("\n-------------------------------------------------------------------------------");
+ sb.append("\n Already used licenses in project :");
+ for (String license : licenses) {
+ if (!LicenseMap.getUnknownLicenseMessage().equals(license)) {
+ sb.append("\n - ").append(license);
+ }
+ }
}
- License license = (License) o;
- String licenseKey = license.getName();
- if (license.getName() == null) {
- licenseKey = license.getUrl();
- }
- licenseMap.put(licenseKey, project);
+ sb.append("\n-------------------------------------------------------------------------------");
+ sb.append("\n Please fill the missing licenses for dependencies :\n\n");
+ getUnsafeMappings().store(writer, sb.toString());
+ } finally {
+ writer.close();
}
}
@@ -492,156 +259,23 @@
return project;
}
- protected String getArtifactId(Artifact artifact) {
- StringBuilder sb = new StringBuilder();
- sb.append(artifact.getGroupId());
- sb.append("--");
- sb.append(artifact.getArtifactId());
- sb.append("--");
- sb.append(artifact.getVersion());
- if (!StringUtils.isEmpty(artifact.getClassifier())) {
- sb.append("--");
- sb.append(artifact.getClassifier());
- }
- return sb.toString();
- }
- protected String getArtifactName(MavenProject project) {
- StringBuilder sb = new StringBuilder();
- sb.append(project.getName());
- sb.append(" (");
- sb.append(project.getGroupId());
- sb.append(":");
- sb.append(project.getArtifactId());
- sb.append(":");
- sb.append(project.getVersion());
- sb.append(" - ");
- String url = project.getUrl();
- sb.append(url == null ? "no url defined" : url);
- sb.append(")");
-
- return sb.toString();
- }
-
- protected String buildThirdPartyFilecontent() {
- StringBuilder sb = new StringBuilder();
- if (licenseMap.isEmpty()) {
- sb.append(NO_DEPENDENCIES_MESSAGE);
- } else {
- sb.append("List of third-party dependencies grouped by " +
- "their license type.");
- for (String licenseName : licenseMap.keySet()) {
- SortedSet<MavenProject> projects = licenseMap.get(licenseName);
- sb.append("\n\n").append(licenseName).append(" : ");
-
-
- for (MavenProject mavenProject : projects) {
- String s = getArtifactName(mavenProject);
- sb.append("\n * ").append(s);
- }
- }
- }
- String content = sb.toString();
- if (getLog().isDebugEnabled()) {
- getLog().debug("third-party file content :\n" + content);
- }
- return content;
- }
-
-
- public static String getUnknownLicenseMessage() {
- return unknownLicenseMessage;
- }
-
- public String getThirdPartyFilename() {
- return thirdPartyFilename;
- }
-
- public File getOutputDirectory() {
- return outputDirectory;
- }
-
public boolean isForce() {
return force;
}
- public boolean isKeepBackup() {
- return keepBackup;
- }
-
- public boolean isGenerateBundle() {
- return generateBundle;
- }
-
public boolean isDoGenerate() {
return doGenerate;
}
- public String getBundleThirdPartyPath() {
- return bundleThirdPartyPath;
- }
-
-
- public File getThirdPartyFile() {
- return thirdPartyFile;
- }
-
- public File getMissingFile() {
- return missingFile;
- }
-
- public boolean isGenerateMissing() {
- return generateMissing;
- }
-
- public boolean isFailIfWarning() {
- return failIfWarning;
- }
-
- public void setThirdPartyFilename(String thirdPartyFilename) {
- this.thirdPartyFilename = thirdPartyFilename;
- }
-
public void setForce(boolean force) {
this.force = force;
}
- public void setOutputDirectory(File outputDirectory) {
- this.outputDirectory = outputDirectory;
- }
-
- public void setKeepBackup(boolean keepBackup) {
- this.keepBackup = keepBackup;
- }
-
- public void setGenerateBundle(boolean generateBundle) {
- this.generateBundle = generateBundle;
- }
-
- public void setBundleThirdPartyPath(String bundleThirdPartyPath) {
- this.bundleThirdPartyPath = bundleThirdPartyPath;
- }
-
public void setDoGenerate(boolean doGenerate) {
this.doGenerate = doGenerate;
}
- public void setThirdPartyFile(File thirdPartyFile) {
- this.thirdPartyFile = thirdPartyFile;
- }
-
- public void setMissingFile(File missingFile) {
- this.missingFile = missingFile;
- }
-
- public void setGenerateMissing(boolean generateMissing) {
- this.generateMissing = generateMissing;
- }
-
- public void setFailIfWarning(boolean failIfWarning) {
- this.failIfWarning = failIfWarning;
- }
-
public boolean isDoGenerateBundle() {
return doGenerateBundle;
}
@@ -658,29 +292,4 @@
this.doGenerateMissing = doGenerateMissing;
}
- protected class LicenseMap extends TreeMap<String, SortedSet<MavenProject>> {
-
- private static final long serialVersionUID = 864199843545688069L;
-
- public SortedSet<MavenProject> put(String key, MavenProject value) {
- // handle multiple values as a set to avoid duplicates
- SortedSet<MavenProject> valueList = get(key);
- if (valueList == null) {
- valueList = new TreeSet<MavenProject>(new Comparator<MavenProject>() {
- @Override
- public int compare(MavenProject o1, MavenProject o2) {
-
- String id1 = getArtifactId(o1.getArtifact());
- String id2 = getArtifactId(o2.getArtifact());
- return id1.compareTo(id2);
- }
- });
- }
- if (getLog().isDebugEnabled()) {
- getLog().debug("key:" + key + ",value: " + value);
- }
- valueList.add(value);
- return put(key, valueList);
- }
- }
}
\ No newline at end of file
Added: trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java 2010-06-25 10:31:27 UTC (rev 1776)
@@ -0,0 +1,154 @@
+/*
+ * #%L
+ * Maven License Plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.license.plugin;
+
+import org.apache.commons.collections.CollectionUtils;
+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.nuiton.io.SortedProperties;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.SortedSet;
+
+/**
+ * This aggregator goal (will be executed only once and only on pom projects)
+ * executed the {@code add-third-party} on all his modules (in a parellel build cycle)
+ * then aggreates all the third-party files in final one in the pom project.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @goal aggregate-add-third-party
+ * @phase generate-resources
+ * @requiresProject true
+ * @aggregator true
+ * @execute goal="add-third-party"
+ * @since 2.3
+ */
+public class AggregatorAddThirdPartyMojo extends AbstractAddThirdPartyMojo {
+
+ /**
+ * The projects in the reactor.
+ *
+ * @parameter expression="${reactorProjects}"
+ * @readonly
+ * @required
+ * @since 2.3
+ */
+ protected List reactorProjects;
+
+ @Override
+ protected boolean checkPackaging() {
+ return acceptPackaging(Packaging.pom);
+ }
+
+ @Override
+ protected LicenseMap createLicenseMap() throws ProjectBuildingException {
+ Log log = getLog();
+
+ LicenseMap licenseMap = new LicenseMap();
+ licenseMap.setLog(log);
+
+ SortedMap<String, MavenProject> artifacts = getArtifactCache();
+ for (MavenProject project : artifacts.values()) {
+ licenseMap.addLicense(project, project.getLicenses());
+ }
+ return licenseMap;
+ }
+
+ @Override
+ protected SortedProperties createUnsafeMapping() throws ProjectBuildingException, IOException {
+
+ String path = getMissingFile().getAbsolutePath().substring(getProject().getBasedir().getAbsolutePath().length() + 1);
+
+ if (isVerbose()) {
+ getLog().info("will use missing file path : " + path);
+ }
+
+ SortedProperties unsafeMappings = new SortedProperties(getEncoding());
+
+ LicenseMap licenseMap = getLicenseMap();
+
+ for (Object o : reactorProjects) {
+ MavenProject p = (MavenProject) o;
+
+ File file = new File(p.getBasedir(), path);
+
+ if (file.exists()) {
+
+ if (isVerbose()) {
+ getLog().info("will load missing file : " + file);
+ }
+
+ SortedProperties tmp = licenseMap.loadUnsafeMapping(getEncoding(), file);
+ unsafeMappings.putAll(tmp);
+ }
+
+ SortedSet<MavenProject> unsafes = licenseMap.getUnsafeDependencies();
+ if (CollectionUtils.isEmpty(unsafes)) {
+ // no more unsafe dependencies, can break
+ break;
+ }
+ }
+ return unsafeMappings;
+ }
+
+ @Override
+ protected void doAction() throws Exception {
+ Log log = getLog();
+
+ if (isVerbose()) {
+ log.info("After executing on " + reactorProjects.size() + " project(s)");
+ }
+ SortedMap<String, MavenProject> artifacts = getArtifactCache();
+
+ LicenseMap licenseMap = getLicenseMap();
+
+ getLog().info(artifacts.size() + " detected artifact(s).");
+ if (isVerbose()) {
+ for (String id : artifacts.keySet()) {
+ getLog().info(" - " + id);
+ }
+ }
+ getLog().info(licenseMap.size() + " detected license(s).");
+ if (isVerbose()) {
+ for (String id : licenseMap.keySet()) {
+ getLog().info(" - " + id);
+ }
+ }
+ boolean unsafe = checkUnsafeDependencies();
+
+ writeThirdPartyFile(true, isGenerateBundle());
+
+ if (unsafe && isFailIfWarning()) {
+ throw new MojoFailureException("There is some dependencies with no license, please review the modules.");
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java (rev 0)
+++ trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-06-25 10:31:27 UTC (rev 1776)
@@ -0,0 +1,201 @@
+/*
+ * #%L
+ * Maven License Plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.license.plugin;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.License;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
+import org.nuiton.io.SortedProperties;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+/**
+ * Map of artifacts (stub in mavenproject) group by their license.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.3
+ */
+public class LicenseMap extends TreeMap<String, SortedSet<MavenProject>> {
+
+ private static final long serialVersionUID = 864199843545688069L;
+
+ private transient Log log;
+
+ public static final String unknownLicenseMessage = "Unknown license";
+
+ public LicenseMap() {
+ }
+
+ public void setLog(Log log) {
+ this.log = log;
+ }
+
+ public Log getLog() {
+ return log;
+ }
+
+ public void addLicense(MavenProject project,
+ List<?> licenses) throws ProjectBuildingException {
+
+ if (Artifact.SCOPE_SYSTEM.equals(project.getArtifact().getScope())) {
+
+ // do NOT treate system dependency
+ return;
+ }
+
+ if (CollectionUtils.isEmpty(licenses)) {
+
+ // no license found for the dependency
+ put(getUnknownLicenseMessage(), project);
+ return;
+ }
+
+ for (Object o : licenses) {
+ if (o == null) {
+ getLog().warn("could not acquire the license for " + AbstractAddThirdPartyMojo.getArtifactId(project.getArtifact()));
+ continue;
+ }
+ License license = (License) o;
+ String licenseKey = license.getName();
+ if (license.getName() == null) {
+ licenseKey = license.getUrl();
+ }
+ put(licenseKey, project);
+ }
+ }
+
+ public SortedSet<MavenProject> getUnsafeDependencies() {
+
+ Log log = getLog();
+ // get unsafe dependencies (says with no license)
+ SortedSet<MavenProject> unsafeDependencies = get(getUnknownLicenseMessage());
+
+ if (log.isDebugEnabled()) {
+ log.debug("There is " + unsafeDependencies.size() + " dependencies with no license from poms : ");
+ for (MavenProject dep : unsafeDependencies) {
+
+ // no license found for the dependency
+ log.debug(" - " + AbstractAddThirdPartyMojo.getArtifactId(dep.getArtifact()));
+ }
+ }
+
+ return unsafeDependencies;
+ }
+
+ protected SortedProperties loadUnsafeMapping(String encoding, File missingFile) throws IOException, ProjectBuildingException {
+
+
+ SortedSet<MavenProject> unsafeDependencies = getUnsafeDependencies();
+
+ SortedProperties unsafeMappings = new SortedProperties(encoding);
+
+ // there is some unsafe dependencies
+ if (missingFile.exists()) {
+
+ // load the missing file
+ unsafeMappings.load(missingFile);
+ }
+
+ // push back loaded dependencies
+ for (Object o : unsafeMappings.keySet()) {
+ String id = (String) o;
+
+ MavenProject project = AbstractAddThirdPartyMojo.getArtifactCache().get(id);
+ if (project == null) {
+ getLog().warn("dependency [" + id + "] does not exists in project.");
+ continue;
+ }
+
+ String license = (String) unsafeMappings.get(id);
+ if (StringUtils.isEmpty(license)) {
+
+ // empty license means not fill, skip it
+ continue;
+ }
+
+ // add license in map
+ License l = new License();
+ l.setName(license.trim());
+ l.setUrl(license.trim());
+
+ // add license
+ addLicense(project, Arrays.asList(l));
+
+ // remove unknown license
+ unsafeDependencies.remove(project);
+ }
+
+ if (unsafeDependencies.isEmpty()) {
+
+
+ // no more unknown license in map
+ remove(getUnknownLicenseMessage());
+ } else {
+
+ // add a "with no value license" for missing dependencies
+ for (MavenProject project : unsafeDependencies) {
+ String id = AbstractAddThirdPartyMojo.getArtifactId(project.getArtifact());
+ unsafeMappings.setProperty(id, "");
+ }
+ }
+ return unsafeMappings;
+ }
+
+ public SortedSet<MavenProject> put(String key, MavenProject value) {
+ // handle multiple values as a set to avoid duplicates
+ SortedSet<MavenProject> valueList = get(key);
+ if (valueList == null) {
+ valueList = new TreeSet<MavenProject>(new Comparator<MavenProject>() {
+ @Override
+ public int compare(MavenProject o1, MavenProject o2) {
+
+ String id1 = AbstractAddThirdPartyMojo.getArtifactId(o1.getArtifact());
+ String id2 = AbstractAddThirdPartyMojo.getArtifactId(o2.getArtifact());
+ return id1.compareTo(id2);
+ }
+ });
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("key:" + key + ",value: " + value);
+ }
+ valueList.add(value);
+ return put(key, valueList);
+ }
+
+ public static String getUnknownLicenseMessage() {
+ return unknownLicenseMessage;
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/src/site/apt/index.apt
===================================================================
--- trunk/src/site/apt/index.apt 2010-06-20 21:41:45 UTC (rev 1775)
+++ trunk/src/site/apt/index.apt 2010-06-25 10:31:27 UTC (rev 1776)
@@ -31,6 +31,7 @@
The Maven License Plugin is used to deal with license stuff on a maven project.
* NOTE
+
The process tags are separated by space otherwise plugin can NOT update header of this file!
@@ -88,6 +89,8 @@
* {{{./add-third-party-mojo.html}add-third-party}} creates the THIRD-PARTY.txt in the build.
+ * {{{./aggregate-add-third-party-mojo.html}aggregate-add-third-party}} creates the THIRD-PARTY.txt of an pom project using the THIRD-PARTY file of all his modules.
+
* {{{./comment-style-list-mojo.html}comment-style-list}} display list of available comment style header (since 2.1).
* {{{./license-list-mojo.html}license-list}} display list of available licenses.
Modified: trunk/src/site/apt/usage.apt
===================================================================
--- trunk/src/site/apt/usage.apt 2010-06-20 21:41:45 UTC (rev 1775)
+++ trunk/src/site/apt/usage.apt 2010-06-25 10:31:27 UTC (rev 1776)
@@ -49,8 +49,23 @@
This goal build the THIRD-PARTY.txt file and add it in build.
+ <Since version 2.3>, we can consolidate the generated file by filling another
+ file (the <<missing file>>) for dependencies without license.
+
+ <Note:> This mojo has not effect on a <<pom>> project.
+
for full detail see {{{./add-third-party-mojo.html}detail page}}.
+
+* aggregate-add-third-party goal
+
+ This goal build the THIRD-PARTY.txt file on a multi-module project from
+ the dependencies of all his modules.
+
+ <Note:> This mojo has only effect on a <<pom>> project.
+
+ for full detail see {{{./aggregate-add-third-party-mojo.html}detail page}}.
+
Get informations
* license-list goal
Modified: trunk/src/site/fr/apt/index.apt
===================================================================
--- trunk/src/site/fr/apt/index.apt 2010-06-20 21:41:45 UTC (rev 1775)
+++ trunk/src/site/fr/apt/index.apt 2010-06-25 10:31:27 UTC (rev 1776)
@@ -32,6 +32,7 @@
Maven.
* NOTE
+
Dans la documentation, les tags de process sont séparés par des espaces où le
plugin ne pourrait PAS gérer la license de ces fichiers !
@@ -95,6 +96,11 @@
* {{{./add-third-party-mojo.html}add-third-party}} crée le fichier
<THIRD-PARTY.txt> dans le build.
+
+ * {{{./aggregate-add-third-party-mojo.html}aggregate-add-third-party}}
+ crée le fichier THIRD-PARTY.txt pour un projet de type <<pom>> en utilisant
+ les THIRD-PARTY de ses modules.
+
* {{{./license-list-mojo.html}license-list}} Affiche la liste des licenses
disponibles.
Modified: trunk/src/site/fr/apt/usage.apt
===================================================================
--- trunk/src/site/fr/apt/usage.apt 2010-06-20 21:41:45 UTC (rev 1775)
+++ trunk/src/site/fr/apt/usage.apt 2010-06-25 10:31:27 UTC (rev 1776)
@@ -51,9 +51,24 @@
Ce goal construit le fichier THIRD-PARTY.txt et l'ajoute au build.
+ <Depuis la version 2.3>, on peut consolider le fichier généré en remplissant
+ un fichier pour les dépendances sans license.
+
+ <Note:> Ce goal n'a pas d'effet sur un projet de type <<pom>>.
+
Pour plus de détails, référez-vous à
{{{./add-third-party-mojo.html}la page de détail}}.
+* aggregate-add-third-party goal
+
+ Ce goal construit le fichier THIRD-PARTY.txt d'un projet multi-module
+ à partir de toutes les dépendences des modules du projet.
+
+ <Note:> Ce goal n'a d'effet que sur un projet de type <<pom>>.
+
+ Pour plus de détails, référez-vous à
+ {{{./aggregate-add-third-party-mojo.html}la page de détail}}.
+
Obtenir des informations
* license-list goal
Modified: trunk/src/site/site_en.xml
===================================================================
--- trunk/src/site/site_en.xml 2010-06-20 21:41:45 UTC (rev 1775)
+++ trunk/src/site/site_en.xml 2010-06-25 10:31:27 UTC (rev 1776)
@@ -63,6 +63,7 @@
<item name="update-project-license" href="update-project-license-mojo.html"/>
<item name="update-file-header" href="update-file-header-mojo.html"/>
<item name="add-third-party" href="add-third-party-mojo.html"/>
+ <item name="aggregate-add-third-party" href="aggregate-add-third-party-mojo.html"/>
</item>
<item name="Get information" href="usage.html#get-information">
<item name="license-list" href="license-list-mojo.html"/>
Modified: trunk/src/site/site_fr.xml
===================================================================
--- trunk/src/site/site_fr.xml 2010-06-20 21:41:45 UTC (rev 1775)
+++ trunk/src/site/site_fr.xml 2010-06-25 10:31:27 UTC (rev 1776)
@@ -62,6 +62,7 @@
<item name="update-project-license" href="update-project-license-mojo.html"/>
<item name="update-file-header" href="update-file-header-mojo.html"/>
<item name="add-third-party" href="add-third-party-mojo.html"/>
+ <item name="aggregate-add-third-party" href="aggregate-add-third-party-mojo.html"/>
</item>
<item name="Obtenir des informations" href="usage.html#obtenir-des-informations">
<item name="license-list" href="license-list-mojo.html"/>
1
0
20 Jun '10
Author: tchemit
Date: 2010-06-20 23:41:45 +0200 (Sun, 20 Jun 2010)
New Revision: 1775
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1775
Log:
clean code + do NOT treate system scope dependencies in add-third-party
Modified:
trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
Modified: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-20 21:22:09 UTC (rev 1774)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-20 21:41:45 UTC (rev 1775)
@@ -28,7 +28,6 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.License;
import org.apache.maven.plugin.MojoFailureException;
@@ -36,7 +35,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.nuiton.io.SortedProperties;
import org.nuiton.plugin.PluginHelper;
@@ -118,7 +116,7 @@
* A flag to generate or update the missing licenses file.
*
* @parameter expression="${license.generateMissing}" default-value="true"
- * @since 1.0.0
+ * @since 2.3
*/
protected boolean generateMissing;
@@ -131,10 +129,10 @@
protected boolean force;
/**
- * A flag to fail the build if there is some unknown license for some dependencies.
+ * A flag to fail the build if at least one dependency was detected without a license.
*
* @parameter expression="${license.failIfWarning}" default-value="false"
- * @since 1.0.0
+ * @since 2.3
*/
protected boolean failIfWarning;
@@ -167,40 +165,6 @@
protected List<?> remoteRepositories;
/**
- * Dependency tree builder component.
- *
- * @component
- */
- protected DependencyTreeBuilder dependencyTreeBuilder;
-
-// /**
-// * Artifact Factory component.
-// *
-// * @component
-// */
-// protected ArtifactFactory factory;
-
- /**
- * Artifact metadata source component.
- *
- * @component
- * @required
- * @readonly
- * @since 1.0.0
- */
- protected ArtifactMetadataSource artifactMetadataSource;
-
-// /**
-// * Artifact collector component.
-// *
-// * @component
-// * @required
-// * @readonly
-// * @since 1.0.0
-// */
-// protected ArtifactCollector collector;
-
- /**
* Maven Project Builder component.
*
* @component
@@ -210,7 +174,6 @@
*/
protected MavenProjectBuilder mavenProjectBuilder;
-
private File thirdPartyFile;
private LicenseMap licenseMap;
@@ -284,7 +247,12 @@
for (Object o : getProject().getArtifacts()) {
Artifact artifact = (Artifact) o;
+ if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
+ // never treate system artifacts (they are mysterious and
+ // no information can be retrive from anywhere)...
+ continue;
+ }
String id = getArtifactId(artifact);
MavenProject project = addArtifact(id, artifact);
@@ -511,18 +479,6 @@
}
return project;
}
-// boolean allowStubModel = false;
-
-// if (!"pom".equals(artifact.getType())) {
-// artifact = factory.createProjectArtifact(
-// artifact.getGroupId(),
-// artifact.getArtifactId(),
-// artifact.getVersion(),
-// artifact.getScope()
-// );
-// allowStubModel = true;
-// }
-
project = mavenProjectBuilder.buildFromRepository(
artifact,
remoteRepositories,
1
0
r1774 - in trunk: . src/it/add-third-party/no-deps src/it/add-third-party/with-deps src/main/java/org/nuiton/license/plugin
by tchemit@users.nuiton.org 20 Jun '10
by tchemit@users.nuiton.org 20 Jun '10
20 Jun '10
Author: tchemit
Date: 2010-06-20 23:22:09 +0200 (Sun, 20 Jun 2010)
New Revision: 1774
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1774
Log:
Evolution #693: Improve Third-party generation (add a fallback file to push unknown license for dependencies)
Evolution #694: Add a failIfWarning propeprty in add-third-party mojo
Simplify its
Modified:
trunk/pom.xml
trunk/src/it/add-third-party/no-deps/invoker.properties
trunk/src/it/add-third-party/no-deps/verify.groovy
trunk/src/it/add-third-party/with-deps/invoker.properties
trunk/src/it/add-third-party/with-deps/verify.groovy
trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-19 18:56:11 UTC (rev 1773)
+++ trunk/pom.xml 2010-06-20 21:22:09 UTC (rev 1774)
@@ -412,7 +412,11 @@
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<pomIncludes>
- <pomInclude>**/pom.xml</pomInclude>
+ <pomInclude>add-third-party/no-deps/pom.xml</pomInclude>
+ <pomInclude>add-third-party/with-deps/pom.xml</pomInclude>
+ <pomInclude>update-file-header/pom.xml</pomInclude>
+ <pomInclude>update-project-license/pom.xml</pomInclude>
+ <!--<pomInclude>**/pom.xml</pomInclude>-->
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath>
Modified: trunk/src/it/add-third-party/no-deps/invoker.properties
===================================================================
--- trunk/src/it/add-third-party/no-deps/invoker.properties 2010-06-19 18:56:11 UTC (rev 1773)
+++ trunk/src/it/add-third-party/no-deps/invoker.properties 2010-06-20 21:22:09 UTC (rev 1774)
@@ -1,6 +1,6 @@
# A comma or space separated list of goals/phases to execute, may
# specify an empty list to execute the default goal of the IT project
-invoker.goals=clean compile
+invoker.goals=clean generate-resources
# Optionally, a list of goals to run during further invocations of Maven
#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run
Modified: trunk/src/it/add-third-party/no-deps/verify.groovy
===================================================================
--- trunk/src/it/add-third-party/no-deps/verify.groovy 2010-06-19 18:56:11 UTC (rev 1773)
+++ trunk/src/it/add-third-party/no-deps/verify.groovy 2010-06-20 21:22:09 UTC (rev 1774)
@@ -9,16 +9,4 @@
content = file.text;
assert content.contains( 'the project has no dependencies.' );
-file = new File(basedir, 'target/classes/THIRD-PARTY.txt');
-assert file.exists();
-
-content = file.text;
-assert content.contains( 'the project has no dependencies.' );
-
-file = new File(basedir, 'target/classes/META-INF/test-add-third-party-THIRD-PARTY.txt');
-assert file.exists();
-
-content = file.text;
-assert content.contains( 'the project has no dependencies.' );
-
return true;
Modified: trunk/src/it/add-third-party/with-deps/invoker.properties
===================================================================
--- trunk/src/it/add-third-party/with-deps/invoker.properties 2010-06-19 18:56:11 UTC (rev 1773)
+++ trunk/src/it/add-third-party/with-deps/invoker.properties 2010-06-20 21:22:09 UTC (rev 1774)
@@ -1,6 +1,6 @@
# A comma or space separated list of goals/phases to execute, may
# specify an empty list to execute the default goal of the IT project
-invoker.goals=clean compile
+invoker.goals=clean generate-resources
# Optionally, a list of goals to run during further invocations of Maven
#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run
Modified: trunk/src/it/add-third-party/with-deps/verify.groovy
===================================================================
--- trunk/src/it/add-third-party/with-deps/verify.groovy 2010-06-19 18:56:11 UTC (rev 1773)
+++ trunk/src/it/add-third-party/with-deps/verify.groovy 2010-06-20 21:22:09 UTC (rev 1774)
@@ -9,14 +9,4 @@
content = file.text;
assert !content.contains( 'the project has no dependencies.' );
-file = new File(basedir, 'target/classes/third.txt');
-assert file.exists();
-content = file.text;
-assert !content.contains( 'the project has no dependencies.' );
-
-file = new File(basedir, 'target/classes/test/third.txt');
-assert file.exists();
-content = file.text;
-assert !content.contains( 'the project has no dependencies.' );
-
return true;
Modified: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-19 18:56:11 UTC (rev 1773)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-20 21:22:09 UTC (rev 1774)
@@ -25,24 +25,31 @@
package org.nuiton.license.plugin;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactCollector;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.model.License;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.shared.dependency.tree.DependencyNode;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.nuiton.io.SortedProperties;
import org.nuiton.plugin.PluginHelper;
import java.io.File;
-import java.util.*;
+import java.io.FileWriter;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
/**
* Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de
@@ -80,6 +87,25 @@
protected String thirdPartyFilename;
/**
+ * The path of the bundled third party file to produce when
+ * {@link #generateBundle} is on.
+ * <p/>
+ * <b>Note:</b> This option is not available for {@code pom} module types.
+ *
+ * @parameter expression="${license.bundleThirdPartyPath}" default-value="META-INF/${project.artifactId}-THIRD-PARTY.txt"
+ * @since 2.2
+ */
+ protected String bundleThirdPartyPath;
+
+ /**
+ * The file where to fill the license for dependencies with unknwon license.
+ *
+ * @parameter expression="${license.missingFile}" default-value="src/license/THIRD-PARTY.properties"
+ * @since 1.0.0
+ */
+ protected File missingFile;
+
+ /**
* Un flag pour faire une copie nommé dans META-INF (prefixe avec le nom de
* l'artifact).
*
@@ -89,15 +115,12 @@
protected boolean generateBundle;
/**
- * The path of the bundled third party file to produce when
- * {@link #generateBundle} is on.
- * <p/>
- * <b>Note:</b> This option is not available for {@code pom} module types.
+ * A flag to generate or update the missing licenses file.
*
- * @parameter expression="${license.bundleThirdPartyPath}" default-value="META-INF/${project.artifactId}-THIRD-PARTY.txt"
- * @since 2.2
+ * @parameter expression="${license.generateMissing}" default-value="true"
+ * @since 1.0.0
*/
- protected String bundleThirdPartyPath;
+ protected boolean generateMissing;
/**
* Un flag pour forcer la generation.
@@ -108,6 +131,14 @@
protected boolean force;
/**
+ * A flag to fail the build if there is some unknown license for some dependencies.
+ *
+ * @parameter expression="${license.failIfWarning}" default-value="false"
+ * @since 1.0.0
+ */
+ protected boolean failIfWarning;
+
+ /**
* Un flag pour conserver un backup des fichiers modifies.
*
* @parameter expression="${license.keepBackup}" default-value="false"
@@ -142,44 +173,67 @@
*/
protected DependencyTreeBuilder dependencyTreeBuilder;
- /**
- * Artifact Factory component.
- *
- * @component
- */
- protected ArtifactFactory factory;
+// /**
+// * Artifact Factory component.
+// *
+// * @component
+// */
+// protected ArtifactFactory factory;
/**
* Artifact metadata source component.
*
* @component
+ * @required
+ * @readonly
+ * @since 1.0.0
*/
protected ArtifactMetadataSource artifactMetadataSource;
- /**
- * Artifact collector component.
- *
- * @component
- */
- protected ArtifactCollector collector;
+// /**
+// * Artifact collector component.
+// *
+// * @component
+// * @required
+// * @readonly
+// * @since 1.0.0
+// */
+// protected ArtifactCollector collector;
/**
* Maven Project Builder component.
*
* @component
+ * @required
+ * @readonly
+ * @since 1.0.0
*/
protected MavenProjectBuilder mavenProjectBuilder;
- /**
- * content of third party file (only computed if {@link #force} is active or
- * the {@link #thirdPartyFile} does not exist, or is not up-to-date.
- */
- protected String thirdPartyFileContent;
- protected File thirdPartyFile;
+ private File thirdPartyFile;
- boolean doGenerate;
+ private LicenseMap licenseMap;
+ private SortedSet<MavenProject> unsafeDependencies;
+
+ private SortedProperties unsafeMappings;
+
+ private boolean doGenerate;
+
+ private boolean doGenerateBundle;
+
+ private boolean doGenerateMissing;
+
+ private static SortedMap<String, MavenProject> artifactCache;
+
+ public static SortedMap<String, MavenProject> getArtifactCache() {
+ if (artifactCache == null) {
+ artifactCache = new TreeMap<String, MavenProject>();
+ }
+ return artifactCache;
+ }
+
public static final String NO_DEPENDENCIES_MESSAGE = "the project has no dependencies.";
@Override
@@ -189,219 +243,356 @@
@Override
protected void init() throws Exception {
- if (getLog().isDebugEnabled()) {
+ Log log = getLog();
+ if (log.isDebugEnabled()) {
// always be verbose in debug mode
setVerbose(true);
}
+ licenseMap = new LicenseMap();
+
File file = new File(getOutputDirectory(), getThirdPartyFilename());
setThirdPartyFile(file);
setDoGenerate(isForce() || !file.exists() || !isFileNewerThanPomFile(file));
- String content;
- if (isDoGenerate()) {
+ if (isGenerateBundle()) {
- if (isVerbose()) {
- getLog().info("will generate third-party content...");
+ File bundleFile =
+ PluginHelper.getFile(getOutputDirectory(), getBundleThirdPartyPath());
+
+ setDoGenerateBundle(isForce() ||
+ !bundleFile.exists() ||
+ !isFileNewerThanPomFile(bundleFile) ||
+ file.lastModified() > bundleFile.lastModified());
+ } else {
+
+ // not generating bundled file
+ setDoGenerateBundle(false);
+ }
+
+ if (!isDoGenerate() && !isDoGenerateBundle()) {
+
+ // nothing to do
+ return;
+ }
+
+ // build the license map for the dependencies of the project
+
+ for (Object o : getProject().getArtifacts()) {
+
+ Artifact artifact = (Artifact) o;
+
+ String id = getArtifactId(artifact);
+
+ MavenProject project = addArtifact(id, artifact);
+
+ addLicense(project, project.getLicenses());
+ }
+
+ // get unsafe dependencies (says with no license)
+ unsafeDependencies = licenseMap.get(getUnknownLicenseMessage());
+
+ if (CollectionUtils.isEmpty(unsafeDependencies)) {
+
+ // no unsafe dependencies, so no need to generate missing file
+ setDoGenerateMissing(false);
+ return;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("There is " + unsafeDependencies.size() + " dependencies with no license from poms : ");
+ for (MavenProject dep : unsafeDependencies) {
+
+ // no license found for the dependency
+ log.debug(" - " + getArtifactId(dep.getArtifact()));
}
+ }
- // build thirdPartyFileContent
- content = buildThirdPartyFilecontent();
+ if (!isGenerateMissing()) {
- } else {
- // read it from existing third party file
- content = PluginHelper.readAsString(getThirdPartyFile(), getEncoding());
+ // user does not ask to generate missing file
+ // so no more thing to do
+ return;
}
- setThirdPartyFileContent(content);
+ unsafeMappings = new SortedProperties(getEncoding());
+
+ // there is some unsafe dependencies
+ if (missingFile.exists()) {
+
+ // load the missing file
+ unsafeMappings.load(missingFile);
+ }
+
+ // push back loaded dependencies
+ for (Object o : unsafeMappings.keySet()) {
+ String id = (String) o;
+
+ MavenProject project = getArtifactCache().get(id);
+ if (project == null) {
+ log.warn("dependency [" + id + "] does not exists in project.");
+ continue;
+ }
+
+ String license = (String) unsafeMappings.get(id);
+ if (StringUtils.isEmpty(license)) {
+
+ // empty license means not fill, skip it
+ continue;
+ }
+
+ // add license in map
+ License l = new License();
+ l.setName(license.trim());
+ l.setUrl(license.trim());
+
+ // add license
+ addLicense(project, Arrays.asList(l));
+
+ // remove unknown license
+ unsafeDependencies.remove(project);
+ }
+
+ if (unsafeDependencies.isEmpty()) {
+
+ // no unsafe dependencies, so no need to generate missing file
+ setDoGenerateMissing(false);
+
+ // no more unknown license in map
+ licenseMap.remove(getUnknownLicenseMessage());
+ return;
+ }
+
+ // mark to regenerate the file (if anything has changed)
+ setDoGenerateMissing(true);
+
+ for (MavenProject project : unsafeDependencies) {
+ String id = getArtifactId(project.getArtifact());
+ unsafeMappings.setProperty(id, "");
+ }
}
@Override
+ protected boolean checkSkip() {
+ if (!isDoGenerate() &&
+ !isDoGenerateBundle() &&
+ !isDoGenerateMissing()) {
+
+ getLog().info("All files are up to date, skip goal execution.");
+ return false;
+ }
+ return super.checkSkip();
+ }
+
+ @Override
protected void doAction() throws Exception {
+ Log log = getLog();
+
File target = getThirdPartyFile();
+ File output = getOutputDirectory();
+
+ boolean unsafe = !CollectionUtils.isEmpty(unsafeDependencies);
+ if (unsafe) {
+
+ log.warn("There is " + unsafeDependencies.size() + " dependencies with no license :");
+ for (MavenProject dep : unsafeDependencies) {
+
+ // no license found for the dependency
+ log.warn(" - " + getArtifactId(dep.getArtifact()));
+ }
+ }
if (isDoGenerate()) {
+
+ // build thirdPartyFileContent
+ String content = buildThirdPartyFilecontent();
+
if (isVerbose()) {
- getLog().info("writing third-party file : " + target);
+ log.info("writing third-party file : " + target + "\n" + content);
}
+
if (isKeepBackup() && target.exists()) {
if (isVerbose()) {
- getLog().info("backup " + target);
+ log.info("backup " + target);
}
backupFile(target);
}
- writeFile(target, getThirdPartyFileContent(), getEncoding());
+ writeFile(target, content, getEncoding());
}
- File output = getOutputDirectory();
- if (isGenerateBundle()) {
+ if (isDoGenerateBundle()) {
+
// creates the bundled license file
File bundleTarget =
PluginHelper.getFile(output, getBundleThirdPartyPath());
copyFile(target, bundleTarget);
}
+
+ if (isDoGenerateMissing()) {
+
+ File file = getMissingFile();
+ createDirectoryIfNecessary(file.getParentFile());
+ if (isVerbose()) {
+ log.info("regenerate missing license file " + file);
+ }
+ FileWriter writer = new FileWriter(file);
+ try {
+ StringBuilder sb = new StringBuilder(" Generated by " + getClass().getName());
+ Set<String> licenses = licenseMap.keySet();
+ if (!licenses.isEmpty()) {
+ sb.append("\n-------------------------------------------------------------------------------");
+ sb.append("\n Already used licenses in project :");
+ for (String license : licenses) {
+ if (getUnknownLicenseMessage().equals(license)) {
+ continue;
+ }
+ sb.append("\n - ").append(license);
+ }
+ }
+ sb.append("\n-------------------------------------------------------------------------------");
+ sb.append("\n Please fill the missing licenses for dependencies :\n\n");
+ unsafeMappings.store(writer, sb.toString());
+ } finally {
+ writer.close();
+ }
+ }
+
+ if (unsafe && isFailIfWarning()) {
+ throw new MojoFailureException("There is some dependencies with no license, please fill the file " + getMissingFile());
+ }
+
addResourceDir(output, "**/*.txt");
}
- protected String buildThirdPartyFilecontent() throws DependencyTreeBuilderException {
- DependencyNode dependencyTreeNode;
- ArtifactFilter artifactFilter =
- new ScopeArtifactFilter(Artifact.SCOPE_TEST);
- dependencyTreeNode = dependencyTreeBuilder.buildDependencyTree(
- getProject(),
- localRepository,
- factory,
- artifactMetadataSource,
- artifactFilter,
- collector
- );
- LicenseMap licenseMap = new LicenseMap();
+ protected void addLicense(MavenProject project,
+ List<?> licenses) throws ProjectBuildingException {
- for (Object o : dependencyTreeNode.getChildren()) {
+ if (Artifact.SCOPE_SYSTEM.equals(project.getArtifact().getScope())) {
- buildLicenseMap((DependencyNode) o, licenseMap);
+ // do NOT treate system dependency
+ return;
}
- // log dependencies with no license
- Set<String> unsafeDependencies =
- licenseMap.get(getUnknownLicenseMessage());
+ if (CollectionUtils.isEmpty(licenses)) {
- if (unsafeDependencies != null) {
- for (String dep : unsafeDependencies) {
- // no license found for the dependency
- getLog().warn("no license found for dependency " + dep);
- }
+ // no license found for the dependency
+ licenseMap.put(getUnknownLicenseMessage(), project);
+ return;
}
- StringBuilder sb = new StringBuilder();
- if (licenseMap.isEmpty()) {
- sb.append(NO_DEPENDENCIES_MESSAGE);
- } else {
- sb.append("List of third-party dependencies grouped by " +
- "their license type.");
- for (String licenseName : licenseMap.keySet()) {
- sb.append("\n\n").append(licenseName).append(" : ");
- SortedSet<String> projects = licenseMap.get(licenseName);
-
- for (String projectName : projects) {
- sb.append("\n * ").append(projectName);
- }
+ for (Object o : licenses) {
+ if (o == null) {
+ getLog().warn("could not acquire the license for " + getArtifactId(project.getArtifact()));
+ continue;
}
+ License license = (License) o;
+ String licenseKey = license.getName();
+ if (license.getName() == null) {
+ licenseKey = license.getUrl();
+ }
+ licenseMap.put(licenseKey, project);
}
- String content = sb.toString();
- if (getLog().isDebugEnabled()) {
- getLog().debug("third-party file content :\n" + content);
- }
- return content;
}
- protected void buildLicenseMap(DependencyNode node, LicenseMap licenseMap) {
- if (node.getState() != DependencyNode.INCLUDED) {
- // this dependency is not included, so do not treate it
+ protected MavenProject addArtifact(String id,
+ Artifact artifact) throws ProjectBuildingException {
+
+ MavenProject project;
+
+ Log log = getLog();
+ if (getArtifactCache().containsKey(id)) {
+ project = getArtifactCache().get(id);
if (isVerbose()) {
- getLog().info("do not include this dependency " +
- node.toNodeString());
+ log.info("add dependency [" + id + "] (from cache)");
}
- return;
+ return project;
}
- Artifact artifact = node.getArtifact();
+// boolean allowStubModel = false;
- if (isVerbose() && getLog().isDebugEnabled()) {
- getLog().debug("treate node " + node.toNodeString());
+// if (!"pom".equals(artifact.getType())) {
+// artifact = factory.createProjectArtifact(
+// artifact.getGroupId(),
+// artifact.getArtifactId(),
+// artifact.getVersion(),
+// artifact.getScope()
+// );
+// allowStubModel = true;
+// }
+
+ project = mavenProjectBuilder.buildFromRepository(
+ artifact,
+ remoteRepositories,
+ localRepository,
+ false
+ );
+ if (isVerbose()) {
+ log.info("add dependency [" + id + "]");
}
+ getArtifactCache().put(id, project);
+ return project;
+ }
- if (!Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
- try {
- MavenProject artifactProject =
- getMavenProjectFromRepository(artifact);
- String artifactName = getArtifactName(artifactProject);
-
- List<?> licenses = artifactProject.getLicenses();
-
- if (licenses.isEmpty()) {
- // no license found for the dependency
- licenseMap.put(getUnknownLicenseMessage(), artifactName);
-
- } else {
- for (Object o : licenses) {
- if (o == null) {
- getLog().warn("could not acquire the license for "
- + artifactName);
- continue;
- }
- License license = (License) o;
- String licenseKey = license.getName();
- if (license.getName() == null) {
- licenseKey = license.getUrl();
- }
- licenseMap.put(licenseKey, artifactName);
- }
- }
- } catch (ProjectBuildingException e) {
- getLog().error("ProjectBuildingException error : ", e);
- }
+ protected String getArtifactId(Artifact artifact) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(artifact.getGroupId());
+ sb.append("--");
+ sb.append(artifact.getArtifactId());
+ sb.append("--");
+ sb.append(artifact.getVersion());
+ if (!StringUtils.isEmpty(artifact.getClassifier())) {
+ sb.append("--");
+ sb.append(artifact.getClassifier());
}
- if (!node.getChildren().isEmpty()) {
- for (Object o : node.getChildren()) {
- buildLicenseMap((DependencyNode) o, licenseMap);
- }
- }
+ return sb.toString();
}
- protected String getArtifactName(MavenProject artifactProject) {
+ protected String getArtifactName(MavenProject project) {
StringBuilder sb = new StringBuilder();
-
- sb.append(artifactProject.getName());
+ sb.append(project.getName());
sb.append(" (");
- sb.append(artifactProject.getGroupId());
+ sb.append(project.getGroupId());
sb.append(":");
- sb.append(artifactProject.getArtifactId());
+ sb.append(project.getArtifactId());
sb.append(":");
- sb.append(artifactProject.getVersion());
+ sb.append(project.getVersion());
sb.append(" - ");
- String url = artifactProject.getUrl();
+ String url = project.getUrl();
sb.append(url == null ? "no url defined" : url);
sb.append(")");
return sb.toString();
}
- /**
- * Get the <code>Maven project</code> from the repository depending the
- * <code>Artifact</code> given.
- *
- * @param artifact an artifact
- * @return the Maven project for the given artifact
- * @throws ProjectBuildingException if any
- */
- protected MavenProject getMavenProjectFromRepository(Artifact artifact)
- throws ProjectBuildingException {
+ protected String buildThirdPartyFilecontent() {
+ StringBuilder sb = new StringBuilder();
+ if (licenseMap.isEmpty()) {
+ sb.append(NO_DEPENDENCIES_MESSAGE);
+ } else {
+ sb.append("List of third-party dependencies grouped by " +
+ "their license type.");
+ for (String licenseName : licenseMap.keySet()) {
+ SortedSet<MavenProject> projects = licenseMap.get(licenseName);
+ sb.append("\n\n").append(licenseName).append(" : ");
- boolean allowStubModel = false;
- if (!"pom".equals(artifact.getType())) {
- artifact = factory.createProjectArtifact(
- artifact.getGroupId(),
- artifact.getArtifactId(),
- artifact.getVersion(),
- artifact.getScope()
- );
- allowStubModel = true;
+ for (MavenProject mavenProject : projects) {
+ String s = getArtifactName(mavenProject);
+ sb.append("\n * ").append(s);
+ }
+ }
}
-
- // TODO: we should use the MavenMetadataSource instead
- return mavenProjectBuilder.buildFromRepository(
- artifact,
- remoteRepositories,
- localRepository,
- allowStubModel
- );
+ String content = sb.toString();
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("third-party file content :\n" + content);
+ }
+ return content;
}
+
public static String getUnknownLicenseMessage() {
return unknownLicenseMessage;
}
@@ -434,14 +625,23 @@
return bundleThirdPartyPath;
}
+
public File getThirdPartyFile() {
return thirdPartyFile;
}
- public String getThirdPartyFileContent() {
- return thirdPartyFileContent;
+ public File getMissingFile() {
+ return missingFile;
}
+ public boolean isGenerateMissing() {
+ return generateMissing;
+ }
+
+ public boolean isFailIfWarning() {
+ return failIfWarning;
+ }
+
public void setThirdPartyFilename(String thirdPartyFilename) {
this.thirdPartyFilename = thirdPartyFilename;
}
@@ -466,10 +666,6 @@
this.bundleThirdPartyPath = bundleThirdPartyPath;
}
- public void setThirdPartyFileContent(String thirdPartyFileContent) {
- this.thirdPartyFileContent = thirdPartyFileContent;
- }
-
public void setDoGenerate(boolean doGenerate) {
this.doGenerate = doGenerate;
}
@@ -478,15 +674,51 @@
this.thirdPartyFile = thirdPartyFile;
}
- protected class LicenseMap extends TreeMap<String, SortedSet<String>> {
+ public void setMissingFile(File missingFile) {
+ this.missingFile = missingFile;
+ }
+ public void setGenerateMissing(boolean generateMissing) {
+ this.generateMissing = generateMissing;
+ }
+
+ public void setFailIfWarning(boolean failIfWarning) {
+ this.failIfWarning = failIfWarning;
+ }
+
+ public boolean isDoGenerateBundle() {
+ return doGenerateBundle;
+ }
+
+ public void setDoGenerateBundle(boolean doGenerateBundle) {
+ this.doGenerateBundle = doGenerateBundle;
+ }
+
+ public boolean isDoGenerateMissing() {
+ return doGenerateMissing;
+ }
+
+ public void setDoGenerateMissing(boolean doGenerateMissing) {
+ this.doGenerateMissing = doGenerateMissing;
+ }
+
+ protected class LicenseMap extends TreeMap<String, SortedSet<MavenProject>> {
+
private static final long serialVersionUID = 864199843545688069L;
- public SortedSet<String> put(String key, String value) {
+ public SortedSet<MavenProject> put(String key, MavenProject value) {
// handle multiple values as a set to avoid duplicates
- SortedSet<String> valueList = get(key);
+ SortedSet<MavenProject> valueList = get(key);
if (valueList == null) {
- valueList = new TreeSet<String>();
+ valueList = new TreeSet<MavenProject>(new Comparator<MavenProject>() {
+ @Override
+ public int compare(MavenProject o1, MavenProject o2) {
+
+ String id1 = getArtifactId(o1.getArtifact());
+ String id2 = getArtifactId(o2.getArtifact());
+ return id1.compareTo(id2);
+ }
+ });
}
if (getLog().isDebugEnabled()) {
getLog().debug("key:" + key + ",value: " + value);
1
0
Author: tchemit
Date: 2010-06-19 20:56:11 +0200 (Sat, 19 Jun 2010)
New Revision: 1773
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1773
Log:
Utilisation de mavenpom4redmine 2.2
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-19 01:02:04 UTC (rev 1772)
+++ trunk/pom.xml 2010-06-19 18:56:11 UTC (rev 1773)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2</version>
</parent>
<artifactId>maven-license-plugin</artifactId>
@@ -330,7 +330,7 @@
<siteSourcesType>apt</siteSourcesType>
<!-- documentation is in english then french -->
- <siteLocales>en,fr</siteLocales>
+ <locales>en,fr</locales>
</properties>
@@ -513,6 +513,7 @@
</properties>
<build>
+ <defaultGoal>validate</defaultGoal>
<plugins>
<plugin>
<groupId>org.nuiton</groupId>
@@ -522,14 +523,16 @@
<id>check-central-safe</id>
<inherited>true</inherited>
<goals>
- <goal>check-central-safe</goal>
+ <goal>check-auto-container</goal>
</goals>
<configuration>
- <extraRepositories>
+ <addMavenCentral>true</addMavenCentral>
+ <failIfNotSafe>true</failIfNotSafe>
+ <repositories>
<nuiton-central-releases>
http://nexus.nuiton.org/nexus/content/repositories/nuiton-central-releases
</nuiton-central-releases>
- </extraRepositories>
+ </repositories>
</configuration>
</execution>
</executions>
1
0
19 Jun '10
Author: tchemit
Date: 2010-06-19 03:02:04 +0200 (Sat, 19 Jun 2010)
New Revision: 1772
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1772
Log:
use mavenpom 2.2 and central-safe profile + remove deprecated api
Removed:
trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-02 10:28:27 UTC (rev 1771)
+++ trunk/pom.xml 2010-06-19 01:02:04 UTC (rev 1772)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.1.5</version>
+ <version>2.2-SNAPSHOT</version>
</parent>
<artifactId>maven-license-plugin</artifactId>
@@ -495,6 +495,49 @@
</reporting>
</profile>
+
+ <profile>
+ <id>central-safe</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+
+ <properties>
+
+ <!-- deploy releases on nuiton-central-releases repository -->
+ <release.repository>${nuiton.central.release.repository}</release.repository>
+
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>check-central-safe</id>
+ <inherited>true</inherited>
+ <goals>
+ <goal>check-central-safe</goal>
+ </goals>
+ <configuration>
+ <extraRepositories>
+ <nuiton-central-releases>
+ http://nexus.nuiton.org/nexus/content/repositories/nuiton-central-releases
+ </nuiton-central-releases>
+ </extraRepositories>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
</profiles>
</project>
Deleted: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java 2010-06-02 10:28:27 UTC (rev 1771)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java 2010-06-19 01:02:04 UTC (rev 1772)
@@ -1,35 +0,0 @@
-/*
- * #%L
- * Maven License Plugin
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.license.plugin;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @deprecated since 2.2, use instead the {@link AddThirdPartyMojo} class.
- */
-@Deprecated
-public class AddThirdPartyFileMojo extends AddThirdPartyMojo {
-
-}
Modified: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-02 10:28:27 UTC (rev 1771)
+++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-06-19 01:02:04 UTC (rev 1772)
@@ -116,17 +116,6 @@
protected boolean keepBackup;
/**
- * Un flag pour faire une copie nommé dans META-INF (prefixe avec le nom de
- * l'artifact).
- *
- * @parameter expression="${license.generateBundle}" default-value="false"
- * @since 1.0.0
- * @deprecated since 2.2 (use instead {@code generateBundle}).
- */
- @Deprecated
- protected boolean copyToMETA_INF;
-
- /**
* Local Repository.
*
* @parameter expression="${localRepository}"
@@ -206,12 +195,6 @@
setVerbose(true);
}
- if (copyToMETA_INF) {
- getLog().warn("\\n copyToMETA_INF is deprecated, prefer" +
- " use the generateBundle parameter\n\n");
- setGenerateBundle(true);
- }
-
File file = new File(getOutputDirectory(), getThirdPartyFilename());
setThirdPartyFile(file);
1
0
Author: tchemit
Date: 2010-06-02 12:28:27 +0200 (Wed, 02 Jun 2010)
New Revision: 1771
Url: http://nuiton.org/repositories/revision/maven-license-plugin/1771
Log:
Utilisation de mavenpom4redmine 2.1.5
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-05-09 12:34:18 UTC (rev 1770)
+++ trunk/pom.xml 2010-06-02 10:28:27 UTC (rev 1771)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.1.4</version>
+ <version>2.1.5</version>
</parent>
<artifactId>maven-license-plugin</artifactId>
1
0