@Test public void mergeToSeparateFile() throws Exception { List<String> files = Arrays.asList( "target/test-classes/META-INF/LICENSE", "target/test-classes/META-INF/LICENSE.txt" ); MergeFilesTransformer mergeFilesTransformer = new MergeFilesTransformer( files, "LICENSE", false ); Path result = Files.createTempFile( "result_transform", ".jetty_tmp.zip" ); try (JarOutputStream outputStream = new JarOutputStream( Files.newOutputStream( result ) )) { mergeFilesTransformer.modifyOutputStream( outputStream ); } try (JarInputStream jarInputStream = new JarInputStream( Files.newInputStream( result ) )) { jarInputStream.getNextJarEntry(); StringWriter stringWriter = new StringWriter(); IOUtil.copy( jarInputStream, stringWriter ); String content = stringWriter.toString(); Assertions.assertTrue( content.contains( "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" ) ); Assertions.assertTrue( content.contains( "Apache License" ) ); Assertions.assertTrue( content.contains( "Version 2.0, January 2004")); Assertions.assertTrue( content.contains( "\"CLASSPATH\" EXCEPTION TO THE GPL VERSION 2")); Assertions.assertTrue( content.contains( "Eclipse Public License - v 1.0" ) ); } finally { Files.deleteIfExists( result ); } }
@Override public void modifyOutputStream( JarOutputStream jos ) throws IOException { for ( String file : files ) { Files.copy( Paths.get( file ), data ); data.write( '\n' ); } jos.putNextEntry( new JarEntry( resource ) ); IOUtil.copy( new ByteArrayInputStream( data.toByteArray() ), jos ); data.reset(); }
MergeFilesTransformer implements ResourceTransformer { @Override public void modifyOutputStream( JarOutputStream jos ) throws IOException { for ( String file : files ) { Files.copy( Paths.get( file ), data ); data.write( '\n' ); } jos.putNextEntry( new JarEntry( resource ) ); IOUtil.copy( new ByteArrayInputStream( data.toByteArray() ), jos ); data.reset(); } }
MergeFilesTransformer implements ResourceTransformer { @Override public void modifyOutputStream( JarOutputStream jos ) throws IOException { for ( String file : files ) { Files.copy( Paths.get( file ), data ); data.write( '\n' ); } jos.putNextEntry( new JarEntry( resource ) ); IOUtil.copy( new ByteArrayInputStream( data.toByteArray() ), jos ); data.reset(); } MergeFilesTransformer();  MergeFilesTransformer( List<String> files, String resource, boolean preserveResourceContent ); }
MergeFilesTransformer implements ResourceTransformer { @Override public void modifyOutputStream( JarOutputStream jos ) throws IOException { for ( String file : files ) { Files.copy( Paths.get( file ), data ); data.write( '\n' ); } jos.putNextEntry( new JarEntry( resource ) ); IOUtil.copy( new ByteArrayInputStream( data.toByteArray() ), jos ); data.reset(); } MergeFilesTransformer();  MergeFilesTransformer( List<String> files, String resource, boolean preserveResourceContent ); @Override boolean canTransformResource( String resource ); @Override void processResource( String resource, InputStream is, List<Relocator> relocators ); @Override boolean hasTransformedResource(); @Override void modifyOutputStream( JarOutputStream jos ); }
MergeFilesTransformer implements ResourceTransformer { @Override public void modifyOutputStream( JarOutputStream jos ) throws IOException { for ( String file : files ) { Files.copy( Paths.get( file ), data ); data.write( '\n' ); } jos.putNextEntry( new JarEntry( resource ) ); IOUtil.copy( new ByteArrayInputStream( data.toByteArray() ), jos ); data.reset(); } MergeFilesTransformer();  MergeFilesTransformer( List<String> files, String resource, boolean preserveResourceContent ); @Override boolean canTransformResource( String resource ); @Override void processResource( String resource, InputStream is, List<Relocator> relocators ); @Override boolean hasTransformedResource(); @Override void modifyOutputStream( JarOutputStream jos );  }