This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch guice
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git

commit 7d1b15b803a35c77499ff65d0214e9e3038d50c5
Author: Elliotte Rusty Harold <elh...@ibiblio.org>
AuthorDate: Sat Dec 14 06:49:13 2024 -0500

    Prefer Guice injection
---
 .../org/apache/maven/plugins/pmd/AbstractPmdReport.java     |  8 +++++---
 .../org/apache/maven/plugins/pmd/AggregatorCpdReport.java   | 10 ++++++++++
 src/main/java/org/apache/maven/plugins/pmd/CpdReport.java   | 13 ++++++++++---
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java 
b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
index fbf2159..fc582b6 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
@@ -38,7 +38,6 @@ import java.util.TreeMap;
 import net.sourceforge.pmd.PMDVersion;
 import org.apache.maven.execution.MavenSession;
 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;
 import org.apache.maven.reporting.AbstractMavenReport;
@@ -261,12 +260,15 @@ public abstract class AbstractPmdReport extends 
AbstractMavenReport {
     @Parameter(defaultValue = "${session}", required = true, readonly = true)
     protected MavenSession session;
 
-    @Component
-    private ToolchainManager toolchainManager;
+    private final ToolchainManager toolchainManager;
 
     /** The files that are being analyzed. */
     protected Map<File, PmdFileInfo> filesToProcess;
 
+    protected AbstractPmdReport(ToolchainManager toolchainManager) {
+        this.toolchainManager = toolchainManager;
+    }
+
     @Override
     protected MavenProject getProject() {
         return project;
diff --git 
a/src/main/java/org/apache/maven/plugins/pmd/AggregatorCpdReport.java 
b/src/main/java/org/apache/maven/plugins/pmd/AggregatorCpdReport.java
index 482b709..91700ff 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/AggregatorCpdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/AggregatorCpdReport.java
@@ -18,7 +18,11 @@
  */
 package org.apache.maven.plugins.pmd;
 
+import javax.inject.Inject;
+
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.i18n.I18N;
 
 /**
  * Creates a report for PMD's Copy/Paste Detector (CPD) tool in an 
<b>aggregator</b> project.
@@ -31,6 +35,12 @@ import org.apache.maven.plugins.annotations.Mojo;
  */
 @Mojo(name = "aggregate-cpd", aggregator = true, threadSafe = true)
 public class AggregatorCpdReport extends CpdReport {
+
+    @Inject
+    public AggregatorCpdReport(ToolchainManager toolchainManager, I18N i18n) {
+        super(toolchainManager, i18n);
+    }
+
     @Override
     protected boolean isAggregator() {
         return true;
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 b087aeb..3ba1b7d 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
@@ -18,11 +18,12 @@
  */
 package org.apache.maven.plugins.pmd;
 
+import javax.inject.Inject;
+
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.Locale;
 
-import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.pmd.exec.CpdExecutor;
@@ -30,6 +31,7 @@ import org.apache.maven.plugins.pmd.exec.CpdRequest;
 import org.apache.maven.plugins.pmd.exec.CpdResult;
 import org.apache.maven.reporting.MavenReportException;
 import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
 import org.codehaus.plexus.i18n.I18N;
 
 /**
@@ -97,8 +99,7 @@ public class CpdReport extends AbstractPmdReport {
     /**
      * Internationalization component
      */
-    @Component
-    private I18N i18n;
+    private final I18N i18n;
 
     /**
      * Contains the result of the last CPD execution.
@@ -107,6 +108,12 @@ public class CpdReport extends AbstractPmdReport {
      */
     private CpdResult cpdResult;
 
+    @Inject
+    public CpdReport(ToolchainManager toolchainManager, I18N i18n) {
+        super(toolchainManager);
+        this.i18n = i18n;
+    }
+
     /** {@inheritDoc} */
     public String getName(Locale locale) {
         return getI18nString(locale, "name");

Reply via email to