You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2015/05/30 00:04:05 UTC

svn commit: r1682559 - in /maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade: ./ filter/ mojo/ pom/

Author: khmarbaise
Date: Fri May 29 22:04:04 2015
New Revision: 1682559

URL: http://svn.apache.org/r1682559
Log:
Refactored code to cleanup checkstyle errors/warngings.

Added:
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/Counter.java
Modified:
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/Filter.java
    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/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java?rev=1682559&r1=1682558&r2=1682559&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java (original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java Fri May 29 22:04:04 2015
@@ -93,29 +93,7 @@ public class DefaultShader
         FileOutputStream fileOutputStream = new FileOutputStream( shadeRequest.getUberJar() );
         JarOutputStream jos = new JarOutputStream( new BufferedOutputStream( fileOutputStream ) );
 
-        if ( manifestTransformer != null )
-        {
-            for ( File jar : shadeRequest.getJars() )
-            {
-                JarFile jarFile = newJarFile( jar );
-                for ( Enumeration<JarEntry> en = jarFile.entries(); en.hasMoreElements(); )
-                {
-                    JarEntry entry = en.nextElement();
-                    String resource = entry.getName();
-                    if ( manifestTransformer.canTransformResource( resource ) )
-                    {
-                        resources.add( resource );
-                        manifestTransformer.processResource( resource, jarFile.getInputStream( entry ),
-                                                             shadeRequest.getRelocators() );
-                        break;
-                    }
-                }
-            }
-            if ( manifestTransformer.hasTransformedResource() )
-            {
-                manifestTransformer.modifyOutputStream( jos );
-            }
-        }
+        goThroughAllJarEntriesForManifestTransformer( shadeRequest, resources, manifestTransformer, jos );
 
         // CHECKSTYLE_OFF: MagicNumber
         Multimap<String, File> duplicates = HashMultimap.create( 10000, 3 );
@@ -211,6 +189,72 @@ public class DefaultShader
         }
 
         // Log a summary of duplicates
+        logSummaryOfDuplicates( overlapping );
+
+        if ( overlapping.keySet().size() > 0 )
+        {
+            showOverlappingWarning();
+        }
+
+        for ( ResourceTransformer transformer : transformers )
+        {
+            if ( transformer.hasTransformedResource() )
+            {
+                transformer.modifyOutputStream( jos );
+            }
+        }
+
+        IOUtil.close( jos );
+
+        for ( Filter filter : shadeRequest.getFilters() )
+        {
+            filter.finished();
+        }
+    }
+
+    private void goThroughAllJarEntriesForManifestTransformer( ShadeRequest shadeRequest, Set<String> resources,
+                                                               ResourceTransformer manifestTransformer,
+                                                               JarOutputStream jos )
+        throws IOException
+    {
+        if ( manifestTransformer != null )
+        {
+            for ( File jar : shadeRequest.getJars() )
+            {
+                JarFile jarFile = newJarFile( jar );
+                for ( Enumeration<JarEntry> en = jarFile.entries(); en.hasMoreElements(); )
+                {
+                    JarEntry entry = en.nextElement();
+                    String resource = entry.getName();
+                    if ( manifestTransformer.canTransformResource( resource ) )
+                    {
+                        resources.add( resource );
+                        manifestTransformer.processResource( resource, jarFile.getInputStream( entry ),
+                                                             shadeRequest.getRelocators() );
+                        break;
+                    }
+                }
+            }
+            if ( manifestTransformer.hasTransformedResource() )
+            {
+                manifestTransformer.modifyOutputStream( jos );
+            }
+        }
+    }
+
+    private void showOverlappingWarning()
+    {
+        getLogger().warn( "maven-shade-plugin has detected that some class files are" );
+        getLogger().warn( "present in two or more JARs. When this happens, only one" );
+        getLogger().warn( "single version of the class is copied to the uber jar." );
+        getLogger().warn( "Usually this is not harmful and you can skip these warnings," );
+        getLogger().warn( "otherwise try to manually exclude artifacts based on" );
+        getLogger().warn( "mvn dependency:tree -Ddetail=true and the above output." );
+        getLogger().warn( "See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin" );
+    }
+
+    private void logSummaryOfDuplicates( Multimap<Collection<File>, String> overlapping )
+    {
         for ( Collection<File> jarz : overlapping.keySet() )
         {
             List<String> jarzS = new LinkedList<String>();
@@ -227,8 +271,9 @@ public class DefaultShader
                 classes.add( clazz.replace( ".class", "" ).replace( "/", "." ) );
             }
 
-            getLogger().warn( Joiner.on( ", " ).join( jarzS ) + " define " + classes.size()
-                              + " overlapping classes: " );
+            //CHECKSTYLE_OFF: LineLength
+            getLogger().warn( Joiner.on( ", " ).join( jarzS ) + " define " + classes.size() + " overlapping classes: " );
+            //CHECKSTYLE_ON: LineLength
 
             int max = 10;
 
@@ -243,32 +288,6 @@ public class DefaultShader
             }
 
         }
-
-        if ( overlapping.keySet().size() > 0 )
-        {
-            getLogger().warn( "maven-shade-plugin has detected that some class files are" );
-            getLogger().warn( "present in two or more JARs. When this happens, only one" );
-            getLogger().warn( "single version of the class is copied to the uber jar." );
-            getLogger().warn( "Usually this is not harmful and you can skip these warnings," );
-            getLogger().warn( "otherwise try to manually exclude artifacts based on" );
-            getLogger().warn( "mvn dependency:tree -Ddetail=true and the above output." );
-            getLogger().warn( "See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin" );
-        }
-
-        for ( ResourceTransformer transformer : transformers )
-        {
-            if ( transformer.hasTransformedResource() )
-            {
-                transformer.modifyOutputStream( jos );
-            }
-        }
-
-        IOUtil.close( jos );
-
-        for ( Filter filter : shadeRequest.getFilters() )
-        {
-            filter.finished();
-        }
     }
 
     private JarFile newJarFile( File jar )

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/Filter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/Filter.java?rev=1682559&r1=1682558&r2=1682559&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/Filter.java (original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/filter/Filter.java Fri May 29 22:04:04 2015
@@ -26,9 +26,20 @@ import java.io.File;
  */
 public interface Filter
 {
+    /**
+     * @param jar The jar file.
+     * @return true if we can filter false otherwise.
+     */
     boolean canFilter( File jar );
 
+    /**
+     * @param classFile
+     * @return true if the file has been filtered false otherwise.
+     */
     boolean isFiltered( String classFile );
 
+    /**
+     * If we are finished.
+     */
     void finished();
 }

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=1682559&r1=1682558&r2=1682559&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 Fri May 29 22:04:04 2015
@@ -55,6 +55,11 @@ public class MinijarFilter
 
     private int classesRemoved;
 
+    /**
+     * @param project {@link MavenProject}
+     * @param log {@link Log}
+     * @throws IOException in case of error.
+     */
     public MinijarFilter( MavenProject project, Log log )
         throws IOException
     {
@@ -62,6 +67,10 @@ public class MinijarFilter
     }
 
     /**
+     * @param project {@link MavenProject}
+     * @param log {@link Log}
+     * @param simpleFilters {@link SimpleFilter}
+     * @throws IOException in case of errors.
      * @since 1.6
      */
     @SuppressWarnings( { "unchecked" } )
@@ -184,11 +193,13 @@ public class MinijarFilter
         }
     }
 
+    /** {@inheritDoc} */
     public boolean canFilter( File jar )
     {
         return true;
     }
 
+    /** {@inheritDoc} */
     public boolean isFiltered( String classFile )
     {
         String className = classFile.replace( '/', '.' ).replaceFirst( "\\.class$", "" );
@@ -205,6 +216,7 @@ public class MinijarFilter
         return false;
     }
 
+    /** {@inheritDoc} */
     public void finished()
     {
         int classesTotal = classesRemoved + classesKept;

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=1682559&r1=1682558&r2=1682559&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 Fri May 29 22:04:04 2015
@@ -28,6 +28,10 @@ import java.util.Set;
 /**
  * @author David Blevins
  */
+/**
+ * @author kama
+ *
+ */
 public class SimpleFilter
     implements Filter
 {
@@ -38,6 +42,11 @@ public class SimpleFilter
 
     private Set<String> excludes;
 
+    /**
+     * @param jars set of {@link File}s.
+     * @param includes set of includes.
+     * @param excludes set of excludes
+     */
     public SimpleFilter( Set<File> jars, Set<String> includes, Set<String> excludes )
     {
         this.jars = ( jars != null ) ? new HashSet<File>( jars ) : new HashSet<File>();
@@ -45,11 +54,13 @@ public class SimpleFilter
         this.excludes = normalizePatterns( excludes );
     }
 
+    /** {@inheritDoc} */
     public boolean canFilter( File jar )
     {
         return jars.contains( jar );
     }
 
+    /** {@inheritDoc} */
     public boolean isFiltered( String classFile )
     {
         String path = normalizePath( classFile );
@@ -57,6 +68,10 @@ public class SimpleFilter
         return !( isIncluded( path ) && !isExcluded( path ) );
     }
 
+    /**
+     * @param classFile The class file.
+     * @return true if included false otherwise.
+     */
     public boolean isSpecificallyIncluded( String classFile )
     {
         if ( includes == null || includes.isEmpty() )
@@ -130,6 +145,7 @@ public class SimpleFilter
         return result;
     }
 
+    /** {@inheritDoc} */
     public void finished()
     {
     }

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=1682559&r1=1682558&r2=1682559&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 Fri May 29 22:04:04 2015
@@ -88,8 +88,9 @@ import org.codehaus.plexus.util.WriterFa
  * @author David Blevins
  * @author Hiram Chirino
  */
-@Mojo( name = "shade", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true,
-       requiresDependencyResolution = ResolutionScope.RUNTIME )
+//CHECKSTYLE_OFF: LineLength
+@Mojo( name = "shade", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true, requiresDependencyResolution = ResolutionScope.RUNTIME )
+//CHECKSTYLE_ON: LineLength
 public class ShadeMojo
     extends AbstractMojo
     implements Contextualizable
@@ -161,6 +162,7 @@ public class ShadeMojo
      * 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>. For example:
+     * 
      * <pre>
      * &lt;artifactSet&gt;
      *   &lt;includes&gt;
@@ -177,6 +179,7 @@ public class ShadeMojo
 
     /**
      * Packages to be relocated. For example:
+     * 
      * <pre>
      * &lt;relocations&gt;
      *   &lt;relocation&gt;
@@ -191,6 +194,7 @@ public class ShadeMojo
      *   &lt;/relocation&gt;
      * &lt;/relocations&gt;
      * </pre>
+     * 
      * <em>Note:</em> Support for includes exists only since version 1.4.
      */
     @SuppressWarnings( "MismatchedReadAndWriteOfArray" )
@@ -211,6 +215,7 @@ public class ShadeMojo
      * 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. For example:
+     * 
      * <pre>
      * &lt;filters&gt;
      *   &lt;filter&gt;
@@ -238,9 +243,9 @@ 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.
+     * 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.
      */
     @Parameter
     private String finalName;
@@ -263,7 +268,7 @@ public class ShadeMojo
 
     /**
      * Defines whether the shaded artifact should be attached as classifier to
-     * the original artifact.  If false, the shaded jar will be the main artifact
+     * the original artifact. If false, the shaded jar will be the main artifact
      * of the project
      */
     @Parameter
@@ -279,7 +284,6 @@ public class ShadeMojo
     @Parameter( defaultValue = "true" )
     private boolean createDependencyReducedPom;
 
-
     /**
      * Where to put the dependency reduced pom.
      * Note: setting a value for this parameter with a directory other than ${basedir} will change the value of
@@ -411,18 +415,9 @@ public class ShadeMojo
         {
             if ( invalidMainArtifact() )
             {
-                getLog().error( "The project main artifact does not exist. This could have the following" );
-                getLog().error( "reasons:" );
-                getLog().error( "- You have invoked the goal directly from the command line. This is not" );
-                getLog().error( "  supported. Please add the goal to the default lifecycle via an" );
-                getLog().error( "  <execution> element in your POM and use \"mvn package\" to have it run." );
-                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." );
-                getLog().error(
-                    "- You removed the configuration of the maven-jar-plugin that produces the main artifact." );
-                throw new MojoExecutionException(
-                    "Failed to create shaded artifact, " + "project main artifact does not exist." );
+                createErrorOutput();
+                throw new MojoExecutionException( "Failed to create shaded artifact, "
+                    + "project main artifact does not exist." );
             }
 
             artifacts.add( project.getArtifact().getFile() );
@@ -461,24 +456,14 @@ public class ShadeMojo
 
             List<ResourceTransformer> resourceTransformers = getResourceTransformers();
 
-            ShadeRequest shadeRequest = new ShadeRequest();
-            shadeRequest.setJars( artifacts );
-            shadeRequest.setUberJar( outputJar );
-            shadeRequest.setFilters( filters );
-            shadeRequest.setRelocators( relocators );
-            shadeRequest.setResourceTransformers( resourceTransformers );
+            ShadeRequest shadeRequest = shadeRequest( artifacts, outputJar, filters, relocators, resourceTransformers );
 
             shader.shade( shadeRequest );
 
             if ( createSourcesJar )
             {
-                ShadeRequest shadeSourcesRequest = new ShadeRequest();
-                shadeSourcesRequest.setJars( sourceArtifacts );
-                shadeSourcesRequest.setUberJar( sourcesJar );
-                shadeSourcesRequest.setFilters( filters );
-                shadeSourcesRequest.setRelocators( relocators );
-                shadeSourcesRequest.setResourceTransformers( resourceTransformers );
-                shadeSourcesRequest.setShadeSourcesContent( shadeSourcesContent );
+                ShadeRequest shadeSourcesRequest =
+                    createShadeSourcesRequest( sourceArtifacts, sourcesJar, filters, relocators, resourceTransformers );
 
                 shader.shade( shadeSourcesRequest );
             }
@@ -486,13 +471,8 @@ public class ShadeMojo
             if ( shadeTestJar )
             {
 
-                ShadeRequest shadeSourcesRequest = new ShadeRequest();
-                shadeSourcesRequest.setJars( testArtifacts );
-                shadeSourcesRequest.setUberJar( testJar );
-                shadeSourcesRequest.setFilters( filters );
-                shadeSourcesRequest.setRelocators( relocators );
-                shadeSourcesRequest.setResourceTransformers( resourceTransformers );
-                shadeSourcesRequest.setShadeSourcesContent( shadeSourcesContent );
+                ShadeRequest shadeSourcesRequest =
+                    createShadeSourcesRequest( testArtifacts, testJar, filters, relocators, resourceTransformers );
 
                 shader.shade( shadeSourcesRequest );
             }
@@ -567,6 +547,41 @@ public class ShadeMojo
         }
     }
 
+    private void createErrorOutput()
+    {
+        getLog().error( "The project main artifact does not exist. This could have the following" );
+        getLog().error( "reasons:" );
+        getLog().error( "- You have invoked the goal directly from the command line. This is not" );
+        getLog().error( "  supported. Please add the goal to the default lifecycle via an" );
+        getLog().error( "  <execution> element in your POM and use \"mvn package\" to have it run." );
+        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." );
+        getLog().error( "- You removed the configuration of the maven-jar-plugin that produces the main artifact." );
+    }
+
+    private ShadeRequest shadeRequest( Set<File> artifacts, File outputJar, List<Filter> filters,
+                                       List<Relocator> relocators, List<ResourceTransformer> resourceTransformers )
+    {
+        ShadeRequest shadeRequest = new ShadeRequest();
+        shadeRequest.setJars( artifacts );
+        shadeRequest.setUberJar( outputJar );
+        shadeRequest.setFilters( filters );
+        shadeRequest.setRelocators( relocators );
+        shadeRequest.setResourceTransformers( resourceTransformers );
+        return shadeRequest;
+    }
+
+    private ShadeRequest createShadeSourcesRequest( Set<File> testArtifacts, File testJar, List<Filter> filters,
+                                                    List<Relocator> relocators,
+                                                    List<ResourceTransformer> resourceTransformers )
+    {
+        ShadeRequest shadeSourcesRequest =
+            shadeRequest( testArtifacts, testJar, filters, relocators, resourceTransformers );
+        shadeSourcesRequest.setShadeSourcesContent( shadeSourcesContent );
+        return shadeSourcesRequest;
+    }
+
     private void setupHintedShader()
         throws MojoExecutionException
     {
@@ -578,8 +593,8 @@ public class ShadeMojo
             }
             catch ( ComponentLookupException e )
             {
-                throw new MojoExecutionException(
-                    "unable to lookup own Shader implementation with hint:'" + shaderHint + "'", e );
+                throw new MojoExecutionException( "unable to lookup own Shader implementation with hint:'" + shaderHint
+                    + "'", e );
             }
         }
     }
@@ -631,33 +646,33 @@ public class ShadeMojo
         File origFile = new File( outputDirectory, "original-" + oldFile.getName() );
         if ( oldFile.exists() && !oldFile.renameTo( origFile ) )
         {
-            //try a gc to see if an unclosed stream needs garbage collecting
+            // try a gc to see if an unclosed stream needs garbage collecting
             System.gc();
             System.gc();
 
             if ( !oldFile.renameTo( origFile ) )
             {
-                // Still didn't work.   We'll do a copy
+                // Still didn't work. We'll do a copy
                 try
                 {
                     copyFiles( oldFile, origFile );
                 }
                 catch ( IOException ex )
                 {
-                    //kind of ignorable here.   We're just trying to save the original
+                    // kind of ignorable here. We're just trying to save the original
                     getLog().warn( ex );
                 }
             }
         }
         if ( !newFile.renameTo( oldFile ) )
         {
-            //try a gc to see if an unclosed stream needs garbage collecting
+            // try a gc to see if an unclosed stream needs garbage collecting
             System.gc();
             System.gc();
 
             if ( !newFile.renameTo( oldFile ) )
             {
-                // Still didn't work.   We'll do a copy
+                // Still didn't work. We'll do a copy
                 try
                 {
                     copyFiles( newFile, oldFile );
@@ -724,8 +739,8 @@ public class ShadeMojo
 
         for ( PackageRelocation r : relocations )
         {
-            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;
@@ -816,8 +831,9 @@ 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 );
     }
 
@@ -851,8 +867,9 @@ public class ShadeMojo
         }
         else
         {
-            shadedName = shadedArtifactId + "-" + artifact.getVersion() + "-sources."
-                + artifact.getArtifactHandler().getExtension();
+            shadedName =
+                shadedArtifactId + "-" + artifact.getVersion() + "-sources."
+                    + artifact.getArtifactHandler().getExtension();
         }
 
         return new File( outputDirectory, shadedName );
@@ -870,8 +887,9 @@ public class ShadeMojo
         }
         else
         {
-            shadedName = shadedArtifactId + "-" + artifact.getVersion() + "-tests."
-                + artifact.getArtifactHandler().getExtension();
+            shadedName =
+                shadedArtifactId + "-" + artifact.getVersion() + "-tests."
+                    + artifact.getArtifactHandler().getExtension();
         }
 
         return new File( outputDirectory, shadedName );
@@ -897,27 +915,10 @@ public class ShadeMojo
                 continue;
             }
 
-            //promote
-            Dependency dep = new Dependency();
-            dep.setArtifactId( artifact.getArtifactId() );
-            if ( artifact.hasClassifier() )
-            {
-                dep.setClassifier( artifact.getClassifier() );
-            }
-            dep.setGroupId( artifact.getGroupId() );
-            dep.setOptional( artifact.isOptional() );
-            dep.setScope( artifact.getScope() );
-            dep.setType( artifact.getType() );
-            if ( useBaseVersion )
-            {
-                dep.setVersion( artifact.getBaseVersion() );
-            }
-            else
-            {
-                dep.setVersion( artifact.getVersion() );
-            }
+            // promote
+            Dependency dep = createDependency( artifact );
 
-            //we'll figure out the exclusions in a bit.
+            // we'll figure out the exclusions in a bit.
 
             transitiveDeps.add( dep );
         }
@@ -978,7 +979,7 @@ public class ShadeMojo
 
                 if ( f.exists() )
                 {
-                    //noinspection ResultOfMethodCallIgnored
+                    // noinspection ResultOfMethodCallIgnored
                     f.delete();
                 }
 
@@ -1033,6 +1034,29 @@ public class ShadeMojo
         }
     }
 
+    private Dependency createDependency( Artifact artifact )
+    {
+        Dependency dep = new Dependency();
+        dep.setArtifactId( artifact.getArtifactId() );
+        if ( artifact.hasClassifier() )
+        {
+            dep.setClassifier( artifact.getClassifier() );
+        }
+        dep.setGroupId( artifact.getGroupId() );
+        dep.setOptional( artifact.isOptional() );
+        dep.setScope( artifact.getScope() );
+        dep.setType( artifact.getType() );
+        if ( useBaseVersion )
+        {
+            dep.setVersion( artifact.getBaseVersion() );
+        }
+        else
+        {
+            dep.setVersion( artifact.getVersion() );
+        }
+        return dep;
+    }
+
     private String getId( Artifact artifact )
     {
         return getId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), artifact.getClassifier() );
@@ -1059,17 +1083,17 @@ public class ShadeMojo
         {
             for ( DependencyNode n3 : n2.getChildren() )
             {
-                //check if it really isn't in the list of original dependencies.  Maven
-                //prior to 2.0.8 may grab versions from transients instead of
-                //from the direct deps in which case they would be marked included
-                //instead of OMITTED_FOR_DUPLICATE
+                // check if it really isn't in the list of original dependencies. Maven
+                // prior to 2.0.8 may grab versions from transients instead of
+                // from the direct deps in which case they would be marked included
+                // instead of OMITTED_FOR_DUPLICATE
 
-                //also, if not promoting the transitives, level 2's would be included
+                // also, if not promoting the transitives, level 2's would be included
                 boolean found = false;
                 for ( Dependency dep : transitiveDeps )
                 {
-                    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;
                         break;
@@ -1080,8 +1104,8 @@ public class ShadeMojo
                 {
                     for ( Dependency dep : dependencies )
                     {
-                        if ( dep.getArtifactId().equals( n2.getArtifact().getArtifactId() ) && dep.getGroupId().equals(
-                            n2.getArtifact().getGroupId() ) )
+                        if ( dep.getArtifactId().equals( n2.getArtifact().getArtifactId() )
+                            && dep.getGroupId().equals( n2.getArtifact().getGroupId() ) )
                         {
                             Exclusion exclusion = new Exclusion();
                             exclusion.setArtifactId( n3.getArtifact().getArtifactId() );

Added: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/Counter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/Counter.java?rev=1682559&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/Counter.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/Counter.java Fri May 29 22:04:04 2015
@@ -0,0 +1,79 @@
+package org.apache.maven.plugins.shade.pom;
+
+/*
+ * 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.
+ */
+
+/**
+ * Separate class for counter.
+ */
+public class Counter
+{
+
+    // --------------------------/
+    // - Class/Member Variables -/
+    // --------------------------/
+
+    /**
+     * Field currentIndex
+     */
+    private int currentIndex = 0;
+
+    /**
+     * Field level
+     */
+    private int level;
+
+    // ----------------/
+    // - Constructors -/
+    // ----------------/
+
+    public Counter( int depthLevel )
+    {
+        level = depthLevel;
+    } // -- org.apache.maven.model.io.jdom.Counter(int)
+
+    // -----------/
+    // - Methods -/
+    // -----------/
+
+    /**
+     * Method getCurrentIndex
+     */
+    public int getCurrentIndex()
+    {
+        return currentIndex;
+    } // -- int getCurrentIndex()
+
+    /**
+     * Method getDepth
+     */
+    public int getDepth()
+    {
+        return level;
+    } // -- int getDepth()
+
+    /**
+     * Method increaseCount
+     */
+    public void increaseCount()
+    {
+        currentIndex = currentIndex + 1;
+    } // -- void increaseCount()
+
+}

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java?rev=1682559&r1=1682558&r2=1682559&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java (original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java Fri May 29 22:04:04 2015
@@ -87,11 +87,6 @@ import java.util.Map;
  */
 public class MavenJDOMWriter
 {
-
-    // --------------------------/
-    // - Class/Member Variables -/
-    // --------------------------/
-
     /**
      * Field factory
      */
@@ -102,20 +97,12 @@ public class MavenJDOMWriter
      */
     private String lineSeparator;
 
-    // ----------------/
-    // - Constructors -/
-    // ----------------/
-
     public MavenJDOMWriter()
     {
         factory = new DefaultJDOMFactory();
         lineSeparator = "\n";
     } // -- org.apache.maven.model.io.jdom.MavenJDOMWriter()
 
-    // -----------/
-    // - Methods -/
-    // -----------/
-
     /**
      * Method findAndReplaceProperties
      *
@@ -130,9 +117,8 @@ public class MavenJDOMWriter
         Element element = updateElement( counter, parent, name, shouldExist );
         if ( shouldExist )
         {
-
             Counter innerCounter = new Counter( counter.getDepth() + 1 );
-            //while ( it.hasNext() )
+            // while ( it.hasNext() )
             for ( Map.Entry<String, String> entry : ( (Map<String, String>) props ).entrySet() )
             {
                 String key = entry.getKey();
@@ -1244,6 +1230,7 @@ public class MavenJDOMWriter
      * @param counter
      * @param xmlTag
      */
+    //CHECKSTYLE_OFF: LineLength
     protected void updateBuild( Build value, String xmlTag, Counter counter, Element element )
     {
         boolean shouldExist = value != null;
@@ -1254,11 +1241,9 @@ public class MavenJDOMWriter
             findAndReplaceSimpleElement( innerCount, root, "sourceDirectory", value.getSourceDirectory(), null );
             findAndReplaceSimpleElement( innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(),
                                          null );
-            findAndReplaceSimpleElement( innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(),
-                                         null );
+            findAndReplaceSimpleElement( innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(), null );
             findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
-            findAndReplaceSimpleElement( innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(),
-                                         null );
+            findAndReplaceSimpleElement( innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(), null );
             iterateExtension( innerCount, root, value.getExtensions(), "extensions", "extension" );
             findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
             iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
@@ -1270,6 +1255,7 @@ public class MavenJDOMWriter
             iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
         }
     } // -- void updateBuild(Build, String, Counter, Element)
+    //CHECKSTYLE_ON: LineLength
 
     /**
      * Method updateBuildBase
@@ -1684,6 +1670,7 @@ public class MavenJDOMWriter
      * @param counter
      * @param xmlTag
      */
+    //CHECKSTYLE_OFF: LineLength
     protected void updateModelBase( ModelBase value, String xmlTag, Counter counter, Element element )
     {
         boolean shouldExist = value != null;
@@ -1699,11 +1686,11 @@ public class MavenJDOMWriter
             findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
             updateReporting( value.getReporting(), "reporting", innerCount, root );
             updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
-            updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount,
-                                          root );
+            updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
             findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
         }
     } // -- void updateModelBase(ModelBase, String, Counter, Element)
+    //CHECKSTYLE_ON: LineLength
 
     /**
      * Method updateNotifier
@@ -1713,6 +1700,7 @@ public class MavenJDOMWriter
      * @param counter
      * @param xmlTag
      */
+    //CHECKSTYLE_OFF: LineLength
     protected void updateNotifier( Notifier value, String xmlTag, Counter counter, Element element )
     {
         Element root = element;
@@ -1721,17 +1709,15 @@ public class MavenJDOMWriter
         findAndReplaceSimpleElement( innerCount, root, "sendOnError",
                                      value.isSendOnError() ? null : String.valueOf( value.isSendOnError() ), "true" );
         findAndReplaceSimpleElement( innerCount, root, "sendOnFailure",
-                                     value.isSendOnFailure() ? null : String.valueOf( value.isSendOnFailure() ),
-                                     "true" );
+                                     value.isSendOnFailure() ? null : String.valueOf( value.isSendOnFailure() ), "true" );
         findAndReplaceSimpleElement( innerCount, root, "sendOnSuccess",
-                                     value.isSendOnSuccess() ? null : String.valueOf( value.isSendOnSuccess() ),
-                                     "true" );
+                                     value.isSendOnSuccess() ? null : String.valueOf( value.isSendOnSuccess() ), "true" );
         findAndReplaceSimpleElement( innerCount, root, "sendOnWarning",
-                                     value.isSendOnWarning() ? null : String.valueOf( value.isSendOnWarning() ),
-                                     "true" );
+                                     value.isSendOnWarning() ? null : String.valueOf( value.isSendOnWarning() ), "true" );
         findAndReplaceSimpleElement( innerCount, root, "address", value.getAddress(), null );
         findAndReplaceProperties( innerCount, root, "configuration", value.getConfiguration() );
     } // -- void updateNotifier(Notifier, String, Counter, Element)
+    //CHECKSTYLE_ON: LineLength
 
     /**
      * Method updateOrganization
@@ -1827,8 +1813,8 @@ public class MavenJDOMWriter
      * @param counter
      * @param xmlTag
      */
-    protected void updatePluginConfiguration( PluginConfiguration value, String xmlTag, Counter counter,
-                                              Element element )
+    //CHECKSTYLE_OFF: LineLength
+    protected void updatePluginConfiguration( PluginConfiguration value, String xmlTag, Counter counter, Element element )
     {
         boolean shouldExist = value != null;
         Element root = updateElement( counter, element, xmlTag, shouldExist );
@@ -1839,6 +1825,7 @@ public class MavenJDOMWriter
             iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
         }
     } // -- void updatePluginConfiguration(PluginConfiguration, String, Counter, Element)
+    //CHECKSTYLE_ON: LineLength
 
     /**
      * Method updatePluginContainer
@@ -2017,9 +2004,8 @@ public class MavenJDOMWriter
         if ( shouldExist )
         {
             Counter innerCount = new Counter( counter.getDepth() + 1 );
-            findAndReplaceSimpleElement( innerCount, root, "excludeDefaults", !value.isExcludeDefaults()
-                ? null
-                : String.valueOf( value.isExcludeDefaults() ), "false" );
+            findAndReplaceSimpleElement( innerCount, root, "excludeDefaults", !value.isExcludeDefaults() ? null
+                            : String.valueOf( value.isExcludeDefaults() ), "false" );
             findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
             iterateReportPlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
         }
@@ -2123,12 +2109,15 @@ public class MavenJDOMWriter
         Element root = updateElement( counter, element, xmlTag, shouldExist );
         if ( shouldExist )
         {
+            //CHECKSTYLE_OFF: LineLength
+
             Counter innerCount = new Counter( counter.getDepth() + 1 );
             findAndReplaceSimpleElement( innerCount, root, "connection", value.getConnection(), null );
-            findAndReplaceSimpleElement( innerCount, root, "developerConnection", value.getDeveloperConnection(),
-                                         null );
+            findAndReplaceSimpleElement( innerCount, root, "developerConnection", value.getDeveloperConnection(), null );
             findAndReplaceSimpleElement( innerCount, root, "tag", value.getTag(), "HEAD" );
             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
+
+            //CHECKSTYLE_ON: LineLength
         }
     } // -- void updateScm(Scm, String, Counter, Element)
 
@@ -2204,69 +2193,4 @@ public class MavenJDOMWriter
         outputter.output( document, writer );
     } // -- void write(Model, Document, Writer, Format)
 
-    // -----------------/
-    // - Inner Classes -/
-    // -----------------/
-
-    /**
-     * Class Counter.
-     *
-     * @version $Revision$ $Date$
-     */
-    public class Counter
-    {
-
-        // --------------------------/
-        // - Class/Member Variables -/
-        // --------------------------/
-
-        /**
-         * Field currentIndex
-         */
-        private int currentIndex = 0;
-
-        /**
-         * Field level
-         */
-        private int level;
-
-        // ----------------/
-        // - Constructors -/
-        // ----------------/
-
-        public Counter( int depthLevel )
-        {
-            level = depthLevel;
-        } // -- org.apache.maven.model.io.jdom.Counter(int)
-
-        // -----------/
-        // - Methods -/
-        // -----------/
-
-        /**
-         * Method getCurrentIndex
-         */
-        public int getCurrentIndex()
-        {
-            return currentIndex;
-        } // -- int getCurrentIndex()
-
-        /**
-         * Method getDepth
-         */
-        public int getDepth()
-        {
-            return level;
-        } // -- int getDepth()
-
-        /**
-         * Method increaseCount
-         */
-        public void increaseCount()
-        {
-            currentIndex = currentIndex + 1;
-        } // -- void increaseCount()
-
-    }
-
 }