Skip to content

Commit

Permalink
[MPMD-324] Ruleset URLs have hyphen replaced with forwardslash
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Feb 3, 2022
1 parent 64e35f7 commit 4eae72c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private String determineRulesetFilename( String ruleset )
{
String result = ruleset.trim();
String lowercase = result.toLowerCase( Locale.ROOT );
if ( lowercase.endsWith( ".xml" ) )
if ( lowercase.startsWith( "http://" ) || lowercase.startsWith( "https://" ) || lowercase.endsWith( ".xml" ) )
{
return result;
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ public void testPmdReportResolveRulesets()
final String sonarExportRulesetUrl = "http://localhost:" + mockServer.port() + sonarProfileUrl;
final String myRulesetBaseUrl = "/config/my-ruleset.xml";
final String myRulesetUrl = "http://localhost:" + mockServer.port() + myRulesetBaseUrl;
final String notAInternalRulesetBaseUrl = "/projects/OURPROJECT/repos/ourproject-pmd/raw/InProgressRuleset.xml?at=refs%2Fheads%2Fmaster";
final String notAInternalRulesetUrl = "http://localhost:" + mockServer.port() + notAInternalRulesetBaseUrl;

WireMock.configureFor( "localhost", port );
WireMock.stubFor( WireMock.get( WireMock.urlEqualTo( sonarProfileUrl ) )
Expand All @@ -727,6 +729,9 @@ public void testPmdReportResolveRulesets()
WireMock.stubFor( WireMock.get( WireMock.urlEqualTo( myRulesetBaseUrl ) )
.willReturn( WireMock.aResponse().withStatus( 200 ).withHeader( "Content-Type",
"text/xml" ).withBody( sonarRuleset ) ) );
WireMock.stubFor( WireMock.get( WireMock.urlEqualTo( notAInternalRulesetBaseUrl ) )
.willReturn( WireMock.aResponse().withStatus( 200 ).withHeader( "Content-Type",
"text/xml" ).withBody( sonarRuleset ) ) );

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

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

generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/InProgressRuleset.xml_at_refs_2Fheads_2Fmaster.xml" );
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );

mockServer.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ under the License.
<!-- note, the port of the http urls will be replaced by the unit test -->
<ruleset>http://localhost:12345/profiles/export?format=pmd&amp;language=java&amp;name=Sonar%2520way</ruleset>
<ruleset>http://localhost:12345/config/my-ruleset.xml</ruleset>
<ruleset>http://localhost:12345/projects/OURPROJECT/repos/ourproject-pmd/raw/InProgressRuleset.xml?at=refs%2Fheads%2Fmaster</ruleset>
</rulesets>
<format>xml</format>
<linkXRef>true</linkXRef>
Expand Down

0 comments on commit 4eae72c

Please sign in to comment.