This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch maven-jar-plugin-3.x
in repository https://gitbox.apache.org/repos/asf/maven-jar-plugin.git
The following commit(s) were added to refs/heads/maven-jar-plugin-3.x by this
push:
new ef8ed4c Migrate component injection to JSR-330
ef8ed4c is described below
commit ef8ed4cf89bcacb2f8ad5c3f4492ba186ead4409
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Sun Nov 9 18:52:01 2025 +0100
Migrate component injection to JSR-330
---
.../apache/maven/plugins/jar/AbstractJarMojo.java | 67 ++++++++++++----------
.../java/org/apache/maven/plugins/jar/JarMojo.java | 19 ++++++
.../org/apache/maven/plugins/jar/TestJarMojo.java | 21 ++++++-
.../org/apache/maven/plugins/jar/JarMojoTest.java | 12 +++-
src/test/resources/unit/jar-basic-test/pom.xml | 34 -----------
.../jar-basic-test/src/main/java/TestCompile1.java | 29 ----------
6 files changed, 83 insertions(+), 99 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
index 57c7e2a..e6d2b18 100644
--- a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
@@ -29,7 +29,6 @@ import org.apache.maven.archiver.MavenArchiver;
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.project.MavenProjectHelper;
@@ -56,12 +55,6 @@ public abstract class AbstractJarMojo extends AbstractMojo {
private static final String SEPARATOR =
FileSystems.getDefault().getSeparator();
- @Component
- private ToolchainsJdkSpecification toolchainsJdkSpecification;
-
- @Component
- private ToolchainManager toolchainManager;
-
/**
* List of files to include. Specified as fileset patterns which are
relative to the input directory whose contents
* is being packaged into the JAR.
@@ -88,24 +81,6 @@ public abstract class AbstractJarMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.finalName}", readonly = true)
private String finalName;
- /**
- * The Jar archiver.
- */
- @Component
- private Map<String, Archiver> archivers;
-
- /**
- * The {@link MavenProject}.
- */
- @Parameter(defaultValue = "${project}", readonly = true, required = true)
- private MavenProject project;
-
- /**
- * The {@link MavenSession}.
- */
- @Parameter(defaultValue = "${session}", readonly = true, required = true)
- private MavenSession session;
-
/**
* The archive configuration to use. See <a
href="http://maven.apache.org/shared/maven-archiver/index.html">Maven
* Archiver Reference</a>.
@@ -124,12 +99,6 @@ public abstract class AbstractJarMojo extends AbstractMojo {
@Deprecated
private boolean useDefaultManifestFile;
- /**
- *
- */
- @Component
- private MavenProjectHelper projectHelper;
-
/**
* Require the jar plugin to build a new JAR even if none of the contents
appear to have changed. By default, this
* plugin looks to see if the output jar exists and inputs have not
changed. If these conditions are true, the
@@ -210,6 +179,42 @@ public abstract class AbstractJarMojo extends AbstractMojo
{
@Parameter(property = "maven.jar.attach", defaultValue = "true")
protected boolean attach;
+ /**
+ * The {@link MavenProject}.
+ */
+ private final MavenProject project;
+
+ /**
+ * The {@link MavenSession}.
+ */
+ private final MavenSession session;
+
+ private final ToolchainsJdkSpecification toolchainsJdkSpecification;
+
+ private final ToolchainManager toolchainManager;
+
+ /**
+ * The Jar archiver.
+ */
+ private final Map<String, Archiver> archivers;
+
+ private final MavenProjectHelper projectHelper;
+
+ AbstractJarMojo(
+ MavenProject project,
+ MavenSession session,
+ ToolchainsJdkSpecification toolchainsJdkSpecification,
+ ToolchainManager toolchainManager,
+ Map<String, Archiver> archivers,
+ MavenProjectHelper projectHelper) {
+ this.project = project;
+ this.session = session;
+ this.toolchainsJdkSpecification = toolchainsJdkSpecification;
+ this.toolchainManager = toolchainManager;
+ this.archivers = archivers;
+ this.projectHelper = projectHelper;
+ }
+
/**
* Return the specific output directory to serve as the root for the
archive.
* @return get classes directory.
diff --git a/src/main/java/org/apache/maven/plugins/jar/JarMojo.java
b/src/main/java/org/apache/maven/plugins/jar/JarMojo.java
index 7ce06d4..74a389c 100644
--- a/src/main/java/org/apache/maven/plugins/jar/JarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jar/JarMojo.java
@@ -18,12 +18,20 @@
*/
package org.apache.maven.plugins.jar;
+import javax.inject.Inject;
+
import java.io.File;
+import java.util.Map;
+import org.apache.maven.execution.MavenSession;
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.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.archiver.Archiver;
/**
* Build a JAR from the current project.
@@ -53,6 +61,17 @@ public class JarMojo extends AbstractJarMojo {
@Parameter
private String classifier;
+ @Inject
+ JarMojo(
+ MavenProject project,
+ MavenSession session,
+ ToolchainsJdkSpecification toolchainsJdkSpecification,
+ ToolchainManager toolchainManager,
+ Map<String, Archiver> archivers,
+ MavenProjectHelper projectHelper) {
+ super(project, session, toolchainsJdkSpecification, toolchainManager,
archivers, projectHelper);
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java
b/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java
index 96b5ac3..e655ae1 100644
--- a/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java
@@ -18,13 +18,21 @@
*/
package org.apache.maven.plugins.jar;
+import javax.inject.Inject;
+
import java.io.File;
+import java.util.Map;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
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.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.archiver.Archiver;
/**
* Build a JAR of the test classes for the current project.
@@ -32,14 +40,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
* @author <a href="[email protected]">Emmanuel Venisse</a>
* @version $Id$
*/
-// CHECKSTYLE_OFF: LineLength
@Mojo(
name = "test-jar",
defaultPhase = LifecyclePhase.PACKAGE,
requiresProject = true,
threadSafe = true,
requiresDependencyResolution = ResolutionScope.TEST)
-// CHECKSTYLE_ON: LineLength
public class TestJarMojo extends AbstractJarMojo {
/**
@@ -61,6 +67,17 @@ public class TestJarMojo extends AbstractJarMojo {
@Parameter(defaultValue = "tests")
private String classifier;
+ @Inject
+ TestJarMojo(
+ MavenProject project,
+ MavenSession session,
+ ToolchainsJdkSpecification toolchainsJdkSpecification,
+ ToolchainManager toolchainManager,
+ Map<String, Archiver> archivers,
+ MavenProjectHelper projectHelper) {
+ super(project, session, toolchainsJdkSpecification, toolchainManager,
archivers, projectHelper);
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java
b/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java
index e3f73fa..6d45c93 100644
--- a/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java
@@ -18,12 +18,15 @@
*/
package org.apache.maven.plugins.jar;
+import javax.inject.Inject;
+
import org.apache.maven.api.plugin.testing.InjectMojo;
import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.project.MavenProject;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
/**
* Test for {@link JarMojo}
@@ -33,13 +36,16 @@ import static
org.junit.jupiter.api.Assertions.assertNotNull;
@MojoTest
class JarMojoTest {
+ @Inject
+ private MavenProject project;
+
/**
* Tests the discovery and configuration of the mojo.
*/
@Test
- @InjectMojo(goal = "jar", pom = "classpath:/unit/jar-basic-test/pom.xml")
+ @InjectMojo(goal = "jar")
void testJarTestEnvironment(JarMojo mojo) {
assertNotNull(mojo);
- assertEquals("foo", mojo.getProject().getGroupId());
+ assertSame(project, mojo.getProject());
}
}
diff --git a/src/test/resources/unit/jar-basic-test/pom.xml
b/src/test/resources/unit/jar-basic-test/pom.xml
deleted file mode 100644
index 0f58dcf..0000000
--- a/src/test/resources/unit/jar-basic-test/pom.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-
-<project>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <project
implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub">
- <groupId implementation="java.lang.String">foo</groupId>
- <artifactId implementation="java.lang.String">bar</artifactId>
- </project>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git
a/src/test/resources/unit/jar-basic-test/src/main/java/TestCompile1.java
b/src/test/resources/unit/jar-basic-test/src/main/java/TestCompile1.java
deleted file mode 100644
index c7e7e5f..0000000
--- a/src/test/resources/unit/jar-basic-test/src/main/java/TestCompile1.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-public class TestCompile1
-{
-
- public TestCompile1()
- {
-
- System.out.println("Woo Hoo!");
- }
-
-}
\ No newline at end of file