maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1590114 - in /maven/plugins/trunk/maven-shade-plugin/src: main/java/org/apache/maven/plugins/shade/DefaultShader.java test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java
Date Fri, 25 Apr 2014 19:28:29 GMT
Author: rfscholte
Date: Fri Apr 25 19:28:29 2014
New Revision: 1590114

URL: http://svn.apache.org/r1590114
Log:
formatting

Modified:
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
    maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.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=1590114&r1=1590113&r2=1590114&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 Apr 25 19:28:29 2014
@@ -19,25 +19,6 @@ package org.apache.maven.plugins.shade;
  * under the License.
  */
 
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.shade.filter.Filter;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-
-import org.apache.maven.plugins.shade.relocation.Relocator;
-import org.apache.maven.plugins.shade.resource.ManifestResourceTransformer;
-import org.apache.maven.plugins.shade.resource.ResourceTransformer;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.IOUtil;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.commons.Remapper;
-import org.objectweb.asm.commons.RemappingClassAdapter;
-
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -60,6 +41,24 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.zip.ZipException;
 
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.shade.filter.Filter;
+import org.apache.maven.plugins.shade.relocation.Relocator;
+import org.apache.maven.plugins.shade.resource.ManifestResourceTransformer;
+import org.apache.maven.plugins.shade.resource.ResourceTransformer;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.IOUtil;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.commons.Remapper;
+import org.objectweb.asm.commons.RemappingClassAdapter;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
 /**
  * @author Jason van Zyl
  */
@@ -89,7 +88,7 @@ public class DefaultShader
 
         RelocatorRemapper remapper = new RelocatorRemapper( shadeRequest.getRelocators()
);
 
-        //noinspection ResultOfMethodCallIgnored
+        // noinspection ResultOfMethodCallIgnored
         shadeRequest.getUberJar().getParentFile().mkdirs();
         FileOutputStream fileOutputStream = new FileOutputStream( shadeRequest.getUberJar()
);
         JarOutputStream jos = new JarOutputStream( new BufferedOutputStream( fileOutputStream
) );
@@ -119,7 +118,7 @@ public class DefaultShader
         }
 
         Multimap<String, File> duplicates = HashMultimap.create( 10000, 3 );
-        
+
         for ( File jar : shadeRequest.getJars() )
         {
 
@@ -162,7 +161,7 @@ public class DefaultShader
 
                     if ( name.endsWith( ".class" ) )
                     {
-                    	duplicates.put(name, jar);
+                        duplicates.put( name, jar );
                         addRemappedClass( remapper, jos, jar, name, is );
                     }
                     else if ( shadeRequest.isShadeSourcesContent() && name.endsWith(
".java" ) )
@@ -172,7 +171,7 @@ public class DefaultShader
                         {
                             continue;
                         }
-                        
+
                         addJavaSource( resources, jos, mappedName, is, shadeRequest.getRelocators()
);
                     }
                     else
@@ -195,52 +194,53 @@ public class DefaultShader
 
             jarFile.close();
         }
-        
+
         Multimap<Collection<File>, String> overlapping = HashMultimap.create(
20, 15 );
-        
-        for ( String clazz: duplicates.keySet() )
+
+        for ( String clazz : duplicates.keySet() )
         {
-        	Collection<File> jarz = duplicates.get( clazz );
-        	if ( jarz.size() > 1 ) {
-        		overlapping.put( jarz, clazz );
-        	}
+            Collection<File> jarz = duplicates.get( clazz );
+            if ( jarz.size() > 1 )
+            {
+                overlapping.put( jarz, clazz );
+            }
         }
-        
+
         // Log a summary of duplicates
         for ( Collection<File> jarz : overlapping.keySet() )
         {
-        	List<String> jarzS = new LinkedList<String>();
-        	
-        	for (File jjar : jarz)
-        		jarzS.add(jjar.getName());
-        	
-    		List<String> classes = new LinkedList<String>();
-        	
-        	for (String clazz : overlapping.get(jarz))
-    			classes.add(clazz.replace(".class", "").replace("/", "."));
-    		
-    		getLogger().warn( Joiner.on( ", " ).join(jarzS) + " define " + classes.size()
-    				+ " overlappping classes: " );
-    		
-    		int max = 10;
-    		
-    		for ( int i = 0; i < Math.min(max, classes.size()); i++ )
-    			getLogger().warn("  - " + classes.get(i));
-    		
-    		if ( classes.size() > max )
-    			getLogger().warn("  - " + (classes.size() - max) + " more...");
-    		
-        }
-        
-        if (overlapping.keySet().size() > 0) {
-        	getLogger().warn("maven-shade-plugin has detected that some .class files");
-        	getLogger().warn("are present in two or more JARs. When this happens, only");
-        	getLogger().warn("one single version of the class is copied in the uberjar.");
-        	getLogger().warn("Usually this is not harmful and you can skeep these");
-        	getLogger().warn("warnings, otherwise try to manually exclude artifacts");
-        	getLogger().warn("based on mvn dependency:tree -Ddetail=true and the above");
-        	getLogger().warn("output");
-        	getLogger().warn("See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin");
+            List<String> jarzS = new LinkedList<String>();
+
+            for ( File jjar : jarz )
+                jarzS.add( jjar.getName() );
+
+            List<String> classes = new LinkedList<String>();
+
+            for ( String clazz : overlapping.get( jarz ) )
+                classes.add( clazz.replace( ".class", "" ).replace( "/", "." ) );
+
+            getLogger().warn( Joiner.on( ", " ).join( jarzS ) + " define " + classes.size()
+ " overlappping classes: " );
+
+            int max = 10;
+
+            for ( int i = 0; i < Math.min( max, classes.size() ); i++ )
+                getLogger().warn( "  - " + classes.get( i ) );
+
+            if ( classes.size() > max )
+                getLogger().warn( "  - " + ( classes.size() - max ) + " more..." );
+
+        }
+
+        if ( overlapping.keySet().size() > 0 )
+        {
+            getLogger().warn( "maven-shade-plugin has detected that some .class files" );
+            getLogger().warn( "are present in two or more JARs. When this happens, only"
);
+            getLogger().warn( "one single version of the class is copied in the uberjar."
);
+            getLogger().warn( "Usually this is not harmful and you can skeep these" );
+            getLogger().warn( "warnings, otherwise try to manually exclude artifacts" );
+            getLogger().warn( "based on mvn dependency:tree -Ddetail=true and the above"
);
+            getLogger().warn( "output" );
+            getLogger().warn( "See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin"
);
         }
 
         for ( ResourceTransformer transformer : transformers )
@@ -258,7 +258,7 @@ public class DefaultShader
             filter.finished();
         }
     }
-    
+
     private JarFile newJarFile( File jar )
         throws IOException
     {
@@ -337,17 +337,22 @@ public class DefaultShader
         // that use the constant pool to determine the dependencies of a class.
         ClassWriter cw = new ClassWriter( 0 );
 
-        final String pkg = name.substring(0, name.lastIndexOf('/') + 1);
-        ClassVisitor cv = new RemappingClassAdapter( cw, remapper ) {
+        final String pkg = name.substring( 0, name.lastIndexOf( '/' ) + 1 );
+        ClassVisitor cv = new RemappingClassAdapter( cw, remapper )
+        {
             @Override
-            public void visitSource(final String source, final String debug) {
-                if (source == null) {
-                    super.visitSource(source, debug);
-                } else {
+            public void visitSource( final String source, final String debug )
+            {
+                if ( source == null )
+                {
+                    super.visitSource( source, debug );
+                }
+                else
+                {
                     final String fqSource = pkg + source;
-                    final String mappedSource = remapper.map(fqSource);
-                    final String filename = mappedSource.substring(mappedSource.lastIndexOf('/')
+ 1);
-                    super.visitSource(filename, debug);
+                    final String mappedSource = remapper.map( fqSource );
+                    final String filename = mappedSource.substring( mappedSource.lastIndexOf(
'/' ) + 1 );
+                    super.visitSource( filename, debug );
                 }
             }
         };
@@ -415,18 +420,18 @@ public class DefaultShader
     }
 
     private void addJavaSource( Set<String> resources, JarOutputStream jos, String
name, InputStream is,
-                                    List<Relocator> relocators )
-            throws IOException
+                                List<Relocator> relocators )
+        throws IOException
     {
         jos.putNextEntry( new JarEntry( name ) );
 
         String sourceContent = IOUtil.toString( new InputStreamReader( is, "UTF-8" ) );
-        
+
         for ( Relocator relocator : relocators )
         {
             sourceContent = relocator.applyToSourceContent( sourceContent );
         }
-        
+
         OutputStreamWriter writer = new OutputStreamWriter( jos, "UTF-8" );
         IOUtil.copy( sourceContent, writer );
         writer.flush();

Modified: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java?rev=1590114&r1=1590113&r2=1590114&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java
Fri Apr 25 19:28:29 2014
@@ -20,13 +20,13 @@ package org.apache.maven.plugins.shade;
  */
 
 import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
-import java.net.URLClassLoader;
-import java.net.URL;
 
 import junit.framework.TestCase;
 
@@ -37,11 +37,8 @@ import org.apache.maven.plugins.shade.re
 import org.apache.maven.plugins.shade.resource.ResourceTransformer;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.logging.console.ConsoleLogger;
-import org.objectweb.asm.Attribute;
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.FieldVisitor;
-import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 
 /**
@@ -51,8 +48,7 @@ import org.objectweb.asm.Opcodes;
 public class DefaultShaderTest
     extends TestCase
 {
-    private static final String[] EXCLUDES = new String[] {
-        "org/codehaus/plexus/util/xml/Xpp3Dom",
+    private static final String[] EXCLUDES = new String[] { "org/codehaus/plexus/util/xml/Xpp3Dom",
         "org/codehaus/plexus/util/xml/pull.*" };
 
     public void testShaderWithDefaultShadedPattern()
@@ -89,7 +85,7 @@ public class DefaultShaderTest
 
         s.shade( shadeRequest );
 
-        URLClassLoader cl = new URLClassLoader( new URL[]{file.toURI().toURL()} );
+        URLClassLoader cl = new URLClassLoader( new URL[] { file.toURI().toURL() } );
         Class<?> c = cl.loadClass( "hidden.org.apache.maven.plugins.shade.Lib" );
         Object o = c.newInstance();
         assertEquals( "foo.bar/baz", c.getDeclaredField( "CONSTANT" ).get( o ) );
@@ -104,59 +100,64 @@ public class DefaultShaderTest
     public void testShaderWithoutExcludesShouldRemoveReferencesOfOriginalPattern()
         throws Exception
     {
-        //FIXME:  shaded jar should not include references to org/codehaus/* (empty dirs)
or org.codehaus.* META-INF files.
-        shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom-without-excludes.jar"
), new String[] {} );
+        // FIXME: shaded jar should not include references to org/codehaus/* (empty dirs)
or org.codehaus.* META-INF
+        // files.
+        shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom-without-excludes.jar"
),
+                           new String[] {} );
     }
 
     public void testShaderWithRelocatedClassname()
         throws Exception
     {
-            DefaultShader s = newShader();
+        DefaultShader s = newShader();
 
-            Set<File> set = new LinkedHashSet<File>();
+        Set<File> set = new LinkedHashSet<File>();
 
-            set.add( new File( "src/test/jars/test-project-1.0-SNAPSHOT.jar" ) );
+        set.add( new File( "src/test/jars/test-project-1.0-SNAPSHOT.jar" ) );
 
-            set.add( new File( "src/test/jars/plexus-utils-1.4.1.jar" ) );
+        set.add( new File( "src/test/jars/plexus-utils-1.4.1.jar" ) );
 
-            List<Relocator> relocators = new ArrayList<Relocator>();
+        List<Relocator> relocators = new ArrayList<Relocator>();
 
-            relocators.add( new SimpleRelocator( "org/codehaus/plexus/util/", "_plexus/util/__",
null, Arrays.<String> asList() ) );
+        relocators.add( new SimpleRelocator( "org/codehaus/plexus/util/", "_plexus/util/__",
null,
+                                             Arrays.<String> asList() ) );
 
-            List<ResourceTransformer> resourceTransformers = new ArrayList<ResourceTransformer>();
+        List<ResourceTransformer> resourceTransformers = new ArrayList<ResourceTransformer>();
 
-            resourceTransformers.add( new ComponentsXmlResourceTransformer() );
+        resourceTransformers.add( new ComponentsXmlResourceTransformer() );
 
-            List<Filter> filters = new ArrayList<Filter>();
+        List<Filter> filters = new ArrayList<Filter>();
+
+        File file = new File( "target/foo-relocate-class.jar" );
 
-            File file = new File( "target/foo-relocate-class.jar" );
+        ShadeRequest shadeRequest = new ShadeRequest();
+        shadeRequest.setJars( set );
+        shadeRequest.setUberJar( file );
+        shadeRequest.setFilters( filters );
+        shadeRequest.setRelocators( relocators );
+        shadeRequest.setResourceTransformers( resourceTransformers );
 
-            ShadeRequest shadeRequest = new ShadeRequest();
-            shadeRequest.setJars( set );
-            shadeRequest.setUberJar( file );
-            shadeRequest.setFilters( filters );
-            shadeRequest.setRelocators( relocators );
-            shadeRequest.setResourceTransformers( resourceTransformers );
+        s.shade( shadeRequest );
 
-            s.shade( shadeRequest );
+        URLClassLoader cl = new URLClassLoader( new URL[] { file.toURI().toURL() } );
+        Class<?> c = cl.loadClass( "_plexus.util.__StringUtils" );
+        // first, ensure it works:
+        Object o = c.newInstance();
+        assertEquals( "", c.getMethod( "clean", String.class ).invoke( o, (String) null )
);
 
-            URLClassLoader cl = new URLClassLoader( new URL[]{file.toURI().toURL()} );
-            Class<?> c = cl.loadClass( "_plexus.util.__StringUtils" );
-            // first, ensure it works:
-            Object o = c.newInstance();
-            assertEquals("", c.getMethod("clean", String.class).invoke(o, (String) null));
-            
-            // now, check that its source file was rewritten:
-            final String[] source = { null };
-            final ClassReader classReader = new ClassReader(cl.getResourceAsStream("_plexus/util/__StringUtils.class"));
-            classReader.accept(new ClassVisitor( Opcodes.ASM4 ) {
-            	@Override
-            	public void visitSource(String arg0, String arg1) {
-            		super.visitSource(arg0, arg1);
-            		source[0] = arg0;
-            	}
-            }, ClassReader.SKIP_CODE);
-            assertEquals("__StringUtils.java", source[0]);
+        // now, check that its source file was rewritten:
+        final String[] source = { null };
+        final ClassReader classReader = new ClassReader( cl.getResourceAsStream( "_plexus/util/__StringUtils.class"
) );
+        classReader.accept( new ClassVisitor( Opcodes.ASM4 )
+        {
+            @Override
+            public void visitSource( String arg0, String arg1 )
+            {
+                super.visitSource( arg0, arg1 );
+                source[0] = arg0;
+            }
+        }, ClassReader.SKIP_CODE );
+        assertEquals( "__StringUtils.java", source[0] );
     }
 
     private void shaderWithPattern( String shadedPattern, File jar, String[] excludes )



Mime
View raw message