Skip to content

Commit

Permalink
[MSHADE-298] Groovy extension module transformer looking in incorrect…
Browse files Browse the repository at this point in the history
… META-INF directory
  • Loading branch information
rfscholte committed Feb 5, 2020
1 parent aba5b7c commit 799e02a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();

Expand All @@ -52,21 +55,17 @@ 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
public void processResource( String resource, InputStream is, List<Relocator> relocators )
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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ private static Properties transform( GroovyResourceTransformer transformer )
{
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 )
Expand All @@ -88,10 +90,6 @@ private static Properties transform( GroovyResourceTransformer transformer )
desc.load( jar.getInputStream( entry ) );
}
}
finally
{
jar.close();
}
return desc;
}

Expand All @@ -100,6 +98,7 @@ public void testFilter()
{
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 ) );
}
Expand Down

0 comments on commit 799e02a

Please sign in to comment.