stevel 2005/03/23 06:09:06 Modified: . build.xml WHATSNEW docs/manual/CoreTasks signjar.html src/main/org/apache/tools/ant/taskdefs SignJar.java src/etc/testcases/taskdefs signjar.xml src/testcases/org/apache/tools/ant/taskdefs SignJarTest.java Log: -tests for old and new signjar features written; working -signjar test patched for offline testing -fixed SignJar to pass the tests -doc updates to match tested code Revision Changes Path 1.464 +0 -1 ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/ant/build.xml,v retrieving revision 1.463 retrieving revision 1.464 diff -u -r1.463 -r1.464 --- build.xml 10 Mar 2005 23:20:02 -0000 1.463 +++ build.xml 23 Mar 2005 14:09:05 -0000 1.464 @@ -334,7 +334,6 @@ <patternset id="onlinetests"> <exclude name="**/GetTest.java" if="offline"/> - <exclude name="**/SignJarTest.java" if="offline"/> </patternset> <patternset id="teststhatfail"> 1.790 +10 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.789 retrieving revision 1.790 diff -u -r1.789 -r1.790 --- WHATSNEW 22 Mar 2005 17:25:19 -0000 1.789 +++ WHATSNEW 23 Mar 2005 14:09:06 -0000 1.790 @@ -40,6 +40,10 @@ 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 @@ * <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 ===================================================== 1.20 +1 -8 ant/docs/manual/CoreTasks/signjar.html Index: signjar.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/signjar.html,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- signjar.html 22 Mar 2005 17:36:58 -0000 1.19 +++ signjar.html 23 Mar 2005 14:09:06 -0000 1.20 @@ -24,16 +24,11 @@ <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 @@ <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.50 +34 -10 ant/src/main/org/apache/tools/ant/taskdefs/SignJar.java Index: SignJar.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/SignJar.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- SignJar.java 23 Mar 2005 10:24:43 -0000 1.49 +++ SignJar.java 23 Mar 2005 14:09:06 -0000 1.50 @@ -59,16 +59,43 @@ 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 @@ /** * mapper for todir work */ - private Mapper mapper; + private FileNameMapper mapper; - /** error string for unit test verification: [EMAIL PROTECTED] */ - public static final String ERROR_SIGNEDJAR_AND_FILESET = - "The signedjar attribute is not supported with filesets"; /** * error string for unit test verification: [EMAIL PROTECTED] */ @@ -113,7 +137,7 @@ */ public static final String ERROR_TOO_MANY_MAPPERS = "Too many mappers"; /** - * error string for unit test verification: [EMAIL PROTECTED] + * error string for unit test verification [EMAIL PROTECTED] */ public static final String ERROR_SIGNEDJAR_AND_FILESETS = "You cannot specify the signed JAR when using filesets"; /** @@ -296,14 +320,14 @@ * @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 @@ //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 @@ /** * 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 1.7 +145 -34 ant/src/etc/testcases/taskdefs/signjar.xml Index: signjar.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/signjar.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- signjar.xml 10 Mar 2005 23:22:16 -0000 1.6 +++ signjar.xml 23 Mar 2005 14:09:06 -0000 1.7 @@ -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="clean"> + <delete dir="${sign.dir}"/> + </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="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="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> - - <target name="help"> - <echo>This build is for use with Ant's test cases</echo> - </target> - + </project> 1.10 +78 -2 ant/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java Index: SignJarTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SignJarTest.java 26 Nov 2004 09:52:06 -0000 1.9 +++ SignJarTest.java 23 Mar 2005 14:09:06 -0000 1.10 @@ -35,6 +35,7 @@ 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 @@ 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 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); + } + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]