PR: 30987 Obtained from: Ignacio Coloma git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277079 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -74,6 +74,7 @@ Harish Prabandham | |||||
| Haroon Rafique | Haroon Rafique | ||||
| Hiroaki Nakamura | Hiroaki Nakamura | ||||
| Holger Engels | Holger Engels | ||||
| Ignacio Coloma | |||||
| Ingenonsya France | Ingenonsya France | ||||
| Ingmar Stein | Ingmar Stein | ||||
| Irene Rusman | Irene Rusman | ||||
| @@ -92,6 +92,9 @@ Other changes: | |||||
| * Added isSigned condition and task, and signedselector selector | * Added isSigned condition and task, and signedselector selector | ||||
| Bugzilla report 32126. | Bugzilla report 32126. | ||||
| * Added preserveLastModified attribute to signjar task. | |||||
| Bugzilla report 30987. | |||||
| Changes from Ant 1.6.2 to current Ant 1.6 CVS version | Changes from Ant 1.6.2 to current Ant 1.6 CVS version | ||||
| ===================================================== | ===================================================== | ||||
| @@ -92,6 +92,12 @@ block</td> | |||||
| style of standard java memory specs (e.g. 128m = 128 MBytes)</td> | style of standard java memory specs (e.g. 128m = 128 MBytes)</td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">preservelastmodified</td> | |||||
| <td valign="top">Give the signed file the same last modified | |||||
| time as the original jar file.</td> | |||||
| <td valign="top" align="center">No; default false.</td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Parameters as nested elements</h3> | <h3>Parameters as nested elements</h3> | ||||
| <table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
| @@ -32,6 +32,32 @@ | |||||
| storepass="apacheant" maxmemory="128m"/> | storepass="apacheant" maxmemory="128m"/> | ||||
| </target> | </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" | |||||
| preservelastmodified="true"/> | |||||
| <!-- Currently there is no condition for testing the date of file - so | |||||
| use a selector --> | |||||
| <pathconvert property="signtest.jar.prop" targetos="unix"> | |||||
| <path> | |||||
| <fileset dir="." includes="signtest.jar"> | |||||
| <date datetime="06/28/2000 2:02 pm" when="equal"/> | |||||
| </fileset> | |||||
| </path> | |||||
| <mapper> | |||||
| <flattenmapper/> | |||||
| </mapper> | |||||
| </pathconvert> | |||||
| <fail message="preserveLastModified did not preserve the last modified time"> | |||||
| <condition> | |||||
| <not> | |||||
| <equals arg1="signtest.jar" arg2="signtest.jar"/> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="clean"> | <target name="clean"> | ||||
| <delete file="signtest.jar"/> | <delete file="signtest.jar"/> | ||||
| </target> | </target> | ||||
| @@ -66,6 +66,7 @@ public class SignJar extends Task { | |||||
| protected boolean verbose; | protected boolean verbose; | ||||
| protected boolean internalsf; | protected boolean internalsf; | ||||
| protected boolean sectionsonly; | protected boolean sectionsonly; | ||||
| protected boolean preserveLastModified; | |||||
| /** The maximum amount of memory to use for Jar signer */ | /** The maximum amount of memory to use for Jar signer */ | ||||
| private String maxMemory; | private String maxMemory; | ||||
| @@ -237,6 +238,7 @@ public class SignJar extends Task { | |||||
| return; | return; | ||||
| } | } | ||||
| long lastModified = jarSource.lastModified(); | |||||
| final ExecTask cmd = (ExecTask) getProject().createTask("exec"); | final ExecTask cmd = (ExecTask) getProject().createTask("exec"); | ||||
| cmd.setExecutable(JavaEnvUtils.getJdkExecutable("jarsigner")); | cmd.setExecutable(JavaEnvUtils.getJdkExecutable("jarsigner")); | ||||
| @@ -302,6 +304,15 @@ public class SignJar extends Task { | |||||
| cmd.setFailonerror(true); | cmd.setFailonerror(true); | ||||
| cmd.setTaskName(getTaskName()); | cmd.setTaskName(getTaskName()); | ||||
| cmd.execute(); | cmd.execute(); | ||||
| // restore the lastModified attribute | |||||
| if (preserveLastModified) { | |||||
| if (jarTarget != null) { | |||||
| jarTarget.setLastModified(lastModified); | |||||
| } else { | |||||
| jarSource.setLastModified(lastModified); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| protected boolean isUpToDate(File jarFile, File signedjarFile) { | protected boolean isUpToDate(File jarFile, File signedjarFile) { | ||||
| @@ -345,5 +356,14 @@ public class SignJar extends Task { | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * true to indicate that the signed jar modification date remains the same as the original. | |||||
| * Defaults to false | |||||
| * @param preserveLastModified if true preserve the last modified time | |||||
| */ | |||||
| public void setPreserveLastModified(boolean preserveLastModified) { | |||||
| this.preserveLastModified = preserveLastModified; | |||||
| } | |||||
| } | } | ||||
| @@ -66,4 +66,8 @@ public class SignJarTest extends BuildFileTest { | |||||
| public void testURLKeystoreHTTP() { | public void testURLKeystoreHTTP() { | ||||
| executeTarget("urlKeystoreHTTP"); | executeTarget("urlKeystoreHTTP"); | ||||
| } | } | ||||
| public void testPreserveLastModified() { | |||||
| executeTarget("preserveLastModified"); | |||||
| } | |||||
| } | } | ||||