Browse Source

zip's whenempty doesn't look at non-filesets at all. PR 50115

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1028813 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 14 years ago
parent
commit
ee4aa01089
3 changed files with 50 additions and 3 deletions
  1. +5
    -0
      WHATSNEW
  2. +22
    -1
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  3. +23
    -2
      src/tests/antunit/taskdefs/zip-test.xml

+ 5
- 0
WHATSNEW View File

@@ -187,6 +187,11 @@ Fixed bugs:
updating a file. updating a file.
Bugzilla Report 50049. 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: Other changes:
-------------- --------------




+ 22
- 1
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -1243,6 +1243,19 @@ public class Zip extends MatchingTask {
return new ArchiveState(as2.isOutOfDate(), toAdd); 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 * Collect the resources that are newer than the corresponding
* entries (or missing) in the original archive. * entries (or missing) in the original archive.
@@ -1272,6 +1285,7 @@ public class Zip extends MatchingTask {


Resource[][] initialResources = grabResources(filesets); Resource[][] initialResources = grabResources(filesets);
if (isEmpty(initialResources)) { if (isEmpty(initialResources)) {
if (Boolean.FALSE.equals(haveNonFileSetResourcesToAdd.get())) {
if (needsUpdate && doUpdate) { if (needsUpdate && doUpdate) {
/* /*
* This is a rather hairy case. * This is a rather hairy case.
@@ -1314,6 +1328,10 @@ public class Zip extends MatchingTask {
needsUpdate = true; needsUpdate = true;
} }
} }
}

// either we there are non-fileset resources or we
// (re-)create the archive anyway
return new ArchiveState(needsUpdate, initialResources); return new ArchiveState(needsUpdate, initialResources);
} }


@@ -1429,7 +1447,9 @@ public class Zip extends MatchingTask {
*/ */


Resource[][] initialResources = grabNonFileSetResources(rcs); 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 // no emptyBehavior handling since the FileSet version
// will take care of it. // will take care of it.
return new ArchiveState(needsUpdate, initialResources); return new ArchiveState(needsUpdate, initialResources);
@@ -1934,6 +1954,7 @@ public class Zip extends MatchingTask {
resources.removeElement(zf); resources.removeElement(zf);
} }
filesetsFromGroupfilesets.removeAllElements(); filesetsFromGroupfilesets.removeAllElements();
haveNonFileSetResourcesToAdd.set(Boolean.FALSE);
} }


/** /**


+ 23
- 2
src/tests/antunit/taskdefs/zip-test.xml View File

@@ -125,12 +125,33 @@


<target name="testFilesetInsideResources" <target name="testFilesetInsideResources"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50115"> 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}"/>
<mkdir dir="${output}/expand"/>
<zip destfile="${output}/test.zip" whenempty="skip"> <zip destfile="${output}/test.zip" whenempty="skip">
<resources> <resources>
<fileset dir="${output}" includes="d**"/>
<fileset dir="${input}" includes="test**"/>
</resources> </resources>
</zip> </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> </target>
</project> </project>

Loading…
Cancel
Save