diff --git a/WHATSNEW b/WHATSNEW index aadefeb4a..c2c85db2d 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -211,7 +211,9 @@ Other changes: As it tests for the implementation, it can be used to check for optional tasks being available. -* check for 1.5.* ant main class. (weblogic.jar in classpath reports) +* check for 1.5.* Ant main class. (weblogic.jar in classpath reports) + +* New condition that tests the return-code of an executable. Changes from Ant 1.6.3 to Ant 1.6.4 =================================== diff --git a/docs/manual/CoreTasks/conditions.html b/docs/manual/CoreTasks/conditions.html index 84802601e..e82d5e3e8 100644 --- a/docs/manual/CoreTasks/conditions.html +++ b/docs/manual/CoreTasks/conditions.html @@ -640,6 +640,24 @@ Verify a file is not empty: <length file="foo" when="greater" length="0"/> +

isfailure

+ +

Test the return code of an executable (see +<exec>) for failure. Since Ant 1.7

+ + + + + + + + + + + + +
AttributeDescriptionRequired
codeThe return code to test.Yes
+

Copyright © 2001-2005 Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/taskdefs/conditions/isfailure.xml b/src/etc/testcases/taskdefs/conditions/isfailure.xml new file mode 100644 index 000000000..798a5489a --- /dev/null +++ b/src/etc/testcases/taskdefs/conditions/isfailure.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/IsFailure.java b/src/main/org/apache/tools/ant/taskdefs/condition/IsFailure.java new file mode 100755 index 000000000..e5a1eaae0 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/condition/IsFailure.java @@ -0,0 +1,53 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed 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.taskdefs.Execute; + +/** + * Condition to test a return-code for failure. + * @since Ant 1.7 + */ +public class IsFailure implements Condition { + private int code; + + /** + * Set the return code to check. + * @param c the return code. + */ + public void setCode(int c) { + code = c; + } + + /** + * Get the return code that will be checked by this IsFailure condition. + * @return return code as int. + */ + public int getCode() { + return code; + } + + /** + * Fulfill the condition interface. + * @return the result of evaluating the specified return code. + */ + public boolean eval() { + return Execute.isFailure(code); + } + +} diff --git a/src/main/org/apache/tools/ant/types/defaults.properties b/src/main/org/apache/tools/ant/types/defaults.properties index c1bbf5219..d1d1fa9c6 100644 --- a/src/main/org/apache/tools/ant/types/defaults.properties +++ b/src/main/org/apache/tools/ant/types/defaults.properties @@ -44,3 +44,4 @@ scriptcondition=org.apache.tools.ant.types.optional.ScriptCondition xor=org.apache.tools.ant.taskdefs.condition.Xor parsersupports=org.apache.tools.ant.taskdefs.condition.ParserSupports scriptmapper=org.apache.tools.ant.types.optional.ScriptMapper +isfailure=org.apache.tools.ant.taskdefs.condition.IsFailure diff --git a/src/testcases/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java b/src/testcases/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java new file mode 100755 index 000000000..86b2f3f35 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed 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.BuildFileTest; + +/** + * Testcases for the <isfailure> condition. + * + */ +public class IsFailureTest extends BuildFileTest { + + public IsFailureTest(String name) { + super(name); + } + + /** + * The JUnit setup method + */ + public void setUp() { + configureProject("src/etc/testcases/taskdefs/conditions/isfailure.xml"); + } + + public void testIsFailure() { + executeTarget("testisfailure"); + } + +}