git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@440876 13f79535-47bb-0310-9956-ffa450edef68master
@@ -32,6 +32,7 @@ Other changes: | |||||
Bugzilla report 35619. | Bugzilla report 35619. | ||||
* Made PatterSet#hasPatterns public to allow custom filesets access. | * Made PatterSet#hasPatterns public to allow custom filesets access. | ||||
Bugzilla report 36772. | Bugzilla report 36772. | ||||
* added searchparents attribute to <available>. Bugzilla report 39549. | |||||
Changes from Ant 1.6.5 to Ant 1.7.0Beta1 | Changes from Ant 1.6.5 to Ant 1.7.0Beta1 | ||||
======================================== | ======================================== | ||||
@@ -75,7 +75,19 @@ execution depending on system parameters.</p> | |||||
classpath. Only affects the "classname" attribute. Defaults to "false"</td> | classpath. Only affects the "classname" attribute. Defaults to "false"</td> | ||||
<td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">searchparents</td> | |||||
<td valign="top">This contains the behaviour of the "file" type. | |||||
If true, the available task will, when | |||||
searching for a file, search not only the directories specified but | |||||
will also search the parent and grandparent directories of those | |||||
specified. | |||||
If false, only the directories specified will be searched. | |||||
Defaults to "true". | |||||
<em>Since Ant 1.7</em> | |||||
</td> | |||||
<td align="center" valign="top">No</td> | |||||
</tr> | |||||
</table> | </table> | ||||
<h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
<h4>classpath</h4> | <h4>classpath</h4> | ||||
@@ -2,6 +2,10 @@ | |||||
<project name="available-test" basedir="." default="test1"> | <project name="available-test" basedir="." default="test1"> | ||||
<target name="tearDown"> | |||||
<delete dir="greatgrandparent"/> | |||||
</target> | |||||
<target name="test1"> | <target name="test1"> | ||||
<available/> | <available/> | ||||
</target> | </target> | ||||
@@ -162,4 +166,91 @@ | |||||
</fail> | </fail> | ||||
</target> | </target> | ||||
<target name="prep.parents"> | |||||
<delete quiet="yes" dir="greatgrandparent"/> | |||||
<mkdir dir="greatgrandparent/grandparent/parent/dir"/> | |||||
<touch file="greatgrandparent/a.txt"/> | |||||
<touch file="greatgrandparent/grandparent/b.txt"/> | |||||
<touch file="greatgrandparent/grandparent/parent/c.txt"/> | |||||
<touch file="greatgrandparent/grandparent/parent/dir/d.txt"/> | |||||
<property name="available.test.dir" | |||||
value="greatgrandparent/grandparent/parent/dir"/> | |||||
</target> | |||||
<target name="search-parents" depends="prep.parents"> | |||||
<echo>testing greatgrandparent - should not see</echo> | |||||
<fail> | |||||
<condition> | |||||
<available file="a.txt"> | |||||
<filepath path="${available.test.dir}"/> | |||||
</available> | |||||
</condition> | |||||
</fail> | |||||
<echo>testing grandparent - should see</echo> | |||||
<fail> | |||||
<condition> | |||||
<not> | |||||
<available file="b.txt"> | |||||
<filepath path="${available.test.dir}"/> | |||||
</available> | |||||
</not> | |||||
</condition> | |||||
</fail> | |||||
<echo>testing parent - should see</echo> | |||||
<fail> | |||||
<condition> | |||||
<not> | |||||
<available file="c.txt"> | |||||
<filepath path="${available.test.dir}"/> | |||||
</available> | |||||
</not> | |||||
</condition> | |||||
</fail> | |||||
<echo>testing dir - should see</echo> | |||||
<fail> | |||||
<condition> | |||||
<not> | |||||
<available file="d.txt"> | |||||
<filepath path="${available.test.dir}"/> | |||||
</available> | |||||
</not> | |||||
</condition> | |||||
</fail> | |||||
</target> | |||||
<target name="search-parents-not" depends="prep.parents"> | |||||
<echo>testing grandparent - should not see</echo> | |||||
<fail> | |||||
<condition> | |||||
<available file="b.txt" searchParents="no"> | |||||
<filepath path="${available.test.dir}"/> | |||||
</available> | |||||
</condition> | |||||
</fail> | |||||
<echo>testing parent - should not see</echo> | |||||
<fail> | |||||
<condition> | |||||
<available file="c.txt" searchParents="false"> | |||||
<filepath path="${available.test.dir}"/> | |||||
</available> | |||||
</condition> | |||||
</fail> | |||||
<echo>testing dir - should see</echo> | |||||
<fail> | |||||
<condition> | |||||
<not> | |||||
<available file="d.txt" searchParents="false"> | |||||
<filepath path="${available.test.dir}"/> | |||||
</available> | |||||
</not> | |||||
</condition> | |||||
</fail> | |||||
</target> | |||||
</project> | </project> |
@@ -53,6 +53,19 @@ public class Available extends Task implements Condition { | |||||
private String value = "true"; | private String value = "true"; | ||||
private boolean isTask = false; | private boolean isTask = false; | ||||
private boolean ignoreSystemclasses = false; | private boolean ignoreSystemclasses = false; | ||||
private boolean searchParents = true; | |||||
/** | |||||
* Set the searchParents attribute. | |||||
* This controls the behaviour of the the "file" type. | |||||
* If true, the path, parent path and grandparent path are | |||||
* searched for the file. If false, only the path is seached. | |||||
* The default value is true. | |||||
* @param searchParents the value to set. | |||||
*/ | |||||
public void setSearchParents(boolean searchParents) { | |||||
this.searchParents = searchParents; | |||||
} | |||||
/** | /** | ||||
* Set the classpath to be used when searching for classes and resources. | * Set the classpath to be used when searching for classes and resources. | ||||
@@ -353,14 +366,14 @@ public class Available extends Task implements Condition { | |||||
} | } | ||||
} | } | ||||
// ** simple name specified == parent dir + name | // ** simple name specified == parent dir + name | ||||
if (parent != null && parent.exists()) { | |||||
if (parent != null && parent.exists() && searchParents) { | |||||
if (checkFile(new File(parent, filename), | if (checkFile(new File(parent, filename), | ||||
filename + " in " + parent)) { | filename + " in " + parent)) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
// ** simple name specified == parent of parent dir + name | // ** simple name specified == parent of parent dir + name | ||||
if (parent != null) { | |||||
if (parent != null && searchParents) { | |||||
File grandParent = parent.getParentFile(); | File grandParent = parent.getParentFile(); | ||||
if (grandParent != null && grandParent.exists()) { | if (grandParent != null && grandParent.exists()) { | ||||
if (checkFile(new File(grandParent, filename), | if (checkFile(new File(grandParent, filename), | ||||
@@ -201,4 +201,13 @@ public class AvailableTest extends BuildFileTest { | |||||
public void testDoubleBasedir() { | public void testDoubleBasedir() { | ||||
executeTarget("testDoubleBasedir"); | executeTarget("testDoubleBasedir"); | ||||
} | } | ||||
// test for searching parents | |||||
public void testSearchParents() { | |||||
executeTarget("search-parents"); | |||||
} | |||||
// test for not searching parents | |||||
public void testSearchParentsNot() { | |||||
executeTarget("search-parents-not"); | |||||
} | |||||
} | } |