ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r807466 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ tests/antunit/
Date Tue, 25 Aug 2009 03:48:02 GMT
Author: bodewig
Date: Tue Aug 25 03:48:01 2009
New Revision: 807466

URL: http://svn.apache.org/viewvc?rev=807466&view=rev
Log:
port roundup from core <zip>

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/conditions-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java?rev=807466&r1=807465&r2=807466&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java (original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java Tue
Aug 25 03:48:01 2009
@@ -33,7 +33,8 @@
         + " directory entries";
 
     public Ar() {
-        super(new ArStreamFactory(),
+        super(new ArStreamFactory());
+        setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
                     boolean isDir = r.getResource().isDirectory();
@@ -69,7 +70,8 @@
                     return new ArArchiveEntry(r.getName(),
                                               r.getResource().getSize(),
                                               uid, gid, mode,
-                                              r.getResource().getLastModified()
+                                              round(r.getResource()
+                                                    .getLastModified(), 1000)
                                               / 1000);
                 }
             });

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=807466&r1=807465&r2=807466&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
Tue Aug 25 03:48:01 2009
@@ -66,7 +66,7 @@
  */
 public abstract class ArchiveBase extends Task {
     private final StreamFactory factory;
-    private final EntryBuilder builder;
+    private EntryBuilder builder;
 
     private Resource dest;
     private List/*<ResourceCollection>*/ sources = new ArrayList();
@@ -74,9 +74,13 @@
     private String encoding;
     private boolean filesOnly = true;
     private boolean preserve0permissions = false;
+    private boolean roundUp = true;
 
-    protected ArchiveBase(StreamFactory factory, EntryBuilder builder) {
+    protected ArchiveBase(StreamFactory factory) {
         this.factory = factory;
+    }
+
+    protected final void setBuilder(EntryBuilder builder) {
         this.builder = builder;
     }
 
@@ -135,6 +139,25 @@
         preserve0permissions = b;
     }
 
+    /**
+     * Whether the file modification times will be rounded up to the
+     * next timestamp (second or even second depending on the archive
+     * format).
+     *
+     * <p>Zip archives store file modification times with a
+     * granularity of two seconds, ar, tar and cpio use a granularity
+     * of one second.  Times will either be rounded up or down.  If
+     * you round down, the archive will always seem out-of-date when
+     * you rerun the task, so the default is to round up.  Rounding up
+     * may lead to a different type of problems like JSPs inside a web
+     * archive that seem to be slightly more recent than precompiled
+     * pages, rendering precompilation useless.</p>
+     * @param r a <code>boolean</code> value
+     */
+    public void setRoundUp(boolean r) {
+        roundUp = r;
+    }
+
     public void execute() {
         validate();
         if (!dest.isExists()) {
@@ -162,6 +185,10 @@
      * Argument validation.
      */
     protected void validate() throws BuildException {
+        if (builder == null) {
+            throw new BuildException("subclass didn't provide a builder"
+                                     + " instance");
+        }
         if (dest == null) {
             throw new BuildException("must provide a destination resource");
         }
@@ -450,6 +477,17 @@
     }
 
     /**
+     * Modify last modified timestamp based on the roundup attribute.
+     *
+     * @param millis the timestamp
+     * @param granularity the granularity of timestamps in the archive
+     * format in millis
+     */
+    protected long round(long millis, long granularity) {
+        return roundUp ? millis + granularity - 1 : millis;
+    }
+
+    /**
      * Valid Modes for create/update/replace.
      */
     public static final class Mode extends EnumeratedAttribute {

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java?rev=807466&r1=807465&r2=807466&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
Tue Aug 25 03:48:01 2009
@@ -28,7 +28,8 @@
  */
 public class Cpio extends ArchiveBase {
     public Cpio() {
-        super(new CpioStreamFactory(),
+        super(new CpioStreamFactory());
+        setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
                     boolean isDir = r.getResource().isDirectory();
@@ -36,7 +37,8 @@
                         new CpioArchiveEntry(r.getName(),
                                              isDir
                                              ? 0 : r.getResource().getSize());
-                    ent.setTime(r.getResource().getLastModified() / 1000);
+                    ent.setTime(round(r.getResource().getLastModified(), 1000)
+                                / 1000);
 
                     int mode = isDir
                         ? ArchiveFileSet.DEFAULT_DIR_MODE

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java?rev=807466&r1=807465&r2=807466&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
Tue Aug 25 03:48:01 2009
@@ -29,7 +29,8 @@
  */
 public class Tar extends ArchiveBase {
     public Tar() {
-        super(new TarStreamFactory(),
+        super(new TarStreamFactory());
+        setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
                     boolean isDir = r.getResource().isDirectory();
@@ -37,7 +38,8 @@
                         new TarArchiveEntry(r.getName(),
                                             isDir ? TarConstants.LF_DIR
                                             : TarConstants.LF_NORMAL);
-                    ent.setModTime(r.getResource().getLastModified());
+                    ent.setModTime(round(r.getResource().getLastModified(),
+                                         1000));
                     ent.setSize(isDir ? 0 : r.getResource().getSize());
 
                     if (!isDir && r.getCollectionFlags().hasModeBeenSet()) {

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java?rev=807466&r1=807465&r2=807466&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
Tue Aug 25 03:48:01 2009
@@ -28,12 +28,13 @@
  */
 public class Zip extends ArchiveBase {
     public Zip() {
-        super(new ZipStreamFactory(),
+        super(new ZipStreamFactory());
+        setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
                     boolean isDir = r.getResource().isDirectory();
                     ZipArchiveEntry ent = new ZipArchiveEntry(r.getName());
-                    ent.setTime(r.getResource().getLastModified());
+                    ent.setTime(round(r.getResource().getLastModified(), 2000));
                     ent.setSize(isDir ? 0 : r.getResource().getSize());
 
                     if (!isDir && r.getCollectionFlags().hasModeBeenSet()) {

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/conditions-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/conditions-test.xml?rev=807466&r1=807465&r2=807466&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/conditions-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/conditions-test.xml Tue Aug 25 03:48:01
2009
@@ -270,7 +270,7 @@
 
   <target name="testCoreZipIsLastModified" depends="setUp">
     <au:assertTrue>
-      <cond:islastmodified datetime="2009-08-19-05:49:20"
+      <cond:islastmodified datetime="2009-08-19-05:49:22"
                            pattern="yyyy-MM-dd-HH:mm:ss">
         <zipentry name="asf-logo.gif">
           <file file="${input}/test.zip"/>
@@ -291,7 +291,7 @@
 
   <target name="testAntlibZipIsLastModified" depends="setUp">
     <au:assertTrue>
-      <cond:islastmodified datetime="2009-08-19-05:49:20"
+      <cond:islastmodified datetime="2009-08-19-05:49:22"
                            pattern="yyyy-MM-dd-HH:mm:ss">
         <cmp:zipentry name="asf-logo.gif">
           <file file="${input}/test.zip"/>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml?rev=807466&r1=807465&r2=807466&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml Tue Aug 25 03:48:01
2009
@@ -60,7 +60,7 @@
     <cmp:zip destfile="${dest}">
       <fileset dir="${input}" includes="asf-logo.gif"/>
     </cmp:zip>
-    <checkProperties dateTime="2009-08-19-05:49:20 +0200"/>
+    <checkProperties dateTime="2009-08-19-05:49:22 +0200"/>
   </target>
 
   <target name="testCoreZipFileSet" depends="setUp">
@@ -106,7 +106,7 @@
       <cmp:arfileset src="../resources/asf-logo.gif.ar"
                      includes="asf-logo.gif"/>
     </cmp:zip>
-    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="644"
+    <checkProperties dateTime="2009-07-31-20:11:14 +0200" mode="644"
                      />
   </target>
 
@@ -115,7 +115,7 @@
       <cmp:cpiofileset src="../resources/asf-logo.gif.cpio"
                        includes="asf-logo.gif"/>
     </cmp:zip>
-    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="644"
+    <checkProperties dateTime="2009-07-31-20:11:14 +0200" mode="644"
                      />
   </target>
 
@@ -201,7 +201,7 @@
                      filemode="600"
                      includes="asf-logo.gif"/>
     </cmp:zip>
-    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="600"/>
+    <checkProperties dateTime="2009-07-31-20:11:14 +0200" mode="600"/>
   </target>
 
   <target name="testFullpath" depends="setUp">
@@ -298,7 +298,7 @@
       <cmp:arfileset src="${src}"
                      includes="asf-logo.gif"/>
     </cmp:zip>
-    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="644"/>
+    <checkProperties dateTime="2009-07-31-20:11:14 +0200" mode="644"/>
   </target>
 
   <target name="testPreserve0Permissions"
@@ -307,6 +307,16 @@
       <cmp:arfileset src="${src}"
                      includes="asf-logo.gif"/>
     </cmp:zip>
-    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="0"/>
+    <checkProperties dateTime="2009-07-31-20:11:14 +0200" mode="0"/>
+  </target>
+
+  <target name="testRoundDown" depends="setUp">
+    <cmp:zip destfile="${dest}" roundup="false">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     includes="asf-logo.gif"/>
+    </cmp:zip>
+    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="644"
+                     />
   </target>
+
 </project>



Mime
View raw message