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; + } }