Author: bodewig
Date: Thu Aug 27 02:49:59 2009
New Revision: 808258
URL: http://svn.apache.org/viewvc?rev=808258&view=rev
Log:
port whenEmpty from <zip>
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=808258&r1=808257&r2=808258&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 Aug 27 02:49:59 2009
@@ -77,6 +77,9 @@
private boolean roundUp = true;
private boolean preserveLeadingSlashes = false;
private Duplicate duplicate = new Duplicate();
+ private WhenEmpty emptyBehavior = new WhenEmpty();
+
+ private static final String NO_SOURCES_MSG = "No sources, nothing to do.";
protected ArchiveBase() {}
@@ -178,13 +181,25 @@
* Possible values are: <code>add</code> (keep both
* of the files); <code>preserve</code> (keep the first version
* of the file found); <code>fail</code> halt a problem
- * Default for is <code>fail</code>
+ * Default is <code>fail</code>
* @param df a <code>Duplicate</code> enumerated value
*/
public void setDuplicate(Duplicate df) {
duplicate = df;
}
+ /**
+ * Sets behavior of the task when no resources are to be added.
+ * Possible values are: <code>fail</code> (throw an exception
+ * and halt the build); <code>skip</code> (do not create
+ * any archive, but issue a warning);.
+ * Default is <code>fail</code>;
+ * @param we a <code>WhenEmpty</code> enumerated value
+ */
+ public void setWhenempty(WhenEmpty we) {
+ emptyBehavior = we;
+ }
+
public void execute() {
validate();
if (!dest.isExists()) {
@@ -198,7 +213,11 @@
throw new BuildException("Failed to read sources", ioex);
}
if (toAdd.length == 0) {
- log("No sources, nothing to do", Project.MSG_WARN);
+ if (WhenEmpty.SKIP.equals(emptyBehavior.getValue())) {
+ log(NO_SOURCES_MSG, Project.MSG_WARN);
+ } else {
+ throw new BuildException(NO_SOURCES_MSG);
+ }
} else {
try {
writeArchive(toAdd);
@@ -597,6 +616,27 @@
}
/**
+ * Possible behaviors when there are no matching files for the task:
+ * "fail", "skip".
+ */
+ public static class WhenEmpty extends EnumeratedAttribute {
+ private static String FAIL = "fail";
+ private static String SKIP = "skip";
+
+ public WhenEmpty() {
+ setValue(FAIL);
+ }
+
+ /**
+ * The string values for the enumerated value
+ * @return the values
+ */
+ public String[] getValues() {
+ return new String[] {FAIL, SKIP};
+ }
+ }
+
+ /**
* Various flags a (archive) resource may hold in addition to
* being a plain resource.
*/
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=808258&r1=808257&r2=808258&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 Aug 27
02:49:59 2009
@@ -353,4 +353,22 @@
</cmp:ar>
</au:expectfailure>
</target>
+
+ <target name="testFailEmpty" depends="setUp">
+ <au:expectfailure
+ message="No sources, nothing to do.">
+ <cmp:ar destfile="${dest}">
+ <fileset dir="." includes="not-there"/>
+ </cmp:ar>
+ </au:expectfailure>
+ </target>
+
+ <target name="testSkipEmpty" depends="setUp">
+ <cmp:ar destfile="${dest}" whenEmpty="skip">
+ <fileset dir="." includes="not-there"/>
+ </cmp:ar>
+ <au:assertLogContains text="No sources, nothing to do."
+ level="warn"/>
+ <au:assertFileDoesntExist file="${dest}"/>
+ </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=808258&r1=808257&r2=808258&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 Aug
27 02:49:59 2009
@@ -386,4 +386,22 @@
</cmp:cpio>
</au:expectfailure>
</target>
+
+ <target name="testFailEmpty" depends="setUp">
+ <au:expectfailure
+ message="No sources, nothing to do.">
+ <cmp:cpio destfile="${dest}">
+ <fileset dir="." includes="not-there"/>
+ </cmp:cpio>
+ </au:expectfailure>
+ </target>
+
+ <target name="testSkipEmpty" depends="setUp">
+ <cmp:cpio destfile="${dest}" whenEmpty="skip">
+ <fileset dir="." includes="not-there"/>
+ </cmp:cpio>
+ <au:assertLogContains text="No sources, nothing to do."
+ level="warn"/>
+ <au:assertFileDoesntExist file="${dest}"/>
+ </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=808258&r1=808257&r2=808258&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 Aug
27 02:49:59 2009
@@ -403,4 +403,22 @@
</cmp:tar>
</au:expectfailure>
</target>
+
+ <target name="testFailEmpty" depends="setUp">
+ <au:expectfailure
+ message="No sources, nothing to do.">
+ <cmp:tar destfile="${dest}">
+ <fileset dir="." includes="not-there"/>
+ </cmp:tar>
+ </au:expectfailure>
+ </target>
+
+ <target name="testSkipEmpty" depends="setUp">
+ <cmp:tar destfile="${dest}" whenEmpty="skip">
+ <fileset dir="." includes="not-there"/>
+ </cmp:tar>
+ <au:assertLogContains text="No sources, nothing to do."
+ level="warn"/>
+ <au:assertFileDoesntExist file="${dest}"/>
+ </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=808258&r1=808257&r2=808258&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 Aug
27 02:49:59 2009
@@ -411,4 +411,22 @@
</cmp:zip>
</au:expectfailure>
</target>
+
+ <target name="testFailEmpty" depends="setUp">
+ <au:expectfailure
+ message="No sources, nothing to do.">
+ <cmp:zip destfile="${dest}">
+ <fileset dir="." includes="not-there"/>
+ </cmp:zip>
+ </au:expectfailure>
+ </target>
+
+ <target name="testSkipEmpty" depends="setUp">
+ <cmp:zip destfile="${dest}" whenEmpty="skip">
+ <fileset dir="." includes="not-there"/>
+ </cmp:zip>
+ <au:assertLogContains text="No sources, nothing to do."
+ level="warn"/>
+ <au:assertFileDoesntExist file="${dest}"/>
+ </target>
</project>