Browse Source

revert broken stuff

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@668698 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 17 years ago
parent
commit
ebff9b41e5
4 changed files with 5 additions and 196 deletions
  1. +0
    -2
      WHATSNEW
  2. +3
    -11
      src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
  3. +2
    -2
      src/main/org/apache/tools/ant/types/optional/ScriptCondition.java
  4. +0
    -181
      src/tests/antunit/types/scriptcondition-test.xml

+ 0
- 2
WHATSNEW View File

@@ -98,8 +98,6 @@ 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.

* <java> with fork now returns gives -1 instead of 0 as result when failonerror * <java> with fork now returns gives -1 instead of 0 as result when failonerror
is false and some exception (including timeout) occurs. Br 42377. is false and some exception (including timeout) occurs. Br 42377.




+ 3
- 11
src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java View File

@@ -17,8 +17,6 @@
*/ */
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;
@@ -26,6 +24,9 @@ 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.
@@ -140,13 +141,4 @@ 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);
}
} }

+ 2
- 2
src/main/org/apache/tools/ant/types/optional/ScriptCondition.java View File

@@ -43,8 +43,8 @@ public class ScriptCondition extends AbstractScriptComponent implements Conditio
*/ */
public boolean eval() throws BuildException { public boolean eval() throws BuildException {
initScriptRunner(); initScriptRunner();
Object result = evaluateScript("ant_condition");
return result instanceof Boolean ? ((Boolean) result).booleanValue() : getValue();
Object result = executeScript("ant_condition");
return getValue();
} }


/** /**


+ 0
- 181
src/tests/antunit/types/scriptcondition-test.xml View File

@@ -1,181 +0,0 @@
<?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="scriptcondition-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
<import file="../antunit-base.xml" />

<macrodef name="t">
<element name="test" implicit="yes" />
<attribute name="message"/>
<sequential>
<au:assertTrue message="query @{message} failed; result was false">
<test />
</au:assertTrue>
</sequential>
</macrodef>

<macrodef name="f">
<element name="test" implicit="yes" />
<attribute name="message"/>
<sequential>
<au:assertFalse message="test @{message} failed; result was true">
<test />
</au:assertFalse>
</sequential>
</macrodef>

<condition property="js.avail">
<available classname="org.mozilla.javascript.EvaluatorException"/>
</condition>

<condition property="beanshell.avail">
<available classname="bsh.BshMethod"/>
</condition>

<!-- this is here to test the macro is well coded -->
<target name="testMacro">
<t message="testMacro">
<istrue value="true"/>
</t>
<f message="testMacro2">
<istrue value="false"/>
</f>
</target>

<target name="testNolanguage">
<au:expectfailure message="Absence of language attribute not detected"
expectedMessage="script language must be specified">
<t message="testNolanguage">
<scriptcondition>
self.setValue(true);
</scriptcondition>
</t>
</au:expectfailure>
</target>

<target name="testClearByDefault" if="js.avail">
<f message="testClearByDefault">
<scriptcondition language="javascript">
</scriptcondition>
</f>
</target>

<target name="testValueWorks" if="js.avail">
<t message="testValueWorks">
<scriptcondition language="javascript" value="true" />
</t>
</target>

<target name="testSetWorks" if="js.avail">
<t message="testSetWorks">
<scriptcondition language="javascript" value="false">
self.setValue(true);
</scriptcondition>
</t>
</target>

<target name="testClearWorks" if="js.avail">
<f message="testClearWorks">
<scriptcondition language="javascript" value="true">
self.setValue(false);
</scriptcondition>
</f>
</target>

<target name="testBeanshellReturnTrue" if="beanshell.avail">
<t message="testBeanshellReturnTrue">
<scriptcondition language="beanshell" value="false">
return true;
</scriptcondition>
</t>
</target>

<target name="testBeanshellReturnFalse" if="beanshell.avail">
<f message="testBeanshellReturnFalse">
<scriptcondition language="beanshell" value="true">
return false;
</scriptcondition>
</f>
</target>

<target name="testBeanshellReturnOverridesValue" if="beanshell.avail">
<f message="testBeanshellReturnOverridesValue">
<scriptcondition language="beanshell" value="false">
self.setValue(true);
return false;
</scriptcondition>
</f>
</target>

<target name="testBeanshellReturnNullIgnored" if="beanshell.avail">
<t message="testBeanshellReturnNullIgnored">
<scriptcondition language="beanshell" value="true">
return null;
</scriptcondition>
</t>
</target>

<target name="testBeanshellReturnNonBooleanIgnored" if="beanshell.avail">
<t message="testBeanshellReturnNonBooleanIgnored">
<scriptcondition language="beanshell" value="true">
return 20;
</scriptcondition>
</t>
</target>

<target name="testJsReturnTrue" if="js.avail">
<t message="testJsReturnTrue">
<scriptcondition language="javascript" value="false">
java.lang.Boolean.TRUE
</scriptcondition>
</t>
</target>

<target name="testJsReturnFalse" if="js.avail">
<f message="testJsReturnFalse">
<scriptcondition language="javascript" value="true">
java.lang.Boolean.FALSE
</scriptcondition>
</f>
</target>

<target name="testJsReturnOverridesValue" if="js.avail">
<f message="testJsReturnOverridesValue">
<scriptcondition language="javascript" value="false">
self.setValue(true);
false
</scriptcondition>
</f>
</target>

<target name="testJsReturnNullIgnored" if="js.avail">
<t message="testJsReturnNullIgnored">
<scriptcondition language="javascript" value="true">
null
</scriptcondition>
</t>
</target>

<target name="testJsReturnNonBooleanIgnored" if="js.avail">
<t message="testJsReturnNonBooleanIgnored">
<scriptcondition language="javascript" value="true">
new java.lang.Integer(20)
</scriptcondition>
</t>
</target>

</project>

Loading…
Cancel
Save