Author: olamy
Date: Tue Mar 13 10:09:19 2012
New Revision: 1300047

URL: http://svn.apache.org/viewvc?rev=1300047&view=rev
Log:
[MSHADE-111] minimizeJar should not remove classes specifically included by 
filters
Submitted by Shane StClair.

Added:
    maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/
    
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/invoker.properties
   (with props)
    
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/pom.xml 
  (with props)
    maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/
    
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/
    
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/
    
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/Main.java
   (with props)
    
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/verify.bsh
   (with props)
Modified:
    
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/MinijarFilter.java
    
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/SimpleFilter.java
    
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
    
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/invoker.properties?rev=1300047&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/invoker.properties
 Tue Mar 13 10:09:19 2012
@@ -0,0 +1 @@
+invoker.java.version = 1.5+

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/pom.xml?rev=1300047&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/pom.xml 
(added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/pom.xml 
Tue Mar 13 10:09:19 2012
@@ -0,0 +1,101 @@
+<?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.mj</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <name>MSHADE-111</name>
+  <description>
+    Prevent minimizeJar from excluding classes that were specifically included 
with filters.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.2</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jdom</groupId>
+      <artifactId>jdom</artifactId>
+      <version>1.1</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm</artifactId>
+      <version>3.3.1</version>
+    </dependency>    
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.2</version>
+      </plugin>
+      <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>
+              <minimizeJar>true</minimizeJar>
+              <filters>
+                <filter>
+                  <artifact>junit:junit</artifact>
+                  <includes>
+                    <include>junit/framework/**</include>
+                    <include>junit/awtui/**</include>
+                    <include>junit/runner/**/*.properties</include>
+                    <include>junit/runner/**/*.gif</include>
+                    <include>junit/swingui/icons/*.gif</include>
+                  </includes>                
+                </filter>
+                <!-- make sure that include patterns only affect their 
specified artifacts -->
+                <filter>
+                  <artifact>org.jdom:jdom</artifact>
+                  <includes>
+                    <include>**</include>
+                  </includes>
+                </filter>
+              </filters>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/Main.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/Main.java?rev=1300047&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/Main.java
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/Main.java
 Tue Mar 13 10:09:19 2012
@@ -0,0 +1,4 @@
+public class Main
+    extends junit.framework.TestCase
+{
+}

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/src/main/java/Main.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/verify.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/verify.bsh?rev=1300047&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/verify.bsh
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/verify.bsh
 Tue Mar 13 10:09:19 2012
@@ -0,0 +1,38 @@
+import java.io.*;
+import java.util.jar.*;
+
+String[] wanted =
+{
+    "Main.class",
+    "junit/framework/TestCase.class",
+    "junit/swingui/icons/error.gif",
+    "junit/awtui/TestRunner.class",
+    "org/jdom/Document.class"
+};
+
+String[] unwanted =
+{
+    "junit/swingui/TestRunner.class",
+    "junit/textui/TestRunner.class",
+    "org/objectweb/asm/Type.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/mini-jar-respect-includes/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/mini-jar-respect-includes/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/MinijarFilter.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/MinijarFilter.java?rev=1300047&r1=1300046&r2=1300047&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/MinijarFilter.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/MinijarFilter.java
 Tue Mar 13 10:09:19 2012
@@ -19,14 +19,6 @@ package org.apache.maven.plugins.shade.f
  * under the License.
  */
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
@@ -35,9 +27,18 @@ import org.vafer.jdependency.Clazz;
 import org.vafer.jdependency.Clazzpath;
 import org.vafer.jdependency.ClazzpathUnit;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
 /**
  * A filter that prevents the inclusion of classes not required in the final 
jar.
- * 
+ *
  * @author Torsten Curdt
  */
 public class MinijarFilter
@@ -52,7 +53,7 @@ public class MinijarFilter
 
     private int classes_removed;
 
-    public MinijarFilter( MavenProject project, Log log )
+    public MinijarFilter( MavenProject project, Log log, List<SimpleFilter> 
simpleFilters )
         throws IOException
     {
 
@@ -80,31 +81,79 @@ public class MinijarFilter
         }
 
         removable = cp.getClazzes();
-        removePackages(artifactUnit);
+        removePackages( artifactUnit );
         removable.removeAll( artifactUnit.getClazzes() );
         removable.removeAll( artifactUnit.getTransitiveDependencies() );
+        removeSpecificallyIncludedClasses( project, simpleFilters );
     }
 
-    private void removePackages(ClazzpathUnit artifactUnit)
+    private void removePackages( ClazzpathUnit artifactUnit )
     {
         Set packageNames = new HashSet();
-        removePackages(artifactUnit.getClazzes(), packageNames);
-        removePackages(artifactUnit.getTransitiveDependencies(), packageNames);
+        removePackages( artifactUnit.getClazzes(), packageNames );
+        removePackages( artifactUnit.getTransitiveDependencies(), packageNames 
);
     }
 
-    private void removePackages(Set clazzes, Set packageNames)
+    private void removePackages( Set clazzes, Set packageNames )
     {
         Iterator it = clazzes.iterator();
-        while(it.hasNext())
+        while ( it.hasNext() )
         {
             Clazz clazz = (Clazz) it.next();
             String name = clazz.getName();
-            while(name.contains("."))
+            while ( name.contains( "." ) )
+            {
+                name = name.substring( 0, name.lastIndexOf( '.' ) );
+                if ( packageNames.add( name ) )
+                {
+                    removable.remove( new Clazz( name + ".package-info" ) );
+                }
+            }
+        }
+    }
+
+    private void removeSpecificallyIncludedClasses( MavenProject project, 
List<SimpleFilter> simpleFilters )
+        throws IOException
+    {
+        //remove classes specifically included in filters
+        Clazzpath checkCp = new Clazzpath();
+        for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
+        {
+            Artifact dependency = (Artifact) it.next();
+            File jar = dependency.getFile();
+
+            for ( Iterator<SimpleFilter> i = simpleFilters.iterator(); 
i.hasNext(); )
             {
-                name = name.substring(0, name.lastIndexOf('.'));
-                if(packageNames.add(name))
+                SimpleFilter simpleFilter = i.next();
+                if ( simpleFilter.canFilter( jar ) )
                 {
-                    removable.remove(new Clazz(name + ".package-info"));
+                    InputStream is = null;
+                    ClazzpathUnit depClazzpathUnit = null;
+                    try
+                    {
+                        is = new FileInputStream( dependency.getFile() );
+                        depClazzpathUnit = checkCp.addClazzpathUnit( is, 
dependency.toString() );
+                    }
+                    finally
+                    {
+                        IOUtil.close( is );
+                    }
+
+                    if ( depClazzpathUnit != null )
+                    {
+                        Iterator<Clazz> j = removable.iterator();
+                        while ( j.hasNext() )
+                        {
+                            Clazz clazz = j.next();
+
+                            if ( depClazzpathUnit.getClazzes().contains( clazz 
) && simpleFilter.isSpecificallyIncluded(
+                                clazz.getName().replace( '.', '/' ) ) )
+                            {
+                                log.info( clazz.getName() + " not removed 
because it was specifically included" );
+                                j.remove();
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -134,7 +183,8 @@ public class MinijarFilter
     public void finished()
     {
         int classes_total = classes_removed + classes_kept;
-        log.info( "Minimized " + classes_total + " -> " + classes_kept + " ("
-            + (int) ( 100 * classes_kept / classes_total ) + "%)" );
+        log.info(
+            "Minimized " + classes_total + " -> " + classes_kept + " (" + 
(int) ( 100 * classes_kept / classes_total )
+                + "%)" );
     }
 }

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/SimpleFilter.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/SimpleFilter.java?rev=1300047&r1=1300046&r2=1300047&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/SimpleFilter.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/SimpleFilter.java
 Tue Mar 13 10:09:19 2012
@@ -58,6 +58,18 @@ public class SimpleFilter
         return !( isIncluded( path ) && !isExcluded( path ) );
     }
 
+    public boolean isSpecificallyIncluded( String classFile )
+    {
+        if ( includes == null || includes.isEmpty() )
+        {
+            return false;
+        }
+
+        String path = normalizePath( classFile );
+
+        return isIncluded( path );
+    }
+
     private boolean isIncluded( String classFile )
     {
         if ( includes == null || includes.isEmpty() )

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=1300047&r1=1300046&r2=1300047&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 Mar 13 10:09:19 2012
@@ -19,22 +19,6 @@ package org.apache.maven.plugins.shade.m
  * under the License.
  */
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@@ -49,6 +33,7 @@ import org.apache.maven.model.Model;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.shade.Shader;
+import org.apache.maven.plugins.shade.filter.Filter;
 import org.apache.maven.plugins.shade.filter.MinijarFilter;
 import org.apache.maven.plugins.shade.filter.SimpleFilter;
 import org.apache.maven.plugins.shade.pom.PomWriter;
@@ -65,6 +50,22 @@ import org.codehaus.plexus.util.FileUtil
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.WriterFactory;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Mojo that performs shading delegating to the Shader component.
  *
@@ -190,7 +191,7 @@ public class ShadeMojo
      *   &lt;/excludes&gt;
      * &lt;/artifactSet&gt;
      * </pre>
-     * 
+     *
      * @parameter
      */
     private ArtifactSet artifactSet;
@@ -212,7 +213,7 @@ public class ShadeMojo
      * &lt;/relocations&gt;
      * </pre>
      * <em>Note:</em> Support for includes exists only since version 1.4.
-     * 
+     *
      * @parameter
      */
     private PackageRelocation[] relocations;
@@ -220,7 +221,7 @@ public class ShadeMojo
     /**
      * Resource transformers to be used. Please see the "Examples" section for 
more information on available
      * transformers and their configuration.
-     * 
+     *
      * @parameter
      */
     private ResourceTransformer[] transformers;
@@ -245,7 +246,7 @@ public class ShadeMojo
      *   &lt;/filter&gt;
      * &lt;/filters&gt;
      * </pre>
-     * 
+     *
      * @parameter
      */
     private ArchiveFilter[] filters;
@@ -259,7 +260,7 @@ public class ShadeMojo
 
     /**
      * The name of the shaded artifactId.
-     * 
+     * <p/>
      * If you like to change the name of the native artifact, you may use the 
&lt;build>&lt;finalName> setting.
      * If this is set to something different than &lt;build>&lt;finalName>, no 
file replacement
      * will be performed, even if shadedArtifactAttached is being used.
@@ -339,7 +340,7 @@ public class ShadeMojo
     /**
      * When true, dependencies will be stripped down on the class level to 
only the transitive hull required for the
      * artifact. <em>Note:</em> Usage of this feature requires Java 1.5 or 
higher.
-     * 
+     *
      * @parameter default-value="false"
      * @since 1.4
      */
@@ -350,13 +351,15 @@ public class ShadeMojo
      * replace the project's main artifact nor will it be attached. Hence, 
this parameter causes the parameters
      * {@link #finalName}, {@link #shadedArtifactAttached}, {@link 
#shadedClassifierName} and
      * {@link #createDependencyReducedPom} to be ignored when used.
-     * 
+     *
      * @parameter
      * @since 1.3
      */
     private File outputFile;
 
-    /** @throws MojoExecutionException  */
+    /**
+     * @throws MojoExecutionException
+     */
     public void execute()
         throws MojoExecutionException
     {
@@ -379,8 +382,8 @@ public class ShadeMojo
                 getLog().error( "- You have bound the goal to a lifecycle 
phase before \"package\". Please" );
                 getLog().error( "  remove this binding from your POM such that 
the goal will be run in" );
                 getLog().error( "  the proper phase." );
-                throw new MojoExecutionException( "Failed to create shaded 
artifact, "
-                    + "project main artifact does not exist." );
+                throw new MojoExecutionException(
+                    "Failed to create shaded artifact, " + "project main 
artifact does not exist." );
             }
 
             artifacts.add( project.getArtifact().getFile() );
@@ -428,7 +431,6 @@ public class ShadeMojo
             }
         }
 
-
         File outputJar = ( outputFile != null ) ? outputFile : 
shadedArtifactFileWithClassifier();
         File sourcesJar = shadedSourceArtifactFileWithClassifier();
 
@@ -455,8 +457,8 @@ public class ShadeMojo
                 // rename the output file if a specific finalName is set
                 // but don't rename if the finalName is the <build><finalName>
                 // because this will be handled implicitely later
-                if ( finalName != null && finalName.length() > 0
-                    && !finalName.equals( project.getBuild().getFinalName() ) )
+                if ( finalName != null && finalName.length() > 0 && 
!finalName.equals(
+                    project.getBuild().getFinalName() ) )
                 {
                     String finalFileName = finalName + "." + 
project.getArtifact().getArtifactHandler().getExtension();
                     File finalFile = new File( outputDirectory, finalFileName 
);
@@ -504,7 +506,8 @@ public class ShadeMojo
         }
     }
 
-    private void replaceFile( File oldFile, File newFile ) throws 
MojoExecutionException
+    private void replaceFile( File oldFile, File newFile )
+        throws MojoExecutionException
     {
         getLog().info( "Replacing " + oldFile + " with " + newFile );
 
@@ -574,11 +577,8 @@ public class ShadeMojo
     {
 
         Artifact resolvedArtifact =
-            artifactFactory.createArtifactWithClassifier( 
artifact.getGroupId(),
-                                                          
artifact.getArtifactId(),
-                                                          
artifact.getVersion(),
-                                                          "java-source",
-                                                          "sources" );
+            artifactFactory.createArtifactWithClassifier( 
artifact.getGroupId(), artifact.getArtifactId(),
+                                                          
artifact.getVersion(), "java-source", "sources" );
 
         try
         {
@@ -613,7 +613,8 @@ public class ShadeMojo
         {
             PackageRelocation r = relocations[i];
 
-            relocators.add( new SimpleRelocator( r.getPattern(), 
r.getShadedPattern(), r.getIncludes(), r.getExcludes(), r.isRawString() ) );
+            relocators.add( new SimpleRelocator( r.getPattern(), 
r.getShadedPattern(), r.getIncludes(), r.getExcludes(),
+                                                 r.isRawString() ) );
         }
 
         return relocators;
@@ -632,7 +633,8 @@ public class ShadeMojo
     private List getFilters()
         throws MojoExecutionException
     {
-        List filters = new ArrayList();
+        List<Filter> filters = new ArrayList<Filter>();
+        List<SimpleFilter> simpleFilters = new ArrayList<SimpleFilter>();
 
         if ( this.filters != null && this.filters.length > 0 )
         {
@@ -683,17 +685,19 @@ public class ShadeMojo
                     continue;
                 }
 
-                filters.add( new SimpleFilter( jars, filter.getIncludes(), 
filter.getExcludes() ) );
+                simpleFilters.add( new SimpleFilter( jars, 
filter.getIncludes(), filter.getExcludes() ) );
             }
         }
 
+        filters.addAll( simpleFilters );
+
         if ( minimizeJar )
         {
             getLog().info( "Minimizing jar " + project.getArtifact() );
 
             try
             {
-                filters.add( new MinijarFilter( project, getLog() ) );
+                filters.add( new MinijarFilter( project, getLog(), 
simpleFilters ) );
             }
             catch ( IOException e )
             {
@@ -707,9 +711,8 @@ public class ShadeMojo
     private File shadedArtifactFileWithClassifier()
     {
         Artifact artifact = project.getArtifact();
-        final String shadedName =
-            shadedArtifactId + "-" + artifact.getVersion() + "-" + 
shadedClassifierName + "."
-                + artifact.getArtifactHandler().getExtension();
+        final String shadedName = shadedArtifactId + "-" + 
artifact.getVersion() + "-" + shadedClassifierName + "."
+            + artifact.getArtifactHandler().getExtension();
         return new File( outputDirectory, shadedName );
     }
 
@@ -757,12 +760,12 @@ public class ShadeMojo
         {
             Artifact artifact = (Artifact) it.next();
 
-          if ( "pom".equals( artifact.getType() ) )
-          {
-              // don't include pom type dependencies in dependency reduced pom
-              continue;
-          }
-            
+            if ( "pom".equals( artifact.getType() ) )
+            {
+                // don't include pom type dependencies in dependency reduced 
pom
+                continue;
+            }
+
             //promote
             Dependency dep = new Dependency();
             dep.setArtifactId( artifact.getArtifactId() );
@@ -874,18 +877,12 @@ public class ShadeMojo
         return groupId + ":" + artifactId + ":" + type + ":" + ( ( classifier 
!= null ) ? classifier : "" );
     }
 
-    public boolean updateExcludesInDeps( MavenProject project,
-                                         List dependencies,
-                                         List transitiveDeps )
+    public boolean updateExcludesInDeps( MavenProject project, List 
dependencies, List transitiveDeps )
         throws DependencyTreeBuilderException
     {
-        DependencyNode node = dependencyTreeBuilder.buildDependencyTree(
-                                                  project,
-                                                  localRepository,
-                                                  artifactFactory,
-                                                  artifactMetadataSource,
-                                                  null,
-                                                  artifactCollector );
+        DependencyNode node = dependencyTreeBuilder.buildDependencyTree( 
project, localRepository, artifactFactory,
+                                                                         
artifactMetadataSource, null,
+                                                                         
artifactCollector );
         boolean modified = false;
         Iterator it = node.getChildren().listIterator();
         while ( it.hasNext() )
@@ -910,8 +907,8 @@ public class ShadeMojo
                     for ( int x = 0; x < transitiveDeps.size(); x++ )
                     {
                         Dependency dep = (Dependency) transitiveDeps.get( x );
-                        if ( dep.getArtifactId().equals( 
n3.getArtifact().getArtifactId() )
-                            && dep.getGroupId().equals( 
n3.getArtifact().getGroupId() ) )
+                        if ( dep.getArtifactId().equals( 
n3.getArtifact().getArtifactId() ) && dep.getGroupId().equals(
+                            n3.getArtifact().getGroupId() ) )
                         {
                             found = true;
                         }

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=1300047&r1=1300046&r2=1300047&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 Mar 13 10:09:19 2012
@@ -151,3 +151,48 @@ Selecting Contents for Uber JAR
   ...
 </project>
 +-----
+
+  As of version 1.6, minimizeJar will respect classes that were specifically 
marked for inclusion in a filter.
+  Note that specifying an include filter for classes in an artifact implicitly 
excludes all non-specified
+  classes in that artifact.
+  
++-----
+<project>
+  ...
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>${project.version}</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <minimizeJar>true</minimizeJar>
+            </configuration>
+            <filters>
+              <filter>
+                 <artifact>log4j:log4j</artifact>
+                 <includes>
+                     <include>**</include>
+                 </includes>
+              </filter>
+              <filter>
+                 <artifact>commons-logging:commons-logging</artifact>
+                 <includes>
+                     <include>**</include>
+                 </includes>
+              </filter>
+            </filters>            
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  ...
+</project>
++-----  
\ No newline at end of file

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java?rev=1300047&r1=1300046&r2=1300047&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
 Tue Mar 13 10:09:19 2012
@@ -48,9 +48,8 @@ public class ComponentsXmlResourceTransf
                                      Collections.EMPTY_LIST );
         transformer.processResource( "components-1.xml", 
getClass().getResourceAsStream( "/components-2.xml" ),
                                      Collections.EMPTY_LIST );
-
+        
         assertEquals( IOUtil.toString( getClass().getResourceAsStream( 
"/components-expected.xml" ), "UTF-8" ),
-                      IOUtil.toString( transformer.getTransformedResource(), 
"UTF-8" ) );
+                      IOUtil.toString( transformer.getTransformedResource(), 
"UTF-8" ).replaceAll("\r\n", "\n") );
     }
-
-}
+}
\ No newline at end of file


Reply via email to