Skip to content

Commit

Permalink
[MPMD-282] Add rule name to HTML report
Browse files Browse the repository at this point in the history
And also fix no problem message
  • Loading branch information
adangel committed Apr 6, 2019
1 parent 67ee139 commit 70ad1f0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/it/mpmd-168-empty-report/verify.groovy
Expand Up @@ -26,12 +26,14 @@ assert projectReports.getText( "UTF-8" ).contains( "cpd.html" )

File pmdReportInSite = new File( siteDir, "pmd.html" )
assert pmdReportInSite.exists()
assert pmdReportInSite.getText( "UTF-8" ).contains( "PMD found no problems in your source code." )

File pmdXmlInTarget = new File( targetDir, "pmd.xml" )
assert pmdXmlInTarget.exists()

File cpdReportInSite = new File( siteDir, "cpd.html" )
assert cpdReportInSite.exists()
assert cpdReportInSite.getText( "UTF-8" ).contains( "CPD found no problems in your source code." )

File cpdXmlInTarget = new File( targetDir, "cpd.xml" )
assert cpdXmlInTarget.exists()
16 changes: 10 additions & 6 deletions src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
Expand Up @@ -62,9 +62,6 @@ public class PmdReportGenerator

private boolean renderRuleViolationPriority;

// The number of erroneous files
private int fileCount = 0;

private Map<File, PmdFileInfo> files;

// private List<Metric> metrics = new ArrayList<Metric>();
Expand Down Expand Up @@ -159,6 +156,9 @@ private void startFileSection( String currentFilename, PmdFileInfo fileInfo )
sink.table();
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.pmd.column.rule" ) );
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.pmd.column.violation" ) );
sink.tableHeaderCell_();
if ( this.renderRuleViolationPriority )
Expand All @@ -183,6 +183,11 @@ private void processSingleRuleViolation( RuleViolation ruleViolation, PmdFileInf
{
sink.tableRow();
sink.tableCell();
sink.link( ruleViolation.getRule().getExternalInfoUrl() );
sink.text( ruleViolation.getRule().getName() );
sink.link_();
sink.tableCell_();
sink.tableCell();
sink.text( ruleViolation.getDescription() );
sink.tableCell_();

Expand All @@ -200,7 +205,7 @@ private void processSingleRuleViolation( RuleViolation ruleViolation, PmdFileInf
int endLine = ruleViolation.getEndLine();
if ( endLine != beginLine )
{
sink.text( "&#x2013;" );
sink.text( "&#x2013;" ); // \u2013 is a medium long dash character
outputLineLink( endLine, fileInfo );
}

Expand All @@ -221,7 +226,6 @@ private void processViolations()

// TODO files summary

fileCount = files.size();
List<RuleViolation> violations2 = new ArrayList<>( violations );
Collections.sort( violations2, new Comparator<RuleViolation>()
{
Expand Down Expand Up @@ -268,7 +272,7 @@ public int compare( RuleViolation o1, RuleViolation o2 )
endFileSection();
}

if ( fileCount == 0 )
if ( violations.isEmpty() )
{
sink.paragraph();
sink.text( bundle.getString( "report.pmd.noProblems" ) );
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/pmd-report.properties
Expand Up @@ -18,6 +18,7 @@
report.pmd.name=PMD
report.pmd.description=Verification of coding rules.
report.pmd.title=PMD Results
report.pmd.column.rule=Rule
report.pmd.column.violation=Violation
report.pmd.column.priority=Priority
report.pmd.column.line=Line
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/pmd-report_de.properties
Expand Up @@ -18,6 +18,7 @@
report.pmd.name=PMD
report.pmd.description=Verifikation von Code-Richtlinien.
report.pmd.title=PMD Ergebnisse
report.pmd.column.rule=Regel
report.pmd.column.violation=Versto\u00df
report.pmd.column.priority=Priorit\u00e4t
report.pmd.column.line=Zeile
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -58,6 +59,7 @@ protected void setUp()
throws Exception
{
super.setUp();
Locale.setDefault( Locale.ENGLISH );
FileUtils.deleteDirectory( new File( getBasedir(), "target/test/unit" ) );
}

Expand Down Expand Up @@ -300,6 +302,7 @@ public void testEmptyReportConfiguration()
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
String str = readFile( new File( getBasedir(), "target/test/unit/empty-report/target/site/cpd.html" ) );
assertFalse( lowerCaseContains( str, "Hello.java" ) );
assertTrue( str.contains( "CPD found no problems in your source code." ) );
}

public void testCpdEncodingConfiguration()
Expand Down
Expand Up @@ -89,7 +89,12 @@ public void testDefaultConfiguration()
assertTrue( str.contains( "/xref/def/configuration/AppSample.html#L45" ) );

// check if there's a priority column
assertTrue( str.contains( "Priority" ) );
assertTrue( str.contains( "<th>Priority</th>" ) );

// there should be a rule column
assertTrue( str.contains( "<th>Rule</th>" ) );
// along with a link to the rule
assertTrue( str.contains( "pmd_rules_java_bestpractices.html#unusedprivatefield\">UnusedPrivateField</a>" ) );
}

public void testDefaultConfigurationNotRenderRuleViolationPriority()
Expand Down Expand Up @@ -339,6 +344,7 @@ public void testEmptyReportConfiguration()
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
String str = readFile( generatedFile );
assertFalse( lowerCaseContains( str, "Hello.java" ) );
assertTrue( str.contains( "PMD found no problems in your source code." ) );
}

public void testInvalidFormat()
Expand Down

0 comments on commit 70ad1f0

Please sign in to comment.