Hi,

I am new to this list. By browsing the archives I could not find
anything related to my problem but forgive me if it has already been
mentioned:

In our hierarchical build structure we use the SubAnt task to delegate
all tasks to our components specific build-scripts. In combination with
CruiseControl we realized that the XML output generated by the XMLLogger
does not represent a correct correlation of messages to tasks when using
SubAnt:

Buildfile: build.xml
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="log.xsl"?>

<build error="D:\prj\test\ant\build.xml:6: Following error occured while 
executing this line
D:\prj\test\ant\sub\build.xml:6: Compile failed; see the compiler error output for details." 
time="1 second">
        <target name="build" time="1 second">
                <task location="D:\prj\test\ant\build.xml:6: " name="subant" time="1 
second">
                        <message 
priority="warn"><![CDATA[D:\prj\test\ant\sub\src\Test.java:4: cannot resolve 
symbol]]></message>
                        <message priority="warn"><![CDATA[symbol  : method printer 
()]]></message>
                        <message priority="warn"><![CDATA[location: class 
java.io.PrintStream]]></message>
                        <message priority="warn"><![CDATA[           
System.out.printer();]]></message>
                        <message priority="warn"><![CDATA[                          
^]]></message>
                        <message priority="warn"><![CDATA[1 error]]></message>
                        <target name="build" time="0 seconds">
                                <task location="D:\prj\test\ant\sub\build.xml:6: " 
name="javac" time="0 seconds">
                                        <message priority="info"><![CDATA[Compiling 1 
source file]]></message>
                                </task>
                        </target>
                </task>
        </target>
        <stacktrace><![CDATA[D:\prj\test\ant\build.xml:6: Following error 
occured while executing this line
D:\prj\test\ant\sub\build.xml:6: Compile failed; see the compiler error output 
for details.
        at 
org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:574)
        at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:422)
        at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:219)
        at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:149)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
        at org.apache.tools.ant.Task.perform(Task.java:401)
        at org.apache.tools.ant.Target.execute(Target.java:338)
        at org.apache.tools.ant.Target.performTasks(Target.java:365)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1237)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1094)
        at org.apache.tools.ant.Main.runBuild(Main.java:669)
        at org.apache.tools.ant.Main.startAnt(Main.java:220)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90)
]]></stacktrace>
</build>


Obviously all the 'message' elements should be children of the 'javac task' element. It seems to me that the SubAnt task does not take care of the new project which is being created by its child Ant tasks.

As a quick fix for us I patched the SubAnt task to work similar as the
Ant task does. But instead of the 'project' variable I made the 'ant'
variable a field which is only valid during execution of the associated
project.

Please let me know if there is anything else I might have missed or if
this is the way to go. Feel free to apply the patch (which has been
performed on Ant 1.6.1) to the Ant sources (although I guess there is a
much cleaner way to accomplish this).

Cheers,
Christian

P.S.: In addition to the patch file I also added the build files to
reproduce the erroneous behaviour.
___________________________________________________________
EADS SPACE Transportation - TE 55 - Phone: +49-421-539-5673


diff -u -r apache-ant-1.6.1\build.xml apache-ant-1.6.1-patched\build.xml
--- apache-ant-1.6.1\build.xml  Thu Feb 12 14:33:18 2004
+++ apache-ant-1.6.1-patched\build.xml  Wed Jun 30 15:30:13 2004
@@ -25,8 +25,8 @@
   -->
   <property name="Name" value="Apache Ant"/>
   <property name="name" value="ant"/>
-  <property name="version" value="1.6.1"/>
-  <property name="manifest-version" value="1.6.1"/>
+  <property name="version" value="1.6.1-patched"/>
+  <property name="manifest-version" value="1.6.1-patched"/>
   <property name="bootstrap.jar" value="ant-bootstrap.jar"/>
 
   <property name="ant.package" value="org/apache/tools/ant"/>
diff -u -r apache-ant-1.6.1\src\main\org\apache\tools\ant\taskdefs\SubAnt.java 
apache-ant-1.6.1-patched\src\main\org\apache\tools\ant\taskdefs\SubAnt.java
--- apache-ant-1.6.1\src\main\org\apache\tools\ant\taskdefs\SubAnt.java Thu Feb 
12 14:33:24 2004
+++ apache-ant-1.6.1-patched\src\main\org\apache\tools\ant\taskdefs\SubAnt.java 
Wed Jun 30 15:35:41 2004
@@ -63,6 +63,7 @@
 
     private Path buildpath;
 
+    private Ant ant = null;
     private String target = null;
     private String antfile = "build.xml";
     private File genericantfile = null;
@@ -74,6 +75,90 @@
     private Vector properties = new Vector();
     private Vector references = new Vector();
     private Vector propertySets = new Vector();
+
+    /**
+     * Pass output sent to System.out to the new project.
+     *
+     * @param output a line of output
+     * @since Ant 1.5
+     */
+    public void handleOutput(String output) {
+        if (ant != null) {
+            ant.handleOutput(output);
+        } else {
+            super.handleOutput(output);
+        }
+    }
+
+    /**
+     * Process input into the ant task
+     *
+     * @param buffer the buffer into which data is to be read.
+     * @param offset the offset into the buffer at which data is stored.
+     * @param length the amount of data to read
+     *
+     * @return the number of bytes read
+     *
+     * @exception IOException if the data cannot be read
+     *
+     * @see Task#handleInput(byte[], int, int)
+     *
+     * @since Ant 1.6
+     */
+    public int handleInput(byte[] buffer, int offset, int length)
+        throws IOException {
+        if (ant != null) {
+            return ant.handleInput(buffer, offset, length);
+        } else {
+            return super.handleInput(buffer, offset, length);
+        }
+    }
+
+    /**
+     * Pass output sent to System.out to the new project.
+     *
+     * @param output The output to log. Should not be <code>null</code>.
+     *
+     * @since Ant 1.5.2
+     */
+    public void handleFlush(String output) {
+        if (ant != null) {
+            ant.handleFlush(output);
+        } else {
+            super.handleFlush(output);
+        }
+    }
+
+    /**
+     * Pass output sent to System.err to the new project.
+     *
+     * @param output The error output to log. Should not be <code>null</code>.
+     *
+     * @since Ant 1.5
+     */
+    public void handleErrorOutput(String output) {
+        if (ant != null) {
+            ant.handleErrorOutput(output);
+        } else {
+            super.handleErrorOutput(output);
+        }
+    }
+
+    /**
+     * Pass output sent to System.err to the new project.
+     *
+     * @param output The error output to log. Should not be <code>null</code>.
+     *
+     * @since Ant 1.5.2
+     */
+    public void handleErrorFlush(String output) {
+        if (ant != null) {
+            ant.handleErrorFlush(output);
+        } else {
+            super.handleErrorFlush(output);
+        }
+    }
+
     /**
      * Runs the various sub-builds.
      */
@@ -169,7 +254,7 @@
             return;
         }
 
-        Ant ant = createAntTask(directory);
+        ant = createAntTask(directory);
         String antfilename = null;
         try {
             antfilename = file.getCanonicalPath();
@@ -188,6 +273,8 @@
                + "' of: " +  antfilename + "\n"
                + e.getMessage(), Project.MSG_WARN);
         }
+
+        ant = null;
     }
 
     /**


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

Reply via email to