Browse Source

Add isfailure condition.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278314 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
5cf7540ba1
6 changed files with 165 additions and 1 deletions
  1. +3
    -1
      WHATSNEW
  2. +18
    -0
      docs/manual/CoreTasks/conditions.html
  3. +48
    -0
      src/etc/testcases/taskdefs/conditions/isfailure.xml
  4. +53
    -0
      src/main/org/apache/tools/ant/taskdefs/condition/IsFailure.java
  5. +1
    -0
      src/main/org/apache/tools/ant/types/defaults.properties
  6. +42
    -0
      src/testcases/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java

+ 3
- 1
WHATSNEW View File

@@ -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 <isfailure> that tests the return-code of an executable.

Changes from Ant 1.6.3 to Ant 1.6.4
===================================


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

@@ -640,6 +640,24 @@ Verify a file is not empty:
&lt;length file=&quot;foo&quot; when=&quot;greater&quot; length=&quot;0&quot;/&gt;
</pre>

<h4>isfailure</h4>

<p>Test the return code of an executable (see
<a href="exec.html">&lt;exec&gt;</a>) for failure. <b>Since Ant 1.7</b></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">code</td>
<td valign="top">The return code to test.</td>
<td valign="top" align="center">Yes</td>
</tr>
</table>

<hr>
<p align="center">Copyright &copy; 2001-2005 Apache Software
Foundation. All rights Reserved.</p>


+ 48
- 0
src/etc/testcases/taskdefs/conditions/isfailure.xml View File

@@ -0,0 +1,48 @@
<project default="testisfailure">

<target name="testisfailure">
<fail>
<condition>
<or>
<and>
<os family="openvms" />
<or>
<isfailure code="1" />
<isfailure code="3" />
<isfailure code="5" />
<isfailure code="7" />
<isfailure code="9" />
<not>
<and>
<isfailure code="0" />
<isfailure code="2" />
<isfailure code="4" />
<isfailure code="6" />
<isfailure code="8" />
</and>
</not>
</or>
</and>
<and>
<not>
<os family="openvms" />
</not>
<or>
<isfailure code="0" />
<not>
<and>
<isfailure code="1" />
<isfailure code="10" />
<isfailure code="50" />
<isfailure code="100" />
<isfailure code="255" />
</and>
</not>
</or>
</and>
</or>
</condition>
</fail>
</target>

</project>

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

@@ -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);
}

}

+ 1
- 0
src/main/org/apache/tools/ant/types/defaults.properties View File

@@ -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

+ 42
- 0
src/testcases/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java View File

@@ -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 &lt;isfailure&gt; 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");
}

}

Loading…
Cancel
Save