You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/02/05 19:40:32 UTC

[maven-shade-plugin] branch MSHADE-298 created (now 799e02a)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MSHADE-298
in repository https://gitbox.apache.org/repos/asf/maven-shade-plugin.git.


      at 799e02a  [MSHADE-298] Groovy extension module transformer looking in incorrect META-INF directory

This branch includes the following new commits:

     new 799e02a  [MSHADE-298] Groovy extension module transformer looking in incorrect META-INF directory

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-shade-plugin] 01/01: [MSHADE-298] Groovy extension module transformer looking in incorrect META-INF directory

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MSHADE-298
in repository https://gitbox.apache.org/repos/asf/maven-shade-plugin.git

commit 799e02abdf936d6f83026403a5ed64e70ad920ef
Author: rfscholte <rf...@apache.org>
AuthorDate: Wed Feb 5 20:40:24 2020 +0100

    [MSHADE-298] Groovy extension module transformer looking in incorrect META-INF directory
---
 .../shade/resource/GroovyResourceTransformer.java     | 15 +++++++--------
 .../shade/resource/GroovyResourceTransformerTest.java | 19 +++++++++----------
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java
index ced9c71..754834f 100644
--- a/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java
+++ b/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java
@@ -39,7 +39,10 @@ public class GroovyResourceTransformer
     implements ResourceTransformer
 {
 
-    static final String EXT_MODULE_NAME = "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule";
+    static final String EXT_MODULE_NAME_LEGACY = "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule";
+
+    // Since Groovy 2.5.x/Java 9 META-INF/services may only be used by Service Providers
+    static final String EXT_MODULE_NAME = "META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule";
 
     private List<String> extensionClassesList = new ArrayList<>();
 
@@ -52,7 +55,7 @@ public class GroovyResourceTransformer
     @Override
     public boolean canTransformResource( String resource )
     {
-        return EXT_MODULE_NAME.equals( resource );
+        return EXT_MODULE_NAME.equals( resource ) || EXT_MODULE_NAME_LEGACY.equals( resource );
     }
 
     @Override
@@ -60,13 +63,9 @@ public class GroovyResourceTransformer
         throws IOException
     {
         Properties out = new Properties();
-        try
-        {
-            out.load( is );
-        }
-        finally
+        try ( InputStream props = is )
         {
-            is.close();
+            out.load( props );
         }
         String extensionClasses = out.getProperty( "extensionClasses", "" ).trim();
         if ( extensionClasses.length() > 0 )
diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformerTest.java b/src/test/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformerTest.java
index d19f2b6..b190e86 100644
--- a/src/test/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformerTest.java
+++ b/src/test/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformerTest.java
@@ -73,13 +73,15 @@ public class GroovyResourceTransformerTest
     {
         File tempJar = File.createTempFile( "shade.", ".jar" );
         tempJar.deleteOnExit();
-        FileOutputStream fos = new FileOutputStream( tempJar );
-        JarOutputStream jaos = new JarOutputStream( fos );
-        transformer.modifyOutputStream( jaos );
-        jaos.close();
+
+        try ( FileOutputStream fos = new FileOutputStream( tempJar );
+              JarOutputStream jaos = new JarOutputStream( fos ) )
+        {
+            transformer.modifyOutputStream( jaos );
+        }
+        
         Properties desc = null;
-        JarFile jar = new JarFile( tempJar );
-        try
+        try ( JarFile jar = new JarFile( tempJar ) )
         {
             ZipEntry entry = jar.getEntry( GroovyResourceTransformer.EXT_MODULE_NAME );
             if ( entry != null )
@@ -88,10 +90,6 @@ public class GroovyResourceTransformerTest
                 desc.load( jar.getInputStream( entry ) );
             }
         }
-        finally
-        {
-            jar.close();
-        }
         return desc;
     }
 
@@ -100,6 +98,7 @@ public class GroovyResourceTransformerTest
     {
         GroovyResourceTransformer transformer = new GroovyResourceTransformer();
         assertTrue( transformer.canTransformResource( GroovyResourceTransformer.EXT_MODULE_NAME ) );
+        assertTrue( transformer.canTransformResource( GroovyResourceTransformer.EXT_MODULE_NAME_LEGACY ) );
         assertFalse( transformer.canTransformResource( "somethingElse" ) );
         assertFalse( transformer.canTransformResource( JarFile.MANIFEST_NAME ) );
     }