diff --git a/src/main/org/apache/tools/ant/taskdefs/SignJar.java b/src/main/org/apache/tools/ant/taskdefs/SignJar.java
index 3e8503474..e975f4061 100644
--- a/src/main/org/apache/tools/ant/taskdefs/SignJar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/SignJar.java
@@ -54,13 +54,20 @@
package org.apache.tools.ant.taskdefs;
import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
import org.apache.tools.ant.*;
import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.FileSet;
/**
* Sign a archive.
- *
+ *
* @author Peter Donald donaldp@apache.org
+ * @author Nick Fortescue nick@ox.compsoc.net
*/
public class SignJar extends Task {
@@ -87,142 +94,223 @@ public class SignJar extends Task {
protected boolean internalsf;
protected boolean sectionsonly;
+ /**
+ * the filesets of the jars to sign
+ */
+ protected Vector filesets = new Vector();
+ /**
+ * Whether to assume a jar which has an appropriate .SF file in is already
+ * signed.
+ */
+ protected boolean lazy;
+
public void setJar(final String jar) {
this.jar = jar;
- }
+ }
public void setAlias(final String alias) {
this.alias = alias;
- }
+ }
public void setKeystore(final String keystore) {
this.keystore = keystore;
- }
+ }
public void setStorepass(final String storepass) {
this.storepass = storepass;
- }
+ }
public void setStoretype(final String storetype) {
this.storetype = storetype;
- }
+ }
public void setKeypass(final String keypass) {
this.keypass = keypass;
- }
+ }
public void setSigfile(final String sigfile) {
this.sigfile = sigfile;
- }
+ }
public void setSignedjar(final String signedjar) {
this.signedjar = signedjar;
- }
+ }
public void setVerbose(final boolean verbose) {
this.verbose = verbose;
- }
+ }
public void setInternalsf(final boolean internalsf) {
this.internalsf = internalsf;
- }
+ }
public void setSectionsonly(final boolean sectionsonly) {
this.sectionsonly = sectionsonly;
- }
+ }
+
+ public void setLazy(final boolean lazy) {
+ this.lazy = lazy;
+ }
+
+ /**
+ * Adds a set of files (nested fileset attribute).
+ */
+ public void addFileset(final FileSet set) {
+ filesets.addElement(set);
+ }
+
public void execute() throws BuildException {
+ if (null == jar && null == filesets) {
+ throw new BuildException("jar must be set through jar attribute or nested filesets");
+ }
+ if( null != jar ) {
+ doOneJar(jar, signedjar);
+ return;
+ } else {
+ //Assume null != filesets
+
+ // deal with the filesets
+ for (int i=0; i jarFile.lastModified())
return true;
+ } else {
+ if( lazy ) {
+ return isSigned(jarSource);
+ }
}
return false;
}
+
+ protected boolean isSigned(String jarFilename) {
+ final String SIG_START = "META-INF/";
+ final String SIG_END = ".SF";
+
+ File file = new File(jarFilename);
+ if( !file.exists() ) {
+ return false;
+ }
+ ZipFile jarFile = null;
+ try {
+ jarFile = new ZipFile(file);
+ if(null == alias) {
+ Enumeration entries = jarFile.entries();
+ while(entries.hasMoreElements()) {
+ String name = ((ZipEntry)entries.nextElement()).getName();
+ if(name.startsWith(SIG_START) && name.endsWith(SIG_END)) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ return jarFile.getEntry(SIG_START+alias.toUpperCase()+
+ SIG_END) != null;
+ }
+ } catch(IOException e) {
+ return false;
+ } finally {
+ if(jarFile != null) {
+ try {jarFile.close();} catch(IOException e) {}
+ }
+ }
+ }
+
}