r1815 - in trunk: . src/it src/it/evol-818 src/main/java/org/nuiton/license/plugin
Author: ymartel Date: 2010-09-22 17:46:33 +0200 (Wed, 22 Sep 2010) New Revision: 1815 Url: http://nuiton.org/repositories/revision/maven-license-plugin/1815 Log: [Evo 818] Add a way to filter (exclude) some groupId or ArtifactId from thirdParty report Added: trunk/src/it/evol-818/ trunk/src/it/evol-818/invoker.properties trunk/src/it/evol-818/pom.xml trunk/src/it/evol-818/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/AggregatorAddThirdPartyMojo.java trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-09-09 09:30:33 UTC (rev 1814) +++ trunk/pom.xml 2010-09-22 15:46:33 UTC (rev 1815) @@ -429,6 +429,7 @@ <artifactId>maven-invoker-plugin</artifactId> <configuration> <pomIncludes> + <pomInclude>evol-818/pom.xml</pomInclude> <pomInclude>ano-816/pom.xml</pomInclude> <pomInclude>add-third-party/no-encoding/pom.xml</pomInclude> <pomInclude>aggregate-add-third-party/pom.xml</pomInclude> Copied: trunk/src/it/evol-818/invoker.properties (from rev 1814, trunk/src/it/ano-816/invoker.properties) =================================================================== --- trunk/src/it/evol-818/invoker.properties (rev 0) +++ trunk/src/it/evol-818/invoker.properties 2010-09-22 15:46:33 UTC (rev 1815) @@ -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/evol-818/pom.xml =================================================================== --- trunk/src/it/evol-818/pom.xml (rev 0) +++ trunk/src/it/evol-818/pom.xml 2010-09-22 15:46:33 UTC (rev 1815) @@ -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>test-it-818</artifactId> + <version>1.0</version> + + <name>License Test :: evo-818</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.i18n</groupId> + <artifactId>nuiton-i18n</artifactId> + <version>1.2.1</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> + <projectFilter>org.nuiton</projectFilter> + <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> + + Copied: trunk/src/it/evol-818/verify.groovy (from rev 1814, trunk/src/it/ano-816/verify.groovy) =================================================================== --- trunk/src/it/evol-818/verify.groovy (rev 0) +++ trunk/src/it/evol-818/verify.groovy 2010-09-22 15:46:33 UTC (rev 1815) @@ -0,0 +1,18 @@ + +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.i18n:nuiton-i18n:1.2.1' ); + + +file = new File(basedir, 'target/generated-sources/license/thirdWithoutArtifact.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.i18n:nuiton-i18n:1.2.1' ); +assert content.contains( 'org.nuiton:maven-helper-plugin:1.2.3' ); + +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-09 09:30:33 UTC (rev 1814) +++ trunk/src/main/java/org/nuiton/license/plugin/AbstractAddThirdPartyMojo.java 2010-09-22 15:46:33 UTC (rev 1815) @@ -25,6 +25,16 @@ package org.nuiton.license.plugin; +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; + import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.artifact.Artifact; @@ -35,16 +45,6 @@ import org.nuiton.plugin.PluginHelper; import org.nuiton.plugin.PluginWithEncoding; -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; - /** * Goal to generate the THIRD-PARTY.txt file which resumes all dependencies with * their licenses. @@ -158,6 +158,13 @@ protected boolean groupByLicense; /** + * A filter for projects licenses. + * @parameter expression="${license.projectFilter}" default-value="" + * @since 2.3.2 + */ + protected String projectFilter; + + /** * Encoding used to read and writes files. * <p/> * <b>Note:</b> If nothing is filled here, we will use the system @@ -506,4 +513,14 @@ public void setDoGenerateBundle(boolean doGenerateBundle) { this.doGenerateBundle = doGenerateBundle; } + + public String getProjectFilter() + { + return projectFilter; + } + + public void setProjectFilter(String projectFilter) + { + this.projectFilter = projectFilter; + } } \ 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-09 09:30:33 UTC (rev 1814) +++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyMojo.java 2010-09-22 15:46:33 UTC (rev 1815) @@ -25,6 +25,13 @@ package org.nuiton.license.plugin; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; + import org.apache.commons.collections.CollectionUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -35,13 +42,6 @@ import org.apache.maven.project.ProjectBuildingException; import org.nuiton.io.SortedProperties; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; - /** * 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 @@ -97,7 +97,7 @@ protected LicenseMap createLicenseMap() throws ProjectBuildingException { Log log = getLog(); - LicenseMap licenseMap = new LicenseMap(); + LicenseMap licenseMap = new LicenseMap(this.getProjectFilter()); licenseMap.setLog(log); // build the license map for the dependencies of the project @@ -242,4 +242,4 @@ this.doGenerateMissing = doGenerateMissing; } -} \ 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-09-09 09:30:33 UTC (rev 1814) +++ trunk/src/main/java/org/nuiton/license/plugin/AggregatorAddThirdPartyMojo.java 2010-09-22 15:46:33 UTC (rev 1815) @@ -25,6 +25,12 @@ package org.nuiton.license.plugin; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.SortedMap; +import java.util.SortedSet; + import org.apache.commons.collections.CollectionUtils; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; @@ -32,12 +38,6 @@ 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) @@ -83,7 +83,7 @@ protected LicenseMap createLicenseMap() throws ProjectBuildingException { Log log = getLog(); - LicenseMap licenseMap = new LicenseMap(); + LicenseMap licenseMap = new LicenseMap(this.getProjectFilter()); licenseMap.setLog(log); SortedMap<String, MavenProject> artifacts = getArtifactCache(); @@ -159,4 +159,4 @@ } } -} \ No newline at end of file +} Modified: trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-09-09 09:30:33 UTC (rev 1814) +++ trunk/src/main/java/org/nuiton/license/plugin/LicenseMap.java 2010-09-22 15:46:33 UTC (rev 1815) @@ -47,6 +47,9 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; /** * Map of artifacts (stub in mavenproject) group by their license. @@ -59,10 +62,12 @@ private static final long serialVersionUID = 864199843545688069L; private transient Log log; + private transient String licenseFilterPattern; public static final String unknownLicenseMessage = "Unknown license"; - public LicenseMap() { + public LicenseMap(String someLicenseFilterPattern) { + licenseFilterPattern = someLicenseFilterPattern; } public void setLog(Log log) { @@ -82,6 +87,31 @@ return; } + if (StringUtils.isNotEmpty(licenseFilterPattern)) { + // we have some defined license filters + try { + Pattern pattern = Pattern.compile(licenseFilterPattern); + Matcher matchGroupId = pattern.matcher(project.getGroupId()); + if (matchGroupId.find()) { + if (log.isDebugEnabled()) { + log.debug("Exclude " + project.getGroupId()); + } + return; + } + Matcher matchArtifactId = pattern.matcher(project.getArtifactId()); + if (matchArtifactId.find()) { + if (log.isDebugEnabled()) { + log.debug("Exclude " + project.getGroupId() + ":" + + project.getArtifactId()); + } + return; + } + } + catch (PatternSyntaxException e) { + getLog().warn("The pattern specified by expression <" + licenseFilterPattern + "> seems to be invalid."); + } + } + if (CollectionUtils.isEmpty(licenses)) { // no license found for the dependency
participants (1)
-
ymartel@users.nuiton.org