From 8df1ef0ecfcd30c0445cb3f7300cdf8e16e32df1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 16 Jul 2009 11:24:47 +0000 Subject: [PATCH] make update="true" and filesetmanifest="merge" work together. PR 30751 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@794630 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++ .../org/apache/tools/ant/taskdefs/Jar.java | 37 ++++++++++++++++++- src/tests/antunit/taskdefs/jar-test.xml | 33 +++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 3c58661ca..53aa4f202 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -404,6 +404,10 @@ Fixed bugs: * didn't work properly with nested builds. Bugzilla Report 41368. + * 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 diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index 2251b3c8d..fdc9eadff 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -47,6 +47,7 @@ import org.apache.tools.ant.BuildException; 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 @@ public class Jar extends Zip { 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 @@ public class Jar extends Zip { 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 @@ public class Jar extends Zip { } } + 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. */ diff --git a/src/tests/antunit/taskdefs/jar-test.xml b/src/tests/antunit/taskdefs/jar-test.xml index 0edae8ccd..9ca2a8738 100644 --- a/src/tests/antunit/taskdefs/jar-test.xml +++ b/src/tests/antunit/taskdefs/jar-test.xml @@ -146,4 +146,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +