Author: peterreilly Date: Wed Sep 6 14:19:42 2006 New Revision: 440876 URL: http://svn.apache.org/viewvc?view=rev&rev=440876 Log: Bugzilla 39549: add searchparents attribute to <available>
Modified: ant/core/trunk/WHATSNEW ant/core/trunk/docs/manual/CoreTasks/available.html ant/core/trunk/src/etc/testcases/taskdefs/available.xml ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=440876&r1=440875&r2=440876 ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Wed Sep 6 14:19:42 2006 @@ -32,6 +32,7 @@ Bugzilla report 35619. * Made PatterSet#hasPatterns public to allow custom filesets access. Bugzilla report 36772. +* added searchparents attribute to <available>. Bugzilla report 39549. Changes from Ant 1.6.5 to Ant 1.7.0Beta1 ======================================== Modified: ant/core/trunk/docs/manual/CoreTasks/available.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/available.html?view=diff&rev=440876&r1=440875&r2=440876 ============================================================================== --- ant/core/trunk/docs/manual/CoreTasks/available.html (original) +++ ant/core/trunk/docs/manual/CoreTasks/available.html Wed Sep 6 14:19:42 2006 @@ -75,7 +75,19 @@ classpath. Only affects the "classname" attribute. Defaults to "false"</td> <td align="center" valign="top">No</td> </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> <h3>Parameters specified as nested elements</h3> <h4>classpath</h4> Modified: ant/core/trunk/src/etc/testcases/taskdefs/available.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/available.xml?view=diff&rev=440876&r1=440875&r2=440876 ============================================================================== --- ant/core/trunk/src/etc/testcases/taskdefs/available.xml (original) +++ ant/core/trunk/src/etc/testcases/taskdefs/available.xml Wed Sep 6 14:19:42 2006 @@ -2,6 +2,10 @@ <project name="available-test" basedir="." default="test1"> + <target name="tearDown"> + <delete dir="greatgrandparent"/> + </target> + <target name="test1"> <available/> </target> @@ -162,4 +166,91 @@ </fail> </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> Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java?view=diff&rev=440876&r1=440875&r2=440876 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java Wed Sep 6 14:19:42 2006 @@ -53,6 +53,19 @@ private String value = "true"; private boolean isTask = 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. @@ -353,14 +366,14 @@ } } // ** simple name specified == parent dir + name - if (parent != null && parent.exists()) { + if (parent != null && parent.exists() && searchParents) { if (checkFile(new File(parent, filename), filename + " in " + parent)) { return true; } } // ** simple name specified == parent of parent dir + name - if (parent != null) { + if (parent != null && searchParents) { File grandParent = parent.getParentFile(); if (grandParent != null && grandParent.exists()) { if (checkFile(new File(grandParent, filename), Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java?view=diff&rev=440876&r1=440875&r2=440876 ============================================================================== --- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java (original) +++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java Wed Sep 6 14:19:42 2006 @@ -201,4 +201,13 @@ public void 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"); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]