Skip to content

Commit 4eae72c

Browse files
committed
[MPMD-324] Ruleset URLs have hyphen replaced with forwardslash
1 parent 64e35f7 commit 4eae72c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/main/java/org/apache/maven/plugins/pmd/PmdReport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ private String determineRulesetFilename( String ruleset )
460460
{
461461
String result = ruleset.trim();
462462
String lowercase = result.toLowerCase( Locale.ROOT );
463-
if ( lowercase.endsWith( ".xml" ) )
463+
if ( lowercase.startsWith( "http://" ) || lowercase.startsWith( "https://" ) || lowercase.endsWith( ".xml" ) )
464464
{
465465
return result;
466466
}

src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ public void testPmdReportResolveRulesets()
719719
final String sonarExportRulesetUrl = "http://localhost:" + mockServer.port() + sonarProfileUrl;
720720
final String myRulesetBaseUrl = "/config/my-ruleset.xml";
721721
final String myRulesetUrl = "http://localhost:" + mockServer.port() + myRulesetBaseUrl;
722+
final String notAInternalRulesetBaseUrl = "/projects/OURPROJECT/repos/ourproject-pmd/raw/InProgressRuleset.xml?at=refs%2Fheads%2Fmaster";
723+
final String notAInternalRulesetUrl = "http://localhost:" + mockServer.port() + notAInternalRulesetBaseUrl;
722724

723725
WireMock.configureFor( "localhost", port );
724726
WireMock.stubFor( WireMock.get( WireMock.urlEqualTo( sonarProfileUrl ) )
@@ -727,6 +729,9 @@ public void testPmdReportResolveRulesets()
727729
WireMock.stubFor( WireMock.get( WireMock.urlEqualTo( myRulesetBaseUrl ) )
728730
.willReturn( WireMock.aResponse().withStatus( 200 ).withHeader( "Content-Type",
729731
"text/xml" ).withBody( sonarRuleset ) ) );
732+
WireMock.stubFor( WireMock.get( WireMock.urlEqualTo( notAInternalRulesetBaseUrl ) )
733+
.willReturn( WireMock.aResponse().withStatus( 200 ).withHeader( "Content-Type",
734+
"text/xml" ).withBody( sonarRuleset ) ) );
730735

731736
FileUtils.copyDirectoryStructure( new File( getBasedir(),
732737
"src/test/resources/unit/default-configuration/jxr-files" ),
@@ -738,6 +743,7 @@ public void testPmdReportResolveRulesets()
738743
PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom );
739744
mojo.rulesets[3] = sonarExportRulesetUrl;
740745
mojo.rulesets[4] = myRulesetUrl;
746+
mojo.rulesets[5] = notAInternalRulesetUrl;
741747
mojo.execute();
742748

743749
// these are the rulesets, that have been copied to target/pmd/rulesets
@@ -756,6 +762,9 @@ public void testPmdReportResolveRulesets()
756762
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/my-ruleset.xml" );
757763
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
758764

765+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/InProgressRuleset.xml_at_refs_2Fheads_2Fmaster.xml" );
766+
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
767+
759768
mockServer.stop();
760769
}
761770

src/test/resources/unit/default-configuration/pmd-report-resolve-rulesets.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ under the License.
4444
<!-- note, the port of the http urls will be replaced by the unit test -->
4545
<ruleset>http://localhost:12345/profiles/export?format=pmd&amp;language=java&amp;name=Sonar%2520way</ruleset>
4646
<ruleset>http://localhost:12345/config/my-ruleset.xml</ruleset>
47+
<ruleset>http://localhost:12345/projects/OURPROJECT/repos/ourproject-pmd/raw/InProgressRuleset.xml?at=refs%2Fheads%2Fmaster</ruleset>
4748
</rulesets>
4849
<format>xml</format>
4950
<linkXRef>true</linkXRef>

0 commit comments

Comments
 (0)