Author: bodewig
Date: Sat Aug 22 05:56:29 2009
New Revision: 806790

URL: http://svn.apache.org/viewvc?rev=806790&view=rev
Log:
resourceexists condition

Added:
    
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java
   (with props)
    ant/core/trunk/src/tests/antunit/taskdefs/condition/resourceexists-test.xml 
  (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/conditions.html
    ant/core/trunk/src/main/org/apache/tools/ant/types/conditions/antlib.xml

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=806790&r1=806789&r2=806790&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Sat Aug 22 05:56:29 2009
@@ -875,6 +875,8 @@
  * 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
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/conditions.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/conditions.html?rev=806790&r1=806789&r2=806790&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/conditions.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/conditions.html Sat Aug 22 05:56:29 
2009
@@ -1057,5 +1057,20 @@
   &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>

Added: 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java?rev=806790&view=auto
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java
 (added)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java
 Sat Aug 22 05:56:29 2009
@@ -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();
+    }
+}

Propchange: 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourceExists.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/types/conditions/antlib.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/conditions/antlib.xml?rev=806790&r1=806789&r2=806790&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/conditions/antlib.xml 
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/conditions/antlib.xml 
Sat Aug 22 05:56:29 2009
@@ -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"

Added: 
ant/core/trunk/src/tests/antunit/taskdefs/condition/resourceexists-test.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/condition/resourceexists-test.xml?rev=806790&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/condition/resourceexists-test.xml 
(added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/condition/resourceexists-test.xml 
Sat Aug 22 05:56:29 2009
@@ -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>

Propchange: 
ant/core/trunk/src/tests/antunit/taskdefs/condition/resourceexists-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to