diff --git a/WHATSNEW b/WHATSNEW index ebe5c8d5f..f74830a16 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -152,6 +152,7 @@ Other changes: can be used with the jar attribute or nested filesets -a mapper to permit filename remapping on signing -tsaurl and tsacert attributes for timestamped JAR signing + -nested elements, which can be used for proxy setup and the like Changes from Ant 1.6.2 to current Ant 1.6 CVS version ===================================================== diff --git a/docs/manual/CoreTasks/signjar.html b/docs/manual/CoreTasks/signjar.html index 9d098c66a..96a89296c 100644 --- a/docs/manual/CoreTasks/signjar.html +++ b/docs/manual/CoreTasks/signjar.html @@ -144,7 +144,15 @@ block A mapper to rename jar files during signing No, and only one can be supplied + + sysproperty + JVM system properties, with the syntax of Ant + environment variables + No, and only one can be supplied + + +

Examples

 <signjar jar="${dist}/lib/ant.jar"
@@ -154,7 +162,34 @@ alias="apache-group" storepass="secret"/>
   signs the ant.jar with alias "apache-group" accessing the
   keystore and private key via "secret" password.
 

+
+<signjar destDir="signed"
+    alias="testonly" keystore="testkeystore"
+    storepass="apacheant"
+    preservelastmodified="true">
+  <fileset dir="dist" includes="**/*.jar" />
+  <flattenmapper />
+</signjar>
+
+

+Sign all JAR files matching the dist/**/*.jar pattern, copying them to the +directory "signed" afterwards. The flatten mapper means that they will +all be copied to this directory, not to subdirectories. +

+
+<signjar
+    alias="testonly" keystore="testkeystore"
+    storepass="apacheant"
+    lazy="true"
+    >
+  <fileset dir="dist" includes="**/*.jar" />
+</signjar>
+
+

+Sign all the JAR files in dist/**/*.jar in-situ. Lazy signing is used, +so the files will only be signed if they are not already signed. +

About timestamp signing

diff --git a/src/etc/testcases/taskdefs/signjar.xml b/src/etc/testcases/taskdefs/signjar.xml index 191532268..adfb060a6 100644 --- a/src/etc/testcases/taskdefs/signjar.xml +++ b/src/etc/testcases/taskdefs/signjar.xml @@ -6,8 +6,6 @@ - - @@ -35,8 +33,13 @@ + + + + + - + @@ -117,9 +120,8 @@ - - - + + @@ -181,6 +183,12 @@ + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java b/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java index 7b5b6cb9d..fde4087a0 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java @@ -18,12 +18,15 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.RedirectorElement; +import org.apache.tools.ant.types.Environment; import java.io.File; import java.util.Vector; +import java.util.Enumeration; /** * This is factored out from {@link SignJar}; a base class that can be used @@ -75,6 +78,12 @@ public abstract class AbstractJarSignerTask extends Task { * redirector used to talk to the jarsigner program */ private RedirectorElement redirector; + + /** + * Java declarations -J-Dname=value + */ + private Environment sysProperties=new Environment(); + /** * error string for unit test verification: {@value} */ @@ -164,6 +173,14 @@ public abstract class AbstractJarSignerTask extends Task { filesets.addElement(set); } + /** + * Add a system property. + * + * @param sysp system property. + */ + public void addSysproperty(Environment.Variable sysp) { + sysProperties.addVariable(sysp); + } /** * init processing logic; this is retained through our execution(s) */ @@ -201,14 +218,33 @@ public abstract class AbstractJarSignerTask extends Task { */ protected void setCommonOptions(final ExecTask cmd) { if (maxMemory != null) { - cmd.createArg().setValue("-J-Xmx" + maxMemory); + addValue(cmd,"-J-Xmx" + maxMemory); } if (verbose) { - cmd.createArg().setValue("-verbose"); + addValue(cmd,"-verbose"); } + + //now patch in all system properties + Vector props=sysProperties.getVariablesVector(); + Enumeration e=props.elements(); + while (e.hasMoreElements()) { + Environment.Variable variable = (Environment.Variable) e.nextElement(); + declareSysProperty(cmd,variable); + } + } + + /** + * + * @param cmd command to configure + * @param property property to set + * @throws BuildException if the property is not correctly defined. + */ + protected void declareSysProperty(ExecTask cmd,Environment.Variable property) { + addValue(cmd, "-J-D"+property.getContent()); } + /** * bind to a keystore if the attributes are there * @param cmd command to configure @@ -216,7 +252,7 @@ public abstract class AbstractJarSignerTask extends Task { protected void bindToKeystore(final ExecTask cmd) { if (null != keystore) { // is the keystore a file - cmd.createArg().setValue("-keystore"); + addValue(cmd,"-keystore"); String location; File keystoreFile = getProject().resolveFile(keystore); if (keystoreFile.exists()) { @@ -225,11 +261,11 @@ public abstract class AbstractJarSignerTask extends Task { // must be a URL - just pass as is location = keystore; } - cmd.createArg().setValue(location); + addValue(cmd,location); } if (null != storetype) { - cmd.createArg().setValue("-storetype"); - cmd.createArg().setValue(storetype); + addValue(cmd,"-storetype"); + addValue(cmd, storetype); } } diff --git a/src/main/org/apache/tools/ant/types/Environment.java b/src/main/org/apache/tools/ant/types/Environment.java index eeafd3913..6de33008d 100644 --- a/src/main/org/apache/tools/ant/types/Environment.java +++ b/src/main/org/apache/tools/ant/types/Environment.java @@ -151,4 +151,14 @@ public class Environment { } return result; } + + /** + * Get the raw vector of variables. This is not a clone. + * @return a potentially empty (but never null) vector of elements of type + * Variable + * @since Ant 1.7 + */ + public Vector getVariablesVector() { + return variables; + } } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java index 9e3ab34c3..564c9bc00 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java @@ -150,6 +150,10 @@ public class SignJarTest extends BuildFileTest { } } + public void testSysProperty() { + executeTarget("testSysProperty"); + } + public void testVerifyJar() { executeTarget("testVerifyJar"); }