KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > coberturareportplugin > CoberturaReportPluginReport


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: PackageAssemblyMojo.java 16:56:43 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.tools.coberturareportplugin;
23
24 import java.io.File JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Locale JavaDoc;
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 /**
35  * Generate a summary of cobertura ser files
36  *
37  * @goal report
38  * @phase verify
39  * @description Generate a Cobertura report
40  * @aggregator false
41  * @requiresOnline false
42  * @author ddesjardins - eBMWebsourcing
43  */

44 public class CoberturaReportPluginReport extends AbstractMavenReport {
45
46     /**
47      * Base directory
48      *
49      * @parameter expression="${basedir}"
50      * @required
51      */

52     protected String JavaDoc baseDir;
53
54     /**
55      * Datafile
56      *
57      * @parameter expression="${basedir}/target/cobertura.ser"
58      * @required
59      * @editable false
60      */

61     protected String JavaDoc dataFile;
62
63     /**
64      * Destination directory
65      *
66      * @parameter expression="${project.reporting.outputDirectory}/cobertura-sum"
67      * @required
68      * @editable false
69      */

70     protected String JavaDoc destination;
71
72     /**
73      * The Maven Project.
74      *
75      * @parameter expression="${project}"
76      * @required
77      * @readonly
78      */

79     protected MavenProject project;
80
81     /**
82      * Specifies the directory where the report will be generated
83      *
84      * @parameter default-value="${project.reporting.outputDirectory}"
85      * @required
86      */

87     protected File JavaDoc outputDirectory;
88
89     /**
90      * @component
91      * @required
92      * @readonly
93      */

94     protected Renderer siteRenderer;
95
96     public String JavaDoc getDescription(Locale JavaDoc arg0) {
97         return "Cobertura Summary Report Generator Task";
98     }
99
100     public String JavaDoc getName(Locale JavaDoc arg0) {
101         return "CSRG Task";
102     }
103
104     public String JavaDoc getOutputName() {
105         return "CSRG Task";
106     }
107
108     protected void executeReport(Locale JavaDoc arg0) throws MavenReportException {
109         String JavaDoc destination = outputDirectory.getAbsolutePath() + File.separator
110             + "cobertura-sum";
111         String JavaDoc dataFile = baseDir + File.separator + "cobertura.ser";
112
113         if (project.getModules().size() > 0) {
114             new File JavaDoc(dataFile).delete();
115             List JavaDoc<String JavaDoc> args = new ArrayList JavaDoc<String JavaDoc>();
116             args.add("--datafile");
117             args.add(dataFile);
118             args.add("--basedir");
119             args.add(baseDir);
120             for (Object JavaDoc obj : project.getModules()) {
121                 args.add((String JavaDoc) 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 JavaDoc[0]));
127             } catch (Exception JavaDoc e) {
128                 // Do nothing
129
}
130             System.out.println("Merge done.");
131             if (new File JavaDoc(dataFile).exists()) {
132                 System.out.println("Generate Cobertura report " + dataFile
133                     + " to " + destination);
134                 args = new ArrayList JavaDoc<String JavaDoc>();
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 JavaDoc obj : project.getModules()) {
142                     String JavaDoc srcDir = baseDir + File.separator + (String JavaDoc) 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 JavaDoc[0]));
149                 } catch (Exception JavaDoc e) {
150                     // Do nothing
151
}
152                 System.out.println("Generate done.");
153             }
154         }
155     }
156
157     protected String JavaDoc 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