Patched Environment.java for raw access to the variables, rather than just a string array. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278059 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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 <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 | |||
===================================================== | |||
@@ -144,7 +144,15 @@ block</td> | |||
<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 @@ alias="apache-group" storepass="secret"/> | |||
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> | |||
@@ -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}"/> | |||
@@ -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); | |||
} | |||
} | |||
@@ -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; | |||
} | |||
} |
@@ -150,6 +150,10 @@ public class SignJarTest extends BuildFileTest { | |||
} | |||
} | |||
public void testSysProperty() { | |||
executeTarget("testSysProperty"); | |||
} | |||
public void testVerifyJar() { | |||
executeTarget("testVerifyJar"); | |||
} | |||