Skip to content

Commit 05514fb

Browse files
committed
[MPMD-375] Replace *ReportGenerators with a new *ReportRenderers
This closes #130
1 parent 931a292 commit 05514fb

File tree

7 files changed

+606
-694
lines changed

7 files changed

+606
-694
lines changed

pom.xml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ under the License.
8686
<pmdVersion>6.55.0</pmdVersion>
8787
<slf4jVersion>1.7.36</slf4jVersion>
8888
<aetherVersion>1.0.0.v20140518</aetherVersion>
89+
<doxiaVersion>1.12.0</doxiaVersion>
8990
<compilerPluginVersion>3.11.0</compilerPluginVersion>
9091
<sitePluginVersion>3.12.1</sitePluginVersion>
9192
<projectInfoReportsPluginVersion>3.4.3</projectInfoReportsPluginVersion>
@@ -139,6 +140,12 @@ under the License.
139140
<groupId>org.apache.maven.shared</groupId>
140141
<artifactId>maven-common-artifact-filters</artifactId>
141142
<version>3.3.2</version>
143+
<exclusions>
144+
<exclusion>
145+
<groupId>org.sonatype.sisu</groupId>
146+
<artifactId>sisu-inject-plexus</artifactId>
147+
</exclusion>
148+
</exclusions>
142149
</dependency>
143150
<dependency>
144151
<groupId>org.apache.maven</groupId>
@@ -190,7 +197,24 @@ under the License.
190197
<dependency>
191198
<groupId>org.apache.maven.doxia</groupId>
192199
<artifactId>doxia-sink-api</artifactId>
193-
<version>1.12.0</version>
200+
<version>${doxiaVersion}</version>
201+
<exclusions>
202+
<exclusion>
203+
<groupId>org.codehaus.plexus</groupId>
204+
<artifactId>plexus-container-default</artifactId>
205+
</exclusion>
206+
</exclusions>
207+
</dependency>
208+
<dependency>
209+
<groupId>org.apache.maven.doxia</groupId>
210+
<artifactId>doxia-core</artifactId>
211+
<version>${doxiaVersion}</version>
212+
<exclusions>
213+
<exclusion>
214+
<groupId>org.codehaus.plexus</groupId>
215+
<artifactId>plexus-container-default</artifactId>
216+
</exclusion>
217+
</exclusions>
194218
</dependency>
195219
<dependency>
196220
<groupId>org.apache.maven.doxia</groupId>
@@ -207,6 +231,14 @@ under the License.
207231
<groupId>org.apache.httpcomponents</groupId>
208232
<artifactId>httpclient</artifactId>
209233
</exclusion>
234+
<exclusion>
235+
<groupId>org.codehaus.plexus</groupId>
236+
<artifactId>plexus-container-default</artifactId>
237+
</exclusion>
238+
<exclusion>
239+
<groupId>org.codehaus.plexus</groupId>
240+
<artifactId>plexus-component-api</artifactId>
241+
</exclusion>
210242
</exclusions>
211243
</dependency>
212244

@@ -227,6 +259,17 @@ under the License.
227259
<groupId>org.codehaus.plexus</groupId>
228260
<artifactId>plexus-utils</artifactId>
229261
</dependency>
262+
<dependency>
263+
<groupId>org.codehaus.plexus</groupId>
264+
<artifactId>plexus-i18n</artifactId>
265+
<version>1.0-beta-10</version>
266+
<exclusions>
267+
<exclusion>
268+
<groupId>org.codehaus.plexus</groupId>
269+
<artifactId>plexus-component-api</artifactId>
270+
</exclusion>
271+
</exclusions>
272+
</dependency>
230273

231274
<!-- test -->
232275
<dependency>
@@ -240,6 +283,12 @@ under the License.
240283
<artifactId>maven-plugin-testing-harness</artifactId>
241284
<version>3.3.0</version>
242285
<scope>test</scope>
286+
<exclusions>
287+
<exclusion>
288+
<groupId>org.codehaus.plexus</groupId>
289+
<artifactId>plexus-container-default</artifactId>
290+
</exclusion>
291+
</exclusions>
243292
</dependency>
244293
<dependency>
245294
<groupId>com.github.tomakehurst</groupId>

src/main/java/org/apache/maven/plugins/pmd/CpdReport.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
import java.io.UnsupportedEncodingException;
2323
import java.util.Locale;
2424
import java.util.Properties;
25-
import java.util.ResourceBundle;
2625

2726
import net.sourceforge.pmd.cpd.JavaTokenizer;
2827
import net.sourceforge.pmd.cpd.renderer.CPDRenderer;
28+
import org.apache.maven.plugins.annotations.Component;
2929
import org.apache.maven.plugins.annotations.Mojo;
3030
import org.apache.maven.plugins.annotations.Parameter;
3131
import org.apache.maven.plugins.pmd.exec.CpdExecutor;
3232
import org.apache.maven.plugins.pmd.exec.CpdRequest;
3333
import org.apache.maven.plugins.pmd.exec.CpdResult;
3434
import org.apache.maven.reporting.MavenReportException;
3535
import org.apache.maven.toolchain.Toolchain;
36+
import org.codehaus.plexus.i18n.I18N;
3637

3738
/**
3839
* Creates a report for PMD's Copy/Paste Detector (CPD) tool.
@@ -96,25 +97,36 @@ public class CpdReport extends AbstractPmdReport {
9697
@Parameter(property = "cpd.ignoreAnnotations", defaultValue = "false")
9798
private boolean ignoreAnnotations;
9899

100+
/**
101+
* Internationalization component
102+
*/
103+
@Component
104+
private I18N i18n;
105+
99106
/**
100107
* Contains the result of the last CPD execution.
101108
* It might be <code>null</code> which means, that CPD
102109
* has not been executed yet.
103110
*/
104111
private CpdResult cpdResult;
105112

106-
/**
107-
* {@inheritDoc}
108-
*/
113+
/** {@inheritDoc} */
109114
public String getName(Locale locale) {
110-
return getBundle(locale).getString("report.cpd.name");
115+
return getI18nString(locale, "name");
116+
}
117+
118+
/** {@inheritDoc} */
119+
public String getDescription(Locale locale) {
120+
return getI18nString(locale, "description");
111121
}
112122

113123
/**
114-
* {@inheritDoc}
124+
* @param locale The locale
125+
* @param key The key to search for
126+
* @return The text appropriate for the locale.
115127
*/
116-
public String getDescription(Locale locale) {
117-
return getBundle(locale).getString("report.cpd.description");
128+
protected String getI18nString(Locale locale, String key) {
129+
return i18n.getString("cpd-report", locale, "report.cpd." + key);
118130
}
119131

120132
/**
@@ -126,7 +138,9 @@ public void executeReport(Locale locale) throws MavenReportException {
126138
try {
127139
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
128140

129-
generateMavenSiteReport(locale);
141+
CpdReportRenderer r = new CpdReportRenderer(
142+
getSink(), i18n, locale, filesToProcess, cpdResult.getDuplications(), isAggregator());
143+
r.render();
130144
} finally {
131145
Thread.currentThread().setContextClassLoader(origLoader);
132146
}
@@ -209,22 +223,13 @@ private void executeCpd() throws MavenReportException {
209223
}
210224
}
211225

212-
private void generateMavenSiteReport(Locale locale) {
213-
CpdReportGenerator gen = new CpdReportGenerator(getSink(), filesToProcess, getBundle(locale), isAggregator());
214-
gen.generate(cpdResult.getDuplications());
215-
}
216-
217226
/**
218227
* {@inheritDoc}
219228
*/
220229
public String getOutputName() {
221230
return "cpd";
222231
}
223232

224-
private static ResourceBundle getBundle(Locale locale) {
225-
return ResourceBundle.getBundle("cpd-report", locale, CpdReport.class.getClassLoader());
226-
}
227-
228233
/**
229234
* Create and return the correct renderer for the output type.
230235
*

0 commit comments

Comments
 (0)