Author: bodewig
Date: Mon Oct 5 04:18:34 2009
New Revision: 821676
URL: http://svn.apache.org/viewvc?rev=821676&view=rev
Log:
Make fail task use the same if/unless logic as target
Added:
ant/core/trunk/src/tests/antunit/taskdefs/fail-test.xml (with props)
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Exit.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Exit.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Exit.java?rev=821676&r1=821675&r2=821676&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Exit.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Exit.java Mon Oct 5
04:18:34 2009
@@ -19,6 +19,7 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExitStatusException;
@@ -59,7 +60,7 @@
}
private String message;
- private String ifCondition, unlessCondition;
+ private Object ifCondition, unlessCondition;
private NestedCondition nestedCondition;
private Integer status;
@@ -73,23 +74,44 @@
}
/**
- * Only fail if a property of the given name exists in the current project.
- * @param c property name
+ * Only fail if the given expression evaluates to true or the name
+ * of an existing property.
+ * @param c property name or evaluated expression
+ * @since Ant 1.8.0
*/
- public void setIf(String c) {
+ public void setIf(Object c) {
ifCondition = c;
}
/**
- * Only fail if a property of the given name does not
- * exist in the current project.
- * @param c property name
+ * Only fail if the given expression evaluates to true or the name
+ * of an existing property.
+ * @param c property name or evaluated expression
*/
- public void setUnless(String c) {
+ public void setIf(String c) {
+ setIf((Object) c);
+ }
+
+ /**
+ * Only fail if the given expression evaluates to false or tno
+ * property of the given name exists.
+ * @param c property name or evaluated expression
+ * @since Ant 1.8.0
+ */
+ public void setUnless(Object c) {
unlessCondition = c;
}
/**
+ * Only fail if the given expression evaluates to false or tno
+ * property of the given name exists.
+ * @param c property name or evaluated expression
+ */
+ public void setUnless(String c) {
+ setUnless((Object) c);
+ }
+
+ /**
* Set the status code to associate with the thrown Exception.
* @param i the <code>int</code> status
*/
@@ -117,12 +139,10 @@
if (message != null && message.trim().length() > 0) {
text = message.trim();
} else {
- if (ifCondition != null && ifCondition.length() > 0
- && getProject().getProperty(ifCondition) != null) {
+ if (!testIfCondition()) {
text = "if=" + ifCondition;
}
- if (unlessCondition != null && unlessCondition.length() > 0
- && getProject().getProperty(unlessCondition) == null) {
+ if (!testUnlessCondition()) {
if (text == null) {
text = "";
} else {
@@ -173,10 +193,8 @@
* @return true if there is no if condition, or the named property exists
*/
private boolean testIfCondition() {
- if (ifCondition == null || "".equals(ifCondition)) {
- return true;
- }
- return getProject().getProperty(ifCondition) != null;
+ return PropertyHelper.getPropertyHelper(getProject())
+ .testIfCondition(ifCondition);
}
/**
@@ -185,10 +203,8 @@
* or there is a named property but it doesn't exist
*/
private boolean testUnlessCondition() {
- if (unlessCondition == null || "".equals(unlessCondition)) {
- return true;
- }
- return getProject().getProperty(unlessCondition) == null;
+ return PropertyHelper.getPropertyHelper(getProject())
+ .testUnlessCondition(unlessCondition);
}
/**
Added: ant/core/trunk/src/tests/antunit/taskdefs/fail-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/fail-test.xml?rev=821676&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/fail-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/fail-test.xml Mon Oct 5 04:18:34
2009
@@ -0,0 +1,46 @@
+<?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 name="echo-test" default="antunit"
+ xmlns:au="antlib:org.apache.ant.antunit">
+ <import file="../antunit-base.xml" />
+
+ <target name="testIfNotSet">
+ <au:expectfailure>
+ <fail unless="${if}"/>
+ </au:expectfailure>
+ <fail if="${if}"/>
+ </target>
+
+ <target name="testIfTrue">
+ <property name="if" value="true"/>
+ <fail unless="${if}"/>
+ <au:expectfailure>
+ <fail if="${if}"/>
+ </au:expectfailure>
+ </target>
+
+ <target name="testIfFalse">
+ <property name="if" value="false"/>
+ <au:expectfailure>
+ <fail unless="${if}"/>
+ </au:expectfailure>
+ <fail if="${if}"/>
+ </target>
+
+</project>
Propchange: ant/core/trunk/src/tests/antunit/taskdefs/fail-test.xml
------------------------------------------------------------------------------
svn:eol-style = native