ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nico Seessle" <Nico.Sees...@epost.de>
Subject Re: [PATCH] New <case> task
Date Thu, 12 Oct 2000 07:54:18 GMT
----- Original Message -----
From: "Jose Alberto Fernandez" <JFernandez@viquity.com>
To: <ant-dev@jakarta.apache.org>
Sent: Wednesday, October 11, 2000 9:01 PM
Subject: RE: [PATCH] New <case> task


> Nico, please do not misunderstand me. I am all for having the scripting
> tasks. The only thing I was commenting about was on having to use
scripting
> just to be able to find the value of a property. That is where I disagree
> scriptig must be the required tool.
>
> I am also not sure, whether the current <script> gives the proper
highlevel
> access, or whether it is too low-level. I confess, I have not used
<script>
> at all, but what I saw on e-mails, it seem to require knowledge about ANTs
> architecture, knowledge that regular users should not need to have, as
> opposed to developers.
>
I think I would define it as low-level since it is possible to override
properties which are already set (which will ant not do normally). For the
knowledge needed I wouldn't think there is more knowledge required than for
writing a task which does the same (ok, you need to know javascript-syntax).

> Could you show us how to write a generic script that does what the <case>
> task is doing? The input is a property and a list of value property pairs.
>

Quick hack:

<?xml version="1.0" encoding="utf-8"?>
<project name="myProject" default="default" basedir=".">
  <target name="default">

    <echo message="prop.name: ${prop.name}"/>

    <script language="javascript"> <![CDATA[
        var myProperty = myProject.getProperty('prop.name');
     if      (myProperty == 'oracle') myProject.setProperty('runOnOracle',
'true');
        else if (myProperty == 'sybase')
myProject.setProperty('runOnSybase', 'true');
        else if (myProperty == 'informix')
myProject.setProperty('runOnInformix', 'true');
        else {
          failTask = myProject.createTask('fail');
          failTask.setMessage('Unknown Database specified (' + myProperty +
')');
          failTask.execute();
        }
    ]]></script>

    <echo message="Oracle: ${runOnOracle}"/>
    <echo message="Informix: ${runOnInformix}"/>
    <echo message="Sybase: ${runOnSybase}"/>

  </target>
</project>

Gives you (the first one is a bit ugly, but this may be my fault or can be
fixed...):

C:\VAMOS50\SourceExt\test>ant -buildfile test9.xml
Buildfile: test9.xml

default:
prop.name: ${prop.name}

BUILD FAILED

test9.xml:13: Unknown Database specified (null)
Unknown Database specified (null)
        at org.apache.tools.ant.taskdefs.Exit.execute(Exit.java:74)
        at java.lang.reflect.Method.invoke(Native Method)
        at
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:21
6)
        at
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1216)
        at org.mozilla.javascript.gen.c1.call(<ANT>:8)
        at org.mozilla.javascript.gen.c1.exec(<ANT>)
        at org.mozilla.javascript.Context.evaluateReader(Context.java:741)
        at org.mozilla.javascript.Context.evaluateString(Context.java:705)
        at
com.ibm.bsf.engines.javascript.JavaScriptEngine.eval(JavaScriptEngine
.java:82)
        at com.ibm.bsf.util.BSFEngineImpl.exec(BSFEngineImpl.java:112)
        at com.ibm.bsf.BSFManager.exec(BSFManager.java:482)
        at
org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:110
)
        at org.apache.tools.ant.Target.execute(Target.java:142)
        at org.apache.tools.ant.Project.runTarget(Project.java:818)
        at org.apache.tools.ant.Project.executeTarget(Project.java:532)
        at org.apache.tools.ant.Project.executeTargets(Project.java:506)
        at org.apache.tools.ant.Main.runBuild(Main.java:400)
        at org.apache.tools.ant.Main.main(Main.java:130)

Total time: 1 second
Unknown Database specified (null)

C:\VAMOS50\SourceExt\test>ant -buildfile test9.xml -Dprop.name=oracle
Buildfile: test9.xml

default:
prop.name: oracle
Oracle: true
Informix: ${runOnInformix}
Sybase: ${runOnSybase}

BUILD SUCCESSFUL

Total time: 1 second
C:\VAMOS50\SourceExt\test>ant -buildfile test9.xml -Dprop.name=sybase
Buildfile: test9.xml

default:
prop.name: sybase
Oracle: ${runOnOracle}
Informix: ${runOnInformix}
Sybase: true

BUILD SUCCESSFUL

Total time: 1 second
C:\VAMOS50\SourceExt\test>ant -buildfile test9.xml -Dprop.name=informix
Buildfile: test9.xml

default:
prop.name: informix
Oracle: ${runOnOracle}
Informix: true
Sybase: ${runOnSybase}

BUILD SUCCESSFUL

Total time: 1 second


Mime
View raw message