You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Andy Stevens <in...@googlemail.com> on 2008/07/01 19:09:16 UTC

Re: Is it possible to run a target for each file in a fileset?

2008/6/26 Andy Stevens <in...@googlemail.com>:
> Another possiblity I was wondering about, given jslint is itself
> written in javascript, was using the <script> optional task to run it
> rather than calling Rhino.  Ideally, I'd use the src attribute to read
> in an unmodified jslint.js then some inline javascript to set up
> various options and call it.  Can that be done in a single <script>
> task, though? i.e. would it read/execute the external src file and
> then execute the inline script as well?  Or, if I use more than one
> <script> task in a target (one using src, one with the inline script)
> would the objects/functions defined in the first one still be
> available in the subsequent task or does each one run in a completely
> separate/clean context?

To answer my own questions, in case anyone else is interested...

        <script language="javascript"><![CDATA[
            function helloWorld() {
                var echo = project.createTask("echo");
                echo.setMessage("Hello World");
                echo.perform();
            }
        ]]></script>
        <script language="javascript"><![CDATA[
            helloWorld();
        ]]></script>
produces the error
javax.script.ScriptException:
sun.org.mozilla.javascript.internal.EcmaError: ReferenceError:
"helloWorld" is not defined. (<Unknown source>#2) in <Unknown source>
at line number 2
so I conclude that each script task does indeed start with a blank slate.

Moving the function definition into a separate file and trying
        <script language="javascript" src="lib/test/test.js"><![CDATA[
            helloWorld();
        ]]></script>
gave the error
build.xml:136: file lib\test\test.js not found.
which is interesting since passing "lib/test/jslint.js" as the first
(<arg value=...) argument to Rhino (in my previous <java> task) worked
okay.  However,
        <script language="javascript"
src="${basedir}/lib/test/test.js"><![CDATA[
            helloWorld();
        ]]></script>
successfully wrote "Hello World" to the console.

So, my next step is to pull in JSLint's fulljslint.js using the src
attribute, and write a nested "Ant companion" script that allows the
various available options to be set before calling it.
One more question - I see in the Ant manual how to dynamically create
a fileset within the script, and also that the task supports a nested
<classpath> element.  Is it possible, though, to have a nested fileset
and access that via the self object?


Andy.
-- 
http://pseudoq.sourceforge.net/  Open source java Sudoku application

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