diff --git a/docs/manual/CoreTasks/signjar.html b/docs/manual/CoreTasks/signjar.html index bfa52afa9..03829acdb 100644 --- a/docs/manual/CoreTasks/signjar.html +++ b/docs/manual/CoreTasks/signjar.html @@ -14,7 +14,7 @@ tool detailed dependency checking: files are only signed if they are not signed. The signjar attribute can point to the file to generate; if this file exists then its modification date is used as a cue as to whether to resign any JAR file. -
+
Note: Requires Java 1.2 or later.

Parameters

@@ -83,9 +83,15 @@ block lazy flag to control whether the presence of a signature - file means a JAR is signed + file means a JAR is signed No; default false - + + + maxmemory + Specifies the maximum memory the jarsigner VM will use. Specified in the + style of standard java memory specs (e.g. 128m = 128 MBytes) + No +

Parameters as nested elements

@@ -99,7 +105,7 @@ block -
fileset of JAR files to sign No
+

Examples

<signjar jar="${dist}/lib/ant.jar" diff --git a/src/etc/testcases/taskdefs/signjar.xml b/src/etc/testcases/taskdefs/signjar.xml new file mode 100644 index 000000000..01809c864 --- /dev/null +++ b/src/etc/testcases/taskdefs/signjar.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + This build is for use with Ant's test cases + + + + diff --git a/src/etc/testcases/testkeystore b/src/etc/testcases/testkeystore new file mode 100644 index 000000000..2fd22c9f4 Binary files /dev/null and b/src/etc/testcases/testkeystore differ diff --git a/src/main/org/apache/tools/ant/taskdefs/SignJar.java b/src/main/org/apache/tools/ant/taskdefs/SignJar.java index 938c69a85..515373186 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SignJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/SignJar.java @@ -71,13 +71,13 @@ import org.apache.tools.ant.util.JavaEnvUtils; * are not signed. The signjar attribute can point to the file to * generate; if this file exists then * its modification date is used as a cue as to whether to resign any JAR file. - *
+ *
* Note: Requires Java 1.2 or later.

- * - * @author Peter Donald + * + * @author Peter Donald * donaldp@apache.org - * @author Nick Fortescue + * @author Nick Fortescue * nick@ox.compsoc.net * @since Ant 1.1 * @ant.task category="java" @@ -102,12 +102,15 @@ public class SignJar extends Task { protected String storepass; protected String storetype; protected String keypass; - protected File sigfile; + protected String sigfile; protected File signedjar; protected boolean verbose; protected boolean internalsf; protected boolean sectionsonly; + /** The maximum amount of memory to use for Jar signer */ + private String maxMemory; + /** * the filesets of the jars to sign */ @@ -118,6 +121,17 @@ public class SignJar extends Task { */ protected boolean lazy; + + /** + * Set the maximum memory to be used by the jarsigner process + * + * @param max a string indicating the maximum memory according to the + * JVM conventions (e.g. 128m is 128 Megabytes) + */ + public void setMaxmemory(String max) { + maxMemory = max; + } + /** * the jar file to sign; required */ @@ -163,7 +177,7 @@ public class SignJar extends Task { /** * name of .SF/.DSA file; optional */ - public void setSigfile(final File sigfile) { + public void setSigfile(final String sigfile) { this.sigfile = sigfile; } @@ -216,7 +230,7 @@ public class SignJar extends Task { } - /** + /** * sign the jar(s) */ public void execute() throws BuildException { @@ -245,7 +259,7 @@ public class SignJar extends Task { /** * sign one jar */ - private void doOneJar(File jarSource, File jarTarget) + private void doOneJar(File jarSource, File jarTarget) throws BuildException { if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) { throw new BuildException("The signjar task is only available on " @@ -267,6 +281,10 @@ public class SignJar extends Task { final ExecTask cmd = (ExecTask) getProject().createTask("exec"); cmd.setExecutable("jarsigner"); + if (maxMemory != null) { + cmd.createArg().setValue("-J-Xmx" + maxMemory); + } + if (null != keystore) { cmd.createArg().setValue("-keystore"); cmd.createArg().setValue(keystore.toString()); @@ -289,7 +307,7 @@ public class SignJar extends Task { if (null != sigfile) { cmd.createArg().setValue("-sigfile"); - cmd.createArg().setValue(sigfile.toString()); + cmd.createArg().setValue(sigfile); } if (null != jarTarget) { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java new file mode 100644 index 000000000..67eedc332 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java @@ -0,0 +1,100 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.tools.ant.taskdefs; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Date; +import java.util.Vector; +import java.util.Enumeration; +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.Project; + +/** + * Testcase for the Signjar task + * + * @author Conor MacNeill + */ +public class SignJarTest extends BuildFileTest { + + public static final String EXPANDED_MANIFEST + = "src/etc/testcases/taskdefs/manifests/META-INF/MANIFEST.MF"; + + public SignJarTest(String name) { + super(name); + } + + public void setUp() { + configureProject("src/etc/testcases/taskdefs/signjar.xml"); + } + + public void tearDown() { + executeTarget("clean"); + } + + public void testBasicSigning() { + executeTarget("basic"); + } + + public void testSigFile() { + executeTarget("sigfile"); + } + + public void testMaxMemory() { + executeTarget("maxmemory"); + } + +}