You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2009/09/17 06:22:12 UTC

svn commit: r816045 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ArchiveBase.java tests/antunit/ar-test.xml tests/antunit/cpio-test.xml tests/antunit/tar-test.xml tests/antunit/zip-test.xml

Author: bodewig
Date: Thu Sep 17 04:22:11 2009
New Revision: 816045

URL: http://svn.apache.org/viewvc?rev=816045&view=rev
Log:
replace mode for archiving tasks

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-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/ArchiveBase.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=816045&r1=816044&r2=816045&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 Thu Sep 17 04:22:11 2009
@@ -61,6 +61,10 @@
 import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.types.resources.MappedResource;
 import org.apache.tools.ant.types.resources.Resources;
+import org.apache.tools.ant.types.resources.Restrict;
+import org.apache.tools.ant.types.resources.selectors.Name;
+import org.apache.tools.ant.types.resources.selectors.Not;
+import org.apache.tools.ant.types.resources.selectors.Or;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.IdentityMapper;
 import org.apache.tools.ant.util.MergingMapper;
@@ -279,8 +283,9 @@
                 : new FileResource(copyOfDest);
             ArchiveFileSet existingEntries =
                 fileSetBuilder.buildFileSet(destOrCopy);
+            existingEntries.setProject(getProject());
             try {
-                    
+
                 List/*<ResourceWithFlags>*/ toAdd
                     = new ArrayList/*<ResourceWithFlags>*/();
                 toAdd.addAll(Arrays.asList(sourceResources));
@@ -290,6 +295,7 @@
                     return;
                 }
 
+                addResourcesToKeep(toAdd, existingEntries, sourceResources);
                 sort(toAdd);
 
                 try {
@@ -404,6 +410,62 @@
     }
 
     /**
+     * Add the resources of the target archive that shall be kept when
+     * creating the new one.
+     */
+    private void addResourcesToKeep(List/*<ResourceWithFlags>*/ toAdd,
+                                    ArchiveFileSet target,
+                                    ResourceWithFlags[] src) {
+        if (!Mode.FORCE_CREATE.equals(mode.getValue())
+            && !Mode.CREATE.equals(mode.getValue())) {
+            try {
+                toAdd.addAll(Arrays.asList(findUnmatchedTargets(target, src)));
+            } catch (IOException ioex) {
+                throw new BuildException("Failed to read target archive", ioex);
+            }
+        }
+    }
+
+    /**
+     * Find the resources from the target archive that don't have a
+     * matching resource in the sources to be added.
+     */
+    protected ResourceWithFlags[] findUnmatchedTargets(ArchiveFileSet target,
+                                                       ResourceWithFlags[] src)
+        throws IOException {
+
+        List/*<ResourceWithFlags>*/ l = new ArrayList/*<ResourceWithFlags>*/();
+        ResourceCollectionFlags rcFlags = getFlags(target);
+
+        Restrict res = new Restrict();
+        res.setProject(getProject());
+        res.add(target);
+
+        Not not = new Not();
+        Or or = new Or();
+        not.add(or);
+        for (int i = 0; i < src.length; i++) {
+            Name name = new Name();
+            name.setName(src[i].getName());
+            or.add(name);
+        }
+        res.add(not);
+
+        for (Iterator rs = res.iterator(); rs.hasNext(); ) {
+            Resource r = (Resource) rs.next();
+            String name = r.getName();
+            if ("".equals(name) || "/".equals(name)) {
+                continue;
+            }
+            if (!isFilesOnly() || !r.isDirectory()) {
+                l.add(new ResourceWithFlags(r, rcFlags, getFlags(r)));
+            }
+        }
+
+        return (ResourceWithFlags[]) l.toArray(new ResourceWithFlags[l.size()]);
+    }
+
+    /**
      * Sorts the list of resources to add.
      */
     protected void sort(List/*<ResourceWithFlags>*/ l) {

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml?rev=816045&r1=816044&r2=816045&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml Thu Sep 17 04:22:11 2009
@@ -392,7 +392,7 @@
   <target name="-prepareArchive" depends="setUp">
     <mkdir dir="${input}"/>
     <copy todir="${input}">
-      <file file="ar-test.xml"/>
+      <fileset dir="." includes="*r-test.xml"/>
     </copy>
     <cmp:ar dest="${dest}">
       <fileset dir="${input}"/>
@@ -408,7 +408,7 @@
 
   <target name="testCreateOfUpToDate" depends="-prepareArchive">
     <cmp:ar dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:ar>
     <au:assertLogContains
        text="test.ar is up-to-date, nothing to do."/>
@@ -418,23 +418,73 @@
 
   <target name="testForceCreateOfUpToDate" depends="-prepareArchive">
     <cmp:ar dest="${dest}" mode="force-create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:ar>
     <au:assertLogDoesntContain
        text="test.ar is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:arentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceDoesntExist>
   </target>
 
   <target name="testCreateOfOutOfDate" depends="-prepareArchive">
     <touch file="${input}/ar-test.xml"/>
     <cmp:ar dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:ar>
+    <au:assertLogDoesntContain
+       text="test.ar is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:arentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:ar dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:ar>
+    <au:assertLogContains
+       text="test.ar is up-to-date, nothing to do."/>
+    <au:assertDestIsUptodate
+       src="${dest}" dest="${dest}.bak"/>
+  </target>
+
+  <target name="testForceReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:ar dest="${dest}" mode="force-replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:ar>
     <au:assertLogDoesntContain
        text="test.ar is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:arentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceExists>
   </target>
 
+  <target name="testReplaceOfOutOfDate" depends="-prepareArchive">
+    <touch file="${input}/ar-test.xml"/>
+    <cmp:ar dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:ar>
+    <au:assertLogDoesntContain
+       text="test.ar is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:arentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceExists>
+  </target>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml?rev=816045&r1=816044&r2=816045&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml Thu Sep 17 04:22:11 2009
@@ -425,7 +425,7 @@
   <target name="-prepareArchive" depends="setUp">
     <mkdir dir="${input}"/>
     <copy todir="${input}">
-      <file file="ar-test.xml"/>
+      <fileset dir="." includes="*r-test.xml"/>
     </copy>
     <cmp:cpio dest="${dest}">
       <fileset dir="${input}"/>
@@ -441,7 +441,7 @@
 
   <target name="testCreateOfUpToDate" depends="-prepareArchive">
     <cmp:cpio dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:cpio>
     <au:assertLogContains
        text="test.cpio is up-to-date, nothing to do."/>
@@ -451,22 +451,73 @@
 
   <target name="testForceCreateOfUpToDate" depends="-prepareArchive">
     <cmp:cpio dest="${dest}" mode="force-create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:cpio>
     <au:assertLogDoesntContain
        text="test.cpio is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:cpioentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceDoesntExist>
   </target>
 
   <target name="testCreateOfOutOfDate" depends="-prepareArchive">
     <touch file="${input}/ar-test.xml"/>
     <cmp:cpio dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:cpio>
+    <au:assertLogDoesntContain
+       text="test.cpio is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:cpioentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:cpio dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:cpio>
+    <au:assertLogContains
+       text="test.cpio is up-to-date, nothing to do."/>
+    <au:assertDestIsUptodate
+       src="${dest}" dest="${dest}.bak"/>
+  </target>
+
+  <target name="testForceReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:cpio dest="${dest}" mode="force-replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:cpio>
+    <au:assertLogDoesntContain
+       text="test.cpio is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:cpioentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
+  </target>
+
+  <target name="testReplaceOfOutOfDate" depends="-prepareArchive">
+    <touch file="${input}/ar-test.xml"/>
+    <cmp:cpio dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:cpio>
     <au:assertLogDoesntContain
        text="test.cpio is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:cpioentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
   </target>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml?rev=816045&r1=816044&r2=816045&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml Thu Sep 17 04:22:11 2009
@@ -442,7 +442,7 @@
   <target name="-prepareArchive" depends="setUp">
     <mkdir dir="${input}"/>
     <copy todir="${input}">
-      <file file="ar-test.xml"/>
+      <fileset dir="." includes="*r-test.xml"/>
     </copy>
     <cmp:tar dest="${dest}">
       <fileset dir="${input}"/>
@@ -458,7 +458,7 @@
 
   <target name="testCreateOfUpToDate" depends="-prepareArchive">
     <cmp:tar dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:tar>
     <au:assertLogContains
        text="test.tar is up-to-date, nothing to do."/>
@@ -468,22 +468,73 @@
 
   <target name="testForceCreateOfUpToDate" depends="-prepareArchive">
     <cmp:tar dest="${dest}" mode="force-create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:tar>
     <au:assertLogDoesntContain
        text="test.tar is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:tarentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceDoesntExist>
   </target>
 
   <target name="testCreateOfOutOfDate" depends="-prepareArchive">
     <touch file="${input}/ar-test.xml"/>
     <cmp:tar dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:tar>
+    <au:assertLogDoesntContain
+       text="test.tar is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:tarentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:tar dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:tar>
+    <au:assertLogContains
+       text="test.tar is up-to-date, nothing to do."/>
+    <au:assertDestIsUptodate
+       src="${dest}" dest="${dest}.bak"/>
+  </target>
+
+  <target name="testForceReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:tar dest="${dest}" mode="force-replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:tar>
+    <au:assertLogDoesntContain
+       text="test.tar is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:tarentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceExists>
+  </target>
+
+  <target name="testReplaceOfOutOfDate" depends="-prepareArchive">
+    <touch file="${input}/ar-test.xml"/>
+    <cmp:tar dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:tar>
     <au:assertLogDoesntContain
        text="test.tar is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:tarentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceExists>
   </target>
 </project>

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=816045&r1=816044&r2=816045&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 Thu Sep 17 04:22:11 2009
@@ -450,7 +450,7 @@
   <target name="-prepareArchive" depends="setUp">
     <mkdir dir="${input}"/>
     <copy todir="${input}">
-      <file file="ar-test.xml"/>
+      <fileset dir="." includes="*r-test.xml"/>
     </copy>
     <cmp:zip dest="${dest}">
       <fileset dir="${input}"/>
@@ -466,7 +466,7 @@
 
   <target name="testCreateOfUpToDate" depends="-prepareArchive">
     <cmp:zip dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:zip>
     <au:assertLogContains
        text="test.zip is up-to-date, nothing to do."/>
@@ -476,22 +476,73 @@
 
   <target name="testForceCreateOfUpToDate" depends="-prepareArchive">
     <cmp:zip dest="${dest}" mode="force-create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:zip>
     <au:assertLogDoesntContain
        text="test.zip is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:zipentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceDoesntExist>
   </target>
 
   <target name="testCreateOfOutOfDate" depends="-prepareArchive">
     <touch file="${input}/ar-test.xml"/>
     <cmp:zip dest="${dest}" mode="create">
-      <fileset dir="${input}"/>
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:zip>
+    <au:assertLogDoesntContain
+       text="test.zip is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceDoesntExist>
+      <cmp:zipentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:zip dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:zip>
+    <au:assertLogContains
+       text="test.zip is up-to-date, nothing to do."/>
+    <au:assertDestIsUptodate
+       src="${dest}" dest="${dest}.bak"/>
+  </target>
+
+  <target name="testForceReplaceOfUpToDate" depends="-prepareArchive">
+    <cmp:zip dest="${dest}" mode="force-replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
+    </cmp:zip>
+    <au:assertLogDoesntContain
+       text="test.zip is up-to-date, nothing to do."/>
+    <au:assertDestIsOutofdate
+       src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:zipentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceExists>
+  </target>
+
+  <target name="testReplaceOfOutOfDate" depends="-prepareArchive">
+    <touch file="${input}/ar-test.xml"/>
+    <cmp:zip dest="${dest}" mode="replace">
+      <fileset dir="${input}" includes="ar-test.xml"/>
     </cmp:zip>
     <au:assertLogDoesntContain
        text="test.zip is up-to-date, nothing to do."/>
     <au:assertDestIsOutofdate
        src="${dest}" dest="${dest}.bak"/>
+    <assertResourceExists>
+      <cmp:zipentry name="tar-test.xml">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceExists>
   </target>
 </project>