1 26 27 package net.sourceforge.groboutils.codecoverage.v2.ant; 28 29 import java.io.File ; 30 import java.io.FileOutputStream ; 31 import java.io.IOException ; 32 import java.io.OutputStreamWriter ; 33 34 import net.sourceforge.groboutils.codecoverage.v2.report.OutputXml; 35 36 import org.apache.tools.ant.BuildException; 37 import org.apache.tools.ant.Project; 38 import org.w3c.dom.Document ; 39 40 41 42 49 public class XmlReportStyle implements IReportStyle 50 { 51 private File outdir; 52 private String prefix = "CoverageReport-"; 53 private String suffix = ".xml"; 54 55 56 public void setPrefix( String p ) 57 { 58 if (p == null) 59 { 60 p = ""; 61 } 62 this.prefix = p; 63 } 64 65 66 public void setSuffix( String s ) 67 { 68 if (s == null) 69 { 70 s = ""; 71 } 72 this.suffix = s; 73 } 74 75 76 public void setDestDir( File dir ) 77 { 78 this.outdir = dir; 79 } 80 81 82 86 public void reportComplete( Project project, java.util.Vector errorList ) 87 throws BuildException, IOException 88 { 89 } 91 92 93 public void generateReport( Project project, Document doc, 94 String moduleName ) 95 throws BuildException, IOException 96 { 97 if (this.outdir == null) 98 { 99 throw new BuildException( "Must set the 'destdir' attribute." ); 100 } 101 project.log( "Generating XML report for module "+moduleName, 102 Project.MSG_VERBOSE ); 103 File outFile = new File ( this.outdir, 104 this.prefix + moduleName + this.suffix ); 105 File parent = outFile.getParentFile(); 106 if (!parent.exists()) 107 { 108 parent.mkdirs(); 109 } 110 OutputStreamWriter osw = null; 111 try 112 { 113 osw = new OutputStreamWriter ( new FileOutputStream ( outFile ), 114 "UTF8" ); 115 (new OutputXml()).write( doc.getDocumentElement(), osw, null ); 116 } 117 finally 118 { 119 if (osw != null) 120 { 121 osw.close(); 122 } 123 } 124 } 125 } 126 127 | Popular Tags |