2222import java .io .UnsupportedEncodingException ;
2323import java .util .Locale ;
2424import java .util .Properties ;
25- import java .util .ResourceBundle ;
2625
2726import net .sourceforge .pmd .cpd .JavaTokenizer ;
2827import net .sourceforge .pmd .cpd .renderer .CPDRenderer ;
28+ import org .apache .maven .plugins .annotations .Component ;
2929import org .apache .maven .plugins .annotations .Mojo ;
3030import org .apache .maven .plugins .annotations .Parameter ;
3131import org .apache .maven .plugins .pmd .exec .CpdExecutor ;
3232import org .apache .maven .plugins .pmd .exec .CpdRequest ;
3333import org .apache .maven .plugins .pmd .exec .CpdResult ;
3434import org .apache .maven .reporting .MavenReportException ;
3535import 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