ASF Bugzilla – Attachment 23841 Details for
Bug 47373
Zip.java patch to support setting last modified date
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch ready for code review
Bug47373.patch (text/plain), 8.01 KB, created by
Mark Farnsworth
on 2009-06-21 15:37:36 UTC
(
hide
)
Description:
Patch ready for code review
Filename:
MIME Type:
Creator:
Mark Farnsworth
Created:
2009-06-21 15:37:36 UTC
Size:
8.01 KB
patch
obsolete
>Index: contributors.xml >=================================================================== >--- contributors.xml (revision 787061) >+++ contributors.xml (working copy) >@@ -643,6 +643,10 @@ > </name> > <name> > <first>Mark</first> >+ <last>Farnsworth</last> >+ </name> >+ <name> >+ <first>Mark</first> > <last>Hecker</last> > </name> > <name> >Index: src/main/org/apache/tools/ant/taskdefs/Zip.java >=================================================================== >--- src/main/org/apache/tools/ant/taskdefs/Zip.java (revision 787061) >+++ src/main/org/apache/tools/ant/taskdefs/Zip.java (working copy) >@@ -58,6 +58,12 @@ > import org.apache.tools.zip.ZipFile; > import org.apache.tools.zip.ZipOutputStream; > >+import java.text.DateFormat; >+import java.text.ParseException; >+import java.text.SimpleDateFormat; >+import java.util.Date; >+import java.util.Locale; >+ > /** > * Create a Zip file. > * >@@ -140,6 +146,60 @@ > private int level = ZipOutputStream.DEFAULT_COMPRESSION; > > /** >+ * Date time >+ */ >+ private Long dateTime; >+ >+ /** >+ * Date String >+ */ >+ private String dateString = ""; >+ >+ /** >+ * Pattern for dates >+ */ >+ private String pattern = ""; >+ >+ private void resolveDateTime() { >+ if(dateString.equals("")) >+ return; >+ DateFormat dateFormat; >+ if(pattern.equals("")) { >+ final int SHORT = DateFormat.SHORT; >+ final int MEDIUM = DateFormat.MEDIUM; >+ final Locale US = Locale.US; >+ dateFormat = DateFormat.getDateTimeInstance(SHORT, SHORT, US); >+ try { >+ System.out.println("Parsing " + dateString); >+ dateTime = new Long(dateFormat.parse(dateString).getTime()); >+ return; >+ } catch(ParseException pe) { >+ dateFormat = DateFormat.getDateTimeInstance(SHORT, MEDIUM, US); >+ } >+ } else { >+ dateFormat = new SimpleDateFormat(pattern); >+ } >+ try { >+ dateTime = new Long(dateFormat.parse(dateString).getTime()); >+ } catch(ParseException pe) { >+ throw new BuildException("Invalid datetime attribute"); >+ } >+ } >+ /** >+ * Set the pattern used when parsing the dateString. >+ * @param pattern the <code>SimpleDateFormat</code>-compatible format pattern. >+ * @since Ant 1.6.3 >+ */ >+ public void setPattern(final String value) { >+ pattern = value; >+ } >+ /** >+ * Allows user to set the last modified time for content within the zip. >+ */ >+ public void setDateTime(String value) { >+ dateString = value; >+ } >+ /** > * This is the name/location of where to > * create the .zip file. > * @param zipFile the path of the zipFile >@@ -406,7 +466,7 @@ > * @throws BuildException on error > */ > public void execute() throws BuildException { >- >+ resolveDateTime(); > if (doubleFilePass) { > skipWriting = true; > executeMain(); >@@ -1390,6 +1450,14 @@ > protected void zipDir(File dir, ZipOutputStream zOut, String vPath, > int mode, ZipExtraField[] extra) > throws IOException { >+ if (dateTime != null) { >+ // 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 dateTime.longValue(); >+ } >+ }; >+ } > if (doFilesonly) { > log("skipping directory " + vPath + " for file-only archive", > Project.MSG_VERBOSE); >@@ -1445,6 +1513,10 @@ > protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath, > long lastModified, File fromArchive, int mode) > throws IOException { >+ if (dateTime != null) { >+ // Use last modification time set in the task rather then the one from the file system. >+ lastModified = dateTime.longValue(); >+ } > if (entries.contains(vPath)) { > > if (duplicate.equals("preserve")) { >Index: docs/manual/CoreTasks/zip.html >=================================================================== >--- docs/manual/CoreTasks/zip.html (revision 787061) >+++ docs/manual/CoreTasks/zip.html (working copy) >@@ -188,6 +188,17 @@ > <td valign="top" align="center">No</td> > </tr> > <tr> >+ <td valign="top">datetime</td> >+ <td valign="top">Specifies modification time for the file stored in the >+ archive. Same datetime feature as <a href='touch.html'>Touch</a>. Using >+ an empty string or ommiting this attribute results in the default archive >+ behavior of using date stamps from the filesystem.</td> >+ </tr> >+ <tr> >+ <td valign="top">pattern</td> >+ <td valign="top">Pattern for datetme, see <a href='touch.html'>Touch task</a> for details</a></td> >+ </tr> >+ <tr> > <td valign="top">roundup</td> > <td valign="top">Whether the file modification times will be > rounded up to the next even number of seconds.<br> >Index: docs/manual/CoreTasks/jar.html >=================================================================== >--- docs/manual/CoreTasks/jar.html (revision 787061) >+++ docs/manual/CoreTasks/jar.html (working copy) >@@ -208,6 +208,17 @@ > <td valign="top" align="center">No, defaults to the platform encoding.</td> > </tr> > <tr> >+ <td valign="top">datetime</td> >+ <td valign="top">Specifies modification time for the file stored in the >+ archive. Same datetime feature as <a href='touch.html'>Touch</a>. Using >+ an empty string or ommiting this attribute results in the default archive >+ behavior of using date stamps from the filesystem.</td> >+ </tr> >+ <tr> >+ <td valign="top">pattern</td> >+ <td valign="top">Pattern for datetme, see <a href='touch.html'>Touch task</a> for details</a></td> >+ </tr> >+ <tr> > <td valign="top">roundup</td> > <td valign="top">Whether the file modification times will be > rounded up to the next even number of seconds.<br> >Index: docs/manual/CoreTasks/ear.html >=================================================================== >--- docs/manual/CoreTasks/ear.html (revision 787061) >+++ docs/manual/CoreTasks/ear.html (working copy) >@@ -176,6 +176,17 @@ > <td valign="top" align="center">No</td> > </tr> > <tr> >+ <td valign="top">datetime</td> >+ <td valign="top">Specifies modification time for the file stored in the >+ archive. Same datetime feature as <a href='touch.html'>Touch</a>. Using >+ an empty string or ommiting this attribute results in the default archive >+ behavior of using date stamps from the filesystem.</td> >+ </tr> >+ <tr> >+ <td valign="top">pattern</td> >+ <td valign="top">Pattern for datetme, see <a href='touch.html'>Touch task</a> for details</a></td> >+ </tr> >+ <tr> > <td valign="top">roundup</td> > <td valign="top">Whether the file modification times will be > rounded up to the next even number of seconds.<br> >Index: docs/manual/CoreTasks/war.html >=================================================================== >--- docs/manual/CoreTasks/war.html (revision 787061) >+++ docs/manual/CoreTasks/war.html (working copy) >@@ -182,6 +182,17 @@ > <td valign="top" align="center">No</td> > </tr> > <tr> >+ <td valign="top">datetime</td> >+ <td valign="top">Specifies modification time for the file stored in the >+ archive. Same datetime feature as <a href='touch.html'>Touch</a>. Using >+ an empty string or ommiting this attribute results in the default archive >+ behavior of using date stamps from the filesystem.</td> >+ </tr> >+ <tr> >+ <td valign="top">pattern</td> >+ <td valign="top">Pattern for datetme, see <a href='touch.html'>Touch task</a> for details</a></td> >+ </tr> >+ <tr> > <td valign="top">roundup</td> > <td valign="top">Whether the file modification times will be > rounded up to the next even number of seconds.<br>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 47373
:
23810
| 23841