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

commit d788b1f27905eb4406ae16f5354f3d5468b4e7a3
Author: Elliotte Rusty Harold <elh...@ibiblio.org>
AuthorDate: Mon Dec 2 12:12:58 2024 -0500

    Switch to @Inject
---
 .../maven/plugins/jlink/AbstractJLinkMojo.java     |  6 ++--
 .../org/apache/maven/plugins/jlink/JLinkMojo.java  | 33 +++++++++++++++-------
 .../apache/maven/plugins/jlink/JLinkMojoTest.java  |  2 +-
 .../maven/plugins/jlink/MultipleLauncherTest.java  | 30 ++++++++------------
 4 files changed, 40 insertions(+), 31 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java 
b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
index c99ac2f..d195559 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
@@ -46,7 +46,6 @@ import java.util.Optional;
 
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.toolchain.Toolchain;
@@ -72,9 +71,12 @@ public abstract class AbstractJLinkMojo extends AbstractMojo 
{
     @Parameter(defaultValue = "${session}", readonly = true, required = true)
     private MavenSession session;
 
-    @Component
     private ToolchainManager toolchainManager;
 
+    public AbstractJLinkMojo(ToolchainManager toolchainManager) {
+        this.toolchainManager = toolchainManager;
+    }
+
     /**
      * Overload this to produce a zip with another classifier, for example a 
jlink-zip.
      * @return get the classifier.
diff --git a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java 
b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
index 9c00684..e69517e 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -37,6 +37,8 @@ package org.apache.maven.plugins.jlink;
  * under the License.
  */
 
+import javax.inject.Inject;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -67,6 +69,7 @@ import 
org.apache.maven.shared.filtering.MavenFilteringException;
 import org.apache.maven.shared.filtering.MavenResourcesExecution;
 import org.apache.maven.shared.filtering.MavenResourcesFiltering;
 import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
 import org.apache.maven.toolchain.ToolchainPrivate;
 import org.apache.maven.toolchain.java.DefaultJavaToolChain;
 import org.codehaus.plexus.archiver.Archiver;
@@ -89,8 +92,6 @@ import static java.util.Collections.singletonMap;
  */
 @Mojo(name = "jlink", requiresDependencyResolution = ResolutionScope.RUNTIME, 
defaultPhase = LifecyclePhase.PACKAGE)
 public class JLinkMojo extends AbstractJLinkMojo {
-    @Component
-    private LocationManager locationManager;
 
     /**
      * <p>
@@ -367,22 +368,34 @@ public class JLinkMojo extends AbstractJLinkMojo {
     private String outputTimestamp;
 
     /**
-     * Convenience interface for plugins to add or replace artifacts and 
resources on projects.
-     */
-    @Component
-    private MavenProjectHelper projectHelper;
-
-    /**
-     * These file are added to the image after calling the jlink, but before 
creating the zipfile.
+     * These files are added to the image after calling the jlink, but before 
creating the zipfile.
      *
      * @since 3.2.0
      */
     @Parameter
     private List<Resource> additionalResources;
 
-    @Component(role = MavenResourcesFiltering.class, hint = "default")
+    /**
+     * Convenience interface for plugins to add or replace artifacts and 
resources on projects.
+     */
+    private MavenProjectHelper projectHelper;
+
     private MavenResourcesFiltering mavenResourcesFiltering;
 
+    private LocationManager locationManager;
+
+    @Inject
+    public JLinkMojo(
+            MavenProjectHelper projectHelper,
+            ToolchainManager toolchainManager,
+            MavenResourcesFiltering mavenResourcesFiltering,
+            LocationManager locationManager) {
+        super(toolchainManager);
+        this.mavenResourcesFiltering = mavenResourcesFiltering;
+        this.projectHelper = projectHelper;
+        this.locationManager = locationManager;
+    }
+
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         failIfParametersAreNotInTheirValidValueRanges();
diff --git a/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java 
b/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
index 77d670f..4cc55ec 100644
--- a/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
@@ -30,7 +30,7 @@ public class JLinkMojoTest {
     @Test
     void quote_every_argument() throws Exception {
         // given
-        JLinkMojo mojo = new JLinkMojo();
+        JLinkMojo mojo = new JLinkMojo(null, null, null, null);
         Field stripDebug = mojo.getClass().getDeclaredField("stripDebug");
         stripDebug.setAccessible(true);
         stripDebug.set(mojo, Boolean.TRUE);
diff --git 
a/src/test/java/org/apache/maven/plugins/jlink/MultipleLauncherTest.java 
b/src/test/java/org/apache/maven/plugins/jlink/MultipleLauncherTest.java
index c4dce9e..527879f 100644
--- a/src/test/java/org/apache/maven/plugins/jlink/MultipleLauncherTest.java
+++ b/src/test/java/org/apache/maven/plugins/jlink/MultipleLauncherTest.java
@@ -25,19 +25,26 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 public class MultipleLauncherTest {
+
+    private JLinkMojo mojo = new JLinkMojo(null, null, null, null);
+    private Field launcher;
+
+    @BeforeEach
+    public void setUp() throws NoSuchFieldException, IllegalAccessException {
+        // It's OK to specify one launcher with "<launcher>" given
+        launcher = mojo.getClass().getDeclaredField("launcher");
+        launcher.setAccessible(true);
+    }
+
     @Test
     void testSingleLauncher() throws Exception {
-        // It's OK to specify one launcher with "<launcher>"
-        // given
-        JLinkMojo mojo = new JLinkMojo();
-        Field launcher = mojo.getClass().getDeclaredField("launcher");
-        launcher.setAccessible(true);
         launcher.set(mojo, "l=com.example.Launch");
 
         // when
@@ -49,9 +56,6 @@ public class MultipleLauncherTest {
 
     @Test
     void testOneMultipleLauncher() throws Exception {
-        // It's OK to specify one launcher with "<launchers>"
-        // given
-        JLinkMojo mojo = new JLinkMojo();
         Field launchers = mojo.getClass().getDeclaredField("launchers");
         launchers.setAccessible(true);
         launchers.set(mojo, List.of("l=com.example.Launch"));
@@ -65,11 +69,6 @@ public class MultipleLauncherTest {
 
     @Test
     void testMultipleLaunchers() throws Exception {
-        // It's OK to specify multiple launchers with the "<launchers>" element
-        // given
-        JLinkMojo mojo = new JLinkMojo();
-        Field launcher = mojo.getClass().getDeclaredField("launchers");
-        launcher.setAccessible(true);
         launcher.set(mojo, List.of("l1=com.example.Launch1", 
"l2=com.example.Launch2"));
 
         // when
@@ -81,11 +80,6 @@ public class MultipleLauncherTest {
 
     @Test
     void testInvalidLauncherConfig() throws Exception {
-        // It's an error to specify both "<launcher>" and "<launchers>"
-        // given
-        JLinkMojo mojo = new JLinkMojo();
-        Field launcher = mojo.getClass().getDeclaredField("launcher");
-        launcher.setAccessible(true);
         launcher.set(mojo, "l3=com.example.Launch3");
         Field launchers = mojo.getClass().getDeclaredField("launchers");
         launchers.setAccessible(true);

Reply via email to