With <scriptdef> you can define the same task differently in different targets or you can provide the expression as a parameter into that <scriptdef>. <macrodef> with <script> even allows text substitution inside the script text - parameters will be inlined by using @{} notation.

- Alexey.

Marcel Ruff wrote:
Alexey N. Solofnenko wrote:
Can you use <scriptdef> instead? See: http://ant.apache.org/manual/OptionalTasks/scriptdef.html .
i have tried already with no success (probably not hard enough :-),

thanks,
Marcel

- Alexey.

Marcel Ruff wrote:
After fiddling further i have found this workaround:

-----------------
  <target name="pre">
     <script language="javascript">
var expr = 'function doPrecond() { project.log("HELLO PRECOND"); }'
        project.setProperty("expr", expr);
     </script>
  </target>

  <target name="t" depends="pre">
     <script language="javascript">
        eval(""+project.getProperty("expr"));
        doPrecond();
     </script>
  </target>
---------------------

1) Setting a property "expr" to transport the script
2) Executing the script in the calling task "t"
Note that without the ""+ at the beginning of eval() it does not work

I hope this helps others, like this it is possible to collect
precondition code at a single place.

But still I'm wondering about the scope of scripts ...

thanks
Marcel
http://www.xmlBlaster.org

Marcel Ruff wrote:
Hi,

i have defined a javascript function in a "pre" task,
but when i want to call it later i get:

  ReferenceError: "doPrecond" is not defined

Here is the xml, i call it with 'ant y':

---------------------
  <target name="pre">
<script language="javascript">function doPrecond() { project.log("HELLO PRECOND"); }</script>
  </target>

  <target name="y" depends="pre">
     <script language="javascript">doPrecond();</script>
  </target>
---------------------

Any ideas?

Thanks
Marcel
http://www.xmlBlaster.org

Note: This works fine:
   <target name="z">
      <script language="javascript">
         function doPrecond() { project.log("HELLO PRECOND"); }
         doPrecond();
      </script>
   </target>

This fails as well:
   <target name="r">
      <script language="javascript">
         function doPrecond() { project.log("HELLO PRECOND"); }
      </script>
      <script language="javascript">
         doPrecond();
      </script>
   </target>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to