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-ffa450edef68master
@@ -14,7 +14,7 @@ tool detailed dependency checking: files are only signed if they | |||
are not signed. The <tt>signjar</tt> 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. | |||
<br> | |||
<br> | |||
<strong>Note:</strong> Requires Java 1.2 or later. </p> | |||
<h3>Parameters</h3> | |||
@@ -83,9 +83,15 @@ block</td> | |||
<tr> | |||
<td valign="top">lazy</td> | |||
<td valign="top">flag to control whether the presence of a signature | |||
file means a JAR is signed</td> | |||
file means a JAR is signed</td> | |||
<td valign="top" align="center">No; default false</td> | |||
</tr> | |||
</tr> | |||
<tr> | |||
<td valign="top">maxmemory</td> | |||
<td valign="top">Specifies the maximum memory the jarsigner VM will use. Specified in the | |||
style of standard java memory specs (e.g. 128m = 128 MBytes)</td> | |||
<td valign="top" align="center">No</td> | |||
</tr> | |||
</table> | |||
<h3>Parameters as nested elements</h3> | |||
<table border="1" cellpadding="2" cellspacing="0"> | |||
@@ -99,7 +105,7 @@ block</td> | |||
<td valign="top">fileset of JAR files to sign</td> | |||
<td valign="top" align="center">No</td> | |||
</tr> | |||
</table> | |||
</table> | |||
<h3>Examples</h3> | |||
<blockquote> | |||
<p><code><signjar jar="${dist}/lib/ant.jar" | |||
@@ -0,0 +1,32 @@ | |||
<project name="signjartest" default="help"> | |||
<property name="classes.dir" value="../../../../build/classes"/> | |||
<target name="basic"> | |||
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/> | |||
<signjar jar="signtest.jar" alias="testonly" keystore="../testkeystore" | |||
storepass="apacheant"/> | |||
</target> | |||
<target name="sigfile"> | |||
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/> | |||
<signjar jar="signtest.jar" alias="testonly" keystore="../testkeystore" | |||
storepass="apacheant" sigfile="TEST"/> | |||
</target> | |||
<target name="maxmemory"> | |||
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/> | |||
<signjar jar="signtest.jar" alias="testonly" keystore="../testkeystore" | |||
storepass="apacheant" maxmemory="128m"/> | |||
</target> | |||
<target name="clean"> | |||
<delete file="signtest.jar"/> | |||
</target> | |||
<target name="help"> | |||
<echo>This build is for use with Ant's test cases</echo> | |||
</target> | |||
</project> | |||
@@ -71,13 +71,13 @@ import org.apache.tools.ant.util.JavaEnvUtils; | |||
* are not signed. The <tt>signjar</tt> 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. | |||
* <br> | |||
* <br> | |||
* <strong>Note:</strong> Requires Java 1.2 or later. </p> | |||
* | |||
* @author Peter Donald | |||
* | |||
* @author Peter Donald | |||
* <a href="mailto:donaldp@apache.org">donaldp@apache.org</a> | |||
* @author Nick Fortescue | |||
* @author Nick Fortescue | |||
* <a href="mailto:nick@ox.compsoc.net">nick@ox.compsoc.net</a> | |||
* @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) { | |||
@@ -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 | |||
* <http://www.apache.org/>. | |||
*/ | |||
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"); | |||
} | |||
} |