ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gle...@ca.ibm.com
Subject [PATCH] to XmlLogger to support subbuilds
Date Tue, 18 Jul 2000 13:13:42 GMT




First off, congrats on the release, and thanks to all the commiters for the
hard work.  You've built a great tool, and we all appreciate it.  Now back
to business. :-)

This patch adds subbuild support to XmlLogger.  The new build targets and
tasks are elements of the ant task.  Also added support for a different
output filename with a -DXmlLogger.file=blah.xml addition to the command
line.  This will do in the short term untill there is concensous on a
general mechanism for passing that kind of information to a listener from
the command line.

Index: jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java,v
retrieving revision 1.2
diff -u -r1.2 XmlLogger.java
--- jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java
2000/06/29 15:32:37        1.2
+++ jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java
2000/07/18 13:09:51
@@ -55,6 +55,7 @@
 package org.apache.tools.ant;

 import java.io.*;
+import java.util.*;
 import javax.xml.parsers.*;
 import org.w3c.dom.*;

@@ -96,6 +97,12 @@
     private long buildStartTime;
     private long targetStartTime;
     private long taskStartTime;
+
+    private Stack targetTimeStack = new Stack();
+    private Stack targetStack = new Stack();
+    private Stack taskTimeStack = new Stack();
+    private Stack taskStack = new Stack();
+

     /**
      *  Constructs a new BuildListener that logs build events to an XML
file.
@@ -105,7 +112,6 @@

     public void buildStarted(BuildEvent event) {
         buildStartTime = System.currentTimeMillis();
-
         doc = builder.newDocument();
         buildElement = doc.createElement(BUILD_TAG);
     }
@@ -117,21 +123,29 @@
         if (event.getException() != null) {
             buildElement.setAttribute(ERROR_ATTR,
event.getException().toString());
         }
-
+
         try {
-                Writer out = new FileWriter("log.xml");
-                out.write("<?xml:stylesheet type=\"text/xsl\"
href=\"log.xsl\"?>\n\n");
-                write(buildElement, out, 0);
-                out.flush();
-                out.close();
-
+            String outFilename =
event.getProject().getProperty("XmlLogger.file");
+            if (outFilename == null) {
+                outFilename = "log.xml";
+            }
+            Writer out = new FileWriter(outFilename);
+            out.write("<?xml:stylesheet type=\"text/xsl\"
href=\"log.xsl\"?>\n\n");
+            write(buildElement, out, 0);
+            out.flush();
+            out.close();
         }
         catch(IOException exc) {
             throw new BuildException("Unable to close log file", exc);
         }
+        buildElement = null;
     }

     public void targetStarted(BuildEvent event) {
+        if (targetElement != null) {
+            targetTimeStack.push(new Long(targetStartTime));
+            targetStack.push(targetElement);
+        }
         targetStartTime = System.currentTimeMillis();
         targetElement = doc.createElement(TARGET_TAG);
         targetElement.setAttribute(NAME_ATTR,
event.getTarget().getName());
@@ -140,12 +154,27 @@
     public void targetFinished(BuildEvent event) {
         long totalTime = System.currentTimeMillis() - targetStartTime;
         targetElement.setAttribute(TIME_ATTR, formatTime(totalTime));
-        buildElement.appendChild(targetElement);
+
+        if (taskElement == null) {
+            buildElement.appendChild(targetElement);
+        } else {
+            taskElement.appendChild(targetElement);
+        }

         targetElement = null;
+
+        if (!targetStack.isEmpty()) {
+            targetStartTime = ((Long) targetTimeStack.pop()).longValue();
+            targetElement = (Element) targetStack.pop();
+        }
     }

     public void taskStarted(BuildEvent event) {
+        if (taskElement != null) {
+            taskTimeStack.push(new Long(taskStartTime));
+            taskStack.push(taskElement);
+        }
+
         taskStartTime = System.currentTimeMillis();
         taskElement = doc.createElement(TASK_TAG);

@@ -165,6 +194,11 @@
         targetElement.appendChild(taskElement);

         taskElement = null;
+
+        if (!taskStack.isEmpty()) {
+            taskStartTime = ((Long) taskTimeStack.pop()).longValue();
+            taskElement = (Element) taskStack.pop();
+        }
     }

     public void messageLogged(BuildEvent event)
{();p()).longValue();e(););>\n\n");n");

Glenn McAllister
TID - Software Developer - VisualAge for Java
IBM Toronto Lab, (416) 448-3805
"An approximate answer to the right question is better than the
right answer to the wrong question." - John W. Tukey



Mime
View raw message