stevel 2005/03/24 07:01:30 Modified: src/main/org/apache/tools/ant/taskdefs AbstractJarSignerTask.java src/main/org/apache/tools/ant/types Environment.java docs/manual/CoreTasks signjar.html src/etc/testcases/taskdefs signjar.xml src/testcases/org/apache/tools/ant/taskdefs SignJarTest.java . WHATSNEW Log: system properties are in <signjar>, so you can (manually) propagate proxy settings. Updated docs and examples. Patched Environment.java for raw access to the variables, rather than just a string array. Revision Changes Path 1.2 +42 -6 ant/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java Index: AbstractJarSignerTask.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractJarSignerTask.java 23 Mar 2005 16:51:42 -0000 1.1 +++ AbstractJarSignerTask.java 24 Mar 2005 15:01:30 -0000 1.2 @@ -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 [EMAIL PROTECTED] SignJar}; a base class that can be used @@ -75,6 +78,12 @@ * 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: [EMAIL PROTECTED] */ @@ -165,6 +174,14 @@ } /** + * 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) */ protected void beginExecution() { @@ -201,14 +218,33 @@ */ 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 @@ 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 @@ // 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); } } 1.18 +10 -0 ant/src/main/org/apache/tools/ant/types/Environment.java Index: Environment.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Environment.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- Environment.java 9 Mar 2004 16:48:41 -0000 1.17 +++ Environment.java 24 Mar 2005 15:01:30 -0000 1.18 @@ -151,4 +151,14 @@ } 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; + } } 1.22 +35 -0 ant/docs/manual/CoreTasks/signjar.html Index: signjar.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/signjar.html,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- signjar.html 23 Mar 2005 15:06:48 -0000 1.21 +++ signjar.html 24 Mar 2005 15:01:30 -0000 1.22 @@ -144,7 +144,15 @@ <td valign="top">A mapper to rename jar files during signing</td> <td valign="top" align="center">No, and only one can be supplied</td> </tr> + <tr> + <td valign="top">sysproperty</td> + <td valign="top">JVM system properties, with the syntax of Ant + <a href="exec.html#env">environment variables</a> </td> + <td valign="top" align="center">No, and only one can be supplied</td> + </tr> </table> + + <h3>Examples</h3> <blockquote><pre> <signjar jar="${dist}/lib/ant.jar" @@ -154,7 +162,34 @@ signs the ant.jar with alias "apache-group" accessing the keystore and private key via "secret" password. </p> + <blockquote><pre> +<signjar destDir="signed" + alias="testonly" keystore="testkeystore" + storepass="apacheant" + preservelastmodified="true"> + <fileset dir="dist" includes="**/*.jar" /> + <flattenmapper /> +</signjar> +</pre></blockquote> +<p> +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. +</p> + <blockquote><pre> +<signjar + alias="testonly" keystore="testkeystore" + storepass="apacheant" + lazy="true" + > + <fileset dir="dist" includes="**/*.jar" /> +</signjar> +</pre></blockquote> +<p> +Sign all the JAR files in dist/**/*.jar <i>in-situ</i>. Lazy signing is used, +so the files will only be signed if they are not already signed. +</p> <h3>About timestamp signing</h3> <p> 1.10 +14 -6 ant/src/etc/testcases/taskdefs/signjar.xml Index: signjar.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/signjar.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- signjar.xml 23 Mar 2005 16:51:42 -0000 1.9 +++ signjar.xml 24 Mar 2005 15:01:30 -0000 1.10 @@ -6,8 +6,6 @@ <property name="test.jar" location="${sign.dir}/signtest.jar" /> <property name="subdirtest.jar" location="${subdir}/signtest.jar" /> - <mkdir dir="${sign.dir}" /> - <mkdir dir="${subdir}" /> <macrodef name="assertSigned"> <attribute name="jar" default="${test.jar}" /> @@ -35,8 +33,13 @@ <presetdef name="sign"> <sign-base jar="${test.jar}" /> </presetdef> + + <target name="init"> + <mkdir dir="${sign.dir}" /> + <mkdir dir="${subdir}" /> + </target> - <target name="jar" > + <target name="jar" depends="init"> <jar jarfile="${test.jar}" basedir="${classes.dir}" includes="**/Task.class"/> </target> @@ -117,9 +120,8 @@ </target> <target name="testSignedJar" depends="jar"> - <property name="new.jar" location="${sign.dir}/newfile.jar" /> - <sign signedjar="${new.jar}"/> - <assertSigned jar="${new.jar}"/> + <sign signedjar="${subdirtest.jar}"/> + <assertSigned jar="${subdirtest.jar}"/> </target> <target name="testDestDirAndSignedJar" depends="jar"> @@ -181,6 +183,12 @@ <sign tsaurl="http://localhost:0/" /> </target> + <target name="testSysProperty" depends="jar"> + <sign> + <sysproperty key="ant.home" value="${ant.home}" /> + </sign> + <assertSigned/> + </target> <target name="testVerifyJar" depends="basic"> <verify-base jar="${test.jar}"/> 1.14 +4 -0 ant/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java Index: SignJarTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- SignJarTest.java 23 Mar 2005 16:51:42 -0000 1.13 +++ SignJarTest.java 24 Mar 2005 15:01:30 -0000 1.14 @@ -150,6 +150,10 @@ } } + public void testSysProperty() { + executeTarget("testSysProperty"); + } + public void testVerifyJar() { executeTarget("testVerifyJar"); } 1.793 +1 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.792 retrieving revision 1.793 diff -u -r1.792 -r1.793 --- WHATSNEW 24 Mar 2005 08:35:49 -0000 1.792 +++ WHATSNEW 24 Mar 2005 15:01:30 -0000 1.793 @@ -152,6 +152,7 @@ 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 <sysproperty> elements, which can be used for proxy setup and the like Changes from Ant 1.6.2 to current Ant 1.6 CVS version =====================================================
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]