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-jmod-plugin.git
commit 539395c4395c15db73fc04a9b1dcfd7d1a00c164 Author: Elliotte Rusty Harold <elh...@ibiblio.org> AuthorDate: Tue Dec 17 08:11:45 2024 -0500 Prefer Guice injection --- .../org/apache/maven/plugins/jmod/AbstractJModMojo.java | 12 +++++++----- .../java/org/apache/maven/plugins/jmod/JModCreateMojo.java | 13 ++++++++++--- .../org/apache/maven/plugins/jmod/JModDescribeMojo.java | 8 ++++++++ .../java/org/apache/maven/plugins/jmod/JModHashMojo.java | 8 ++++++++ .../java/org/apache/maven/plugins/jmod/JModListMojo.java | 8 ++++++++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java b/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java index 6be98ac..49d8804 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java @@ -29,7 +29,6 @@ import java.util.Properties; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.utils.Os; @@ -55,12 +54,9 @@ public abstract class AbstractJModMojo extends AbstractMojo { @Parameter(defaultValue = "${session}", readonly = true, required = true) private MavenSession session; - @Component - private ToolchainManager toolchainManager; - /** * <p> - * Specify the requirements for this jdk toolchain. This overrules the toolchain selected by the + * Specify the requirements for this JDK toolchain. This overrules the toolchain selected by the * maven-toolchain-plugin. * </p> * <strong>note:</strong> requires at least Maven 3.3.1 @@ -68,6 +64,12 @@ public abstract class AbstractJModMojo extends AbstractMojo { @Parameter private Map<String, String> jdkToolchain; + private final ToolchainManager toolchainManager; + + protected AbstractJModMojo(ToolchainManager toolchainManager) { + this.toolchainManager = toolchainManager; + } + // TODO: Check how to prevent code duplication in maven-jlink, maven-jmod and maven-jdeps plugin? protected String getJModExecutable() throws IOException { Toolchain tc = getToolchain(); diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java index b818185..8a40aec 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.jmod; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.io.PrintStream; @@ -30,7 +32,6 @@ import java.util.Map; import org.apache.maven.artifact.Artifact; 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.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -41,6 +42,7 @@ import org.apache.maven.shared.utils.cli.Commandline; import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.logging.MessageUtils; import org.apache.maven.toolchain.Toolchain; +import org.apache.maven.toolchain.ToolchainManager; import org.apache.maven.toolchain.java.DefaultJavaToolChain; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor; import org.codehaus.plexus.languages.java.jpms.LocationManager; @@ -72,8 +74,7 @@ public class JModCreateMojo extends AbstractJModMojo { @Parameter(defaultValue = "${project.compileClasspathElements}", readonly = true, required = true) private List<String> compilePath; - @Component - private LocationManager locationManager; + private final LocationManager locationManager; /** * Specifies one or more directories containing native commands to be copied. The given directories are relative to @@ -281,6 +282,12 @@ public class JModCreateMojo extends AbstractJModMojo { // calculated based on jmod(.exe)/../.. private File javaHome; + @Inject + public JModCreateMojo(ToolchainManager toolchainManager, LocationManager locationManager) { + super(toolchainManager); + this.locationManager = locationManager; + } + public void execute() throws MojoExecutionException, MojoFailureException { String jModExecutable; diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java index 44ee73e..01589f5 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.jmod; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.io.PrintStream; @@ -29,6 +31,7 @@ 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.shared.utils.cli.Commandline; +import org.apache.maven.toolchain.ToolchainManager; /** * This goal is to support the usage of <code>jmod describe</code>. @@ -52,6 +55,11 @@ public class JModDescribeMojo extends AbstractJModMojo { // @formatter:on private File jmodFile; + @Inject + public JModDescribeMojo(ToolchainManager toolchainManager) { + super(toolchainManager); + } + public void execute() throws MojoExecutionException, MojoFailureException { String jModExecutable; diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java index ad9802e..f5e2009 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.jmod; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.util.List; @@ -29,6 +31,7 @@ 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.shared.utils.cli.Commandline; +import org.apache.maven.toolchain.ToolchainManager; /** * <pre> @@ -81,6 +84,11 @@ public class JModHashMojo extends AbstractJModMojo { @Parameter(required = true) private File modulePath; + @Inject + public JModHashMojo(ToolchainManager toolchainManager) { + super(toolchainManager); + } + public void execute() throws MojoExecutionException, MojoFailureException { String jModExecutable; diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java index 05c1f70..a2ddd7f 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.jmod; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.io.PrintStream; @@ -29,6 +31,7 @@ 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.shared.utils.cli.Commandline; +import org.apache.maven.toolchain.ToolchainManager; /** * This goal is to support the usage of <code>jmod list</code> to show the content of a <code>jmod</code> file. @@ -52,6 +55,11 @@ public class JModListMojo extends AbstractJModMojo { // @formatter:on private File jmodFile; + @Inject + public JModListMojo(ToolchainManager toolchainManager) { + super(toolchainManager); + } + public void execute() throws MojoExecutionException, MojoFailureException { String jModExecutable;