[ 
https://jira.codehaus.org/browse/MPMD-174?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=358214#comment-358214
 ] 

Maciek Siemczyk commented on MPMD-174:
--------------------------------------

So it is not the Sonar issue rather that the plugin is incorrectly stripping 
the http resources. The problem is actually in PMD's code (in 
RuleSetReferenceId class), where constructor builds rule set filename. It so 
happens that sonar link looks like:

http://[sonar-instance]/profiles/export?format=pmd&language=java&name=[default]

and that constructor strips incorrectly to http://[sonar-instance]/profiles. 
That link will in turn return Sonar's main page (HTML), which fails parsing. As 
far as I know all of the 3.x versions of maven PMD plugin are affected, but I 
don't know for sure. Also I don't have permission to add the versions.

The attached proposed solution is acceptable and I modified the unit test to 
include this scenario. The unit test using the old code will actually error out 
in the test with exact same error as in the production so this should prevent 
any future regression. 

Here is a sample of unit test output when code does not have the patch:

Running org.apache.maven.plugin.pmd.PmdReportTest
[Fatal Error] :20:50: White spaces are required between publicId and systemId.
org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 50; White spaces 
are required between publicId and systemId.
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
        at 
net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:200)
        at 
net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:164)
        at 
net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:129)
        at 
net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:114)
        at 
net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSets(RulesetsFactoryUtils.java:31)
        at 
net.sourceforge.pmd.processor.AbstractPMDProcessor.createRuleSets(AbstractPMDProcessor.java:54)
        at 
net.sourceforge.pmd.processor.MultiThreadProcessor.processFiles(MultiThreadProcessor.java:38)
        at net.sourceforge.pmd.PMD.processFiles(PMD.java:331)
        at org.apache.maven.plugin.pmd.PmdReport.executePmd(PmdReport.java:375)
        at 
org.apache.maven.plugin.pmd.PmdReport.executePmdWithClassloader(PmdReport.java:262)
        at 
org.apache.maven.plugin.pmd.PmdReport.canGenerateReport(PmdReport.java:237)
        at 
org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:81)
        at 
org.apache.maven.plugin.pmd.PmdReportTest.testFileURL(PmdReportTest.java:165)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:243)
        at junit.framework.TestSuite.run(TestSuite.java:238)
        at 
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
        at 
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
        at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
        at 
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
        at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
        at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
        at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Tests run: 10, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.864 sec <<< 
FAILURE! - in org.apache.maven.plugin.pmd.PmdReportTest


> Using a permalink from sonar as a ruleset does not work
> -------------------------------------------------------
>
>                 Key: MPMD-174
>                 URL: https://jira.codehaus.org/browse/MPMD-174
>             Project: Maven PMD Plugin
>          Issue Type: Bug
>            Reporter: Cremers stijn
>         Attachments: MPMD-174.patch
>
>
> I am trying to use a permalink from sonar with the pmd configuration from 
> sonar as a rulest in the maven-pmd-plugin.
> This is my maven configuration:
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-pmd-plugin</artifactId>
>     <version>3.0.1</version>
>     <configuration>
>         <rulesets>
>             
> <ruleset>http://my-tools.mycompany.com/sonar/profiles/export?format=pmd&amp;language=java&amp;name=MyProfile</ruleset>
>         </rulesets>
>     </configuration>
>     <executions>
>         <execution>
>             <id>pmd</id>
>             <goals><goal>check</goal></goals>
>         </execution>
>     </executions>
> </plugin>
> But i get the following error when i run "mvn clean install": 
> [ERROR] Failed to execute goal 
> org.apache.maven.plugins:maven-pmd-plugin:3.0.1:pmd (pmd) on project my-pmd: 
> An error has occurred in PMD Report report generation. Could not find 
> resource 'rulesets/http://my/tools.mycompany.com/sonar/profiles.xml'. -> 
> [Help 1]
> I have tried to use the link from the sonar demo site:
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-pmd-plugin</artifactId>
>     <version>3.0.1</version>
>     <configuration>
>         <rulesets>
>             
> <ruleset>http://nemo.sonarqube.org/profiles/export?format=pmd&amp;language=java&amp;name=Nemo</ruleset>
>         </rulesets>
>     </configuration>
>     <executions>
>         <execution>
>             <id>pmd</id>
>             <goals><goal>check</goal></goals>
>         </execution>
>     </executions>
> </plugin>
> But then i get the following error:
> [INFO] --- maven-pmd-plugin:3.0.1:pmd (pmd) @ my-pmd ---
> [WARNING] Unable to locate Source XRef to link to - DISABLED
> [WARNING] Failure executing PMD: Couldn't find the class White spaces are 
> required between publicId and systemId.
> java.lang.RuntimeException: Couldn't find the class White spaces are required 
> between publicId and systemId.
>       at 
> net.sourceforge.pmd.RuleSetFactory.classNotFoundProblem(RuleSetFactory.java:244)
>       at 
> net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:238)
>       at 
> net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:161)
>       at 
> net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:126)
>       at 
> net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:111)
>       at 
> net.sourceforge.pmd.processor.AbstractPMDProcessor.createRuleSets(AbstractPMDProcessor.java:56)
>       at 
> net.sourceforge.pmd.processor.MonoThreadProcessor.processFiles(MonoThreadProcessor.java:41)
>       at net.sourceforge.pmd.PMD.processFiles(PMD.java:271)
>       at 
> org.apache.maven.plugin.pmd.PmdReport.generateReport(PmdReport.java:296)
>       at org.apache.maven.plugin.pmd.PmdReport.execute(PmdReport.java:194)
>       at 
> org.apache.maven.plugin.pmd.PmdReport.executeReport(PmdReport.java:168)
>       at 
> org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:190)
>       at 
> org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:99)
>       at 
> org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:364)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:198)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
>       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
>       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
>       at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
>       at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
>       at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:414)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:357)



--
This message was sent by Atlassian JIRA
(v6.1.6#6162)

Reply via email to