git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@551592 13f79535-47bb-0310-9956-ffa450edef68master
@@ -14,6 +14,8 @@ Changes that could break older environments: | |||||
been modified to encode outgoing (InputStream) content as well as encoding | been modified to encode outgoing (InputStream) content as well as encoding | ||||
incoming (OutputStream) content. | incoming (OutputStream) content. | ||||
* <scriptcondition> now prefers evaluation result/return value over value property. | |||||
Fixed bugs: | Fixed bugs: | ||||
----------- | ----------- | ||||
* Regression: Locator fails with URI encoding problem when spaces in path | * Regression: Locator fails with URI encoding problem when spaces in path | ||||
@@ -17,6 +17,8 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.types.optional; | package org.apache.tools.ant.types.optional; | ||||
import java.io.File; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
@@ -24,9 +26,6 @@ import org.apache.tools.ant.types.Reference; | |||||
import org.apache.tools.ant.util.ScriptRunnerBase; | import org.apache.tools.ant.util.ScriptRunnerBase; | ||||
import org.apache.tools.ant.util.ScriptRunnerHelper; | import org.apache.tools.ant.util.ScriptRunnerHelper; | ||||
import java.io.File; | |||||
/** | /** | ||||
* This is a {@link ProjectComponent} that has script support built in | * This is a {@link ProjectComponent} that has script support built in | ||||
* Use it as a foundation for scriptable things. | * Use it as a foundation for scriptable things. | ||||
@@ -141,4 +140,13 @@ public abstract class AbstractScriptComponent extends ProjectComponent { | |||||
protected void executeScript(String execName) { | protected void executeScript(String execName) { | ||||
getRunner().executeScript(execName); | getRunner().executeScript(execName); | ||||
} | } | ||||
/** | |||||
* Evaluate a script. | |||||
* @param execName name of the script. | |||||
* @return the result of the evaluation. | |||||
*/ | |||||
protected Object evaluateScript(String execName) { | |||||
return getRunner().evaluateScript(execName); | |||||
} | |||||
} | } |
@@ -33,7 +33,6 @@ public class ScriptCondition extends AbstractScriptComponent implements Conditio | |||||
*/ | */ | ||||
private boolean value = false; | private boolean value = false; | ||||
/** | /** | ||||
* Is this condition true? | * Is this condition true? | ||||
* | * | ||||
@@ -44,8 +43,8 @@ public class ScriptCondition extends AbstractScriptComponent implements Conditio | |||||
*/ | */ | ||||
public boolean eval() throws BuildException { | public boolean eval() throws BuildException { | ||||
initScriptRunner(); | initScriptRunner(); | ||||
executeScript("ant_condition"); | |||||
return getValue(); | |||||
Object result = evaluateScript("ant_condition"); | |||||
return result instanceof Boolean ? ((Boolean) result).booleanValue() : getValue(); | |||||
} | } | ||||
/** | /** | ||||
@@ -70,4 +70,87 @@ | |||||
</scriptcondition> | </scriptcondition> | ||||
</f> | </f> | ||||
</target> | </target> | ||||
<target name="testBeanshellReturnTrue"> | |||||
<t message="testBeanshellReturnTrue"> | |||||
<scriptcondition language="beanshell" value="false"> | |||||
return true; | |||||
</scriptcondition> | |||||
</t> | |||||
</target> | |||||
<target name="testBeanshellReturnFalse"> | |||||
<f message="testBeanshellReturnFalse"> | |||||
<scriptcondition language="beanshell" value="true"> | |||||
return false; | |||||
</scriptcondition> | |||||
</f> | |||||
</target> | |||||
<target name="testBeanshellReturnOverridesValue"> | |||||
<f message="testBeanshellReturnOverridesValue"> | |||||
<scriptcondition language="beanshell" value="false"> | |||||
self.setValue(true); | |||||
return false; | |||||
</scriptcondition> | |||||
</f> | |||||
</target> | |||||
<target name="testBeanshellReturnNullIgnored"> | |||||
<t message="testBeanshellReturnNullIgnored"> | |||||
<scriptcondition language="beanshell" value="true"> | |||||
return null; | |||||
</scriptcondition> | |||||
</t> | |||||
</target> | |||||
<target name="testBeanshellReturnNonBooleanIgnored"> | |||||
<t message="testBeanshellReturnNonBooleanIgnored"> | |||||
<scriptcondition language="beanshell" value="true"> | |||||
return 20; | |||||
</scriptcondition> | |||||
</t> | |||||
</target> | |||||
<target name="testJsReturnTrue"> | |||||
<t message="testJsReturnTrue"> | |||||
<scriptcondition language="javascript" value="false"> | |||||
java.lang.Boolean.TRUE | |||||
</scriptcondition> | |||||
</t> | |||||
</target> | |||||
<target name="testJsReturnFalse"> | |||||
<f message="testJsReturnFalse"> | |||||
<scriptcondition language="javascript" value="true"> | |||||
java.lang.Boolean.FALSE | |||||
</scriptcondition> | |||||
</f> | |||||
</target> | |||||
<target name="testJsReturnOverridesValue"> | |||||
<f message="testJsReturnOverridesValue"> | |||||
<scriptcondition language="javascript" value="false"> | |||||
self.setValue(true); | |||||
false | |||||
</scriptcondition> | |||||
</f> | |||||
</target> | |||||
<target name="testJsReturnNullIgnored"> | |||||
<t message="testJsReturnNullIgnored"> | |||||
<scriptcondition language="javascript" value="true"> | |||||
null | |||||
</scriptcondition> | |||||
</t> | |||||
</target> | |||||
<target name="testJsReturnNonBooleanIgnored"> | |||||
<t message="testJsReturnNonBooleanIgnored"> | |||||
<scriptcondition language="javascript" value="true"> | |||||
new java.lang.Integer(20) | |||||
</scriptcondition> | |||||
</t> | |||||
</target> | |||||
</project> | </project> |