ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scotte Zinn" <sz...@patronix.com>
Subject RE: [PATCH] New <case> task
Date Thu, 12 Oct 2000 10:21:33 GMT
The example you gave doesn't seem, to me, to be a real-world example.  When
Ant is invoked, the property prop.name has to be set to one of the three
values.  Why not set the other properties at that time?  It doesn't make
sense to me to add the complexity of scripting (not the implementation of it
in Ant, rather the use of it in everyone's build scripts and the added
maintenance required to support the build scripts) to Ant.  Scripting is
much better handled by a wrapper script that builds up the appropriate
environment and then invokes Ant.

In fact, here is an equivalent implementation of the script without a
script.

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

  <!-- Load the build properties from the specified file -->
  <property file="${prop.name}.properties"/>

  <target name="no_default_check" unless="default.set">
    <fail message="Unknown database specified: ${prop.name}"/>
  </target>

  <target name="default" depends="no_default_check">
    <echo message="Oracle: ${runOnOracle}"/>
    <echo message="Informix: ${runOnInformix}"/>
    <echo message="Sybase: ${runOnSybase}"/>
  </target>
</project>

There are configuration files runOnOracle.properties,
runOnInformix.properties, runOnSybase.properties.  Support for added
environments can be added by adding a new .properties file rather than
having to mess with embedded scripts.

The file runOnOracle.properties contains:

runOnOracle=true
default.set=true

A lot of the asking for scripts seems to be the requirement for a
conditional setting of properties, which is getting around the fact that
properties are executed at parse time, rather than at execute time.  It
seems to me that keeping the fact that properties, once set, cannot be
changed is good, but having properties be defined at execute time would be a
powerful addition.  It would also remove the "special" execution rules from
property, making it more like all the other tasks.

Another alternative to scripting:  Put the stuff you would put into a script
into a .java file by itself and make that class into a task via taskdef and
then execute it as part of your build.xml processing.

In any case, IMHO adding scripting to Ant would be a really bad thing.  Read
the first paragraph in the introduction to Ant.

	"Ant is a Java based build tool. In theory it is kind of like make without
make's wrinkles."

Scripting is just one of those many wrinkles.

-- Scotte

-----Original Message-----
From: Nico Seessle [mailto:Nico.Seessle@epost.de]
Sent: Thursday, October 12, 2000 3:54 AM
To: ant-dev@jakarta.apache.org
Subject: Re: [PATCH] New <case> task


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