rfscholte closed pull request #9: [MSHADE-291] - Fixes bug in ServicesResourceTransformer URL: https://github.com/apache/maven-shade-plugin/pull/9
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/pom.xml b/pom.xml index 8fca8d3..cb10a84 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,9 @@ <contributor> <name>Anthony Dahanne</name> </contributor> + <contributor> + <name>Fabiano Cipriano de Oliveira</name> + </contributor> </contributors> <dependencies> diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java index f1cb9d6..d087522 100644 --- a/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java +++ b/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java @@ -138,20 +138,6 @@ public void modifyOutputStream( JarOutputStream jos ) while ( ( className = reader.readLine() ) != null ) { - - if ( relocators != null ) - { - for ( Relocator relocator : relocators ) - { - //if the class can be relocated then relocate it - if ( relocator.canRelocateClass( className ) ) - { - className = relocator.applyToSourceContent( className ); - break; - } - } - } - writer.println( className ); writer.flush(); } diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java b/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java index a9f78db..18dab2f 100644 --- a/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java +++ b/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java @@ -89,6 +89,50 @@ public void relocatedClasses() throws Exception { tempJar.delete(); } } + + @Test + public void concatanationAppliedMultipleTimes() throws Exception { + SimpleRelocator relocator = + new SimpleRelocator( "org.eclipse", "org.eclipse1234", null, null ); + List<Relocator> relocators = Lists.<Relocator>newArrayList( relocator ); + + String content = "org.eclipse.osgi.launch.EquinoxFactory\n"; + byte[] contentBytes = content.getBytes( "UTF-8" ); + InputStream contentStream = new ByteArrayInputStream( contentBytes ); + String contentResource = "META-INF/services/org.osgi.framework.launch.FrameworkFactory"; + + ServicesResourceTransformer xformer = new ServicesResourceTransformer(); + xformer.processResource( contentResource, contentStream, relocators ); + contentStream.close(); + + File tempJar = File.createTempFile("shade.", ".jar"); + tempJar.deleteOnExit(); + FileOutputStream fos = new FileOutputStream( tempJar ); + JarOutputStream jos = new JarOutputStream( fos ); + try { + xformer.modifyOutputStream( jos ); + jos.close(); + jos = null; + JarFile jarFile = new JarFile( tempJar ); + JarEntry jarEntry = jarFile.getJarEntry( contentResource ); + assertNotNull( jarEntry ); + InputStream entryStream = jarFile.getInputStream( jarEntry ); + try { + String xformedContent = IOUtils.toString(entryStream, "utf-8"); + assertEquals( "org.eclipse1234.osgi.launch.EquinoxFactory" + System.getProperty( "line.separator" ), xformedContent ); + + } finally { + IOUtils.closeQuietly( entryStream ); + jarFile.close(); + } + } finally { + if (jos != null) + { + IOUtils.closeQuietly( jos ); + } + tempJar.delete(); + } + } @Test public void concatenation() throws Exception { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services