-signjar test patched for offline testing -fixed SignJar to pass the tests -doc updates to match tested code git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278049 13f79535-47bb-0310-9956-ffa450edef68master
@@ -40,6 +40,10 @@ Changes that could break older environments: | |||
actually crashes the JVM on our (Java1.5) systems, we don't think any | |||
build files which actually worked will be affected by the change. | |||
* <signjar> used to ignore a nested fileset when a jar was also provided | |||
as an attribute, printing a warning message; now it signs files in the | |||
fileset. | |||
Fixed bugs: | |||
----------- | |||
@@ -141,6 +145,12 @@ Other changes: | |||
* <sync> has a new nested element <preserveInTarget> that can be used | |||
to protect extra-content in the target directory. Bugzilla Report | |||
21832. | |||
* <signjar> now supports: | |||
-nested filesets at the same time as the jar attribute | |||
-a destDir attribute with the appropriate dependency logic, which | |||
can be used with the jar attribute or nested filesets | |||
-a mapper to permit filename remapping on signing | |||
Changes from Ant 1.6.2 to current Ant 1.6 CVS version | |||
===================================================== | |||
@@ -334,7 +334,6 @@ | |||
<patternset id="onlinetests"> | |||
<exclude name="**/GetTest.java" if="offline"/> | |||
<exclude name="**/SignJarTest.java" if="offline"/> | |||
</patternset> | |||
<patternset id="teststhatfail"> | |||
@@ -24,16 +24,11 @@ Dependency rules | |||
<li>Out of date destination JARs are created/signed</li> | |||
<li>If a destination file and a source file are the same, | |||
and <tt>lazy</tt> is true, the JAR is only signed if it does not | |||
contain any signature.</li> | |||
contain a signature by this alias.</li> | |||
<li>If a destination file and a source file are the same, | |||
and <tt>lazy</tt> is false, the JAR is signed.</li> | |||
</ul> | |||
<p> | |||
When checking signatures, the actual signatory itself is not verified. This | |||
means that "lazy" checks do not work if a JAR is signed by multiple authors. | |||
</p> | |||
<h3>Parameters</h3> | |||
<table border="1" cellpadding="2" cellspacing="0"> | |||
<tr> | |||
@@ -131,13 +126,11 @@ block</td> | |||
<td valign="top">fileset of JAR files to sign. </td> | |||
<td valign="top" align="center">No</td> | |||
</tr> | |||
<!-- | |||
<tr> | |||
<td valign="top">mapper</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> | |||
--> | |||
</table> | |||
<h3>Examples</h3> | |||
<blockquote><pre> | |||
@@ -1,48 +1,86 @@ | |||
<project name="signjartest" default="help" basedir=".."> | |||
<property name="classes.dir" value="../../../build/classes"/> | |||
<property name="sign.dir" location="signedjars" /> | |||
<property name="subdir" location="${sign.dir}/subdir" /> | |||
<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}" /> | |||
<sequential> | |||
<fail message="not signed: @{jar}" > | |||
<condition> | |||
<not><issigned file="@{jar}" /></not> | |||
</condition> | |||
</fail> | |||
</sequential> | |||
</macrodef> | |||
<presetdef name="sign-base"> | |||
<signjar alias="testonly" keystore="testkeystore" | |||
storepass="apacheant"/> | |||
</presetdef> | |||
<presetdef name="sign"> | |||
<sign-base jar="${test.jar}" /> | |||
</presetdef> | |||
<target name="jar" > | |||
<jar jarfile="${test.jar}" basedir="${classes.dir}" includes="**/Task.class"/> | |||
</target> | |||
<target name="basic"> | |||
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/> | |||
<signjar jar="signtest.jar" alias="testonly" keystore="testkeystore" | |||
storepass="apacheant"/> | |||
<target name="clean"> | |||
<delete dir="${sign.dir}"/> | |||
</target> | |||
<target name="help"> | |||
<echo>This build is for use with Ant's test cases</echo> | |||
</target> | |||
<target name="basic" depends="jar"> | |||
<sign /> | |||
<assertSigned/> | |||
</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 name="sigfile" depends="jar"> | |||
<sign sigfile="TEST"/> | |||
<assertSigned/> | |||
</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 name="maxmemory" depends="jar"> | |||
<sign maxmemory="128m"/> | |||
<assertSigned/> | |||
</target> | |||
<target name="urlKeystoreFile"> | |||
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/> | |||
<signjar jar="signtest.jar" alias="testonly" keystore="file://../testkeystore" | |||
storepass="apacheant" maxmemory="128m"/> | |||
<target name="urlKeystoreFile" depends="jar"> | |||
<sign keystore="file://../testkeystore" | |||
maxmemory="128m"/> | |||
<assertSigned/> | |||
</target> | |||
<!--TODO: change this when we move to SUBVERSION--> | |||
<target name="urlKeystoreHTTP"> | |||
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/> | |||
<signjar jar="signtest.jar" alias="testonly" | |||
keystore="http://cvs.apache.org/viewcvs.cgi/*checkout*/ant/src/etc/testcases/testkeystore?rev=HEAD" | |||
storepass="apacheant" maxmemory="128m"/> | |||
<target name="urlKeystoreHTTP" depends="jar"> | |||
<sign | |||
keystore="http://cvs.apache.org/viewcvs.cgi/*checkout*/ant/src/etc/testcases/testkeystore?rev=HEAD" | |||
/> | |||
<assertSigned/> | |||
</target> | |||
<target name="preserveLastModified"> | |||
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/> | |||
<touch file="signtest.jar" datetime="06/28/2000 2:02 pm"/> | |||
<signjar jar="signtest.jar" alias="testonly" keystore="testkeystore" storepass="apacheant" | |||
<target name="preserveLastModified" depends="jar"> | |||
<touch file="${test.jar}" datetime="06/28/2000 2:02 pm"/> | |||
<sign | |||
preservelastmodified="true"/> | |||
<assertSigned /> | |||
<fail message="preserveLastModified did not preserve the last modified time"> | |||
<condition> | |||
<not> | |||
<isfileselected file="signtest.jar"> | |||
<isfileselected file="${test.jar}" > | |||
<date datetime="06/28/2000 2:02 pm" when="equal"/> | |||
</isfileselected> | |||
</not> | |||
@@ -50,13 +88,86 @@ | |||
</fail> | |||
</target> | |||
<target name="clean"> | |||
<delete file="signtest.jar"/> | |||
<target name="testFileset" depends="jar"> | |||
<sign-base> | |||
<fileset file="${test.jar}" /> | |||
</sign-base> | |||
<assertSigned/> | |||
</target> | |||
<target name="help"> | |||
<echo>This build is for use with Ant's test cases</echo> | |||
<target name="testFilesetAndJar" depends="jar"> | |||
<sign-base jar="${test.jar}" lazy="true"> | |||
<fileset file="${test.jar}" /> | |||
</sign-base> | |||
<assertSigned/> | |||
</target> | |||
<target name="testFilesetAndSignedJar" depends="jar"> | |||
<sign-base signedjar="${sign.dir}/newfile.jar"> | |||
<fileset file="${test.jar}" /> | |||
</sign-base> | |||
</target> | |||
<target name="testSignedJar" depends="jar"> | |||
<property name="new.jar" location="${sign.dir}/newfile.jar" /> | |||
<sign signedjar="${new.jar}"/> | |||
<assertSigned jar="${new.jar}"/> | |||
</target> | |||
<target name="testDestDirAndSignedJar" depends="jar"> | |||
<sign destDir="${subdir}" signedjar="${sign.dir}/newfile.jar"/> | |||
</target> | |||
<target name="testDestDir" depends="jar"> | |||
<sign destDir="${subdir}" /> | |||
<assertSigned jar="${subdirtest.jar}"/> | |||
</target> | |||
<target name="testDestDirFileset" depends="jar"> | |||
<sign-base destDir="${subdir}"> | |||
<fileset file="${test.jar}" /> | |||
</sign-base> | |||
<assertSigned jar="${subdirtest.jar}"/> | |||
</target> | |||
<target name="testMapperNoDest" depends="jar"> | |||
<sign-base > | |||
<flattenmapper /> | |||
<fileset file="${test.jar}" /> | |||
</sign-base> | |||
</target> | |||
<target name="testMapperFileset" depends="jar"> | |||
<sign-base destDir="${subdir}"> | |||
<fileset file="${test.jar}" /> | |||
<flattenmapper /> | |||
</sign-base> | |||
<assertSigned jar="${subdirtest.jar}"/> | |||
</target> | |||
<target name="testTwoMappers" depends="jar"> | |||
<sign-base destDir="${subdir}"> | |||
<fileset file="${test.jar}" /> | |||
<flattenmapper /> | |||
<flattenmapper /> | |||
</sign-base> | |||
</target> | |||
<target name="testNoAlias" depends="jar"> | |||
<signjar keystore="testkeystore" | |||
jar="${test.jar}" | |||
storepass="apacheant"/> | |||
</target> | |||
<target name="testNoFiles" > | |||
<sign-base /> | |||
</target> | |||
<target name="testNoStorePass" depends="jar"> | |||
<signjar keystore="testkeystore" | |||
alias="testonly" | |||
jar="${test.jar}"/> | |||
</target> | |||
</project> | |||
@@ -59,16 +59,43 @@ public class SignJar extends Task { | |||
protected String alias; | |||
/** | |||
* The name of keystore file. | |||
* The url or path of keystore file. | |||
*/ | |||
private String keystore; | |||
/** | |||
* password for the store | |||
*/ | |||
protected String storepass; | |||
/** | |||
* type of store,-storetype param | |||
*/ | |||
protected String storetype; | |||
/** | |||
* password for the key in the store | |||
*/ | |||
protected String keypass; | |||
/** | |||
* name to a signature file | |||
*/ | |||
protected String sigfile; | |||
/** | |||
* name of a single jar | |||
*/ | |||
protected File signedjar; | |||
/** | |||
* verbose output | |||
*/ | |||
protected boolean verbose; | |||
/** | |||
* flag for | |||
*/ | |||
protected boolean internalsf; | |||
protected boolean sectionsonly; | |||
private boolean preserveLastModified; | |||
@@ -98,11 +125,8 @@ public class SignJar extends Task { | |||
/** | |||
* mapper for todir work | |||
*/ | |||
private Mapper mapper; | |||
private FileNameMapper mapper; | |||
/** error string for unit test verification: {@value} */ | |||
public static final String ERROR_SIGNEDJAR_AND_FILESET = | |||
"The signedjar attribute is not supported with filesets"; | |||
/** | |||
* error string for unit test verification: {@value} | |||
*/ | |||
@@ -113,7 +137,7 @@ public class SignJar extends Task { | |||
*/ | |||
public static final String ERROR_TOO_MANY_MAPPERS = "Too many mappers"; | |||
/** | |||
* error string for unit test verification: {@value} | |||
* error string for unit test verification {@value} | |||
*/ | |||
public static final String ERROR_SIGNEDJAR_AND_FILESETS = "You cannot specify the signed JAR when using filesets"; | |||
/** | |||
@@ -296,14 +320,14 @@ public class SignJar extends Task { | |||
* @param newMapper | |||
* @since Ant 1.7 | |||
*/ | |||
public void addMapper(Mapper newMapper) { | |||
public void add(FileNameMapper newMapper) { | |||
if (mapper != null) { | |||
throw new BuildException(ERROR_TOO_MANY_MAPPERS); | |||
} | |||
mapper = newMapper; | |||
} | |||
public Mapper getMapper() { | |||
public FileNameMapper getMapper() { | |||
return mapper; | |||
} | |||
@@ -373,7 +397,7 @@ public class SignJar extends Task { | |||
//set up our mapping policy | |||
FileNameMapper destMapper; | |||
if (hasMapper) { | |||
destMapper = mapper.getImplementation(); | |||
destMapper = mapper; | |||
} else { | |||
//no mapper? use the identity policy | |||
destMapper = new IdentityMapper(); | |||
@@ -563,7 +587,7 @@ public class SignJar extends Task { | |||
/** | |||
* test for a file being signed, by looking for a signature in the META-INF | |||
* directory | |||
* directory with our alias. | |||
* | |||
* @param file the file to be checked | |||
* @return true if the file is signed | |||
@@ -35,6 +35,7 @@ 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); | |||
} | |||
@@ -47,6 +48,13 @@ public class SignJarTest extends BuildFileTest { | |||
executeTarget("clean"); | |||
} | |||
/** | |||
* check for being offline | |||
* @return true iff the system property "offline" is "true" | |||
*/ | |||
private boolean isOffline() { | |||
return Boolean.getBoolean("offline"); | |||
} | |||
public void testBasicSigning() { | |||
executeTarget("basic"); | |||
} | |||
@@ -64,10 +72,78 @@ public class SignJarTest extends BuildFileTest { | |||
} | |||
public void testURLKeystoreHTTP() { | |||
executeTarget("urlKeystoreHTTP"); | |||
if(!isOffline()) { | |||
executeTarget("urlKeystoreHTTP"); | |||
} | |||
} | |||
public void testPreserveLastModified() { | |||
executeTarget("preserveLastModified"); | |||
} | |||
} | |||
public void testFileset() { | |||
executeTarget("testFileset"); | |||
} | |||
public void testFilesetAndJar() { | |||
executeTarget("testFilesetAndJar"); | |||
} | |||
public void testFilesetAndSignedJar() { | |||
expectBuildExceptionContaining("testFilesetAndSignedJar", | |||
"incompatible attributes", | |||
SignJar.ERROR_SIGNEDJAR_AND_FILESETS); | |||
} | |||
public void testSignedJar() { | |||
executeTarget("testSignedJar"); | |||
} | |||
public void testDestDir() { | |||
executeTarget("testDestDir"); | |||
} | |||
public void testDestDirAndSignedJar() { | |||
expectBuildExceptionContaining("testFilesetAndSignedJar", | |||
"incompatible attributes", | |||
SignJar.ERROR_SIGNEDJAR_AND_FILESETS); | |||
} | |||
public void testDestDirFileset() { | |||
executeTarget("testDestDirFileset"); | |||
} | |||
public void testMapperFileset() { | |||
executeTarget("testMapperFileset"); | |||
} | |||
public void testMapperNoDest() { | |||
expectBuildExceptionContaining("testMapperNoDest", | |||
"two mappers", | |||
SignJar.ERROR_MAPPER_WITHOUT_DEST); | |||
} | |||
public void testTwoMappers() { | |||
expectBuildExceptionContaining("testTwoMappers", | |||
"two mappers", | |||
SignJar.ERROR_TOO_MANY_MAPPERS); | |||
} | |||
public void testNoAlias() { | |||
expectBuildExceptionContaining("testNoAlias", | |||
"no alias", | |||
SignJar.ERROR_NO_ALIAS); | |||
} | |||
public void testNoFiles() { | |||
expectBuildExceptionContaining("testNoFiles", | |||
"no files", | |||
SignJar.ERROR_NO_SOURCE); | |||
} | |||
public void testNoStorePass() { | |||
expectBuildExceptionContaining("testNoStorePass", | |||
"no files", | |||
SignJar.ERROR_NO_STOREPASS); | |||
} | |||
} |