Index: src/main/org/apache/tools/ant/taskdefs/Zip.java =================================================================== --- src/main/org/apache/tools/ant/taskdefs/Zip.java (revision 784603) +++ src/main/org/apache/tools/ant/taskdefs/Zip.java (working copy) @@ -25,6 +25,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.DateFormat; +import java.text.ParseException; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; @@ -1525,6 +1527,31 @@ } /** + * Last modification time for files stored in zip. + */ + protected long lastModifed; + + /** + * Flag to indicate that last modifed has been set in the task. + *
+ * Using a boolean is preferable to using -1 for the time since + * -1 is a valid time. + */ + protected boolean lastModifedSet; + + /** + * Allows user to set the last modified time for content within the zip. + */ + public void setLastModified(String dateString) { + try { + lastModifed = DateFormat.getInstance().parse(dateString).getTime(); + lastModifedSet = true; + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + /** * Add a directory to the zip stream. * @param dir the directort to add to the archive * @param zOut the stream to write to @@ -1537,6 +1564,16 @@ protected void zipDir(File dir, ZipOutputStream zOut, String vPath, int mode, ZipExtraField[] extra) throws IOException { + + if (lastModifedSet) { + // Use last modification time set in the task rather then the one from the file system. + dir = new File(dir.toURI()) { + public long lastModified() { + return lastModifed; + } + }; + } + if (doFilesonly) { logOnFirstPass("skipping directory " + vPath + " for file-only archive", @@ -1594,6 +1631,12 @@ protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode) throws IOException { + + if (lastModifedSet) { + // Use last modification time set in the task rather then the one from the file system. + lastModified = this.lastModifed; + } + if (entries.contains(vPath)) { if (duplicate.equals("preserve")) {