Author: ymartel Date: 2010-09-23 12:22:07 +0200 (Thu, 23 Sep 2010) New Revision: 1816 Url: http://nuiton.org/repositories/revision/maven-license-plugin/1816 Log: Add parameter excludedGroups to exclude some groupIds from the thirdParty reports. Added: trunk/src/it/excluded-included/ trunk/src/it/excluded-included/invoker.properties trunk/src/it/excluded-included/pom.xml trunk/src/it/excluded-included/verify.groovy Modified: trunk/pom.xml 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/LicenseMap.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-09-22 15:46:33 UTC (rev 1815) +++ trunk/pom.xml 2010-09-23 10:22:07 UTC (rev 1816) @@ -429,6 +429,7 @@ <artifactId>maven-invoker-plugin</artifactId> <configuration> <pomIncludes> + <pomInclude>excluded-included/pom.xml</pomInclude> <pomInclude>evol-818/pom.xml</pomInclude> <pomInclude>ano-816/pom.xml</pomInclude> <pomInclude>add-third-party/no-encoding/pom.xml</pomInclude> @@ -438,7 +439,6 @@ <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> Added: trunk/src/it/excluded-included/invoker.properties =================================================================== --- trunk/src/it/excluded-included/invoker.properties (rev 0) +++ trunk/src/it/excluded-included/invoker.properties 2010-09-23 10:22:07 UTC (rev 1816) @@ -0,0 +1,21 @@ +# 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=validate + +# Optionally, a list of goals to run during further invocations of Maven +#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run + +# A comma or space separated list of profiles to activate +#invoker.profiles=run-all run-once + +# The value for the environment variable MAVEN_OPTS +#invoker.mavenOpts=-Dfile.encoding=UTF-16 -Xms32m -Xmx256m + +# Possible values are "fail-fast" (default), "fail-at-end" and "fail-never" +invoker.failureBehavior=fail-at-end + +# The expected result of the build, possible values are "success" (default) and "failure" +#invoker.buildResult=success + +# A boolean value controlling the -N flag, defaults to "false" +#invoker.nonRecursive=false Added: trunk/src/it/excluded-included/pom.xml =================================================================== --- trunk/src/it/excluded-included/pom.xml (rev 0) +++ trunk/src/it/excluded-included/pom.xml 2010-09-23 10:22:07 UTC (rev 1816) @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.nuiton.license.test</groupId> + <artifactId>excluded-included</artifactId> + <version>1.0</version> + + <name>License Test :: excluded-included</name> + + <url>no-url</url> + <properties> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <license.verbose>true</license.verbose> + </properties> + + + <dependencies> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>maven-helper-plugin</artifactId> + <version>1.2.3</version> + </dependency> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + <version>1.4</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + </dependency> + </dependencies> + + <build> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <version>@pom.version@</version> + </plugin> + </plugins> + </pluginManagement> + + <plugins> + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <executions> + <execution> + <id>group-filter</id> + <goals> + <goal>add-third-party</goal> + </goals> + <phase>validate</phase> + <configuration> + <excludedGroups>org.nuiton*</excludedGroups> + <thirdPartyFilename>thirdWithoutGroup.txt</thirdPartyFilename> + </configuration> + </execution> + <!--<execution>--> + <!--<id>artifact-filter</id>--> + <!--<goals>--> + <!--<goal>add-third-party</goal>--> + <!--</goals>--> + <!--<phase>validate</phase>--> + <!--<configuration>--> + <!--<projectFilter>nuiton-i18n</projectFilter>--> + <!--<thirdPartyFilename>thirdWithoutArtifact.txt</thirdPartyFilename>--> + <!--</configuration>--> + <!--</execution>--> + </executions> + </plugin> + </plugins> + </build> + +</project> + + Added: trunk/src/it/excluded-included/verify.groovy =================================================================== --- trunk/src/it/excluded-included/verify.groovy (rev 0) +++ trunk/src/it/excluded-included/verify.groovy 2010-09-23 10:22:07 UTC (rev 1816) @@ -0,0 +1,9 @@ + +file = new File(basedir, 'target/generated-sources/license/thirdWithoutGroup.txt'); +assert file.exists(); +content = file.text; +assert !content.contains( 'the project has no dependencies.' ); +assert content.contains( 'commons-logging:commons-logging:1.1.1' ); +assert !content.contains( 'org.nuiton:nuiton-util:1.4' ); + +return true; Modified: trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-09-22 15:46:33 UTC (rev 1815) +++ trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-09-23 10:22:07 UTC (rev 1816) @@ -163,8 +163,16 @@ * @since 2.3.2 */ protected String projectFilter; - + /** + * A filter to exclude some GroupIds + * + * @parameter expression="${license.excludedGroups}" default-value="" + * @since 2.3.2 + */ + protected String excludedGroups; + + /** * Encoding used to read and writes files. * <p/> * <b>Note:</b> If nothing is filled here, we will use the system @@ -523,4 +531,14 @@ { this.projectFilter = projectFilter; } + + public String getExcludedGroups() + { + return excludedGroups; + } + + public void setExcludedGroups(String excludedGroups) + { + this.excludedGroups = excludedGroups; + } } \ 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-09-22 15:46:33 UTC (rev 1815) +++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-09-23 10:22:07 UTC (rev 1816) @@ -31,8 +31,12 @@ import java.util.List; import java.util.Set; import java.util.SortedSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; 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.plugin.MojoFailureException; @@ -115,7 +119,25 @@ MavenProject project = addArtifact(id, artifact); - licenseMap.addLicense(project, project.getLicenses()); + // filter with the excluded groupIds + if (StringUtils.isNotEmpty(excludedGroups)) { + // we have some defined license filters + try { + Pattern pattern = Pattern.compile(excludedGroups); + Matcher matchGroupId = pattern.matcher(project.getGroupId()); + if (!matchGroupId.find()) { + if (log.isDebugEnabled()) { + log.debug("Exclude " + project.getGroupId()); + } + licenseMap.addLicense(project, project.getLicenses()); + } + } + catch (PatternSyntaxException e) { + getLog().warn("The pattern specified by expression <" + excludedGroups + "> seems to be invalid."); + } + } else { + licenseMap.addLicense(project, project.getLicenses()); + } } return licenseMap; } @@ -125,7 +147,7 @@ SortedProperties unsafeMappings = getLicenseMap().loadUnsafeMapping(getEncoding(), - getMissingFile()); + getMissingFile()); SortedSet<MavenProject> unsafeDependencies = getUnsafeDependencies(); @@ -150,8 +172,8 @@ @Override protected boolean checkSkip() { if (!isDoGenerate() && - !isDoGenerateBundle() && - !isDoGenerateMissing()) { + !isDoGenerateBundle() && + !isDoGenerateMissing()) { getLog().info("All files are up to date, skip goal execution."); return false; @@ -186,7 +208,7 @@ createDirectoryIfNecessary(file.getParentFile()); log.info("Regenerate missing license file " + file); - + FileWriter writer = new FileWriter(file); try { StringBuilder sb = new StringBuilder(" Generated by " + getClass().getName()); Modified: trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-09-22 15:46:33 UTC (rev 1815) +++ trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-09-23 10:22:07 UTC (rev 1816) @@ -62,10 +62,13 @@ private static final long serialVersionUID = 864199843545688069L; private transient Log log; - private transient String licenseFilterPattern; + private String licenseFilterPattern; public static final String unknownLicenseMessage = "Unknown license"; + public LicenseMap() { + } + public LicenseMap(String someLicenseFilterPattern) { licenseFilterPattern = someLicenseFilterPattern; }