From 1a5742bb8b486fd45c4fd805a8409dcaa77e2796 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 19 Dec 2024 13:31:09 +0000 Subject: [PATCH] Use Guice injection for ZipArchiver (#235) --- .../apache/maven/plugins/jlink/JLinkMojo.java | 16 ++++++++-------- .../maven/plugins/jlink/JLinkMojoTest.java | 2 +- .../plugins/jlink/MultipleLauncherTest.java | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) 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 1bf5e2b..5525239 100644 --- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java +++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java @@ -38,6 +38,7 @@ */ import javax.inject.Inject; +import javax.inject.Named; import java.io.File; import java.io.IOException; @@ -59,7 +60,6 @@ import org.apache.maven.model.Resource; 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; @@ -73,7 +73,6 @@ 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; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.zip.ZipArchiver; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor; @@ -330,12 +329,6 @@ public class JLinkMojo extends AbstractJLinkMojo { @Parameter(defaultValue = "false") private boolean verbose; - /** - * The JAR archiver needed for archiving the environments. - */ - @Component(role = Archiver.class, hint = "zip") - private ZipArchiver zipArchiver; - /** * Set the JDK location to create a Java custom runtime image. */ @@ -385,13 +378,20 @@ public class JLinkMojo extends AbstractJLinkMojo { private final LocationManager locationManager; + /** + * The JAR archiver needed for archiving the environments. + */ + private final ZipArchiver zipArchiver; + @Inject public JLinkMojo( MavenProjectHelper projectHelper, ToolchainManager toolchainManager, + @Named("zip") ZipArchiver zipArchiver, MavenResourcesFiltering mavenResourcesFiltering, LocationManager locationManager) { super(toolchainManager); + this.zipArchiver = zipArchiver; this.mavenResourcesFiltering = mavenResourcesFiltering; this.projectHelper = projectHelper; this.locationManager = locationManager; 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 b6cfc33..eed3ae6 100644 --- a/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java @@ -33,7 +33,7 @@ public class JLinkMojoTest { - private JLinkMojo mojo = new JLinkMojo(null, null, null, null); + private JLinkMojo mojo = new JLinkMojo(null, null, null, null, null); @BeforeEach public void setUp() throws NoSuchFieldException, IllegalAccessException { 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 5a49cbf..c8530d7 100644 --- a/src/test/java/org/apache/maven/plugins/jlink/MultipleLauncherTest.java +++ b/src/test/java/org/apache/maven/plugins/jlink/MultipleLauncherTest.java @@ -32,7 +32,7 @@ public class MultipleLauncherTest { - private JLinkMojo mojo = new JLinkMojo(null, null, null, null); + private JLinkMojo mojo = new JLinkMojo(null, null, null, null, null); @Test void testSingleLauncher() throws Exception {