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 May 4, 2024
1 parent a511fa5 commit 47275ba
Show file tree
Hide file tree
Showing 46 changed files with 244 additions and 221 deletions.
47 changes: 5 additions & 42 deletions pom.xml
Expand Up @@ -85,12 +85,12 @@ under the License.
<javaVersion>8</javaVersion>
<pmdVersion>7.0.0</pmdVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<doxiaVersion>2.0.0-M8</doxiaVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion>
<doxiaVersion>1.12.0</doxiaVersion>
<compilerPluginVersion>3.11.0</compilerPluginVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.4.3</projectInfoReportsPluginVersion>
<jxrPluginVersion>3.3.0</jxrPluginVersion>
<sitePluginVersion>4.0.0-M13</sitePluginVersion>
<projectInfoReportsPluginVersion>4.0.0-M1-SNAPSHOT</projectInfoReportsPluginVersion>
<jxrPluginVersion>4.0.0-M1-SNAPSHOT</jxrPluginVersion>
<project.build.outputTimestamp>2024-04-18T10:13:24Z</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-M13</version>
</dependency>

<!-- plexus -->
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-165/verify.groovy
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
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
Expand Up @@ -32,18 +32,18 @@ assert pmdReport.exists()
assert pmdReport.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="35" rule="ExtendsObject"' )
assert pmdReport.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' )

File cpdReport = new File( basedir, 'target/cpd.xml' )
assert cpdReport.exists()
assert cpdReport.text.contains( 'Name.java' )
assert cpdReport.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
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
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 @@ -159,12 +160,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 @@ -251,12 +252,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 @@ -275,6 +270,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 @@ -459,11 +462,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 @@ -489,7 +488,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
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
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
Expand Up @@ -194,7 +194,7 @@ private CpdResult run() throws MavenReportException {

private void writeXmlReport(CPDReport cpd) throws MavenReportException {
File targetFile = writeReport(cpd, new XMLRenderer(request.getOutputEncoding()), "xml");
if (request.isIncludeXmlInSite()) {
if (request.isIncludeXmlInReports()) {
File siteDir = new File(request.getReportOutputDirectory());
siteDir.mkdirs();
try {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java
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
Expand Up @@ -315,11 +315,11 @@ private Report processFilesWithPMD(PMDConfiguration pmdConfiguration, List<File>
*/
private void writeXmlReport(Report report) throws MavenReportException {
File targetFile = writeReport(report, new XMLRenderer(request.getOutputEncoding()));
if (request.isIncludeXmlInSite()) {
File siteDir = new File(request.getReportOutputDirectory());
siteDir.mkdirs();
if (request.isIncludeXmlInReports()) {
File outputDirectory = new File(request.getReportOutputDirectory());
outputDirectory.mkdirs();
try {
FileUtils.copyFile(targetFile, new File(siteDir, "pmd.xml"));
FileUtils.copyFile(targetFile, new File(outputDirectory, "pmd.xml"));
} catch (IOException e) {
throw new MavenReportException(e.getMessage(), e);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java
Expand Up @@ -55,7 +55,7 @@ public class PmdRequest implements Serializable {
private String outputEncoding;
private String format;
private String benchmarkOutputLocation;
private boolean includeXmlInSite;
private boolean includeXmlInReports;
private String reportOutputDirectory;

/**
Expand Down Expand Up @@ -133,8 +133,8 @@ public void setSkipPmdError(boolean skipPmdError) {
this.skipPmdError = skipPmdError;
}

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 @@ -213,8 +213,8 @@ public boolean isSkipPmdError() {
return skipPmdError;
}

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

public String getReportOutputDirectory() {
Expand Down

0 comments on commit 47275ba

Please sign in to comment.