Author: bentmann Date: Sun Sep 20 17:24:16 2009 New Revision: 817056 URL: http://svn.apache.org/viewvc?rev=817056&view=rev Log: [MJARSIGNER-7] jarsigner plugin to support all "types" of zip files
Added: maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/some.zip (with props) Modified: maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/verify.bsh maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java Modified: maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml?rev=817056&r1=817055&r2=817056&view=diff ============================================================================== --- maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml (original) +++ maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml Sun Sep 20 17:24:16 2009 @@ -78,6 +78,12 @@ <type>bar</type> <classifier>b</classifier> </artifact> + <artifact> + <!-- see MJARSIGNER-7 --> + <file>some.zip</file> + <type>zip</type> + <classifier>c</classifier> + </artifact> </artifacts> </configuration> </execution> Added: maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/some.zip URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/some.zip?rev=817056&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/some.zip ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/verify.bsh?rev=817056&r1=817055&r2=817056&view=diff ============================================================================== --- maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/verify.bsh (original) +++ maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/verify.bsh Sun Sep 20 17:24:16 2009 @@ -1,5 +1,5 @@ import java.io.*; -import java.util.jar.*; +import java.util.zip.*; File attachedJarFile = new File( basedir, "jar-with-unusual.ext" ); System.out.println( "Checking for existence of " + attachedJarFile ); @@ -8,7 +8,7 @@ throw new Exception( "missing " + attachedJarFile ); } -JarFile attachedJar = new JarFile( attachedJarFile ); +ZipFile attachedJar = new ZipFile( attachedJarFile ); System.out.println( "Checking for existence of " + attachedJarFile.getName() + "!/META-INF/TESTING.SF" ); if ( attachedJar.getEntry( "META-INF/TESTING.SF" ) == null ) { @@ -21,4 +21,24 @@ } attachedJar.close(); +File attachedZipFile = new File( basedir, "some.zip" ); +System.out.println( "Checking for existence of " + attachedZipFile ); +if ( !attachedZipFile.isFile() ) +{ + throw new Exception( "missing " + attachedZipFile ); +} + +ZipFile attachedZip = new ZipFile( attachedZipFile ); +System.out.println( "Checking for existence of " + attachedZipFile.getName() + "!/META-INF/TESTING.SF" ); +if ( attachedZip.getEntry( "META-INF/TESTING.SF" ) == null ) +{ + throw new Exception( "missing " + attachedZipFile.getName() + "!/META-INF/TESTING.SF" ); +} +System.out.println( "Checking for existence of " + attachedZipFile.getName() + "!/META-INF/TESTING.DSA" ); +if ( attachedZip.getEntry( "META-INF/TESTING.DSA" ) == null ) +{ + throw new Exception( "missing " + attachedZipFile.getName() + "!/META-INF/TESTING.DSA" ); +} +attachedZip.close(); + return true; Modified: maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java?rev=817056&r1=817055&r2=817056&view=diff ============================================================================== --- maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java (original) +++ maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java Sun Sep 20 17:24:16 2009 @@ -28,7 +28,6 @@ import java.util.List; import java.util.Properties; import java.util.ResourceBundle; -import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.apache.maven.artifact.Artifact; @@ -126,8 +125,8 @@ private boolean processMainArtifact; /** - * Controls processing of project attachments. If enabled, attached artifacts that are no JARs will be automatically - * excluded from processing. + * Controls processing of project attachments. If enabled, attached artifacts that are no JAR/ZIP files will be + * automatically excluded from processing. * * @parameter expression="${jarsigner.processAttachedArtifacts}" default-value="true" * @since 1.1 @@ -266,40 +265,32 @@ } /** - * Checks Java language capability of an artifact. + * Checks whether the specified artifact is a ZIP file. * - * @param artifact The artifact to check. + * @param artifact The artifact to check, may be <code>null</code>. * - * @return {...@code true} if {...@code artifact} is Java language capable; {...@code false} if not. + * @return <code>true</code> if the artifact looks like a ZIP file, <code>false</code> otherwise. */ - private boolean isJarFile( final Artifact artifact ) + private boolean isZipFile( final Artifact artifact ) { - return artifact != null && artifact.getFile() != null && isJarFile( artifact.getFile() ); + return artifact != null && artifact.getFile() != null && isZipFile( artifact.getFile() ); } /** - * Checks whether the specified file is a JAR file. For our purposes, a JAR file is a (non-empty) ZIP stream with a - * META-INF directory or some class files. + * Checks whether the specified file is a JAR file. For our purposes, a ZIP file is a ZIP stream with at least one + * entry. * * @param file The file to check, must not be <code>null</code>. - * @return <code>true</code> if the file looks like a JAR file, <code>false</code> otherwise. + * @return <code>true</code> if the file looks like a ZIP file, <code>false</code> otherwise. */ - private boolean isJarFile( final File file ) + private boolean isZipFile( final File file ) { try { - // NOTE: ZipFile.getEntry() might be shorter but is several factors slower on large files - ZipInputStream zis = new ZipInputStream( new FileInputStream( file ) ); try { - for ( ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry() ) - { - if ( ze.getName().startsWith( "META-INF/" ) || ze.getName().endsWith( ".class" ) ) - { - return true; - } - } + return zis.getNextEntry() != null; } finally { @@ -333,7 +324,7 @@ boolean processed = false; - if ( isJarFile( artifact ) ) + if ( isZipFile( artifact ) ) { processArchive( artifact.getFile() );