1 22 package org.objectweb.petals.tools.coberturareportplugin; 23 24 import java.io.File ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.Locale ; 28 29 import org.apache.maven.doxia.siterenderer.Renderer; 30 import org.apache.maven.project.MavenProject; 31 import org.apache.maven.reporting.AbstractMavenReport; 32 import org.apache.maven.reporting.MavenReportException; 33 34 44 public class CoberturaReportPluginReport extends AbstractMavenReport { 45 46 52 protected String baseDir; 53 54 61 protected String dataFile; 62 63 70 protected String destination; 71 72 79 protected MavenProject project; 80 81 87 protected File outputDirectory; 88 89 94 protected Renderer siteRenderer; 95 96 public String getDescription(Locale arg0) { 97 return "Cobertura Summary Report Generator Task"; 98 } 99 100 public String getName(Locale arg0) { 101 return "CSRG Task"; 102 } 103 104 public String getOutputName() { 105 return "CSRG Task"; 106 } 107 108 protected void executeReport(Locale arg0) throws MavenReportException { 109 String destination = outputDirectory.getAbsolutePath() + File.separator 110 + "cobertura-sum"; 111 String dataFile = baseDir + File.separator + "cobertura.ser"; 112 113 if (project.getModules().size() > 0) { 114 new File (dataFile).delete(); 115 List <String > args = new ArrayList <String >(); 116 args.add("--datafile"); 117 args.add(dataFile); 118 args.add("--basedir"); 119 args.add(baseDir); 120 for (Object obj : project.getModules()) { 121 args.add((String ) obj + File.separator + "cobertura.ser"); 122 } 123 System.out.println("Cobertura merge report to " + dataFile); 124 try { 125 net.sourceforge.cobertura.merge.Main.main(args 126 .toArray(new String [0])); 127 } catch (Exception e) { 128 } 130 System.out.println("Merge done."); 131 if (new File (dataFile).exists()) { 132 System.out.println("Generate Cobertura report " + dataFile 133 + " to " + destination); 134 args = new ArrayList <String >(); 135 args.add("--datafile"); 136 args.add(dataFile); 137 args.add("--destination"); 138 args.add(destination); 139 args.add("--format"); 140 args.add("html"); 141 for (Object obj : project.getModules()) { 142 String srcDir = baseDir + File.separator + (String ) obj 143 + File.separator + "src" + File.separator + "java"; 144 args.add(srcDir); 145 } 146 try { 147 net.sourceforge.cobertura.reporting.Main.main(args 148 .toArray(new String [0])); 149 } catch (Exception e) { 150 } 152 System.out.println("Generate done."); 153 } 154 } 155 } 156 157 protected String getOutputDirectory() { 158 return outputDirectory.getAbsolutePath(); 159 } 160 161 protected MavenProject getProject() { 162 return project; 163 } 164 165 protected Renderer getSiteRenderer() { 166 return (Renderer) siteRenderer; 167 } 168 169 } 170 | Popular Tags |