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-jdeps-plugin.git

commit 0e29a1683c5f93d83709caa2124c8d1164a02141
Author: Elliotte Rusty Harold <elh...@ibiblio.org>
AuthorDate: Mon Dec 16 07:10:01 2024 -0500

    Prefer Guice injection
---
 pom.xml                                                           | 6 ++++++
 .../org/apache/maven/plugins/jdeps/AbstractJDKInternalsMojo.java  | 8 ++++++++
 .../java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java    | 8 +++++---
 .../java/org/apache/maven/plugins/jdeps/JDKInternalsMojo.java     | 8 ++++++++
 .../java/org/apache/maven/plugins/jdeps/TestJDKInternalsMojo.java | 8 ++++++++
 5 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7078493..b1f748b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,6 +78,12 @@ under the License.
       <artifactId>maven-plugin-annotations</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <version>1</version>
+      <scope>provided</scope>
+    </dependency>
     <!-- Maven -->
     <dependency>
       <groupId>org.apache.maven</groupId>
diff --git 
a/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDKInternalsMojo.java 
b/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDKInternalsMojo.java
index 82007d8..bd8dea7 100644
--- a/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDKInternalsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDKInternalsMojo.java
@@ -18,10 +18,13 @@
  */
 package org.apache.maven.plugins.jdeps;
 
+import javax.inject.Inject;
+
 import java.nio.file.Path;
 import java.util.Set;
 
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.toolchain.ToolchainManager;
 import org.codehaus.plexus.util.cli.Commandline;
 
 /**
@@ -31,6 +34,11 @@ import org.codehaus.plexus.util.cli.Commandline;
  */
 public abstract class AbstractJDKInternalsMojo extends AbstractJDepsMojo {
 
+    @Inject
+    protected AbstractJDKInternalsMojo(ToolchainManager toolchainManager) {
+        super(toolchainManager);
+    }
+
     @Override
     protected void addJDepsOptions(Commandline cmd, Set<Path> 
dependenciesToAnalyze) throws MojoFailureException {
         super.addJDepsOptions(cmd, dependenciesToAnalyze);
diff --git 
a/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java 
b/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java
index ab4a641..280dd5d 100644
--- a/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java
@@ -43,7 +43,6 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.jdeps.consumers.JDepsConsumer;
 import org.apache.maven.project.MavenProject;
@@ -200,8 +199,11 @@ public abstract class AbstractJDepsMojo extends 
AbstractMojo {
     @Parameter(property = "jdeps.module")
     private String module;
 
-    @Component
-    private ToolchainManager toolchainManager;
+    private final ToolchainManager toolchainManager;
+
+    protected AbstractJDepsMojo(ToolchainManager toolchainManager) {
+        this.toolchainManager = toolchainManager;
+    }
 
     protected MavenProject getProject() {
         return project;
diff --git a/src/main/java/org/apache/maven/plugins/jdeps/JDKInternalsMojo.java 
b/src/main/java/org/apache/maven/plugins/jdeps/JDKInternalsMojo.java
index f2acd55..985351e 100644
--- a/src/main/java/org/apache/maven/plugins/jdeps/JDKInternalsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeps/JDKInternalsMojo.java
@@ -18,6 +18,8 @@
  */
 package org.apache.maven.plugins.jdeps;
 
+import javax.inject.Inject;
+
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Collection;
@@ -28,6 +30,7 @@ import 
org.apache.maven.artifact.DependencyResolutionRequiredException;
 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.toolchain.ToolchainManager;
 
 /**
  * Check if main classes depend on internal JDK classes
@@ -42,6 +45,11 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
         threadSafe = true)
 public class JDKInternalsMojo extends AbstractJDepsMojo {
 
+    @Inject
+    public JDKInternalsMojo(ToolchainManager toolchainManager) {
+        super(toolchainManager);
+    }
+
     @Override
     protected String getClassesDirectory() {
         return getProject().getBuild().getOutputDirectory();
diff --git 
a/src/main/java/org/apache/maven/plugins/jdeps/TestJDKInternalsMojo.java 
b/src/main/java/org/apache/maven/plugins/jdeps/TestJDKInternalsMojo.java
index 47e626f..06d6bb2 100644
--- a/src/main/java/org/apache/maven/plugins/jdeps/TestJDKInternalsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeps/TestJDKInternalsMojo.java
@@ -18,6 +18,8 @@
  */
 package org.apache.maven.plugins.jdeps;
 
+import javax.inject.Inject;
+
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Collection;
@@ -29,6 +31,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.toolchain.ToolchainManager;
 
 /**
  * Check if test classes depend on internal JDK classes
@@ -48,6 +51,11 @@ public class TestJDKInternalsMojo extends AbstractJDepsMojo {
     @Parameter(defaultValue = "true", property = "jdeps.test.failOnWarning")
     private boolean failOnWarning;
 
+    @Inject
+    public TestJDKInternalsMojo(ToolchainManager toolchainManager) {
+        super(toolchainManager);
+    }
+
     @Override
     protected boolean isFailOnWarning() {
         return failOnWarning;

Reply via email to