Browse Source

Bugzilla 39549: available should not search parent directories

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@443456 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 19 years ago
parent
commit
b971cbef85
4 changed files with 21 additions and 25 deletions
  1. +3
    -0
      WHATSNEW
  2. +2
    -2
      docs/manual/CoreTasks/available.html
  3. +12
    -10
      src/etc/testcases/taskdefs/available.xml
  4. +4
    -13
      src/main/org/apache/tools/ant/taskdefs/Available.java

+ 3
- 0
WHATSNEW View File

@@ -36,6 +36,9 @@ Fixed bugs:
* documented minimal version of jsch now 0.1.29. * documented minimal version of jsch now 0.1.29.
Bugzilla report 40333. Bugzilla report 40333.


* <available> searched parent directories for files.
Bugzilla report 37148.

Other changes: Other changes:
-------------- --------------




+ 2
- 2
docs/manual/CoreTasks/available.html View File

@@ -96,10 +96,10 @@ execution depending on system parameters.</p>
<td valign="top">This contains the behaviour of the "file" type. <td valign="top">This contains the behaviour of the "file" type.
If true, the available task will, when If true, the available task will, when
searching for a file, search not only the directories specified but searching for a file, search not only the directories specified but
will also search the parent and grandparent directories of those
will also search the parent directories of those
specified. specified.
If false, only the directories specified will be searched. If false, only the directories specified will be searched.
Defaults to "true".
Defaults to "false".
<em>Since Ant 1.7</em> <em>Since Ant 1.7</em>
</td> </td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>


+ 12
- 10
src/etc/testcases/taskdefs/available.xml View File

@@ -177,13 +177,15 @@
value="greatgrandparent/grandparent/parent/dir"/> value="greatgrandparent/grandparent/parent/dir"/>
</target> </target>
<target name="search-parents" depends="prep.parents"> <target name="search-parents" depends="prep.parents">
<echo>testing greatgrandparent - should not see</echo>
<echo>testing greatgrandparent - should see</echo>


<fail> <fail>
<condition> <condition>
<available file="a.txt">
<filepath path="${available.test.dir}"/>
</available>
<not>
<available file="a.txt" searchparents="yes">
<filepath path="${available.test.dir}"/>
</available>
</not>
</condition> </condition>
</fail> </fail>


@@ -191,7 +193,7 @@
<fail> <fail>
<condition> <condition>
<not> <not>
<available file="b.txt">
<available file="b.txt" searchparents="yes">
<filepath path="${available.test.dir}"/> <filepath path="${available.test.dir}"/>
</available> </available>
</not> </not>
@@ -202,7 +204,7 @@
<fail> <fail>
<condition> <condition>
<not> <not>
<available file="c.txt">
<available file="c.txt" searchparents="yes">
<filepath path="${available.test.dir}"/> <filepath path="${available.test.dir}"/>
</available> </available>
</not> </not>
@@ -213,7 +215,7 @@
<fail> <fail>
<condition> <condition>
<not> <not>
<available file="d.txt">
<available file="d.txt" searchparents="yes">
<filepath path="${available.test.dir}"/> <filepath path="${available.test.dir}"/>
</available> </available>
</not> </not>
@@ -226,7 +228,7 @@
<echo>testing grandparent - should not see</echo> <echo>testing grandparent - should not see</echo>
<fail> <fail>
<condition> <condition>
<available file="b.txt" searchParents="no">
<available file="b.txt">
<filepath path="${available.test.dir}"/> <filepath path="${available.test.dir}"/>
</available> </available>
</condition> </condition>
@@ -235,7 +237,7 @@
<echo>testing parent - should not see</echo> <echo>testing parent - should not see</echo>
<fail> <fail>
<condition> <condition>
<available file="c.txt" searchParents="false">
<available file="c.txt">
<filepath path="${available.test.dir}"/> <filepath path="${available.test.dir}"/>
</available> </available>
</condition> </condition>
@@ -245,7 +247,7 @@
<fail> <fail>
<condition> <condition>
<not> <not>
<available file="d.txt" searchParents="false">
<available file="d.txt">
<filepath path="${available.test.dir}"/> <filepath path="${available.test.dir}"/>
</available> </available>
</not> </not>


+ 4
- 13
src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -53,14 +53,14 @@ 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;
private boolean searchParents = false;


/** /**
* Set the searchParents attribute. * Set the searchParents attribute.
* This controls the behaviour of the the "file" type. * This controls the behaviour of the the "file" type.
* If true, the path, parent path and grandparent path are * If true, the path, parent path and grandparent path are
* searched for the file. If false, only the path is seached. * searched for the file. If false, only the path is seached.
* The default value is true.
* The default value is false.
* @param searchParents the value to set. * @param searchParents the value to set.
*/ */
public void setSearchParents(boolean searchParents) { public void setSearchParents(boolean searchParents) {
@@ -366,21 +366,12 @@ public class Available extends Task implements Condition {
} }
} }
// ** simple name specified == parent dir + name // ** simple name specified == parent dir + name
if (parent != null && parent.exists() && searchParents) {
while (searchParents && parent != null && parent.exists()) {
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
if (parent != null && searchParents) {
File grandParent = parent.getParentFile();
if (grandParent != null && grandParent.exists()) {
if (checkFile(new File(grandParent, filename),
filename + " in " + grandParent)) {
return true;
}
}
parent = parent.getParentFile();
} }
} }
} }


Loading…
Cancel
Save