diff --git a/webstart-maven-plugin/pom.xml b/webstart-maven-plugin/pom.xml index ec0edbef..298de70b 100644 --- a/webstart-maven-plugin/pom.xml +++ b/webstart-maven-plugin/pom.xml @@ -46,6 +46,13 @@ + + org.apache.commons + commons-compress + 1.24.0 + + + org.codehaus.mojo keytool-api-1.7 diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java index 1934e644..11137824 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java @@ -407,6 +407,17 @@ public boolean isPack200() return pack200 != null && pack200.isEnabled(); } + /** + * Returns the flag that indicates whether or not jar resources + * will be compressed using the Apache Commons Compress pack200 variant. + * + * @return Returns the value of the pack200.enabled field. + */ + public boolean isCommonsCompressEnabled() + { + return pack200 != null && pack200.isCommonsCompressEnabled(); + } + /** * Returns the files to be passed without pack200 compression. * @@ -691,7 +702,7 @@ protected void signOrRenameJars() // http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html // we need to pack then unpack the files before signing them - unpackJars( getLibDirectory() ); + unpackJars( getLibDirectory(), isCommonsCompressEnabled() ); // As out current Pack200 ant tasks don't give us the ability to use a temporary area for // creating those temporary packing, we have to delete the temporary files. @@ -733,7 +744,7 @@ protected void pack200Jars( File directory, FileFilter filter ) { try { - getPack200Tool().packJars( directory, filter, isGzip(), getPack200PassFiles() ); + getPack200Tool().packJars( directory, filter, isGzip(), getPack200PassFiles(), isCommonsCompressEnabled() ); } catch ( IOException e ) { @@ -798,7 +809,7 @@ protected void verboseLog( String msg ) // Private Methods // ---------------------------------------------------------------------- - private void unpackJars( File directory ) + private void unpackJars( File directory, boolean commonsCompress ) throws MojoExecutionException { getLog().info( "-- Unpack jars before sign operation " ); @@ -812,7 +823,7 @@ private void unpackJars( File directory ) // then unpack try { - getPack200Tool().unpackJars( directory, unprocessedPack200FileFilter ); + getPack200Tool().unpackJars( directory, unprocessedPack200FileFilter, commonsCompress ); } catch ( IOException e ) { diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractJnlpMojo.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractJnlpMojo.java index d438012b..37de27e8 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractJnlpMojo.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractJnlpMojo.java @@ -827,6 +827,7 @@ private void checkInput() getLog().debug( "basedir " + this.basedir ); getLog().debug( "gzip " + isGzip() ); getLog().debug( "pack200 " + isPack200() ); + getLog().debug( "Commons Compress pack200 " + isCommonsCompressEnabled() ); getLog().debug( "project " + this.getProject() ); getLog().debug( "verbose " + isVerbose() ); diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyConfig.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyConfig.java index a76edd5b..76907d7a 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyConfig.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyConfig.java @@ -113,6 +113,17 @@ public boolean isPack200() return globalConfig.isPack200(); } + /** + * Returns the flag that indicates whether or not jar resources + * will be compressed using pack200. + * + * @return Returns the value of the pack200.enabled field. + */ + public boolean isCommonsCompressEnabled() + { + return globalConfig.isCommonsCompressEnabled(); + } + /** * Returns the files to be passed without pack200 compression. * diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyGlobalConfig.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyGlobalConfig.java index 51816a15..1c461fa7 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyGlobalConfig.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/JnlpDependencyGlobalConfig.java @@ -153,4 +153,10 @@ public boolean isPack200() { return pack200 != null && pack200.isEnabled(); } + + + public boolean isCommonsCompressEnabled() + { + return pack200 != null && pack200.isCommonsCompressEnabled(); + } } diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/Pack200Task.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/Pack200Task.java index 020a60b5..19260be9 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/Pack200Task.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/Pack200Task.java @@ -78,7 +78,7 @@ public File execute( JnlpDependencyConfig config, File file ) verboseLog( config, "Pack200 file: " + file ); try { - File result = pack200Tool.packJar( file, config.isGzip(), config.getPack200PassFiles() ); + File result = pack200Tool.packJar( file, config.isGzip(), config.getPack200PassFiles(), config.isCommonsCompressEnabled() ); getLogger().debug( "packed200 file: " + result ); return result; } diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/UnPack200Task.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/UnPack200Task.java index dc185d5a..b76170a5 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/UnPack200Task.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/UnPack200Task.java @@ -87,7 +87,7 @@ public File execute( JnlpDependencyConfig config, File file ) verboseLog( config, "Unpack 200 file: " + file ); try { - File result = pack200Tool.unpackJar( file ); + File result = pack200Tool.unpackJar( file, config.isCommonsCompressEnabled() ); getLogger().debug( "Unpacked 200 file: " + result ); return result; } diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/DefaultPack200Tool.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/DefaultPack200Tool.java index e835be2b..86b28e17 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/DefaultPack200Tool.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/DefaultPack200Tool.java @@ -60,7 +60,7 @@ public class DefaultPack200Tool public static final String PACK_EXTENSION = ".pack"; @Override - public void pack( File source, File destination, Map props, boolean gzip ) + public void pack( File source, File destination, Map props, boolean gzip, boolean commonsCompress ) throws IOException { JarFile jar = null; @@ -81,9 +81,15 @@ public void pack( File source, File destination, Map props, bool jar = new JarFile( source, false ); - Pack200.Packer packer = Pack200.newPacker(); - packer.properties().putAll( props ); - packer.pack( jar, out ); + if (commonsCompress) { + org.apache.commons.compress.java.util.jar.Pack200.Packer packer = org.apache.commons.compress.java.util.jar.Pack200.newPacker(); + packer.properties().putAll( props ); + packer.pack( jar, out ); + } else { + Pack200.Packer packer = Pack200.newPacker(); + packer.properties().putAll( props ); + packer.pack( jar, out ); + } } finally { @@ -96,15 +102,15 @@ public void pack( File source, File destination, Map props, bool } @Override - public void repack( File source, File destination, Map props ) - throws IOException + public void repack( File source, File destination, Map props, boolean commonsCompress ) + throws IOException { File tempFile = new File( source.toString() + ".tmp" ); try { - pack( source, tempFile, props, false ); - unpack( tempFile, destination, props ); + pack( source, tempFile, props, false, commonsCompress ); + unpack( tempFile, destination, props, commonsCompress ); } finally { @@ -113,7 +119,7 @@ public void repack( File source, File destination, Map props ) } @Override - public void unpack( File source, File destination, Map props ) + public void unpack( File source, File destination, Map props, boolean commonsCompress ) throws IOException { InputStream in = null; @@ -129,9 +135,15 @@ public void unpack( File source, File destination, Map props ) out = new JarOutputStream( new BufferedOutputStream( new FileOutputStream( destination ) ) ); - Pack200.Unpacker unpacker = Pack200.newUnpacker(); - unpacker.properties().putAll( props ); - unpacker.unpack( in, out ); + if (commonsCompress) { + org.apache.commons.compress.java.util.jar.Pack200.Unpacker unpacker = org.apache.commons.compress.java.util.jar.Pack200.newUnpacker(); + unpacker.properties().putAll( props ); + unpacker.unpack( in, out ); + } else { + Pack200.Unpacker unpacker = Pack200.newUnpacker(); + unpacker.properties().putAll( props ); + unpacker.unpack( in, out ); + } } finally { @@ -141,7 +153,7 @@ public void unpack( File source, File destination, Map props ) } @Override - public void packJars( File directory, FileFilter jarFileFilter, boolean gzip, List passFiles ) + public void packJars( File directory, FileFilter jarFileFilter, boolean gzip, List passFiles, boolean commonsCompress ) throws IOException { // getLog().debug( "packJars for " + directory ); @@ -171,13 +183,13 @@ public void packJars( File directory, FileFilter jarFileFilter, boolean gzip, Li } } - pack( jarFile, pack200Jar, propMap, gzip ); + pack( jarFile, pack200Jar, propMap, gzip, commonsCompress ); setLastModified( pack200Jar, jarFile.lastModified() ); } } @Override - public File packJar( File jarFile, boolean gzip, List passFiles ) + public File packJar( File jarFile, boolean gzip, List passFiles, boolean commonsCompress) throws IOException { final String extension = gzip ? PACK_GZ_EXTENSION : PACK_EXTENSION; @@ -199,14 +211,14 @@ public File packJar( File jarFile, boolean gzip, List passFiles ) } } - pack( jarFile, pack200Jar, propMap, gzip ); + pack( jarFile, pack200Jar, propMap, gzip, commonsCompress ); setLastModified( pack200Jar, jarFile.lastModified() ); return pack200Jar; } @Override - public void unpackJars( File directory, FileFilter pack200FileFilter ) + public void unpackJars( File directory, FileFilter pack200FileFilter, boolean commonsCompress ) throws IOException { // getLog().debug( "unpackJars for " + directory ); @@ -220,13 +232,13 @@ public void unpackJars( File directory, FileFilter pack200FileFilter ) deleteFile( jarFile ); - unpack( packFile, jarFile, Collections.emptyMap() ); + unpack( packFile, jarFile, Collections.emptyMap(), commonsCompress ); setLastModified( jarFile, packFile.lastModified() ); } } @Override - public File unpackJar( File packFile ) + public File unpackJar( File packFile, boolean commonsCompress ) throws IOException { final String packedJarPath = packFile.getAbsolutePath(); @@ -236,7 +248,7 @@ public File unpackJar( File packFile ) deleteFile( jarFile ); - unpack( packFile, jarFile, Collections.emptyMap() ); + unpack( packFile, jarFile, Collections.emptyMap(), commonsCompress ); setLastModified( jarFile, packFile.lastModified() ); return jarFile; } diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Config.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Config.java index 2dd8299a..a6696153 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Config.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Config.java @@ -39,6 +39,13 @@ public class Pack200Config */ private boolean enabled; + /** + * Whether the commons compress version of pack200 is enabled + * + * @see #isCommonsCompressEnabled() + */ + private boolean commonsCompressEnabled; + /** * The files to be passed without compression. * @@ -83,4 +90,12 @@ public void setPassFiles( List passFiles ) this.passFiles = passFiles; } + public boolean isCommonsCompressEnabled() { + return commonsCompressEnabled; + } + + public void setCommonsCompressEnabled(boolean commonsCompressEnabled) { + this.commonsCompressEnabled = commonsCompressEnabled; + } + } diff --git a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Tool.java b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Tool.java index 3bc4b2fe..0dbc9f20 100644 --- a/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Tool.java +++ b/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/pack200/Pack200Tool.java @@ -58,7 +58,7 @@ public interface Pack200Tool * @param gzip true if the destination file * @throws IOException TODO */ - void pack( File source, File destination, Map props, boolean gzip ) + void pack( File source, File destination, Map props, boolean gzip, boolean commonsCompress ) throws IOException; /** @@ -69,7 +69,7 @@ void pack( File source, File destination, Map props, boolean gzi * @param props the packing properties * @throws IOException TODO */ - void repack( File source, File destination, Map props ) + void repack( File source, File destination, Map props, boolean commonsCompress ) throws IOException; /** @@ -80,7 +80,7 @@ void repack( File source, File destination, Map props ) * @param props the packing properties * @throws IOException TODO */ - void unpack( File source, File destination, Map props ) + void unpack( File source, File destination, Map props, boolean commonsCompress ) throws IOException; /** @@ -94,7 +94,7 @@ void unpack( File source, File destination, Map props ) * @param passFiles the list of file names to be passed as not pack200 compressed * @throws IOException TODO */ - void packJars( File directory, FileFilter jarFileFilter, boolean gzip, List passFiles ) + void packJars( File directory, FileFilter jarFileFilter, boolean gzip, List passFiles, boolean commonsCompress ) throws IOException; /** @@ -106,7 +106,7 @@ void packJars( File directory, FileFilter jarFileFilter, boolean gzip, List passFiles ) + File packJar( File jarFile, boolean gzip, List passFiles, boolean commonsCompress ) throws IOException; /** @@ -116,7 +116,7 @@ File packJar( File jarFile, boolean gzip, List passFiles ) * @param pack200FileFilter the fileter to determin which files to unpakc * @throws IOException TODO */ - void unpackJars( File directory, FileFilter pack200FileFilter ) + void unpackJars( File directory, FileFilter pack200FileFilter, boolean commonsCompress ) throws IOException; /** @@ -126,6 +126,6 @@ void unpackJars( File directory, FileFilter pack200FileFilter ) * @return the unpacked file * @throws IOException TODO */ - File unpackJar( File packFile ) + File unpackJar( File packFile, boolean commonsCompress ) throws IOException; }