This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch maven-plugin-tools-3.x
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git
The following commit(s) were added to refs/heads/maven-plugin-tools-3.x by this
push:
new 73f78dc6 Begin converting this plugin to Guice constructor injection
73f78dc6 is described below
commit 73f78dc67d1ee5e7178aaed38dc354b82cc21433
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sun Dec 15 00:05:18 2024 +0000
Begin converting this plugin to Guice constructor injection
* Prefer Guice injection
(cherry picked from commit c1c0a69224efcaf948b14ebb637c28491aa6fcd0)
---
maven-plugin-plugin/pom.xml | 6 ++++++
.../maven/plugin/plugin/AbstractGeneratorMojo.java | 15 +++++++++------
.../maven/plugin/plugin/DescriptorGeneratorMojo.java | 16 ++++++++++++----
.../apache/maven/plugin/plugin/HelpGeneratorMojo.java | 12 +++++++++---
.../maven/plugin/plugin/HelpGeneratorMojoTest.java | 3 +--
5 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml
index 2d9d98d7..dfbbaba1 100644
--- a/maven-plugin-plugin/pom.xml
+++ b/maven-plugin-plugin/pom.xml
@@ -130,6 +130,12 @@
<artifactId>maven-resolver-util</artifactId>
<version>${resolverVersion}</version>
</dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ <scope>provided</scope>
+ </dependency>
<!-- plexus -->
<dependency>
diff --git
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
index d6524aae..3dda7fd2 100644
---
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
+++
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
@@ -23,7 +23,6 @@ import java.util.List;
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;
@@ -34,11 +33,6 @@ import org.apache.maven.project.MavenProject;
*
*/
public abstract class AbstractGeneratorMojo extends AbstractMojo {
- /**
- * The project currently being built.
- */
- @Component
- protected MavenProject project;
/**
* The goal prefix that will appear before the ":".
@@ -67,6 +61,15 @@ public abstract class AbstractGeneratorMojo extends
AbstractMojo {
*/
protected static final String LS = System.lineSeparator();
+ /**
+ * The project currently being built.
+ */
+ protected final MavenProject project;
+
+ protected AbstractGeneratorMojo(MavenProject project) {
+ this.project = project;
+ }
+
protected abstract void generate() throws MojoExecutionException;
@Override
diff --git
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java
index 862edeae..8434aa55 100644
---
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java
+++
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java
@@ -18,6 +18,8 @@
*/
package org.apache.maven.plugin.plugin;
+import javax.inject.Inject;
+
import java.io.File;
import java.net.URI;
import java.util.Arrays;
@@ -38,6 +40,7 @@ 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.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.ExtendedPluginDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
@@ -262,11 +265,16 @@ public class DescriptorGeneratorMojo extends
AbstractGeneratorMojo {
/**
* The component used for scanning the source tree for mojos.
*/
- @Component
- private MojoScanner mojoScanner;
+ private final MojoScanner mojoScanner;
- @Component
- protected BuildContext buildContext;
+ protected final BuildContext buildContext;
+
+ @Inject
+ public DescriptorGeneratorMojo(MavenProject project, MojoScanner
mojoScanner, BuildContext buildContext) {
+ super(project);
+ this.mojoScanner = mojoScanner;
+ this.buildContext = buildContext;
+ }
public void generate() throws MojoExecutionException {
diff --git
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java
index eeadd65e..00a7f3d6 100644
---
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java
+++
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java
@@ -18,6 +18,7 @@
*/
package org.apache.maven.plugin.plugin;
+import javax.inject.Inject;
import javax.lang.model.SourceVersion;
import java.io.File;
@@ -25,11 +26,11 @@ import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.maven.plugin.MojoExecutionException;
-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;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.generator.GeneratorException;
import org.apache.maven.tools.plugin.generator.PluginHelpGenerator;
import org.codehaus.plexus.util.StringUtils;
@@ -71,8 +72,13 @@ public class HelpGeneratorMojo extends AbstractGeneratorMojo
{
/**
* Velocity component.
*/
- @Component
- private VelocityComponent velocity;
+ private final VelocityComponent velocity;
+
+ @Inject
+ public HelpGeneratorMojo(MavenProject project, VelocityComponent velocity)
{
+ super(project);
+ this.velocity = velocity;
+ }
String getHelpPackageName() {
String packageName = null;
diff --git
a/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/HelpGeneratorMojoTest.java
b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/HelpGeneratorMojoTest.java
index 748a4ad2..3473ce35 100644
---
a/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/HelpGeneratorMojoTest.java
+++
b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/HelpGeneratorMojoTest.java
@@ -40,8 +40,7 @@ class HelpGeneratorMojoTest {
@ParameterizedTest
@MethodSource
void packageNameShouldBeCorrect(MavenProject project, String
expectedPackageName) {
- HelpGeneratorMojo mojo = new HelpGeneratorMojo();
- mojo.project = project;
+ HelpGeneratorMojo mojo = new HelpGeneratorMojo(project, null);
String packageName = mojo.getHelpPackageName();
assertEquals(expectedPackageName, packageName);