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-jdeprscan-plugin.git
commit f3b45d4241a9a95d7b631486ed6dbce720a9c1aa Author: Elliotte Rusty Harold <elh...@ibiblio.org> AuthorDate: Mon Dec 9 17:51:11 2024 -0500 Convert to Guice constructor injection --- .../apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java | 8 +++++--- .../org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java | 5 +++++ .../java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java | 9 +++++++++ src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java | 8 ++++++++ .../org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java | 9 +++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java index 9225e0b..155cc38 100644 --- a/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java +++ b/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java @@ -32,7 +32,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.toolchain.Toolchain; import org.apache.maven.toolchain.ToolchainManager; @@ -51,8 +50,11 @@ public abstract class AbstractJDeprScanMojo extends AbstractMojo { @Parameter(defaultValue = "${session}", readonly = true, required = true) private MavenSession session; - @Component - private ToolchainManager toolchainManager; + private final ToolchainManager toolchainManager; + + protected AbstractJDeprScanMojo(ToolchainManager toolchainManager) { + this.toolchainManager = toolchainManager; + } @Override public void execute() throws MojoExecutionException, MojoFailureException { diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java index 3faa81b..29a3b26 100644 --- a/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java +++ b/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java @@ -31,6 +31,7 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.jdeprscan.consumers.JDeprScanConsumer; import org.apache.maven.project.MavenProject; +import org.apache.maven.toolchain.ToolchainManager; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer; import org.codehaus.plexus.util.cli.Commandline; @@ -66,6 +67,10 @@ public abstract class BaseJDeprScanMojo extends AbstractJDeprScanMojo { private final JDeprScanConsumer consumer = new JDeprScanConsumer(); + protected BaseJDeprScanMojo(ToolchainManager toolchainManager) { + super(toolchainManager); + } + @Override public void execute() throws MojoExecutionException, MojoFailureException { if (!Files.exists(getClassesDirectory())) { diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java index 904c87a..a18c7c0 100644 --- a/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java +++ b/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.jdeprscan; +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.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; /** * Scans main classes with jdeprscan tool @@ -42,6 +45,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope; defaultPhase = LifecyclePhase.PROCESS_CLASSES, threadSafe = true) public class JDeprScanMojo extends BaseJDeprScanMojo { + + @Inject + public JDeprScanMojo(ToolchainManager toolchainManager) { + super(toolchainManager); + } + @Override protected Path getClassesDirectory() { return Paths.get(getProject().getBuild().getOutputDirectory()); diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java index a2fa38f..e52a9b8 100644 --- a/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java +++ b/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java @@ -18,9 +18,12 @@ */ package org.apache.maven.plugins.jdeprscan; +import javax.inject.Inject; + import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.toolchain.ToolchainManager; import org.codehaus.plexus.util.cli.Commandline; /** @@ -38,6 +41,11 @@ public class ListMojo extends AbstractJDeprScanMojo { @Parameter(property = "for-removal") private boolean forRemoval; + @Inject + public ListMojo(ToolchainManager toolchainManager) { + super(toolchainManager); + } + @Override protected boolean isForRemoval() { return forRemoval; diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java index 6b2b2eb..8d570d2 100644 --- a/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java +++ b/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.jdeprscan; +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.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; /** * Scans test classes with jdeprscan @@ -42,6 +45,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope; defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, threadSafe = true) public class TestJDeprScanMojo extends BaseJDeprScanMojo { + + @Inject + public TestJDeprScanMojo(ToolchainManager toolchainManager) { + super(toolchainManager); + } + @Override protected Path getClassesDirectory() { return Paths.get(getProject().getBuild().getTestOutputDirectory());