Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPMD-389] Upgrade to Doxia 2.0.0 Milestone Stack #126

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 6 additions & 43 deletions pom.xml
Expand Up @@ -28,7 +28,7 @@ under the License.
</parent>

<artifactId>maven-pmd-plugin</artifactId>
<version>3.22.1-SNAPSHOT</version>
<version>4.0.0-M1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven PMD Plugin</name>
Expand Down 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
70 changes: 39 additions & 31 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 @@ -77,22 +78,26 @@ public abstract class AbstractPmdReport extends AbstractMavenReport {
protected String format = "xml";

/**
* Link the violation line numbers to the source xref. Links will be created automatically if the jxr plugin is
* Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is
* being used.
*/
@Parameter(property = "linkXRef", defaultValue = "true")
private boolean linkXRef;

/**
* Location of the Xrefs to link to.
* Location where Source XRef is generated for this project.
* <br>
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref}
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref")
@Parameter
private File xrefLocation;

/**
* Location of the Test Xrefs to link to.
* Location where Test Source XRef is generated for this project.
* <br>
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref-test}
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test")
@Parameter
private File xrefTestLocation;

/**
Expand Down Expand Up @@ -159,12 +164,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 +256,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,18 +274,26 @@ protected MavenProject getProject() {
return project;
}

protected String constructXRefLocation(boolean test) {
protected List<MavenProject> getReactorProjects() {
return reactorProjects;
}

protected MojoExecution getMojoExecution() {
return mojoExecution;
}

protected String constructXrefLocation(boolean test) {
String location = null;
if (linkXRef) {
File xrefLoc = test ? xrefTestLocation : xrefLocation;
File xrefLocation = getXrefLocation(test);

String relativePath =
PathTool.getRelativePath(getReportOutputDirectory().getAbsolutePath(), xrefLoc.getAbsolutePath());
String relativePath = PathTool.getRelativePath(
getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
if (relativePath == null || relativePath.isEmpty()) {
relativePath = ".";
}
relativePath = relativePath + "/" + xrefLoc.getName();
if (xrefLoc.exists()) {
relativePath = relativePath + "/" + xrefLocation.getName();
if (xrefLocation.exists()) {
// XRef was already generated by manual execution of a lifecycle binding
location = relativePath;
} else {
Expand All @@ -296,19 +303,24 @@ protected String constructXRefLocation(boolean test) {
reporting != null ? reporting.getPlugins() : Collections.<ReportPlugin>emptyList();
for (ReportPlugin plugin : reportPlugins) {
String artifactId = plugin.getArtifactId();
if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
if ("maven-jxr-plugin".equals(artifactId)) {
location = relativePath;
}
}
}

if (location == null) {
getLog().warn("Unable to locate Source XRef to link to - DISABLED");
getLog().warn("Unable to locate" + (test ? " Test" : "") + " Source XRef to link to - DISABLED");
}
}
return location;
}

protected File getXrefLocation(boolean test) {
File location = test ? xrefTestLocation : xrefLocation;
return location != null ? location : new File(getReportOutputDirectory(), test ? "xref-test" : "xref");
}

/**
* Convenience method to get the list of files where the PMD tool will be executed
*
Expand Down Expand Up @@ -342,7 +354,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
for (String root : compileSourceRoots) {
File sroot = new File(root);
if (sroot.exists()) {
String sourceXref = constructXRefLocation(false);
String sourceXref = constructXrefLocation(false);
directories.add(new PmdFileInfo(project, sroot, sourceXref));
}
}
Expand All @@ -355,7 +367,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
for (String root : testSourceRoots) {
File sroot = new File(root);
if (sroot.exists()) {
String testXref = constructXRefLocation(true);
String testXref = constructXrefLocation(true);
directories.add(new PmdFileInfo(project, sroot, testXref));
}
}
Expand All @@ -366,7 +378,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
for (String root : localCompileSourceRoots) {
File sroot = new File(root);
if (sroot.exists()) {
String sourceXref = constructXRefLocation(false);
String sourceXref = constructXrefLocation(false);
directories.add(new PmdFileInfo(localProject, sroot, sourceXref));
}
}
Expand All @@ -375,7 +387,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
for (String root : localTestCompileSourceRoots) {
File sroot = new File(root);
if (sroot.exists()) {
String testXref = constructXRefLocation(true);
String testXref = constructXrefLocation(true);
directories.add(new PmdFileInfo(localProject, sroot, testXref));
}
}
Expand Down Expand Up @@ -459,11 +471,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 +497,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