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/07/16 13:24:48 UTC

svn commit: r794630 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/Jar.java src/tests/antunit/taskdefs/jar-test.xml

Author: bodewig
Date: Thu Jul 16 11:24:47 2009
New Revision: 794630

URL: http://svn.apache.org/viewvc?rev=794630&view=rev
Log:
make update="true" and filesetmanifest="merge" work together.  PR 30751

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
    ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=794630&r1=794629&r2=794630&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Jul 16 11:24:47 2009
@@ -404,6 +404,10 @@
  * <record> didn't work properly with nested builds.
    Bugzilla Report 41368. 
 
+ * <jar> with filesetmanifest different from skip didn't work if the
+   update attribute has been set to true.
+   Bugzilla Report 30751.
+
 Other changes:
 --------------
  * The get task now also follows redirects from http to https

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java?rev=794630&r1=794629&r2=794630&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java Thu Jul 16 11:24:47 2009
@@ -47,6 +47,7 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Manifest.Section;
 import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
@@ -778,6 +779,14 @@
                                              boolean needsUpdate)
         throws BuildException {
 
+        if (skipWriting) {
+            // this pass is only there to construct the merged
+            // manifest this means we claim an update was needed and
+            // only include the manifests, skipping any uptodate
+            // checks here defering them for the second run
+            return new ArchiveState(true, grabManifests(rcs));
+        }
+
         // need to handle manifest as a special check
         if (zipFile.exists()) {
             // if it doesn't exist, it will get created anyway, don't
@@ -786,13 +795,13 @@
             try {
                 originalManifest = getManifestFromJar(zipFile);
                 if (originalManifest == null) {
-                    logOnFirstPass("Updating jar since the current jar has"
+                    log("Updating jar since the current jar has"
                                    + " no manifest", Project.MSG_VERBOSE);
                     needsUpdate = true;
                 } else {
                     Manifest mf = createManifest();
                     if (!mf.equals(originalManifest)) {
-                        logOnFirstPass("Updating jar since jar manifest has"
+                        log("Updating jar since jar manifest has"
                                        + " changed", Project.MSG_VERBOSE);
                         needsUpdate = true;
                     }
@@ -1117,6 +1126,30 @@
         }
     }
 
+    private Resource[][] grabManifests(ResourceCollection[] rcs) {
+        Resource[][] manifests = new Resource[rcs.length][];
+        for (int i = 0; i < rcs.length; i++) {
+            Resource[][] resources = null;
+            if (rcs[i] instanceof FileSet) {
+                resources = grabResources(new FileSet[] {(FileSet) rcs[i]});
+            } else {
+                resources = grabNonFileSetResources(new ResourceCollection[] {
+                        rcs[i]
+                    });
+            }
+            for (int j = 0; j < resources[0].length; j++) {
+                if (resources[0][j].getName().equalsIgnoreCase(MANIFEST_NAME)) {
+                    manifests[i] = new Resource[] {resources[0][j]};
+                    break;
+                }
+            }
+            if (manifests[i] == null) {
+                manifests[i] = new Resource[0];
+            }
+        }
+        return manifests;
+    }
+
     /** The strict enumerated type. */
     public static class StrictMode extends EnumeratedAttribute {
         /** Public no arg constructor. */

Modified: ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml?rev=794630&r1=794629&r2=794630&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml Thu Jul 16 11:24:47 2009
@@ -146,4 +146,37 @@
       </jar>
     </au:expectfailure>
   </target>
+
+  <target name="test-update-and-filesetmanifest"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=30751">
+    <mkdir dir="${input}"/>
+    <mkdir dir="${output}"/>
+    <jar destfile="${input}/manifest.jar">
+      <manifest>
+        <attribute name="Origin" value="manifest.jar"/>
+      </manifest>
+    </jar>
+
+    <touch file="${input}/foo"/>
+    <jar destfile="${output}/test.jar">
+      <fileset dir="${input}" excludes="*.jar"/>
+      <manifest>
+        <attribute name="Second-Origin" value="test.jar"/>
+      </manifest>
+    </jar>
+
+    <touch file="${input}/bar"/>
+    <jar destfile="${output}/test.jar" update="true" filesetmanifest="merge">
+      <fileset dir="${input}" excludes="*.jar"/>
+      <zipgroupfileset dir="${input}" includes="*.jar"/>
+    </jar>
+
+    <unjar src="${output}/test.jar" dest="${output}"/>
+    <au:assertFileExists file="${output}/foo"/>
+    <au:assertFileExists file="${output}/bar"/>
+    <au:assertResourceContains value="Origin: manifest.jar"
+                               resource="${output}/META-INF/MANIFEST.MF"/>
+    <au:assertResourceContains value="Second-Origin: test.jar"
+                               resource="${output}/META-INF/MANIFEST.MF"/>
+  </target>
 </project>



Re: svn commit: r794630 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/Jar.java src/tests/antunit/taskdefs/jar-test.xml

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-07-16, <bo...@apache.org> wrote:

> URL: http://svn.apache.org/viewvc?rev=794630&view=rev
> Log:
> make update="true" and filesetmanifest="merge" work together.  PR 30751

with this change the whole doublePassMode in <zip> stuff becomes
redundant since it only ever existed to support <jar>'s
filesetmanifest and the logic that is now applied on the first pass
could as well be used before starting the any pass at all.

OTOH the zip task is one that gets subclassed in unrelated projects so
I don't really dare to remove the doublePass logic completely.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org