ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant XmlLogger.java
Date Fri, 21 Jul 2000 11:44:34 GMT
bodewig     00/07/21 04:44:34

  Modified:    src/main/org/apache/tools/ant XmlLogger.java
  Log:
  Better support for subbuilds in XmlLogger. Output of XmlLogger can be
  sent to another file using the XmlLogger.file property.
  Submitted by:	Glenn McAllister <glennm@ca.ibm.com>
  
  Revision  Changes    Path
  1.3       +44 -9     jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java
  
  Index: XmlLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XmlLogger.java	2000/06/29 15:32:37	1.2
  +++ XmlLogger.java	2000/07/21 11:44:34	1.3
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant;
   
   import java.io.*;
  +import java.util.*;
   import javax.xml.parsers.*;
   import org.w3c.dom.*;
   
  @@ -97,6 +98,11 @@
       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.
        */
  @@ -119,19 +125,30 @@
           }
   
           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");
   
  -        }
  -        catch(IOException exc) {
  +            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 +157,26 @@
       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 +196,10 @@
           targetElement.appendChild(taskElement);
   
           taskElement = null;
  +        if (!taskStack.isEmpty()) {
  +            taskStartTime = ((Long) taskTimeStack.pop()).longValue();
  +            taskElement = (Element) taskStack.pop();
  +        }
       }
   
       public void messageLogged(BuildEvent event) {
  @@ -266,4 +301,4 @@
           }
   
       }
  -}
  \ No newline at end of file
  +}
  
  
  

Mime
View raw message