1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.codehaus.mojo.cobertura.tasks;
36
37 import org.apache.maven.plugin.MojoExecutionException;
38 import org.codehaus.plexus.util.StringUtils;
39
40 import java.io.File;
41 import java.util.Collections;
42 import java.util.List;
43
44
45
46
47
48
49 public class ReportTask
50 extends AbstractTask
51 {
52 private File dataFile;
53
54 private File outputDirectory;
55
56 private String outputFormat;
57
58 private String sourceEncoding;
59
60 private List<String> compileSourceRoots;
61
62
63
64
65 public ReportTask()
66 {
67 super( net.sourceforge.cobertura.reporting.ReportMain.class.getName() );
68 }
69
70
71
72
73 public void execute()
74 throws MojoExecutionException
75 {
76 outputDirectory.mkdirs();
77
78 for ( String directory : compileSourceRoots )
79 {
80 cmdLineArgs.addArg( "--source", directory );
81 }
82
83 if ( outputDirectory != null )
84 {
85 cmdLineArgs.addArg( "--destination", outputDirectory.getAbsolutePath() );
86 }
87
88 if ( dataFile != null )
89 {
90 cmdLineArgs.addArg( "--datafile", dataFile.getAbsolutePath() );
91 }
92
93 if ( StringUtils.isNotEmpty( outputFormat ) )
94 {
95 cmdLineArgs.addArg( "--format", outputFormat );
96 }
97
98 if ( StringUtils.isNotEmpty( sourceEncoding ) )
99 {
100 cmdLineArgs.addArg( "--encoding", sourceEncoding );
101 }
102
103 int returnCode = executeJava();
104
105
106 if ( returnCode == 0 )
107 {
108 getLog().info( "Cobertura Report generation was successful." );
109 }
110 else
111 {
112 throw new MojoExecutionException( "Unable to generate Cobertura Report for project." );
113 }
114 }
115
116
117
118
119 public File getDataFile()
120 {
121 return dataFile;
122 }
123
124
125
126
127 public File getOutputDirectory()
128 {
129 return outputDirectory;
130 }
131
132
133
134
135 public String getOutputFormat()
136 {
137 return outputFormat;
138 }
139
140
141
142
143 public String getSourceEncoding()
144 {
145 return sourceEncoding;
146 }
147
148
149
150
151 public void setDataFile( File dataFile )
152 {
153 this.dataFile = dataFile;
154 }
155
156
157
158
159 public void setOutputDirectory( File outputDirectory )
160 {
161 this.outputDirectory = outputDirectory;
162 }
163
164
165
166
167 public void setOutputFormat( String outputFormat )
168 {
169 this.outputFormat = outputFormat;
170 }
171
172
173
174
175 public void setSourceEncoding( String sourceEncoding )
176 {
177 this.sourceEncoding = sourceEncoding;
178 }
179
180
181
182
183
184
185 public void setCompileSourceRoots( List<String> compileSourceRoots )
186 {
187 this.compileSourceRoots = Collections.unmodifiableList( compileSourceRoots );
188 }
189 }