git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@806790 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -875,6 +875,8 @@ Other changes: | |||||
| * The <resources> resource collection can now optionally cache its | * The <resources> resource collection can now optionally cache its | ||||
| contents. | contents. | ||||
| * A new <resourceexists> condition can check whether resources exists. | |||||
| Changes from Ant 1.7.0 TO Ant 1.7.1 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
| ============================================= | ============================================= | ||||
| @@ -1057,5 +1057,20 @@ is redundant and will be ignored.</p> | |||||
| <file file="${file}"/> | <file file="${file}"/> | ||||
| </islastmodified> | </islastmodified> | ||||
| </pre></blockquote> | </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> | |||||
| <resourceexists> | |||||
| <file file="${file}"/> | |||||
| </resourceexists> | |||||
| </pre></blockquote> | |||||
| </body> | </body> | ||||
| </html> | </html> | ||||
| @@ -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(); | |||||
| } | |||||
| } | |||||
| @@ -76,6 +76,8 @@ | |||||
| classname="org.apache.tools.ant.taskdefs.condition.Os"/> | classname="org.apache.tools.ant.taskdefs.condition.Os"/> | ||||
| <typedef name="parsersupports" onerror="ignore" | <typedef name="parsersupports" onerror="ignore" | ||||
| classname="org.apache.tools.ant.taskdefs.condition.ParserSupports"/> | 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" | <typedef name="resourcesmatch" onerror="ignore" | ||||
| classname="org.apache.tools.ant.taskdefs.condition.ResourcesMatch"/> | classname="org.apache.tools.ant.taskdefs.condition.ResourcesMatch"/> | ||||
| <typedef name="resourcecontains" onerror="ignore" | <typedef name="resourcecontains" onerror="ignore" | ||||
| @@ -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> | |||||