git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@719582 13f79535-47bb-0310-9956-ffa450edef68master
@@ -539,6 +539,11 @@ Other changes: | |||
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 | |||
============================================= | |||
@@ -117,6 +117,17 @@ directories. Default is 755.</td> | |||
</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 | |||
@@ -98,6 +98,17 @@ directories. Default is 755. <em>since Ant 1.5.2</em>.</td> | |||
<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 | |||
@@ -68,6 +68,8 @@ public abstract class ArchiveFileSet extends FileSet { | |||
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 @@ public abstract class ArchiveFileSet extends FileSet { | |||
dirMode = fileset.dirMode; | |||
fileModeHasBeenSet = fileset.fileModeHasBeenSet; | |||
dirModeHasBeenSet = fileset.dirModeHasBeenSet; | |||
errorOnMissingArchive = fileset.errorOnMissingArchive; | |||
} | |||
/** | |||
@@ -161,6 +164,18 @@ public abstract class ArchiveFileSet extends FileSet { | |||
return getSrc(); | |||
} | |||
/** | |||
* 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 @@ public abstract class ArchiveFileSet extends FileSet { | |||
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 @@ public abstract class ArchiveFileSet extends FileSet { | |||
+ " can't be a directory"); | |||
} | |||
ArchiveScanner as = newArchiveScanner(); | |||
as.setErrorOnMissingArchive(errorOnMissingArchive); | |||
as.setSrc(src); | |||
super.setDir(p.getBaseDir()); | |||
setupDirectoryScanner(as, p); | |||
@@ -86,12 +86,28 @@ public abstract class ArchiveScanner extends DirectoryScanner { | |||
*/ | |||
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 @@ public abstract class ArchiveScanner extends DirectoryScanner { | |||
* 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(), | |||
@@ -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> |
@@ -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> |