Output hijacking bug in foreach?

Help
2003-03-07
2003-03-11
  • Todd V. Jonker

    Todd V. Jonker - 2003-03-07

    I'm new to these tasks, but I'm having trouble with foreach.  My loop's target calls a java program and tries to send the output to a file.  However, if this target is called via foreach, the output never goes to the file, and instead goes to the console.

    The files included below demonstrate the problem.  The nobug target calls loop-target three times.  Afterwards the file output.txt holds a hello message.  The bug target uses for-each to call loop-target; afterwards the file output.txt is empty, and the console shows the hello message.

    Note that the bug doesn't exist if the java task forks the JVM.

    Here are the two files needed to demonstrate the bug: build.xml and Hello.java  I'm using ant 1.5.2

    --------build.xml--------
    <?xml version="1.0"?>
    <project name="foreach-bug" default="bug">
      <taskdef resource="net/sf/antcontrib/antcontrib.properties" />

      <target name="compile">
        <javac srcdir="${basedir}" />
      </target>

      <target name="nobug">
        <antcall target="loop-target">
          <param name="index" value="1" />
        </antcall>
        <antcall target="loop-target">
          <param name="index" value="2" />
        </antcall>
        <antcall target="loop-target">
          <param name="index" value="3" />
        </antcall>
      </target>

      <target name="bug">
        <foreach list="1,2,3" param="index" target="loop-target"/>
      </target>

      <target name="loop-target" depends="compile">
        <echo>This is index ${index}</echo>
        <java classname="Hello" classpath="${basedir}" output="output.txt" />
      </target>

    </project>
    ----------------

    --------Hello.java--------
    public class Hello
    {
        public static void main(String[] args)
        {
            System.out.println("hello");
        }
    }
    ----------------

     

Log in to post a comment.