You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2011/11/25 17:01:41 UTC

svn commit: r1206240 - /maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java

Author: olamy
Date: Fri Nov 25 16:01:40 2011
New Revision: 1206240

URL: http://svn.apache.org/viewvc?rev=1206240&view=rev
Log:
[MSHARED-213] Please add a method to class JarSignerUtil to test an archive to contain signature files.
Submitted by Christian Schulte.

Modified:
    maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java

Modified: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java?rev=1206240&r1=1206239&r2=1206240&view=diff
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java (original)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java Fri Nov 25 16:01:40 2011
@@ -121,6 +121,63 @@ public class JarSignerUtil
     }
 
     /**
+     * Scans an archive for existing signatures.
+     *
+     * @param jarFile The archive to scan, must not be <code>null</code>.
+     *
+     * @return <code>true</code>, if the archive contains at least one signature file; <code>false</code>, if the
+     * archive does not contain any signature files.
+     *
+     * @throws IOException if scanning <code>jarFile</code> fails.
+     */
+    public static boolean isArchiveSigned( final File jarFile )
+        throws IOException
+    {
+        if ( jarFile == null )
+        {
+            throw new NullPointerException( "jarFile" );
+        }
+
+        ZipInputStream in = null;
+        boolean suppressExceptionOnClose = true;
+
+        try
+        {
+            boolean signed = false;
+            in = new ZipInputStream( new BufferedInputStream( new FileInputStream( jarFile ) ) );
+
+            for ( ZipEntry ze = in.getNextEntry(); ze != null; ze = in.getNextEntry() )
+            {
+                if ( isSignatureFile( ze.getName() ) )
+                {
+                    signed = true;
+                    break;
+                }
+            }
+
+            suppressExceptionOnClose = false;
+            return signed;
+        }
+        finally
+        {
+            try
+            {
+                if ( in != null )
+                {
+                    in.close();
+                }
+            }
+            catch ( final IOException e )
+            {
+                if ( !suppressExceptionOnClose )
+                {
+                    throw e;
+                }
+            }
+        }
+    }
+
+    /**
      * Checks whether the specified JAR file entry denotes a signature-related file, i.e. matches
      * <code>META-INF/*.SF</code>, <code>META-INF/*.DSA</code> or <code>META-INF/*.RSA</code>.
      *