ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "W. Sean Hennessy" <shenne...@goldenhourdata.com>
Subject RE: array in ant
Date Mon, 02 Jun 2003 20:48:11 GMT
See below example of alternate method for driving target parameters from
input file.

= begin file "build-this.xml" =======
<?xml version="1.0"?>
<project name="newparmvalue" default="try.anttask.input" basedir=".">
    <description>
    build-this.xml
    Sample demonstrating parsing line input as ant task parameter from text
file.
    needs bsf.jar and rhino.jar.
    </description>
<target name="try.anttask.input" >
  <script language="javascript"> <![CDATA[
        importPackage(Packages.org.apache.tools.ant.types);
        importPackage(Packages.org.apache.tools.ant.taskdefs);
        importPackage(java.util);
        importPackage(java.io);

        theFile = new File("canned-user-input.txt");

        tBufferedReader = new java.io.BufferedReader(new
FileReader(theFile));
        tstrUserInput = new java.lang.String();
        prj = self.getProject();
        echo = prj.createTask("echo");
        echo.setMessage(" ================== try.antask.input Start");
        echo.execute();
        tstrUserInput = tBufferedReader.readLine();
        while( tstrUserInput!= null)
        {
        antcall=project.createTask("antcall");
        antcall.init();
        antcall.setTarget("proc.antask.input");
        antcallParam=antcall.createParam();
        antcallParam.setName("proc.antask.input.parm");
        antcallParam.setValue( tstrUserInput );
        antcall.execute();
        tstrUserInput = tBufferedReader.readLine();
        }//eoif
        echo.setMessage(" ================== try.antask.input End");
        echo.execute();
        tBufferedReader.close();
        /**
        */

    ]]> </script>
</target>
<target name="proc.antask.input" >
   <echo message="proc.antask.input with ${proc.antask.input.parm}"/>
</target>
</project>
= end file "build-this.xml" ========


= begin file "build.cmd" =======
:: build.cmd
:: Win2K command file
set CLASSPATH=C:\Tools\bsf-2_2\lib\bsf.jar;C:\Tools\rhino1_5R4_1\rhino.jar
ant -buildfile build-this.xml -logfile build-dbg.log

::EOF
= end file "build.cmd" ===============


= begin file "canned-user-input.txt" =======
Line one of user input.
Line two of same user input.
Last line of input.
= end file "canned-user-input.txt" ========


= begin file "build-dbg.log" ===============

try.anttask.input:
     [echo]  ================== try.antask.input Start

proc.antask.input:
     [echo] proc.antask.input with Line one of user input.

proc.antask.input:
     [echo] proc.antask.input with Line two of same user input.

proc.antask.input:
     [echo] proc.antask.input with Last line of input.
     [echo]  ================== try.antask.input End

BUILD SUCCESSFUL
Total time: 2 seconds
= end file "build-dbg.log" ===============


-----Original Message-----
From: Xiaohong Wang [mailto:xwang@esri.com]
Sent: Monday, June 02, 2003 10:04 AM
To: 'user@ant.apache.org'
Subject: array in ant


hello,

I need to create an array in ant build process. I was using <input
message="Enter Foo Name:" addproperty="FooName" /> to get the Foo Name and
loop through it to try to get the list of Foo Name. However in ant,
properties are immutable, so it can't be changed once it first time be set.
So what I get is always the first time  input value.  I try not to write
custom task here. Is this something that has to be done in custom task or is
there any way to use built-in task? Appreciate any help.

Thanks
Xiao



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org




Mime
View raw message