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 2010/10/29 17:52:23 UTC
svn commit: r1028813 - in /ant/core/trunk: WHATSNEW
src/main/org/apache/tools/ant/taskdefs/Zip.java
src/tests/antunit/taskdefs/zip-test.xml
Author: bodewig
Date: Fri Oct 29 15:52:23 2010
New Revision: 1028813
URL: http://svn.apache.org/viewvc?rev=1028813&view=rev
Log:
zip's whenempty doesn't look at non-filesets at all. PR 50115
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java
ant/core/trunk/src/tests/antunit/taskdefs/zip-test.xml
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1028813&r1=1028812&r2=1028813&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Oct 29 15:52:23 2010
@@ -187,6 +187,11 @@ Fixed bugs:
updating a file.
Bugzilla Report 50049.
+ * <zip>'s whenEmpty behavior never consulted the non-fileset
+ resources so the task could fail even though resources have been
+ provided using non-fileset resource collections.
+ Bugzilla Issue 50115.
+
Other changes:
--------------
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java?rev=1028813&r1=1028812&r2=1028813&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java Fri Oct 29 15:52:23 2010
@@ -1243,6 +1243,19 @@ public class Zip extends MatchingTask {
return new ArchiveState(as2.isOutOfDate(), toAdd);
}
+ /*
+ * This is yet a hacky construct to extend the getResourcesToAdd
+ * method so we can pass the information whether non-fileset
+ * resources have been available to it without having to move the
+ * withEmpty behavior checks (since it would break subclasses in
+ * several ways otherwise).
+ */
+ private static ThreadLocal haveNonFileSetResourcesToAdd = new ThreadLocal() {
+ protected Object initialValue() {
+ return Boolean.FALSE;
+ }
+ };
+
/**
* Collect the resources that are newer than the corresponding
* entries (or missing) in the original archive.
@@ -1272,6 +1285,7 @@ public class Zip extends MatchingTask {
Resource[][] initialResources = grabResources(filesets);
if (isEmpty(initialResources)) {
+ if (Boolean.FALSE.equals(haveNonFileSetResourcesToAdd.get())) {
if (needsUpdate && doUpdate) {
/*
* This is a rather hairy case.
@@ -1314,6 +1328,10 @@ public class Zip extends MatchingTask {
needsUpdate = true;
}
}
+ }
+
+ // either we there are non-fileset resources or we
+ // (re-)create the archive anyway
return new ArchiveState(needsUpdate, initialResources);
}
@@ -1429,7 +1447,9 @@ public class Zip extends MatchingTask {
*/
Resource[][] initialResources = grabNonFileSetResources(rcs);
- if (isEmpty(initialResources)) {
+ boolean empty = isEmpty(initialResources);
+ haveNonFileSetResourcesToAdd.set(Boolean.valueOf(!empty));
+ if (empty) {
// no emptyBehavior handling since the FileSet version
// will take care of it.
return new ArchiveState(needsUpdate, initialResources);
@@ -1934,6 +1954,7 @@ public class Zip extends MatchingTask {
resources.removeElement(zf);
}
filesetsFromGroupfilesets.removeAllElements();
+ haveNonFileSetResourcesToAdd.set(Boolean.FALSE);
}
/**
Modified: ant/core/trunk/src/tests/antunit/taskdefs/zip-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/zip-test.xml?rev=1028813&r1=1028812&r2=1028813&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/zip-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/zip-test.xml Fri Oct 29 15:52:23 2010
@@ -125,12 +125,33 @@
<target name="testFilesetInsideResources"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50115">
+ <mkdir dir="${input}/test2"/>
+ <touch file="${input}/test1.txt"/>
<mkdir dir="${output}"/>
+ <mkdir dir="${output}/expand"/>
<zip destfile="${output}/test.zip" whenempty="skip">
<resources>
- <fileset dir="${output}" includes="d**"/>
+ <fileset dir="${input}" includes="test**"/>
</resources>
</zip>
- <au:assertFileDoesntExist file="${output}/test.zip"/>
+ <au:assertLogDoesntContain text="skipping zip archive"/>
+ <unzip src="${output}/test.zip" dest="${output}/expand"/>
+ <au:assertFileExists file="${output}/expand/test1.txt"/>
+ <!--au:assertFileExists file="${output}/expand/test2"/-->
+ </target>
+
+ <target name="testWhenEmptyChecksNonFileSets"
+ description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50115">
+ <mkdir dir="${input}/"/>
+ <touch file="${input}/test1.txt"/>
+ <mkdir dir="${output}"/>
+ <mkdir dir="${output}/expand"/>
+ <zip destfile="${output}/test.zip" whenempty="fail">
+ <resources>
+ <fileset dir="${input}" includes="test**"/>
+ </resources>
+ </zip>
+ <unzip src="${output}/test.zip" dest="${output}/expand"/>
+ <au:assertFileExists file="${output}/expand/test1.txt"/>
</target>
</project>