Skip to content

Commit fe2379d

Browse files
committed
[MCHECKSTYLE-436] Replace CheckstyleReportGenerator with a new CheckstyleReportRenderer
This closes #118
1 parent b08abc2 commit fe2379d

10 files changed

+221
-445
lines changed

pom.xml

+11
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ under the License.
172172
<artifactId>plexus-utils</artifactId>
173173
<version>3.5.1</version>
174174
</dependency>
175+
<dependency>
176+
<groupId>org.codehaus.plexus</groupId>
177+
<artifactId>plexus-i18n</artifactId>
178+
<version>1.0-beta-10</version>
179+
<exclusions>
180+
<exclusion>
181+
<groupId>org.codehaus.plexus</groupId>
182+
<artifactId>plexus-component-api</artifactId>
183+
</exclusion>
184+
</exclusions>
185+
</dependency>
175186

176187
<!-- checkstyle -->
177188
<dependency>

src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java

+50-41
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.List;
2929
import java.util.Locale;
3030
import java.util.Map;
31-
import java.util.ResourceBundle;
3231

3332
import com.puppycrawl.tools.checkstyle.DefaultLogger;
3433
import com.puppycrawl.tools.checkstyle.XMLLogger;
@@ -53,6 +52,7 @@
5352
import org.apache.maven.reporting.AbstractMavenReport;
5453
import org.apache.maven.reporting.MavenReportException;
5554
import org.codehaus.plexus.configuration.PlexusConfiguration;
55+
import org.codehaus.plexus.i18n.I18N;
5656
import org.codehaus.plexus.resource.ResourceManager;
5757
import org.codehaus.plexus.resource.loader.FileResourceLoader;
5858
import org.codehaus.plexus.util.FileUtils;
@@ -438,16 +438,31 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
438438
@Component(role = CheckstyleExecutor.class, hint = "default")
439439
protected CheckstyleExecutor checkstyleExecutor;
440440

441+
/**
442+
* Internationalization component
443+
*/
444+
@Component
445+
private I18N i18n;
446+
441447
protected ByteArrayOutputStream stringOutputStream;
442448

443449
/** {@inheritDoc} */
444450
public String getName(Locale locale) {
445-
return getBundle(locale).getString("report.checkstyle.name");
451+
return getI18nString(locale, "name");
446452
}
447453

448454
/** {@inheritDoc} */
449455
public String getDescription(Locale locale) {
450-
return getBundle(locale).getString("report.checkstyle.description");
456+
return getI18nString(locale, "description");
457+
}
458+
459+
/**
460+
* @param locale The locale
461+
* @param key The key to search for
462+
* @return The text appropriate for the locale.
463+
*/
464+
protected String getI18nString(Locale locale, String key) {
465+
return i18n.getString("checkstyle-report", locale, "report.checkstyle." + key);
451466
}
452467

453468
/** {@inheritDoc} */
@@ -495,8 +510,34 @@ public void executeReport(Locale locale) throws MavenReportException {
495510

496511
CheckstyleResults results = checkstyleExecutor.executeCheckstyle(request);
497512

498-
ResourceBundle bundle = getBundle(locale);
499-
generateMainReport(results, bundle, effectiveConfigLocation);
513+
CheckstyleReportRenderer r = new CheckstyleReportRenderer(
514+
getSink(),
515+
i18n,
516+
locale,
517+
project,
518+
siteTool,
519+
effectiveConfigLocation,
520+
enableRulesSummary,
521+
enableSeveritySummary,
522+
enableFilesSummary,
523+
results);
524+
if (linkXRef) {
525+
initializeXrefLocation(r);
526+
if (r.getXrefLocation() == null && results.getFileCount() > 0) {
527+
getLog().warn("Unable to locate Source XRef to link to - DISABLED");
528+
}
529+
530+
initializeXrefTestLocation(r);
531+
if (r.getXrefTestLocation() == null && results.getFileCount() > 0) {
532+
getLog().warn("Unable to locate Test Source XRef to link to - DISABLED");
533+
}
534+
535+
r.setTestSourceDirectories(getTestSourceDirectories());
536+
}
537+
if (treeWalkerNames != null) {
538+
r.setTreeWalkerNames(treeWalkerNames);
539+
}
540+
r.render();
500541
} catch (CheckstyleException e) {
501542
throw new MavenReportException("Failed during checkstyle configuration", e);
502543
} catch (CheckstyleExecutorException e) {
@@ -617,49 +658,21 @@ protected DefaultLogger getConsoleListener() throws MavenReportException {
617658
return consoleListener;
618659
}
619660

620-
private void generateMainReport(CheckstyleResults results, ResourceBundle bundle, String configLocation) {
621-
CheckstyleReportGenerator generator =
622-
new CheckstyleReportGenerator(getSink(), bundle, project.getBasedir(), siteTool, configLocation);
623-
624-
generator.setLog(getLog());
625-
generator.setEnableRulesSummary(enableRulesSummary);
626-
generator.setEnableSeveritySummary(enableSeveritySummary);
627-
generator.setEnableFilesSummary(enableFilesSummary);
628-
generator.setCheckstyleConfig(results.getConfiguration());
629-
if (linkXRef) {
630-
initializeXrefLocation(generator);
631-
if (generator.getXrefLocation() == null && results.getFileCount() > 0) {
632-
getLog().warn("Unable to locate Source XRef to link to - DISABLED");
633-
}
634-
635-
initializeXrefTestLocation(generator);
636-
if (generator.getXrefTestLocation() == null && results.getFileCount() > 0) {
637-
getLog().warn("Unable to locate Test Source XRef to link to - DISABLED");
638-
}
639-
640-
generator.setTestSourceDirectories(getTestSourceDirectories());
641-
}
642-
if (treeWalkerNames != null) {
643-
generator.setTreeWalkerNames(treeWalkerNames);
644-
}
645-
generator.generateReport(results);
646-
}
647-
648-
private void initializeXrefLocation(CheckstyleReportGenerator generator) {
661+
private void initializeXrefLocation(CheckstyleReportRenderer renderer) {
649662
String relativePath = determineRelativePath(xrefLocation);
650663
if (xrefLocation.exists() || checkMavenJxrPluginIsConfigured()) {
651664
// XRef was already generated by manual execution of a lifecycle binding
652665
// the report is on its way
653-
generator.setXrefLocation(relativePath);
666+
renderer.setXrefLocation(relativePath);
654667
}
655668
}
656669

657-
private void initializeXrefTestLocation(CheckstyleReportGenerator generator) {
670+
private void initializeXrefTestLocation(CheckstyleReportRenderer renderer) {
658671
String relativePath = determineRelativePath(xrefTestLocation);
659672
if (xrefTestLocation.exists() || checkMavenJxrPluginIsConfigured()) {
660673
// XRef was already generated by manual execution of a lifecycle binding
661674
// the report is on its way
662-
generator.setXrefTestLocation(relativePath);
675+
renderer.setXrefTestLocation(relativePath);
663676
}
664677
}
665678

@@ -683,10 +696,6 @@ private boolean checkMavenJxrPluginIsConfigured() {
683696
return false;
684697
}
685698

686-
private static ResourceBundle getBundle(Locale locale) {
687-
return ResourceBundle.getBundle("checkstyle-report", locale, AbstractCheckstyleReport.class.getClassLoader());
688-
}
689-
690699
protected List<File> getSourceDirectories() {
691700
if (sourceDirectories == null) {
692701
sourceDirectories = project.getCompileSourceRoots();

0 commit comments

Comments
 (0)