Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte committed Apr 2, 2019
2 parents ee481d6 + 52eed09 commit cfe70aa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
<contributor>
<name>Anthony Dahanne</name>
</contributor>
<contributor>
<name>Fabiano Cipriano de Oliveira</name>
</contributor>
</contributors>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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 {
Expand Down

0 comments on commit cfe70aa

Please sign in to comment.