You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/12/30 00:30:40 UTC
svn commit: r894514 - in /maven/plugins/trunk/maven-shade-plugin/src:
it/artifact-includes-excludes/ it/artifact-includes-excludes/repo/
it/artifact-includes-excludes/repo/org/
it/artifact-includes-excludes/repo/org/apache/
it/artifact-includes-exclude...
Author: bentmann
Date: Tue Dec 29 23:30:39 2009
New Revision: 894514
URL: http://svn.apache.org/viewvc?rev=894514&view=rev
Log:
[MSHADE-33] [shade] Support wildcarded excludes
Added:
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/pom.xml (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.jar (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.pom
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/maven-metadata.xml (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.jar (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.pom
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/maven-metadata.xml (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/verify.bsh (with props)
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ArtifactSelector.java (with props)
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ArtifactSelectorTest.java (with props)
Modified:
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/includes-excludes.apt.vm
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/pom.xml?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/pom.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/pom.xml Tue Dec 29 23:30:39 2009
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.aie</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+
+ <name>MSHADE-33</name>
+ <description>
+ Test artifact selection via glob includes/excludes.
+ </description>
+
+ <repositories>
+ <repository>
+ <id>shade-it</id>
+ <url>file:///${basedir}/repo</url>
+ <releases>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.its.shade.aie</groupId>
+ <artifactId>a</artifactId>
+ <version>0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.its.shade.aie</groupId>
+ <artifactId>b</artifactId>
+ <version>0.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>attach-shade</id>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <shadedArtifactAttached>false</shadedArtifactAttached>
+ <artifactSet>
+ <includes>
+ <include>org.apache.maven.its.shade.aie</include>
+ </includes>
+ <excludes>
+ <exclude>*:b:jar:</exclude>
+ </excludes>
+ </artifactSet>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.jar?rev=894514&view=auto
==============================================================================
Binary file - no diff available.
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.pom
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.pom?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.pom (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/0.1/a-0.1.pom Tue Dec 29 23:30:39 2009
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.aie</groupId>
+ <artifactId>a</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+
+ <distributionManagement>
+ <repository>
+ <id>maven-core-it</id>
+ <url>file:///${basedir}/repo</url>
+ </repository>
+ </distributionManagement>
+</project>
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/maven-metadata.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/maven-metadata.xml?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/maven-metadata.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/maven-metadata.xml Tue Dec 29 23:30:39 2009
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+ <groupId>org.apache.maven.its.shade.aie</groupId>
+ <artifactId>a</artifactId>
+ <version>0.1</version>
+ <versioning>
+ <versions>
+ <version>0.1</version>
+ </versions>
+ <lastUpdated>20091229231152</lastUpdated>
+ </versioning>
+</metadata>
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/maven-metadata.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/a/maven-metadata.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.jar?rev=894514&view=auto
==============================================================================
Binary file - no diff available.
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.pom
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.pom?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.pom (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/0.2/b-0.2.pom Tue Dec 29 23:30:39 2009
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.aie</groupId>
+ <artifactId>b</artifactId>
+ <version>0.2</version>
+ <packaging>jar</packaging>
+
+ <distributionManagement>
+ <repository>
+ <id>maven-core-it</id>
+ <url>file:///${basedir}/repo</url>
+ </repository>
+ </distributionManagement>
+</project>
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/maven-metadata.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/maven-metadata.xml?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/maven-metadata.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/maven-metadata.xml Tue Dec 29 23:30:39 2009
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+ <groupId>org.apache.maven.its.shade.aie</groupId>
+ <artifactId>b</artifactId>
+ <version>0.2</version>
+ <versioning>
+ <versions>
+ <version>0.2</version>
+ </versions>
+ <lastUpdated>20091229231210</lastUpdated>
+ </versioning>
+</metadata>
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/maven-metadata.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/repo/org/apache/maven/its/shade/aie/b/maven-metadata.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/verify.bsh?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/verify.bsh (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/verify.bsh Tue Dec 29 23:30:39 2009
@@ -0,0 +1,33 @@
+import java.io.*;
+import java.util.jar.*;
+
+String[] wanted =
+{
+ "a.properties",
+};
+
+String[] unwanted =
+{
+ "b.properties",
+ "junit/framework/TestCase.class",
+};
+
+JarFile jarFile = new JarFile( new File( basedir, "target/test-1.0.jar" ) );
+
+for ( String path : wanted )
+{
+ if ( jarFile.getEntry( path ) == null )
+ {
+ throw new IllegalStateException( "wanted path is missing: " + path );
+ }
+}
+
+for ( String path : unwanted )
+{
+ if ( jarFile.getEntry( path ) != null )
+ {
+ throw new IllegalStateException( "unwanted path is present: " + path );
+ }
+}
+
+jarFile.close();
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/artifact-includes-excludes/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ArtifactSelector.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ArtifactSelector.java?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ArtifactSelector.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ArtifactSelector.java Tue Dec 29 23:30:39 2009
@@ -0,0 +1,94 @@
+package org.apache.maven.plugins.shade.mojo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * @author Benjamin Bentmann
+ */
+class ArtifactSelector
+{
+
+ private Collection includes;
+
+ private Collection excludes;
+
+ public ArtifactSelector( ArtifactSet artifactSet, String groupPrefix )
+ {
+ this( ( artifactSet != null ) ? artifactSet.getIncludes() : null,
+ ( artifactSet != null ) ? artifactSet.getExcludes() : null, groupPrefix );
+ }
+
+ public ArtifactSelector( Collection includes, Collection excludes, String groupPrefix )
+ {
+ this.includes = toIds( includes );
+ this.excludes = toIds( excludes );
+
+ if ( groupPrefix != null && groupPrefix.length() > 0 )
+ {
+ this.includes.add( new ArtifactId( groupPrefix + "*", "*", "*", "*" ) );
+ }
+ }
+
+ private static Collection toIds( Collection patterns )
+ {
+ Collection result = new HashSet();
+
+ if ( patterns != null )
+ {
+ for ( Iterator it = patterns.iterator(); it.hasNext(); )
+ {
+ String pattern = (String) it.next();
+ result.add( new ArtifactId( pattern ) );
+ }
+ }
+
+ return result;
+ }
+
+ public boolean isSelected( Artifact artifact )
+ {
+ return ( artifact != null ) ? isSelected( new ArtifactId( artifact ) ) : false;
+ }
+
+ boolean isSelected( ArtifactId id )
+ {
+ return ( includes.isEmpty() || matches( includes, id ) ) && !matches( excludes, id );
+ }
+
+ private boolean matches( Collection patterns, ArtifactId id )
+ {
+ for ( Iterator it = patterns.iterator(); it.hasNext(); )
+ {
+ ArtifactId pattern = (ArtifactId) it.next();
+ if ( id.matches( pattern ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Propchange: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ArtifactSelector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ArtifactSelector.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java?rev=894514&r1=894513&r2=894514&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java (original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java Tue Dec 29 23:30:39 2009
@@ -172,8 +172,13 @@
protected ArtifactResolver artifactResolver;
/**
- * Artifacts to include/exclude from the final artifact.
- *
+ * Artifacts to include/exclude from the final artifact. Artifacts are denoted by composite identifiers of the
+ * general form <code>groupId:artifactId:type:classifier</code>. Since version 1.3, the wildcard characters '*' and '?' can be used
+ * within the sub parts of those composite identifiers to do pattern matching. For convenience, the syntax
+ * <code>groupId</code> is equivalent to <code>groupId:*:*:*</code>, <code>groupId:artifactId</code> is equivalent
+ * to <code>groupId:artifactId:*:*</code> and <code>groupId:artifactId:classifier</code> is equivalent to
+ * <code>groupId:artifactId:*:classifier</code>.
+ *
* @parameter
*/
private ArtifactSet artifactSet;
@@ -193,16 +198,12 @@
private ResourceTransformer[] transformers;
/**
- * Archive Filters to be used. Allows you to specify an artifact in the form of
- * <code>groupId:artifactId:type:classifier</code> and a set of include/exclude file patterns for filtering which
- * contents of the archive are added to the shaded jar. Just like the include/exclude patterns, the artifact
- * coordinates for the filter support the wildcard characters '*' and '?'. For convenience, the syntax
- * <code>groupId</code> is equivalent to <code>groupId:*:*:*</code>, <code>groupId:artifactId</code> is equivalent
- * to <code>groupId:artifactId:*:*</code> and <code>groupId:artifactId:classifier</code> is equivalent to
- * <code>groupId:artifactId:*:classifier</code>. From a logical perspective, includes are processed before excludes,
- * thus it's possible to use an include to collect a set of files from the archive then use excludes to further
- * reduce the set. By default, all files are included and no files are excluded. If multiple filters apply to an
- * artifact, the intersection of the matched files will be included in the final JAR.
+ * Archive Filters to be used. Allows you to specify an artifact in the form of a composite identifier as used by
+ * {@link #artifactSet} and a set of include/exclude file patterns for filtering which contents of the archive are
+ * added to the shaded jar. From a logical perspective, includes are processed before excludes, thus it's possible
+ * to use an include to collect a set of files from the archive then use excludes to further reduce the set. By
+ * default, all files are included and no files are excluded. If multiple filters apply to an artifact, the
+ * intersection of the matched files will be included in the final JAR.
*
* @parameter
*/
@@ -327,11 +328,13 @@
}
}
+ ArtifactSelector artifactSelector = new ArtifactSelector( artifactSet, shadedGroupFilter );
+
for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
- if ( excludeArtifact( artifact ) )
+ if ( !artifactSelector.isSelected( artifact ) )
{
getLog().info( "Excluding " + artifact.getId() + " from the shaded jar." );
@@ -529,51 +532,6 @@
return null;
}
- private boolean excludeArtifact( Artifact artifact )
- {
- String id = getId( artifact );
-
- // This is the case where we have only stated artifacts to include and no exclusions
- // have been listed. We just want what we have asked to include.
- if ( artifactSet != null && ( artifactSet.getExcludes() == null && artifactSet.getIncludes() != null )
- && !includedArtifacts().contains( id ) )
- {
- return true;
- }
-
- if ( excludedArtifacts().contains( id ) )
- {
- return true;
- }
-
- if ( shadedGroupFilter != null && !artifact.getGroupId().startsWith( shadedGroupFilter ) )
- {
- return true;
- }
-
- return false;
- }
-
- private Set excludedArtifacts()
- {
- if ( artifactSet != null && artifactSet.getExcludes() != null )
- {
- return artifactSet.getExcludes();
- }
-
- return Collections.EMPTY_SET;
- }
-
- private Set includedArtifacts()
- {
- if ( artifactSet != null && artifactSet.getIncludes() != null )
- {
- return artifactSet.getIncludes();
- }
-
- return Collections.EMPTY_SET;
- }
-
private List getRelocators()
{
List relocators = new ArrayList();
@@ -805,24 +763,18 @@
private String getId( Artifact artifact )
{
- return getId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier() );
+ return getId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), artifact.getClassifier() );
}
private String getId( Dependency dependency )
{
- return getId( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier() );
+ return getId( dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(),
+ dependency.getClassifier() );
}
- private String getId( String groupId, String artifactId, String classifier )
+ private String getId( String groupId, String artifactId, String type, String classifier )
{
- if ( classifier == null || "jar".equals( classifier ) )
- {
- return groupId + ":" + artifactId;
- }
- else
- {
- return groupId + ":" + artifactId + ":" + classifier;
- }
+ return groupId + ":" + artifactId + ":" + type + ":" + ( ( classifier != null ) ? classifier : "" );
}
public boolean updateExcludesInDeps( MavenProject project,
Modified: maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/includes-excludes.apt.vm
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/includes-excludes.apt.vm?rev=894514&r1=894513&r2=894514&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/includes-excludes.apt.vm (original)
+++ maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/includes-excludes.apt.vm Tue Dec 29 23:30:39 2009
@@ -47,8 +47,8 @@
<excludes>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
- <exclude>jmock:jmock</exclude>
- <exclude>xml-apis:xml-apis</exclude>
+ <exclude>jmock:*</exclude>
+ <exclude>*:xml-apis</exclude>
</excludes>
</artifactSet>
</configuration>
@@ -62,7 +62,9 @@
+-----
Of course, <<<\<includes\>>>> can be used as well to specify a white list of artifacts. Artifacts are denoted by a
- composite idenitifer of the form <groupId>:<artifactId>[:<classifier>].
+ composite idenitifer of the form <groupId>:<artifactId>[[:<type>]:<classifier>]. Since plugin version 1.3, the
+ wildcard characters '*' and '?' can be used to do glob-like pattern matching.
+
For fine-grained control of which classes from the selected dependencies are included, artifact filters can be used:
Added: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ArtifactSelectorTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ArtifactSelectorTest.java?rev=894514&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ArtifactSelectorTest.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ArtifactSelectorTest.java Tue Dec 29 23:30:39 2009
@@ -0,0 +1,65 @@
+package org.apache.maven.plugins.shade.mojo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Benjamin Bentmann
+ */
+public class ArtifactSelectorTest
+ extends TestCase
+{
+
+ public void testIsSelected()
+ {
+ ArtifactSelector selector;
+
+ selector = new ArtifactSelector( null, null, null );
+ assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
+
+ selector = new ArtifactSelector( null, null, "" );
+ assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
+
+ selector = new ArtifactSelector( null, null, "gid" );
+ assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
+ assertTrue( selector.isSelected( new ArtifactId( "gid.test", "aid", "type", "cls" ) ) );
+ assertFalse( selector.isSelected( new ArtifactId( "id", "aid", "type", "cls" ) ) );
+
+ selector = new ArtifactSelector( Collections.EMPTY_SET, Collections.EMPTY_SET, null );
+ assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
+
+ selector = new ArtifactSelector( Collections.singleton( "gid:aid" ), Collections.EMPTY_SET, null );
+ assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
+ assertFalse( selector.isSelected( new ArtifactId( "gid", "id", "type", "cls" ) ) );
+
+ selector = new ArtifactSelector( Collections.EMPTY_SET, Collections.singleton( "gid:aid" ), null );
+ assertFalse( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
+ assertTrue( selector.isSelected( new ArtifactId( "gid", "id", "type", "cls" ) ) );
+
+ selector = new ArtifactSelector( Collections.singleton( "gid:*" ), Collections.singleton( "*:aid" ), null );
+ assertTrue( selector.isSelected( new ArtifactId( "gid", "id", "type", "cls" ) ) );
+ assertFalse( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
+ assertFalse( selector.isSelected( new ArtifactId( "gid.test", "id", "type", "cls" ) ) );
+ }
+
+}
Propchange: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ArtifactSelectorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ArtifactSelectorTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision