Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278059 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 20 years ago
parent
commit
25e6c497c3
6 changed files with 106 additions and 12 deletions
  1. +1
    -0
      WHATSNEW
  2. +35
    -0
      docs/manual/CoreTasks/signjar.html
  3. +14
    -6
      src/etc/testcases/taskdefs/signjar.xml
  4. +42
    -6
      src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java
  5. +10
    -0
      src/main/org/apache/tools/ant/types/Environment.java
  6. +4
    -0
      src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java

+ 1
- 0
WHATSNEW View File

@@ -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
=====================================================


+ 35
- 0
docs/manual/CoreTasks/signjar.html View File

@@ -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>
&lt;signjar jar=&quot;${dist}/lib/ant.jar&quot;
@@ -154,7 +162,34 @@ alias=&quot;apache-group&quot; storepass=&quot;secret&quot;/&gt;
signs the ant.jar with alias &quot;apache-group&quot; accessing the
keystore and private key via &quot;secret&quot; password.
</p>
<blockquote><pre>
&lt;signjar destDir="signed"
alias="testonly" keystore="testkeystore"
storepass="apacheant"
preservelastmodified="true"&gt;
&lt;fileset dir="dist" includes="**/*.jar" /&gt;
&lt;flattenmapper /&gt;
&lt;/signjar&gt;
</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>
&lt;signjar
alias="testonly" keystore="testkeystore"
storepass="apacheant"
lazy="true"
&gt;
&lt;fileset dir="dist" includes="**/*.jar" /&gt;
&lt;/signjar&gt;
</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>


+ 14
- 6
src/etc/testcases/taskdefs/signjar.xml View File

@@ -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}"/>


+ 42
- 6
src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java View File

@@ -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);
}
}



+ 10
- 0
src/main/org/apache/tools/ant/types/Environment.java View File

@@ -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;
}
}

+ 4
- 0
src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java View File

@@ -150,6 +150,10 @@ public class SignJarTest extends BuildFileTest {
}
}

public void testSysProperty() {
executeTarget("testSysProperty");
}

public void testVerifyJar() {
executeTarget("testVerifyJar");
}


Loading…
Cancel
Save