}
catch (Exception e) {
log.warn("Download failed. " + e.getMessage());
}
Tidy tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowWarnings(false);
if ( resultsFile == null || !resultsFile.exists() ) {
log.info( resultsFileName + " could not be downloaded. Using the template to create anew");
resultsFile = new File(project.getBasedir(), "src/main/resources/" + resultsFileName);
}
FileInputStream is = new FileInputStream( resultsFile );
Document document = tidy.parseDOM(is, null);
is.close();
File reportsDir = new File(targetDirectory, "surefire-reports");
if ( !reportsDir.exists() ) {
log.warn("No surefire-reports directory here");
return;
}
ArrayList files = (ArrayList) FileUtils.getFiles(reportsDir, "TEST-*.xml", null, true);
if ( files.size() > 0 ) {
document = insertNewColumn(document);
if ( document == null ) {
throw new MojoFailureException("Main table cannot be found in the " + resultsFileName + ". The file may be corrupted");
}
}
for ( Iterator itr=files.iterator(); itr.hasNext(); ) {
File file = (File) itr.next();
log.debug("working on " + file.getAbsolutePath() );
document = processFile(document, file);
}
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
// write the document back into a temporary file.
File tempFile = new File(targetDirectory, "ResultsSummary-2.html");
FileOutputStream os = new FileOutputStream( tempFile );
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(os);
transformer.transform(source, result);
os.flush();
os.close();
// tidy the document and create/replace ResultsSummary.html in the target directory
resultsFile = new File(targetDirectory, resultsFileName);
is = new FileInputStream( tempFile );
os = new FileOutputStream( resultsFile );
tidy.parse(is, os);
is.close();
os.close();
// delete the temp file.
tempFile.delete();