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 2008/11/21 15:09:23 UTC
svn commit: r719582 - in /ant/core/trunk: ./ docs/manual/CoreTypes/
src/main/org/apache/tools/ant/types/ src/tests/antunit/types/
Author: bodewig
Date: Fri Nov 21 06:09:22 2008
New Revision: 719582
URL: http://svn.apache.org/viewvc?rev=719582&view=rev
Log:
add an erroronmissingarchive attribute to tar/zipfileset. PR 46091.
Added:
ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml (with props)
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/CoreTypes/tarfileset.html
ant/core/trunk/docs/manual/CoreTypes/zipfileset.html
ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java
ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveScanner.java
ant/core/trunk/src/tests/antunit/types/zipfileset-test.xml
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=719582&r1=719581&r2=719582&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Nov 21 06:09:22 2008
@@ -539,6 +539,11 @@
can be applied to arbitrary resource collections.
Bugzilla Report 4240.
+ * <tarfileset> and <zipfileset> have a new attribute
+ errorOnMissingArchive that allows "optional" filesets that don't
+ break the build if the archive doesn't exist.
+ Bugzilla Report 46091.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/docs/manual/CoreTypes/tarfileset.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/tarfileset.html?rev=719582&r1=719581&r2=719582&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/tarfileset.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/tarfileset.html Fri Nov 21 06:09:22 2008
@@ -117,6 +117,17 @@
</td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">erroronmissingarchive</td>
+ <td valign="top">
+ Specify what happens if the archive does not exist.
+ If true, a build error will happen; if false, the fileset
+ will be ignored/empty.
+ Defaults to true.
+ <em>Since Ant 1.8.0</em>
+ </td>
+ <td valign="top" align="center">No</td>
+ </tr>
</tbody>
</table>
<p>The <i>fullpath</i> attribute can only be set for filesets that
Modified: ant/core/trunk/docs/manual/CoreTypes/zipfileset.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/zipfileset.html?rev=719582&r1=719581&r2=719582&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/zipfileset.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/zipfileset.html Fri Nov 21 06:09:22 2008
@@ -98,6 +98,17 @@
<b>Only supported by zipfileset.</b></td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">erroronmissingarchive</td>
+ <td valign="top">
+ Specify what happens if the archive does not exist.
+ If true, a build error will happen; if false, the fileset
+ will be ignored/empty.
+ Defaults to true.
+ <em>Since Ant 1.8.0</em>
+ </td>
+ <td valign="top" align="center">No</td>
+ </tr>
</tbody>
</table>
<p>The <i>fullpath</i> attribute can only be set for filesets that
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java?rev=719582&r1=719581&r2=719582&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java Fri Nov 21 06:09:22 2008
@@ -68,6 +68,8 @@
private static final String ERROR_DIR_AND_SRC_ATTRIBUTES = "Cannot set both dir and src attributes";
private static final String ERROR_PATH_AND_PREFIX = "Cannot set both fullpath and prefix attributes";
+ private boolean errorOnMissingArchive = true;
+
/** Constructor for ArchiveFileSet */
public ArchiveFileSet() {
super();
@@ -95,6 +97,7 @@
dirMode = fileset.dirMode;
fileModeHasBeenSet = fileset.fileModeHasBeenSet;
dirModeHasBeenSet = fileset.dirModeHasBeenSet;
+ errorOnMissingArchive = fileset.errorOnMissingArchive;
}
/**
@@ -162,6 +165,18 @@
}
/**
+ * Sets whether an error is thrown if an archive does not exist.
+ *
+ * @param errorOnMissingArchive true if missing archives cause errors,
+ * false if not.
+ * @since Ant 1.8.0
+ */
+ public void setErrorOnMissingArchive(boolean errorOnMissingArchive) {
+ checkAttributesAllowed();
+ this.errorOnMissingArchive = errorOnMissingArchive;
+ }
+
+ /**
* Get the archive file from which entries will be extracted.
* @return the archive in case the archive is a file, null otherwise.
*/
@@ -247,7 +262,7 @@
if (src == null) {
return super.getDirectoryScanner(p);
}
- if (!src.isExists()) {
+ if (!src.isExists() && errorOnMissingArchive) {
throw new BuildException(
"The archive " + src.getName() + " doesn't exist");
}
@@ -256,6 +271,7 @@
+ " can't be a directory");
}
ArchiveScanner as = newArchiveScanner();
+ as.setErrorOnMissingArchive(errorOnMissingArchive);
as.setSrc(src);
super.setDir(p.getBaseDir());
setupDirectoryScanner(as, p);
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveScanner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveScanner.java?rev=719582&r1=719581&r2=719582&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveScanner.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveScanner.java Fri Nov 21 06:09:22 2008
@@ -87,11 +87,27 @@
private String encoding;
/**
+ * @since Ant 1.8.0
+ */
+ private boolean errorOnMissingArchive = true;
+
+ /**
+ * Sets whether an error is thrown if an archive does not exist.
+ *
+ * @param errorOnMissingArchive true if missing archives cause errors,
+ * false if not.
+ * @since Ant 1.8.0
+ */
+ public void setErrorOnMissingArchive(boolean errorOnMissingArchive) {
+ this.errorOnMissingArchive = errorOnMissingArchive;
+ }
+
+ /**
* Don't scan when we have no zipfile.
* @since Ant 1.7
*/
public void scan() {
- if (src == null) {
+ if (src == null || (!src.isExists() && !errorOnMissingArchive)) {
return;
}
super.scan();
@@ -304,6 +320,10 @@
* are put into the appropriate tables.
*/
private void scanme() {
+ if (!src.isExists() && !errorOnMissingArchive) {
+ return;
+ }
+
//do not use a FileResource b/c it pulls File info from the filesystem:
Resource thisresource = new Resource(src.getName(),
src.isExists(),
Added: ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml?rev=719582&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml Fri Nov 21 06:09:22 2008
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+ <import file="../antunit-base.xml"/>
+
+ <target name="testMissingArchive">
+ <mkdir dir="${output}"/>
+ <au:expectfailure expectedMessage="The archive foo.tar doesn't exist">
+ <copy todir="${output}">
+ <tarfileset src="foo.tar"/>
+ </copy>
+ </au:expectfailure>
+ </target>
+
+ <target name="testMissingArchiveDoesntMatter">
+ <mkdir dir="${output}"/>
+ <copy todir="${output}">
+ <tarfileset src="foo.tar" errorOnMissingArchive="false"/>
+ </copy>
+ </target>
+
+</project>
Propchange: ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: ant/core/trunk/src/tests/antunit/types/zipfileset-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/zipfileset-test.xml?rev=719582&r1=719581&r2=719582&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/zipfileset-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/types/zipfileset-test.xml Fri Nov 21 06:09:22 2008
@@ -64,4 +64,20 @@
</au:expectfailure>
</target>
+ <target name="testMissingArchive">
+ <mkdir dir="${output}"/>
+ <au:expectfailure expectedMessage="The archive foo.zip doesn't exist">
+ <copy todir="${output}">
+ <zipfileset src="foo.zip"/>
+ </copy>
+ </au:expectfailure>
+ </target>
+
+ <target name="testMissingArchiveDoesntMatter">
+ <mkdir dir="${output}"/>
+ <copy todir="${output}">
+ <zipfileset src="foo.zip" errorOnMissingArchive="false"/>
+ </copy>
+ </target>
+
</project>