28
28
import java .util .List ;
29
29
import java .util .Locale ;
30
30
import java .util .Map ;
31
- import java .util .ResourceBundle ;
32
31
33
32
import com .puppycrawl .tools .checkstyle .DefaultLogger ;
34
33
import com .puppycrawl .tools .checkstyle .XMLLogger ;
53
52
import org .apache .maven .reporting .AbstractMavenReport ;
54
53
import org .apache .maven .reporting .MavenReportException ;
55
54
import org .codehaus .plexus .configuration .PlexusConfiguration ;
55
+ import org .codehaus .plexus .i18n .I18N ;
56
56
import org .codehaus .plexus .resource .ResourceManager ;
57
57
import org .codehaus .plexus .resource .loader .FileResourceLoader ;
58
58
import org .codehaus .plexus .util .FileUtils ;
@@ -438,16 +438,31 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
438
438
@ Component (role = CheckstyleExecutor .class , hint = "default" )
439
439
protected CheckstyleExecutor checkstyleExecutor ;
440
440
441
+ /**
442
+ * Internationalization component
443
+ */
444
+ @ Component
445
+ private I18N i18n ;
446
+
441
447
protected ByteArrayOutputStream stringOutputStream ;
442
448
443
449
/** {@inheritDoc} */
444
450
public String getName (Locale locale ) {
445
- return getBundle (locale ). getString ( "report.checkstyle. name" );
451
+ return getI18nString (locale , " name" );
446
452
}
447
453
448
454
/** {@inheritDoc} */
449
455
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 );
451
466
}
452
467
453
468
/** {@inheritDoc} */
@@ -495,8 +510,34 @@ public void executeReport(Locale locale) throws MavenReportException {
495
510
496
511
CheckstyleResults results = checkstyleExecutor .executeCheckstyle (request );
497
512
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 ();
500
541
} catch (CheckstyleException e ) {
501
542
throw new MavenReportException ("Failed during checkstyle configuration" , e );
502
543
} catch (CheckstyleExecutorException e ) {
@@ -617,49 +658,21 @@ protected DefaultLogger getConsoleListener() throws MavenReportException {
617
658
return consoleListener ;
618
659
}
619
660
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 ) {
649
662
String relativePath = determineRelativePath (xrefLocation );
650
663
if (xrefLocation .exists () || checkMavenJxrPluginIsConfigured ()) {
651
664
// XRef was already generated by manual execution of a lifecycle binding
652
665
// the report is on its way
653
- generator .setXrefLocation (relativePath );
666
+ renderer .setXrefLocation (relativePath );
654
667
}
655
668
}
656
669
657
- private void initializeXrefTestLocation (CheckstyleReportGenerator generator ) {
670
+ private void initializeXrefTestLocation (CheckstyleReportRenderer renderer ) {
658
671
String relativePath = determineRelativePath (xrefTestLocation );
659
672
if (xrefTestLocation .exists () || checkMavenJxrPluginIsConfigured ()) {
660
673
// XRef was already generated by manual execution of a lifecycle binding
661
674
// the report is on its way
662
- generator .setXrefTestLocation (relativePath );
675
+ renderer .setXrefTestLocation (relativePath );
663
676
}
664
677
}
665
678
@@ -683,10 +696,6 @@ private boolean checkMavenJxrPluginIsConfigured() {
683
696
return false ;
684
697
}
685
698
686
- private static ResourceBundle getBundle (Locale locale ) {
687
- return ResourceBundle .getBundle ("checkstyle-report" , locale , AbstractCheckstyleReport .class .getClassLoader ());
688
- }
689
-
690
699
protected List <File > getSourceDirectories () {
691
700
if (sourceDirectories == null ) {
692
701
sourceDirectories = project .getCompileSourceRoots ();
0 commit comments