Browse Source

Bugzilla 39549: add searchparents attribute to <available>

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@440876 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 19 years ago
parent
commit
6820b64345
5 changed files with 129 additions and 3 deletions
  1. +1
    -0
      WHATSNEW
  2. +13
    -1
      docs/manual/CoreTasks/available.html
  3. +91
    -0
      src/etc/testcases/taskdefs/available.xml
  4. +15
    -2
      src/main/org/apache/tools/ant/taskdefs/Available.java
  5. +9
    -0
      src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java

+ 1
- 0
WHATSNEW View File

@@ -32,6 +32,7 @@ Other changes:
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
========================================


+ 13
- 1
docs/manual/CoreTasks/available.html View File

@@ -75,7 +75,19 @@ execution depending on system parameters.</p>
classpath. Only affects the "classname" attribute. Defaults to &quot;false&quot;</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>


+ 91
- 0
src/etc/testcases/taskdefs/available.xml View File

@@ -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>

+ 15
- 2
src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -53,6 +53,19 @@ public class Available extends Task implements Condition {
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 @@ public class Available extends Task implements Condition {
}
}
// ** 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),


+ 9
- 0
src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java View File

@@ -201,4 +201,13 @@ public class AvailableTest extends BuildFileTest {
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");
}
}

Loading…
Cancel
Save