Skip to content

Commit

Permalink
[MPMD-389] Upgrade to Doxia 2.0.0 Milestone Stack
Browse files Browse the repository at this point in the history
This closes #126
  • Loading branch information
michael-o committed Aug 19, 2024
1 parent 4d7c080 commit c31b29a
Show file tree
Hide file tree
Showing 48 changed files with 273 additions and 242 deletions.
47 changes: 5 additions & 42 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ under the License.
<pmdVersion>7.3.0</pmdVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<resolverVersion>1.4.1</resolverVersion>
<doxiaVersion>1.12.0</doxiaVersion>
<doxiaVersion>2.0.0-M12</doxiaVersion>
<compilerPluginVersion>3.11.0</compilerPluginVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.4.3</projectInfoReportsPluginVersion>
<jxrPluginVersion>3.3.0</jxrPluginVersion>
<sitePluginVersion>3.20.0</sitePluginVersion>
<projectInfoReportsPluginVersion>3.7.0</projectInfoReportsPluginVersion>
<jxrPluginVersion>3.4.0</jxrPluginVersion>
<project.build.outputTimestamp>2024-07-10T19:17:23Z</project.build.outputTimestamp>
</properties>

Expand Down Expand Up @@ -193,55 +193,18 @@ under the License.
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>${doxiaVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>${doxiaVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>1.11.1</version>
<scope>runtime</scope>
<!--
Note: doxia-site-renderer needs to be defined AFTER pmd:
doxia-site-renderer requires transitively dom4j 1.1 which provides a very old version of jaxen (same jar).
PMD requires a newer version of jaxen, which is not compatible.
-->
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- shared -->
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0-M15</version>
</dependency>

<!-- plexus -->
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-165/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

File pmdHtml = new File( basedir, "target/site/pmd.html" );
File pmdHtml = new File( basedir, "target/reports/pmd.html" );
assert pmdHtml.exists()

// Groovy's getText() automatically detects the correct encoding, so that UTF-16 works out of the box
Expand Down
4 changes: 2 additions & 2 deletions src/it/MPMD-289-format-html-check/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ assert buildLog.exists()
File pmdXml = new File( basedir, 'target/pmd.xml' )
assert pmdXml.exists()

File pmdHtmlReport = new File ( basedir, 'target/site/pmd.html' )
File pmdHtmlReport = new File ( basedir, 'target/reports/pmd.html' )
assert pmdHtmlReport.exists()

File cpdXml = new File( basedir, 'target/cpd.xml' )
assert cpdXml.exists()

File cpdHtmlReport = new File ( basedir, 'target/site/cpd.html' )
File cpdHtmlReport = new File ( basedir, 'target/reports/cpd.html' )
assert cpdHtmlReport.exists()
18 changes: 9 additions & 9 deletions src/it/MPMD-304-toolchain-support/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ assert buildLog.text.contains('[WARNING] CPD ' + pmdVersion + ' has found 1 dupl
assert pmdXml.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="35" rule="ExtendsObject"' )
assert pmdXml.text.contains( '<violation beginline="36" endline="36" begincolumn="9" endcolumn="32" rule="DontCallThreadRun"' )

File pmdSite = new File( basedir, 'target/site/pmd.html' )
assert pmdSite.exists()
assert pmdSite.text.contains( 'Sample.java' )
assert pmdSite.text.contains( 'ExtendsObject' )
assert pmdSite.text.contains( 'DontCallThreadRun' )
File pmdHtmlReport = new File( basedir, 'target/reports/pmd.html' )
assert pmdHtmlReport.exists()
assert pmdHtmlReport.text.contains( 'Sample.java' )
assert pmdHtmlReport.text.contains( 'ExtendsObject' )
assert pmdHtmlReport.text.contains( 'DontCallThreadRun' )

assert cpdXml.text.contains( 'Name.java' )
assert cpdXml.text.contains( 'Name2.java' )

File cpdSite = new File( basedir, 'target/site/cpd.html' )
assert cpdSite.exists()
assert cpdSite.text.contains( 'Name.java' )
assert cpdSite.text.contains( 'Name2.java' )
File cpdHtmlReport = new File( basedir, 'target/reports/cpd.html' )
assert cpdHtmlReport.exists()
assert cpdHtmlReport.text.contains( 'Name.java' )
assert cpdHtmlReport.text.contains( 'Name2.java' )
4 changes: 2 additions & 2 deletions src/it/mpmd-80-included/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ under the License.

<name>MPMD-80 included</name>
<description>
Test that the cpd.xml and pmd.xml files are included in the generated site.
Test that the cpd.xml and pmd.xml files are included in the generated reports output directory.
</description>

<build>
Expand All @@ -48,7 +48,7 @@ under the License.
<version>@project.version@</version>
<configuration>
<skipPmdError>false</skipPmdError>
<includeXmlInSite>true</includeXmlInSite>
<includeXmlInReports>true</includeXmlInReports>
</configuration>
</plugin>
</plugins>
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -160,12 +161,12 @@ public abstract class AbstractPmdReport extends AbstractMavenReport {
protected boolean aggregate;

/**
* Whether to include the xml files generated by PMD/CPD in the site.
* Whether to include the XML files generated by PMD/CPD in the {@link #getReportOutputDirectory()}.
*
* @since 3.0
*/
@Parameter(defaultValue = "false")
protected boolean includeXmlInSite;
protected boolean includeXmlInReports;

/**
* Skip the PMD/CPD report generation if there are no violations or duplications found. Defaults to
Expand Down Expand Up @@ -252,12 +253,6 @@ public abstract class AbstractPmdReport extends AbstractMavenReport {
// Read-only parameters
// ----------------------------------------------------------------------

/**
* The projects in the reactor for aggregation report.
*/
@Parameter(property = "reactorProjects", readonly = true)
protected List<MavenProject> reactorProjects;

/**
* The current build session instance. This is used for
* toolchain manager API calls and for dependency resolver API calls.
Expand All @@ -276,6 +271,14 @@ protected MavenProject getProject() {
return project;
}

protected List<MavenProject> getReactorProjects() {
return reactorProjects;
}

protected MojoExecution getMojoExecution() {
return mojoExecution;
}

protected String constructXRefLocation(boolean test) {
String location = null;
if (linkXRef) {
Expand Down Expand Up @@ -460,11 +463,7 @@ protected boolean isXml() {
return "xml".equals(format);
}

/**
* {@inheritDoc}
*/
@Override
public boolean canGenerateReport() {
protected boolean canGenerateReportInternal() throws MavenReportException {
if (!showPmdLog && !warnedAboutShowPmdLog) {
getLog().warn("The parameter \"showPmdLog\" has been deprecated and will be removed."
+ "Setting it to \"false\" has no effect.");
Expand All @@ -490,7 +489,7 @@ public boolean canGenerateReport() {
return false;
}
} catch (IOException e) {
getLog().error(e);
throw new MavenReportException("Failed to determine files to process for PMD", e);
}
return true;
}
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,16 @@ public void executeReport(Locale locale) throws MavenReportException {
}

@Override
public boolean canGenerateReport() {
public boolean canGenerateReport() throws MavenReportException {
if (skip) {
getLog().info("Skipping CPD execution");
return false;
}

boolean result = super.canGenerateReport();
boolean result = canGenerateReportInternal();
if (result) {
try {
executeCpd();
if (skipEmptyReport) {
result = cpdResult.hasDuplications();
if (!result) {
getLog().debug("Skipping report since skipEmptyReport is true and there are no CPD issues.");
}
}
} catch (MavenReportException e) {
throw new RuntimeException(e);
executeCpd();
if (skipEmptyReport) {
result = cpdResult.hasDuplications();
}
}
return result;
Expand Down Expand Up @@ -190,7 +182,7 @@ private void executeCpd() throws MavenReportException {
request.setTargetDirectory(targetDirectory.getAbsolutePath());
request.setOutputEncoding(getOutputEncoding());
request.setFormat(format);
request.setIncludeXmlInSite(includeXmlInSite);
request.setIncludeXmlInReports(includeXmlInReports);
request.setReportOutputDirectory(getReportOutputDirectory().getAbsolutePath());

Toolchain tc = getToolchain();
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,16 @@ public void executeReport(Locale locale) throws MavenReportException {
}

@Override
public boolean canGenerateReport() {
public boolean canGenerateReport() throws MavenReportException {
if (skip) {
getLog().info("Skipping PMD execution");
return false;
}

boolean result = super.canGenerateReport();
boolean result = canGenerateReportInternal();
if (result) {
try {
executePmd();
if (skipEmptyReport) {
result = pmdResult.hasViolations();
if (!result) {
getLog().debug("Skipping report since skipEmptyReport is true and "
+ "there are no PMD violations.");
}
}
} catch (MavenReportException e) {
throw new RuntimeException(e);
executePmd();
if (skipEmptyReport) {
result = pmdResult.hasViolations();
}
}
return result;
Expand Down Expand Up @@ -370,7 +361,7 @@ private void executePmd() throws MavenReportException {
request.setOutputEncoding(getOutputEncoding());
request.setFormat(format);
request.setSkipPmdError(skipPmdError);
request.setIncludeXmlInSite(includeXmlInSite);
request.setIncludeXmlInReports(includeXmlInReports);
request.setReportOutputDirectory(getReportOutputDirectory().getAbsolutePath());
request.setLogLevel(determineCurrentRootLogLevel());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public void accept(CPDReport report) {

private void writeXmlReport(CPDReport cpd) throws IOException {
File targetFile = writeReport(cpd, new XMLRenderer(request.getOutputEncoding()), "xml");
if (request.isIncludeXmlInSite()) {
File siteDir = new File(request.getReportOutputDirectory());
if (!siteDir.exists() && !siteDir.mkdirs()) {
throw new IOException("Couldn't create report output directory: " + siteDir);
if (request.isIncludeXmlInReports()) {
File outputDirectory = new File(request.getReportOutputDirectory());
if (!outputDirectory.exists() && !outputDirectory.mkdirs()) {
throw new IOException("Couldn't create report output directory: " + outputDirectory);
}
FileUtils.copyFile(targetFile, new File(siteDir, "cpd.xml"));
FileUtils.copyFile(targetFile, new File(outputDirectory, "cpd.xml"));
}
}

Expand All @@ -88,7 +88,7 @@ private File writeReport(CPDReport cpd, CPDReportRenderer renderer, String exten

File targetDir = new File(request.getTargetDirectory());
if (!targetDir.exists() && !targetDir.mkdirs()) {
throw new IOException("Couldn't create report output directory: " + targetDir);
throw new IOException("Couldn't create report target directory: " + targetDir);
}

File targetFile = new File(targetDir, "cpd." + extension);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class CpdRequest implements Serializable {
private String targetDirectory;
private String outputEncoding;
private String format;
private boolean includeXmlInSite;
private boolean includeXmlInReports;
private String reportOutputDirectory;
private boolean ignoreAnnotations;
private boolean ignoreIdentifiers;
Expand Down Expand Up @@ -96,8 +96,8 @@ public void setFormat(String format) {
this.format = format;
}

public void setIncludeXmlInSite(boolean includeXmlInSite) {
this.includeXmlInSite = includeXmlInSite;
public void setIncludeXmlInReports(boolean includeXmlInReports) {
this.includeXmlInReports = includeXmlInReports;
}

public void setReportOutputDirectory(String reportOutputDirectory) {
Expand Down Expand Up @@ -148,8 +148,8 @@ public String getFormat() {
return format;
}

public boolean isIncludeXmlInSite() {
return includeXmlInSite;
public boolean isIncludeXmlInReports() {
return includeXmlInReports;
}

public String getReportOutputDirectory() {
Expand Down
Loading

0 comments on commit c31b29a

Please sign in to comment.