[ 
https://issues.apache.org/jira/browse/MPMD-289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16941125#comment-16941125
 ] 

Will Spurginq commented on MPMD-289:
------------------------------------

I've come across the same issue. When the format is XML, this doesn't happen. 
However, when set to HTML, it does. I believe it originates from the fact that 
the Mojo actually explicitly looks for an XML version of the pmd report:

 
{code:java}
executeCheck( "pmd.xml", "violation", "PMD violation", failurePriority );
{code}
[https://github.com/apache/maven-pmd-plugin/blob/84c56491c0f2ad37b1df5e522e4623e67262e8de/src/main/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojo.java#L82]

 

However, when you set the format, the method that actually writes out the 
report file produces the file in the format that is configured:
{code:java}
File targetFile = new File( targetDirectory, "pmd." + format );
{code}
[https://github.com/apache/maven-pmd-plugin/blob/6c1f0a25d5af6a403b4e851c18caf5d084c4a3d9/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java#L644]

 

If the "check" goal requires that the XML formatted output be present, then we 
should clean up the main two places we write out the file:

 
{code:java}
// in execute
if ( !isHtml() && !isXml() )
{
  writeNonHtml( report );
}

//... further down in executePmd
if ( isXml() && renderer != null )
{
  writeNonHtml( renderer.asReport() );
}{code}
To only have one "write block" in the main execute loop that just writes out 
the XML report, then the configured format report
{code:java}
// in execute
writeXml( report );
writeFormatted ( report );
{code}
Looking at the commit history I'm not sure why the two separate writes have 
lingered (and the {{writeNonHtml}} actually _can_ write HTML). Nor can I find 
the reason why we wouldn't write the report out as HTML (maybe someone else 
here can speak to that).

 

As an aside, the story for how this issue suddenly affected me. I had an almost 
identical configuration to the OP. However, the project I was working with had 
a custom ruleset file that was named (prior to me working with it)....  
{{pmd.xml}} .... I _renamed_ the file as part of moving it into a shared build 
resource jar and suddenly, PMD check started failing (leading me to this bug 
report and source diving the plugin for a few hours). I discovered, in addition 
to the above, that PMD actually copies any ruleset files _into_ the _target_ 
build directory.... which meant that all this time, the check was looking for 
its "pmd" report xml file, but getting the rulesets instead. Because it wasn't 
told to fail on violations, it just swallowed the fact that the file wasn't in 
the format the Mojo expected and pressed on. With the rename of the ruleset 
file, suddenly there was no pmd file for it to check.

That was a fun little discovery. My own 2cents on this whole thing is that:
 # if the check Mojo needs the XML version, we should always output it
 # if we're copying ruleset files into the build dir & expecting very specific 
(and somewhat generic) file names in downstream processes, we should output 
everything into specific sub-directories under the maven build directory (e.g., 
target/pmd/report/pmd.xml, target/pmd/rulesets/pmd.xml)

I have limited experience/history with the PMD maven plugin, so I would rely on 
the more versed community members to voice their wisdom (especially wrt #2 
above). However, I think #1 is easy to do and doesn't change any existing 
behavior (and address this bug). #2 could easily be a discussion point to a 
different feature/ticket altogether.

 

 

> check: unable to find pmd.xml
> -----------------------------
>
>                 Key: MPMD-289
>                 URL: https://issues.apache.org/jira/browse/MPMD-289
>             Project: Maven PMD Plugin
>          Issue Type: Bug
>    Affects Versions: 3.12.0
>            Reporter: Ernst Reissner
>            Priority: Major
>
> With format html, the pmd.xml seems not to be generated.
> Consequently, check whether there are no failures fails.
> This problem does not occur when format is pmd.
> Below i showed my pom.
>  
>  
>  
> {code}
> <plugin>
>  <groupId>org.apache.maven.plugins</groupId>
>  <artifactId>maven-pmd-plugin</artifactId>
>  <version>${versionPmdMvnPlugin}</version>
> <dependencies>
>  <dependency>
>  <groupId>net.sourceforge.pmd</groupId>
>  <artifactId>pmd-core</artifactId>
>  <version>${versionPmd}</version>
>  </dependency>
>  <dependency>
>  <groupId>net.sourceforge.pmd</groupId>
>  <artifactId>pmd-java</artifactId>
>  <version>${versionPmd}</version>
>  </dependency>
>  </dependencies>
> <configuration>
>  <linkXref>true</linkXref><!-- default -->
>  <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
>  <minimumTokens>100</minimumTokens><!-- for cpd -->
>  <!--rulesets>
>  <ruleset>${maven.pmd.rulesetfiles}</ruleset>
>  </rulesets-->
>  <skipEmptyReport>false</skipEmptyReport>
>  <failOnViolation>false</failOnViolation>
>  <format>html</format>
>  <!--targetDirectory>target/</targetDirectory-->
>  </configuration>
> <executions>
>  <execution>
>  <goals>
>  <goal>check</goal>
>  <goal>cpd-check</goal>
>  </goals>
>  </execution>
>  </executions>
>  </plugin>
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to