org.apache.tools.ant.taskdefs.optional.metamata
Class MMetricsStreamHandler

java.lang.Object
  |
  +--org.apache.tools.ant.taskdefs.optional.metamata.MMetricsStreamHandler
All Implemented Interfaces:
ExecuteStreamHandler

public class MMetricsStreamHandler
extends java.lang.Object
implements ExecuteStreamHandler

A handy metrics handler. Most of this code was done only with the screenshots on the documentation since the evaluation version as of this writing does not allow to save metrics or to run it via command line.

This class can be used to transform a text file or to process the output stream directly.

Author:
Stephane Bailliez

Field Summary
protected static java.lang.String[] ATTRIBUTES
           
protected static java.lang.String CLASS
          CLASS construct, it should be named something like 'MyClass'
protected static java.lang.String FILE
          FILE construct, it should look like something 'MyClass.java' or 'MyClass.class'
protected static java.lang.String METHOD
          METHOD construct, it should looke like something 'doSomething(...)' or 'doSomething()'
protected  javax.xml.transform.sax.TransformerHandler metricsHandler
          metrics handler
protected  java.io.InputStream metricsOutput
          reader for stdout
protected static java.lang.String PACKAGE
          package construct, it should be look like 'com.mycompany.something'
protected  java.util.Stack stack
          the stack where are stored the metrics element so that they we can know if we have to close an element or not.
protected  Task task
          the task
protected  java.io.OutputStream xmlOutputStream
          this is where the XML output will go, should mostly be a file the caller is responsible for flushing and closing this stream
 
Method Summary
protected  org.xml.sax.Attributes createAttributes(org.apache.tools.ant.taskdefs.optional.metamata.MetricsElement elem)
          Create all attributes of a MetricsElement skipping those who have an empty string
protected  java.lang.String getConstructType(org.apache.tools.ant.taskdefs.optional.metamata.MetricsElement elem)
          return the construct type of the element.
protected  void parseOutput()
          read each line and process it
protected  void processLine(java.lang.String line)
          Process a metrics line.
 void setProcessErrorStream(java.io.InputStream p1)
          Ignore.
 void setProcessInputStream(java.io.OutputStream p1)
          Ignore.
 void setProcessOutputStream(java.io.InputStream is)
          Set the inputstream
 void start()
          Start handling of the streams.
protected  void startElement(org.apache.tools.ant.taskdefs.optional.metamata.MetricsElement elem)
          Start a new construct.
 void stop()
          Pretty dangerous business here.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS

protected static final java.lang.String CLASS
CLASS construct, it should be named something like 'MyClass'

PACKAGE

protected static final java.lang.String PACKAGE
package construct, it should be look like 'com.mycompany.something'

FILE

protected static final java.lang.String FILE
FILE construct, it should look like something 'MyClass.java' or 'MyClass.class'

METHOD

protected static final java.lang.String METHOD
METHOD construct, it should looke like something 'doSomething(...)' or 'doSomething()'

ATTRIBUTES

protected static final java.lang.String[] ATTRIBUTES

metricsOutput

protected java.io.InputStream metricsOutput
reader for stdout

xmlOutputStream

protected java.io.OutputStream xmlOutputStream
this is where the XML output will go, should mostly be a file the caller is responsible for flushing and closing this stream

metricsHandler

protected javax.xml.transform.sax.TransformerHandler metricsHandler
metrics handler

task

protected Task task
the task

stack

protected java.util.Stack stack
the stack where are stored the metrics element so that they we can know if we have to close an element or not.
Method Detail

setProcessInputStream

public void setProcessInputStream(java.io.OutputStream p1)
                           throws java.io.IOException
Ignore.
Specified by:
setProcessInputStream in interface ExecuteStreamHandler
Following copied from interface: org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Parameters:
os - output stream to write to the standard input stream of the subprocess

setProcessErrorStream

public void setProcessErrorStream(java.io.InputStream p1)
                           throws java.io.IOException
Ignore.
Specified by:
setProcessErrorStream in interface ExecuteStreamHandler
Following copied from interface: org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Parameters:
is - input stream to read from the error stream from the subprocess

setProcessOutputStream

public void setProcessOutputStream(java.io.InputStream is)
                            throws java.io.IOException
Set the inputstream
Specified by:
setProcessOutputStream in interface ExecuteStreamHandler
Following copied from interface: org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Parameters:
is - input stream to read from the error stream from the subprocess

start

public void start()
           throws java.io.IOException
Description copied from interface: ExecuteStreamHandler
Start handling of the streams.
Specified by:
start in interface ExecuteStreamHandler

stop

public void stop()
Pretty dangerous business here.
Specified by:
stop in interface ExecuteStreamHandler

parseOutput

protected void parseOutput()
                    throws java.io.IOException,
                           org.xml.sax.SAXException
read each line and process it

processLine

protected void processLine(java.lang.String line)
                    throws org.xml.sax.SAXException
Process a metrics line. If the metrics is invalid and that this is not the header line, it is display as info.
Parameters:
line - the line to process, it is normally a line full of metrics.

startElement

protected void startElement(org.apache.tools.ant.taskdefs.optional.metamata.MetricsElement elem)
                     throws org.xml.sax.SAXException
Start a new construct. Elements are popped until we are on the same parent node, then the element type is guessed and pushed on the stack.
Parameters:
elem - the element to process.
Throws:
org.xml.sax.SAXException - thrown if there is a problem when sending SAX events.

getConstructType

protected java.lang.String getConstructType(org.apache.tools.ant.taskdefs.optional.metamata.MetricsElement elem)
return the construct type of the element. We can hardly recognize the type of a metrics element, so we are kind of forced to do some black magic based on the name and indentation to recognize the type.
Parameters:
elem - the metrics element to guess for its type.
Returns:
the type of the metrics element, either PACKAGE, FILE, CLASS or METHOD.

createAttributes

protected org.xml.sax.Attributes createAttributes(org.apache.tools.ant.taskdefs.optional.metamata.MetricsElement elem)
Create all attributes of a MetricsElement skipping those who have an empty string
Parameters:
elem -  


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.