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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9e36e61  Prefer Guice injection (#177)
9e36e61 is described below

commit 9e36e6137c91f85460f0a9cc3a5a1f9b4f52ba71
Author: Elliotte Rusty Harold <elh...@users.noreply.github.com>
AuthorDate: Sun Dec 15 00:00:20 2024 +0000

    Prefer Guice injection (#177)
    
    * Prefer Guice injection
---
 .../maven/plugins/pmd/AbstractPmdReport.java       |  8 ++++---
 .../maven/plugins/pmd/AggregatorCpdReport.java     | 10 +++++++++
 .../plugins/pmd/AggregatorPmdNoForkReport.java     | 18 +++++++++++++++-
 .../maven/plugins/pmd/AggregatorPmdReport.java     | 16 ++++++++++++++
 .../org/apache/maven/plugins/pmd/CpdReport.java    | 13 ++++++++---
 .../org/apache/maven/plugins/pmd/PmdReport.java    | 25 ++++++++++++++++------
 6 files changed, 76 insertions(+), 14 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/AggregatorPmdNoForkReport.java 
b/src/main/java/org/apache/maven/plugins/pmd/AggregatorPmdNoForkReport.java
index 8418594..08c8b64 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/AggregatorPmdNoForkReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/AggregatorPmdNoForkReport.java
@@ -18,10 +18,16 @@
  */
 package org.apache.maven.plugins.pmd;
 
+import javax.inject.Inject;
+
 import org.apache.maven.plugins.annotations.Execute;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import 
org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.resource.ResourceManager;
 
 /**
  * Creates a PMD site report in an <b>aggregator</b> project without forking 
the <code>test-compile</code> phase again.
@@ -34,4 +40,14 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
         threadSafe = true,
         requiresDependencyResolution = ResolutionScope.TEST)
 @Execute(phase = LifecyclePhase.NONE)
-public class AggregatorPmdNoForkReport extends AggregatorPmdReport {}
+public class AggregatorPmdNoForkReport extends AggregatorPmdReport {
+
+    @Inject
+    public AggregatorPmdNoForkReport(
+            ToolchainManager toolchainManager,
+            ResourceManager locator,
+            DependencyResolver dependencyResolver,
+            I18N i18n) {
+        super(toolchainManager, locator, dependencyResolver, i18n);
+    }
+}
diff --git 
a/src/main/java/org/apache/maven/plugins/pmd/AggregatorPmdReport.java 
b/src/main/java/org/apache/maven/plugins/pmd/AggregatorPmdReport.java
index 8e635b4..0414c21 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/AggregatorPmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/AggregatorPmdReport.java
@@ -18,10 +18,16 @@
  */
 package org.apache.maven.plugins.pmd;
 
+import javax.inject.Inject;
+
 import org.apache.maven.plugins.annotations.Execute;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import 
org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.resource.ResourceManager;
 
 /**
  * Creates a PMD site report in an <b>aggregator</b> project based on the 
rulesets and configuration set in the plugin.
@@ -32,6 +38,16 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
 @Mojo(name = "aggregate-pmd", aggregator = true, threadSafe = true, 
requiresDependencyResolution = ResolutionScope.TEST)
 @Execute(phase = LifecyclePhase.TEST_COMPILE)
 public class AggregatorPmdReport extends PmdReport {
+
+    @Inject
+    public AggregatorPmdReport(
+            ToolchainManager toolchainManager,
+            ResourceManager locator,
+            DependencyResolver dependencyResolver,
+            I18N i18n) {
+        super(toolchainManager, locator, dependencyResolver, 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");
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 4c9cd6c..b3bf3e9 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
@@ -18,6 +18,8 @@
  */
 package org.apache.maven.plugins.pmd;
 
+import javax.inject.Inject;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -27,7 +29,6 @@ import java.util.Locale;
 
 import net.sourceforge.pmd.renderers.Renderer;
 import org.apache.maven.model.Dependency;
-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.annotations.ResolutionScope;
@@ -45,6 +46,7 @@ import 
org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
 import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
 import 
org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
 import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
 import org.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.resource.ResourceManager;
 import org.codehaus.plexus.resource.loader.FileResourceCreationException;
@@ -231,17 +233,14 @@ public class PmdReport extends AbstractPmdReport {
      * Used to locate configured rulesets. The rulesets could be on the plugin
      * classpath or in the local project file system.
      */
-    @Component
-    private ResourceManager locator;
+    private final ResourceManager locator;
 
-    @Component
-    private DependencyResolver dependencyResolver;
+    private final DependencyResolver dependencyResolver;
 
     /**
      * Internationalization component
      */
-    @Component
-    private I18N i18n;
+    private final I18N i18n;
 
     /**
      * Contains the result of the last PMD execution.
@@ -250,6 +249,18 @@ public class PmdReport extends AbstractPmdReport {
      */
     private PmdResult pmdResult;
 
+    @Inject
+    public PmdReport(
+            ToolchainManager toolchainManager,
+            ResourceManager locator,
+            DependencyResolver dependencyResolver,
+            I18N i18n) {
+        super(toolchainManager);
+        this.locator = locator;
+        this.dependencyResolver = dependencyResolver;
+        this.i18n = i18n;
+    }
+
     /** {@inheritDoc} */
     public String getName(Locale locale) {
         return getI18nString(locale, "name");

Reply via email to