diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java index f1dae2a1..a0943631 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java @@ -183,13 +183,28 @@ private void endFileSection( int level ) sink.section_( level ); } + private void addRuleName( Violation ruleViolation ) + { + boolean hasUrl = StringUtils.isNotBlank( ruleViolation.getExternalInfoUrl() ); + + if ( hasUrl ) + { + sink.link( ruleViolation.getExternalInfoUrl() ); + } + + sink.text( ruleViolation.getRule() ); + + if ( hasUrl ) + { + sink.link_(); + } + } + private void processSingleRuleViolation( Violation ruleViolation, PmdFileInfo fileInfo ) { sink.tableRow(); sink.tableCell(); - sink.link( ruleViolation.getExternalInfoUrl() ); - sink.text( ruleViolation.getRule() ); - sink.link_(); + addRuleName( ruleViolation ); sink.tableCell_(); sink.tableCell(); sink.text( ruleViolation.getText() ); diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java index 4718d87f..8a4fc0bc 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java @@ -664,4 +664,30 @@ public void testCodeClimateRenderer() throws MavenReportException final Renderer renderer = PmdExecutor.createRenderer( "net.sourceforge.pmd.renderers.CodeClimateRenderer", "UTF-8" ); assertNotNull(renderer); } + + public void testPmdReportCustomRulesNoExternalInfoUrl() + throws Exception + { + FileUtils.copyDirectoryStructure( new File( getBasedir(), + "src/test/resources/unit/default-configuration/jxr-files" ), + new File( getBasedir(), "target/test/unit/default-configuration/target/site" ) ); + + File testPom = + new File( getBasedir(), + "src/test/resources/unit/default-configuration/pmd-report-custom-rules.xml" ); + PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom ); + mojo.execute(); + + File generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" ); + renderer( mojo, generatedFile ); + assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + + String str = readFile( generatedFile ); + + // custom rule without link + assertEquals( 2, StringUtils.countMatches( str, "