From 2e83cb6a0d00312c987d6121b1a83ff07ddbc300 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Mon, 23 Dec 2002 13:29:16 +0000 Subject: [PATCH] Add maxmemory option to control memory of the jarsigner VM revert sigfile to a String - does not make sense to be a File Added a testcase with keystore for signjar PR: 1284, 10754 Submitted by: Jonathan Keller git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273684 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTasks/signjar.html | 14 ++- src/etc/testcases/taskdefs/signjar.xml | 32 ++++++ src/etc/testcases/testkeystore | Bin 0 -> 1228 bytes .../apache/tools/ant/taskdefs/SignJar.java | 36 +++++-- .../tools/ant/taskdefs/SignJarTest.java | 100 ++++++++++++++++++ 5 files changed, 169 insertions(+), 13 deletions(-) create mode 100644 src/etc/testcases/taskdefs/signjar.xml create mode 100644 src/etc/testcases/testkeystore create mode 100644 src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java 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 0000000000000000000000000000000000000000..2fd22c9f419561c1c677578f8fb704e2600292cf GIT binary patch literal 1228 zcmezO_TO6u1_mY|W&~r7lGNgo{Jfk>An%iR@jD>R*l*Cp*loba#-+{1$ik?_B*@6f z%D~dZSpLPmyoLSzoJX3aY}amXmY-FYpD!EGWvlS0L{a7Ap9y|plO`D&X#A7-Ng&3!cVZ`MJ|%sqw?xS0d|{2%Kohm>$*29lf+zb6(u;Q{6hXNB=NgbZq7K(fz@C zW3$t@T)A&dT0SzjlLa~ZyA?k^eD@=z&gAjbJO+Oz?T!CuF4UZ}*yMzYgiT1%A#IN{ zbNSYp)w|t&%z3=C=AlgZ0hQ42&htz?Cc3}9H)sC0WlCo<7bahPqW<&g(%E9nx?6p> z%jBJ!^zrW+uHsiyJ-?{(oMoxWJ<2|7=}rULsQstsEqyeFsU+2Os_U8GyRWjmGYh@{ zV!>f2`&kQ;U)AmUa(!!diJ0Um2MNPD8XEicmSr?cwif;tzUAok`rg)6Q@w(ZTEpPw{Ymv66RXTh7S`e$1ipPb5`@^f>i-Q~3Ko0nFLUY-{3xPZ5JV)WT0 z-?*&-JsT=F+j*2XUpo0rGJX24HC{I!2yS0EtE$b^_r|yNU-p6{iZw#d)W8xLbzcmc zm_7jU8YUJyc6Mb0ZZ>wUHji@_EX=G72C;_R2Apinp)72|Opc+3yg*qXheMbp1Q^XQ zE;}lh3zf?aLn9+&LnBioQ^P26USk6TQ$qtNm)6!d zF>VJYO&yqr8G#&mrp88wzxBb5vZX?rLHE7p=)HOJ{F~tRAe;9t42R|H8@2_iWxB>X zC;JYN zlm1~H{`}aAWup8nzni~ZJ}P&Z$uvYbN^GLhx6;q+v=gsuz5k@dEIIe02jg)jQHJRW z0sW%N+-EjT+S#<|bqn{02$`=Sr+t68p!M2p+k2%KF{EtX?(!4EN!- zWp7Fkj12GFbtTgOSs}YXW5X6tu|nk+J{n@e+s|_v^_*Dt&_=APJEW#pQ0Mms18+4Vf3;7civNr zxv_q_eTXEUw^>2?}7pQxK?yYR*Dhu&LGUat$Oy!^JN N^3B|muG2+3signjar 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"); + } + +}