This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch 224 in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git
The following commit(s) were added to refs/heads/224 by this push: new 7fbe888 wip 7fbe888 is described below commit 7fbe888b5639415ef5bd813a7646706fd87dc4fa Author: Elliotte Rusty Harold <elh...@ibiblio.org> AuthorDate: Tue Oct 7 07:48:12 2025 -0400 wip --- .../java/org/apache/maven/plugins/pmd/CpdReport.java | 19 ++++++++++++------- .../java/org/apache/maven/plugins/pmd/PmdReport.java | 2 +- .../org/apache/maven/plugins/pmd/CpdReportTest.java | 9 +++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java index 7217773..c9f433f 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java @@ -18,14 +18,14 @@ */ package org.apache.maven.plugins.pmd; -import java.io.File; -import java.util.Map; import javax.inject.Inject; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Locale; +import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.doxia.sink.SinkFactory; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.pmd.exec.CpdRequest; @@ -143,14 +143,19 @@ public class CpdReport extends AbstractPmdReport { ClassLoader origLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - if (filesToProcess == null) { - filesToProcess = getFilesToProcess(); + if (cpdResult == null) { + executeCpd(); + } + Sink sink = getSink(); + if (sink == null) { + SinkFactory sinkFactory = getSinkFactory(); + sink = sinkFactory.createSink(outputDirectory, "tempreport"); } CpdReportRenderer renderer = new CpdReportRenderer( - getSink(), i18n, locale, filesToProcess, cpdResult.getDuplications(), isAggregator()); + sink, i18n, locale, filesToProcess, cpdResult.getDuplications(), isAggregator()); renderer.render(); - } catch (IOException ex) { - throw new MavenReportException(ex.getMessage(), ex); + } catch (IOException e) { + throw new MavenReportException(e.getMessage(), e); } finally { Thread.currentThread().setContextClassLoader(origLoader); } diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java index bc15fd6..b2a394f 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java @@ -314,7 +314,7 @@ public class PmdReport extends AbstractPmdReport { renderer.render(); } catch (IOException ex) { - throw new MavenReportException(ex.getMessage(), ex); + throw new MavenReportException(ex.getMessage(), ex); } finally { Thread.currentThread().setContextClassLoader(origLoader); } diff --git a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java index bfd5fd2..006606e 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java @@ -27,6 +27,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Locale; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; @@ -48,6 +49,14 @@ public class CpdReportTest extends AbstractPmdReportTestCase { FileUtils.deleteDirectory(new File(getBasedir(), "target/test/unit")); } + public void testExecute() throws Exception { + File pluginXmlFile = new File( + getBasedir(), + "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml"); + CpdReport mojo = (CpdReport) createReportMojo("cpd", pluginXmlFile); + mojo.executeReport(Locale.ROOT); + } + /** * Test CPDReport given the default configuration */