maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1714643 - in /maven/plugins/trunk/maven-shade-plugin/src: main/java/org/apache/maven/plugins/shade/ main/java/org/apache/maven/plugins/shade/resource/ test/java/org/apache/maven/plugins/shade/resource/
Date Mon, 16 Nov 2015 17:52:52 GMT
Author: krosenvold
Date: Mon Nov 16 17:52:52 2015
New Revision: 1714643

URL: http://svn.apache.org/viewvc?rev=1714643&view=rev
Log:
[MSHADE-213] Clarified the contract of the ResourceTransformer wrt closing of stream

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/resource/AppendingTransformer.java
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
    maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
    maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
    maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.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=1714643&r1=1714642&r2=1714643&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
Mon Nov 16 17:52:52 2015
@@ -88,9 +88,7 @@ public class DefaultShader
         RelocatorRemapper remapper = new RelocatorRemapper( shadeRequest.getRelocators()
);
 
         // noinspection ResultOfMethodCallIgnored
-        shadeRequest.getUberJar()
-                    .getParentFile()
-                    .mkdirs();
+        shadeRequest.getUberJar().getParentFile().mkdirs();
         FileOutputStream fileOutputStream = new FileOutputStream( shadeRequest.getUberJar()
);
         JarOutputStream jos = new JarOutputStream( new BufferedOutputStream( fileOutputStream
) );
 
@@ -121,8 +119,7 @@ public class DefaultShader
             // Log a summary of duplicates
             logSummaryOfDuplicates( overlapping );
 
-            if ( overlapping.keySet()
-                            .size() > 0 )
+            if ( overlapping.keySet().size() > 0 )
             {
                 showOverlappingWarning();
             }
@@ -269,8 +266,15 @@ public class DefaultShader
                     if ( manifestTransformer.canTransformResource( resource ) )
                     {
                         resources.add( resource );
-                        manifestTransformer.processResource( resource, jarFile.getInputStream(
entry ),
-                                                             shadeRequest.getRelocators()
);
+                        InputStream inputStream = jarFile.getInputStream( entry );
+                        try
+                        {
+                            manifestTransformer.processResource( resource, inputStream, shadeRequest.getRelocators()
);
+                        }
+                        finally
+                        {
+                            inputStream.close();
+                        }
                         break;
                     }
                 }
@@ -308,13 +312,12 @@ public class DefaultShader
 
             for ( String clazz : overlapping.get( jarz ) )
             {
-                classes.add( clazz.replace( ".class", "" )
-                                  .replace( "/", "." ) );
+                classes.add( clazz.replace( ".class", "" ).replace( "/", "." ) );
             }
 
             //CHECKSTYLE_OFF: LineLength
-            getLogger().warn( Joiner.on( ", " )
-                                    .join( jarzS ) + " define " + classes.size() + " overlapping
classes: " );
+            getLogger().warn(
+                Joiner.on( ", " ).join( jarzS ) + " define " + classes.size() + " overlapping
classes: " );
             //CHECKSTYLE_ON: LineLength
 
             int max = 10;
@@ -480,8 +483,7 @@ public class DefaultShader
         {
             if ( transformer.canTransformResource( name ) )
             {
-                getLogger().debug( "Transforming " + name + " using " + transformer.getClass()
-                                                                                   .getName()
);
+                getLogger().debug( "Transforming " + name + " using " + transformer.getClass().getName()
);
 
                 transformer.processResource( name, is, relocators );
 

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java?rev=1714643&r1=1714642&r2=1714643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java
Mon Nov 16 17:52:52 2015
@@ -55,8 +55,6 @@ public class AppendingTransformer
     {
         IOUtil.copy( is, data );
         data.write( '\n' );
-
-        is.close();
     }
 
     public boolean hasTransformedResource()

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java?rev=1714643&r1=1714642&r2=1714643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java
Mon Nov 16 17:52:52 2015
@@ -20,7 +20,6 @@ package org.apache.maven.plugins.shade.r
  */
 
 import org.apache.maven.plugins.shade.relocation.Relocator;
-import org.codehaus.plexus.util.IOUtil;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -74,7 +73,6 @@ public class ManifestResourceTransformer
         {
             manifest = new Manifest( is );
             manifestDiscovered = true;
-            IOUtil.close( is );
         }
     }
 

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java?rev=1714643&r1=1714642&r2=1714643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java
Mon Nov 16 17:52:52 2015
@@ -31,6 +31,13 @@ public interface ResourceTransformer
 {
     boolean canTransformResource( String resource );
 
+    /**
+     * Transform an individual resource
+     * @param resource The resoure name
+     * @param is An input stream for the resource, the implementation should *not* close
this stream
+     * @param relocators  A list of relocators
+     * @throws IOException When the IO blows up
+     */
     void processResource( String resource, InputStream is, List<Relocator> relocators
)
         throws IOException;
 

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java?rev=1714643&r1=1714642&r2=1714643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
Mon Nov 16 17:52:52 2015
@@ -86,8 +86,6 @@ public class ServicesResourceTransformer
             }
             fout.append( relContent + "\n" );
         }
-
-        is.close();
     }
     public boolean hasTransformedResource()
     {

Modified: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java?rev=1714643&r1=1714642&r2=1714643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
Mon Nov 16 17:52:52 2015
@@ -96,6 +96,7 @@ public class ApacheNoticeResourceTransfo
             final ByteArrayInputStream noticeInputStream = new ByteArrayInputStream( noticeText.getBytes()
);
             final List<Relocator> emptyList = Collections.emptyList();
             subject.processResource( NOTICE_RESOURCE, noticeInputStream, emptyList );
+            noticeInputStream.close();
         }
         catch ( NullPointerException e )
         {

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=1714643&r1=1714642&r2=1714643&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
Mon Nov 16 17:52:52 2015
@@ -27,6 +27,7 @@ import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLAssert;
 import org.custommonkey.xmlunit.XMLUnit;
 
+import java.io.InputStream;
 import java.util.Collections;
 
 /**
@@ -51,10 +52,14 @@ public class ComponentsXmlResourceTransf
 
         XMLUnit.setNormalizeWhitespace( true );
 
-        transformer.processResource( "components-1.xml", getClass().getResourceAsStream(
"/components-1.xml" ),
+        InputStream resourceAsStream = getClass().getResourceAsStream( "/components-1.xml"
);
+        transformer.processResource( "components-1.xml", resourceAsStream,
                                      Collections.<Relocator> emptyList() );
-        transformer.processResource( "components-1.xml", getClass().getResourceAsStream(
"/components-2.xml" ),
+        resourceAsStream.close();
+        InputStream resourceAsStream1 = getClass().getResourceAsStream( "/components-2.xml"
);
+        transformer.processResource( "components-1.xml", resourceAsStream1,
                                      Collections.<Relocator> emptyList() );
+        resourceAsStream1.close();
         Diff diff = XMLUnit.compareXML(
             IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ),
"UTF-8" ),
             IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ) );

Modified: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java?rev=1714643&r1=1714642&r2=1714643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
Mon Nov 16 17:52:52 2015
@@ -56,6 +56,7 @@ public class ServiceResourceTransformerT
 
         ServicesResourceTransformer xformer = new ServicesResourceTransformer();
         xformer.processResource( contentResource, contentStream, relocators );
+        contentStream.close();
 
         File tempJar = File.createTempFile("shade.", ".jar");
         tempJar.deleteOnExit();
@@ -96,6 +97,7 @@ public class ServiceResourceTransformerT
 
         ServicesResourceTransformer xformer = new ServicesResourceTransformer();
         xformer.processResource( contentResource, contentStream, relocators );
+        contentStream.close();
 
         content = "org.blah.Service\n";
         contentBytes = content.getBytes( "UTF-8" );
@@ -103,6 +105,7 @@ public class ServiceResourceTransformerT
         contentResource = "META-INF/services/org.something.another";
 
         xformer.processResource( contentResource, contentStream, relocators );
+        contentStream.close();
 
         File tempJar = File.createTempFile("shade.", ".jar");
         tempJar.deleteOnExit();



Mime
View raw message