Class XMLResultAggregator
- java.lang.Object
- 
- org.apache.tools.ant.ProjectComponent
- 
- org.apache.tools.ant.Task
- 
- org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator
 
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable,- XMLConstants
 
 public class XMLResultAggregator extends Task implements XMLConstants Aggregates all <junit> XML formatter testsuite data under a specific directory and transforms the results via XSLT. It is not particularly clean but should be helpful while I am thinking about another technique.The main problem is due to the fact that a JVM can be forked for a testcase thus making it impossible to aggregate all testcases since the listener is (obviously) in the forked JVM. A solution could be to write a TestListener that will receive events from the TestRunner via sockets. This is IMHO the simplest way to do it to avoid this file hacking thing. 
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringDEFAULT_DIRThe default directory:..static java.lang.StringDEFAULT_FILENAMEthe default file name:TESTS-TestSuites.xmlprotected java.util.Vector<FileSet>filesetsthe list of all filesets, that should contains the xml to aggregateprotected intgeneratedIdthe current generated idprotected java.io.FiletoDirthe directory to write the file toprotected java.lang.StringtoFilethe name of the result fileprotected java.util.Vector<AggregateTransformer>transformers- 
Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
 - 
Fields inherited from interface org.apache.tools.ant.taskdefs.optional.junit.XMLConstantsATTR_CLASSNAME, ATTR_ERRORS, ATTR_FAILURES, ATTR_ID, ATTR_MESSAGE, ATTR_NAME, ATTR_PACKAGE, ATTR_SKIPPED, ATTR_TESTS, ATTR_TIME, ATTR_TYPE, ATTR_VALUE, ERROR, FAILURE, HOSTNAME, PROPERTIES, PROPERTY, SYSTEM_ERR, SYSTEM_OUT, TESTCASE, TESTSUITE, TESTSUITES, TIMESTAMP
 
- 
 - 
Constructor SummaryConstructors Constructor Description XMLResultAggregator()
 - 
Method SummaryModifier and Type Method Description voidaddFileSet(FileSet fs)Add a new fileset containing the XML results to aggregateprotected voidaddTestSuite(org.w3c.dom.Element root, org.w3c.dom.Element testsuite)Add a new testsuite node to the document.protected org.w3c.dom.ElementcreateDocument()Create a DOM tree.AggregateTransformercreateReport()Generate a report based on the document created by the merge.voidexecute()Aggregate all testsuites into a single document and write it to the specified directory and file.java.io.FilegetDestinationFile()Get the full destination file where to write the result.protected java.io.File[]getFiles()Get all.xmlfiles in the fileset.voidsetTodir(java.io.File value)Set the destination directory where the results should be written.voidsetTofile(java.lang.String value)Set the name of the aggregated results file.protected voidwriteDOMTree(org.w3c.dom.Document doc, java.io.File file)Write the DOM tree to a file.- 
Methods inherited from class org.apache.tools.ant.TaskbindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 - 
Methods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
- 
 
- 
- 
- 
Field Detail- 
filesetsprotected java.util.Vector<FileSet> filesets the list of all filesets, that should contains the xml to aggregate
 - 
toFileprotected java.lang.String toFile the name of the result file
 - 
toDirprotected java.io.File toDir the directory to write the file to
 - 
transformersprotected java.util.Vector<AggregateTransformer> transformers 
 - 
DEFAULT_DIRpublic static final java.lang.String DEFAULT_DIR The default directory:.. It is resolved from the project directory- See Also:
- Constant Field Values
 
 - 
DEFAULT_FILENAMEpublic static final java.lang.String DEFAULT_FILENAME the default file name:TESTS-TestSuites.xml- See Also:
- Constant Field Values
 
 - 
generatedIdprotected int generatedId the current generated id
 
- 
 - 
Method Detail- 
createReportpublic AggregateTransformer createReport() Generate a report based on the document created by the merge.- Returns:
- the report
 
 - 
setTofilepublic void setTofile(java.lang.String value) Set the name of the aggregated results file. It must be relative from thetodirattribute. If not set it will useDEFAULT_FILENAME- Parameters:
- value- the name of the file.
- See Also:
- setTodir(File)
 
 - 
setTodirpublic void setTodir(java.io.File value) Set the destination directory where the results should be written. If not set if will useDEFAULT_DIR. When given a relative directory it will resolve it from the project directory.- Parameters:
- value- the directory where to write the results, absolute or relative.
 
 - 
addFileSetpublic void addFileSet(FileSet fs) Add a new fileset containing the XML results to aggregate- Parameters:
- fs- the new fileset of xml results.
 
 - 
executepublic void execute() throws BuildExceptionAggregate all testsuites into a single document and write it to the specified directory and file.- Overrides:
- executein class- Task
- Throws:
- BuildException- thrown if there is a serious error while writing the document.
 
 - 
getDestinationFilepublic java.io.File getDestinationFile() Get the full destination file where to write the result. It is made of thetodirandtofileattributes.- Returns:
- the destination file where should be written the result file.
 
 - 
getFilesprotected java.io.File[] getFiles() Get all.xmlfiles in the fileset.- Returns:
- all files in the fileset that end with a '.xml'.
 
 - 
writeDOMTreeprotected void writeDOMTree(org.w3c.dom.Document doc, java.io.File file) throws java.io.IOExceptionWrite the DOM tree to a file.- Parameters:
- doc- the XML document to dump to disk.
- file- the filename to write the document to. Should obviously be a .xml file.
- Throws:
- java.io.IOException- thrown if there is an error while writing the content.
 
 - 
createDocumentprotected org.w3c.dom.Element createDocument() Create a DOM tree. Has 'testsuites' as firstchild and aggregates all testsuite results that exists in the base directory.- Returns:
- the root element of DOM tree that aggregates all testsuites.
 
 - 
addTestSuiteprotected void addTestSuite(org.w3c.dom.Element root, org.w3c.dom.Element testsuite)Add a new testsuite node to the document. The main difference is that it split the previous fully qualified name into a package and a name. For example: org.apache.Whateverwill be split intoorg.apacheandWhatever.- Parameters:
- root- the root element to which the- testsuitenode should be appended.
- testsuite- the element to append to the given root. It will slightly modify the original node to change the name attribute and add a package one.
 
 
- 
 
-