Browse Source

resourceexists condition

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@806790 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
52f34ecb83
5 changed files with 114 additions and 0 deletions
  1. +2
    -0
      WHATSNEW
  2. +15
    -0
      docs/manual/CoreTasks/conditions.html
  3. +56
    -0
      src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java
  4. +2
    -0
      src/main/org/apache/tools/ant/types/conditions/antlib.xml
  5. +39
    -0
      src/tests/antunit/taskdefs/condition/resourceexists-test.xml

+ 2
- 0
WHATSNEW View File

@@ -875,6 +875,8 @@ Other changes:
* The <resources> resource collection can now optionally cache its
contents.

* A new <resourceexists> condition can check whether resources exists.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 15
- 0
docs/manual/CoreTasks/conditions.html View File

@@ -1057,5 +1057,20 @@ is redundant and will be ignored.</p>
&lt;file file="${file}"/&gt;
&lt;/islastmodified&gt;
</pre></blockquote>

<h4>resourceexists</h4>

<p>Tests a resource for existance. <em>since Ant 1.8.0</em></p>

<p>The actual resource to test is specified as a nested element.</p>

<p>
An example:
</p>
<blockquote><pre>
&lt;resourceexists&gt;
&lt;file file="${file}"/&gt;
&lt;/resourceexists&gt;
</pre></blockquote>
</body>
</html>

+ 56
- 0
src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java View File

@@ -0,0 +1,56 @@
/*
* 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.
*
*/

package org.apache.tools.ant.taskdefs.condition;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.types.Resource;

/**
* Condition that checks whether a given resource exists.
*
* @since Ant 1.8.0
*/
public class ResourceExists extends ProjectComponent implements Condition {
private Resource resource;

/**
* The resource to test.
*/
public void add(Resource r) {
if (resource != null) {
throw new BuildException("only one resource can be tested");
}
resource = r;
}

/**
* Argument validation.
*/
protected void validate() throws BuildException {
if (resource == null) {
throw new BuildException("resource is required");
}
}

public boolean eval() throws BuildException {
validate();
return resource.isExists();
}
}

+ 2
- 0
src/main/org/apache/tools/ant/types/conditions/antlib.xml View File

@@ -76,6 +76,8 @@
classname="org.apache.tools.ant.taskdefs.condition.Os"/>
<typedef name="parsersupports" onerror="ignore"
classname="org.apache.tools.ant.taskdefs.condition.ParserSupports"/>
<typedef name="resourceexists" onerror="ignore"
classname="org.apache.tools.ant.taskdefs.condition.ResourceExists"/>
<typedef name="resourcesmatch" onerror="ignore"
classname="org.apache.tools.ant.taskdefs.condition.ResourcesMatch"/>
<typedef name="resourcecontains" onerror="ignore"


+ 39
- 0
src/tests/antunit/taskdefs/condition/resourceexists-test.xml View File

@@ -0,0 +1,39 @@
<?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"
xmlns:cond="antlib:org.apache.tools.ant.types.conditions">

<import file="../../antunit-base.xml"/>

<target name="test-yes">
<au:assertTrue>
<cond:resourceexists>
<file file="resourceexists-test.xml"/>
</cond:resourceexists>
</au:assertTrue>
</target>

<target name="test-no">
<au:assertFalse>
<cond:resourceexists>
<file file="resourceexists-test-not-there.xml"/>
</cond:resourceexists>
</au:assertFalse>
</target>

</project>

Loading…
Cancel
Save