stevel 2004/01/22 10:02:57 Modified: src/main/org/apache/tools/ant/taskdefs/condition ConditionBase.java docs/manual/CoreTasks conditions.html . WHATSNEW Added: src/testcases/org/apache/tools/ant/taskdefs/condition TypeFoundTest.java src/main/org/apache/tools/ant/taskdefs/condition TypeFound.java src/etc/testcases/taskdefs/conditions typefound.xml Log: new condition: typefound Revision Changes Path 1.1 ant/src/testcases/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java Index: TypeFoundTest.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "Ant" and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.tools.ant.taskdefs.condition; import org.apache.tools.ant.BuildFileTest; /** * test the typeexists condition */ public class TypeFoundTest extends BuildFileTest { public TypeFoundTest(String name) { super(name); } /** * The JUnit setup method */ public void setUp() { configureProject("src/etc/testcases/taskdefs/conditions/typefound.xml"); } public void testTask() { expectPropertySet("testTask", "testTask"); } public void testUndefined() { expectBuildExceptionContaining("testUndefined","left out the name attribute", "No type specified"); } public void testTaskThatDoesntReallyExist() { expectPropertyUnset("testTaskThatDoesntReallyExist", "testTaskThatDoesntReallyExist"); } public void testType() { expectPropertySet("testType", "testType"); } public void testPreset() { expectPropertySet("testPreset", "testPreset"); } public void testMacro() { expectPropertySet("testMacro", "testMacro"); } } 1.23 +8 -1 ant/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java Index: ConditionBase.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- ConditionBase.java 16 Sep 2003 09:08:57 -0000 1.22 +++ ConditionBase.java 22 Jan 2004 18:02:57 -0000 1.23 @@ -253,6 +253,13 @@ } /** + * Add an <typefound> condition. + * @param test + */ + public void addTypeFound(TypeFound test) { + conditions.addElement(test); + } + /** * Add an arbitrary condition * @param c a condition * @since Ant 1.6 1.1 ant/src/main/org/apache/tools/ant/taskdefs/condition/TypeFound.java Index: TypeFound.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "Ant" and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.tools.ant.taskdefs.condition; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.ComponentHelper; import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.AntTypeDefinition; /** * looks for a task or other Ant type that exists. Existence is defined as * the type is defined, and its implementation class is present. This * will work for datatypes and preset, script and macro definitions. */ public class TypeFound extends ProjectComponent implements Condition { private String name; /** * the task or other type to look for * @param name */ public void setName(String name) { this.name = name; } /** * test for a task or other ant type existing in the current project * @param typename * @return true if the typename exists */ protected boolean doesTypeExist(String typename) { ComponentHelper helper=ComponentHelper.getComponentHelper(getProject()); AntTypeDefinition def=helper.getDefinition(typename); if(def==null) { return false; } //now verify that the class has an implementation return def.getExposedClass(getProject())!=null; } /** * Is this condition true? * @return true if the condition is true * @exception BuildException if an error occurs */ public boolean eval() throws BuildException { if(name==null) { throw new BuildException("No type specified"); } return doesTypeExist(name); } } 1.1 ant/src/etc/testcases/taskdefs/conditions/typefound.xml Index: typefound.xml =================================================================== <project name="typefound"> <target name="testTask"> <condition property="testTask"> <typefound name="echo"/> </condition> </target> <target name="testUndefined"> <condition property="testUndefined"> <typefound /> </condition> </target> <target name="testTaskThatDoesntReallyExist"> <!-- <taskdef name="invalid-task-name" classname="org.example.invalid.task.name.hopefully"/> --> <condition property="testTaskThatDoesntReallyExist"> <typefound name="invalid-task-name"/> </condition> </target> <target name="testType"> <condition property="testType"> <typefound name="path"/> </condition> </target> <target name="testPreset"> <presetdef name="important-echo"> <echo level="error"/> </presetdef> <condition property="testPreset"> <typefound name="important-echo"/> </condition> </target> <target name="testMacro"> <macrodef name="error-message"> <element name="text" optional="false"/> <sequential> <echo level="error">@{text}</echo> </sequential> </macrodef> <condition property="testMacro"> <typefound name="error-message"/> </condition> </target> </project> 1.21 +21 -0 ant/docs/manual/CoreTasks/conditions.html Index: conditions.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/conditions.html,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- conditions.html 14 Aug 2003 14:06:54 -0000 1.20 +++ conditions.html 22 Jan 2004 18:02:57 -0000 1.21 @@ -326,6 +326,27 @@ </tr> </table> +<h4>typefound</h4> + +<p>Test whether a given type is defined, and that +its implementation class can be loaded. Types include +tasks, datatypes, scriptdefs, macrodefs and presetdefs.</p> + +<p>This condition has been added in Apache Ant 1.7.</p> + +<table border="1" cellpadding="2" cellspacing="0"> + <tr> + <td valign="top"><b>Attribute</b></td> + <td valign="top"><b>Description</b></td> + <td align="center" valign="top"><b>Required</b></td> + </tr> + <tr> + <td valign="top">name</td> + <td valign="top">name of the type</td> + <td valign="top" align="center">Yes</td> + </tr> +</table> + <hr> <p align="center">Copyright © 2001-2003 Apache Software Foundation. All rights Reserved.</p> 1.529 +6 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.528 retrieving revision 1.529 diff -u -r1.528 -r1.529 --- WHATSNEW 21 Jan 2004 12:55:53 -0000 1.528 +++ WHATSNEW 22 Jan 2004 18:02:57 -0000 1.529 @@ -55,6 +55,12 @@ - Added three new ClearCase commands: ccmkattr, ccmkdir, ccmkelem Bugzilla Report 26253. +* New condition <typefound> that can be used to probe for the declaration + and implementation of a task, type, preset, macro, scriptdef, whatever. + As it tests for the implementation, it can be used to check for optional + tasks being available. + + Changes from Ant 1.5.4 to Ant 1.6.0 ===================================
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]