You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2025/10/12 20:43:59 UTC

(maven-plugin-tools) branch master updated: Use injection instead of Component annotation

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git


The following commit(s) were added to refs/heads/master by this push:
     new 95b748d7 Use injection instead of Component annotation
95b748d7 is described below

commit 95b748d7d6393e2ba7decf032470306c69a42351
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sun Oct 12 18:52:43 2025 +0200

    Use injection instead of Component annotation
---
 .../plugin/plugin/DescriptorGeneratorMojo.java     | 10 +++----
 .../metadata/AddPluginArtifactMetadataMojo.java    | 15 ++++++----
 .../plugin/plugin/report/PluginNoForkReport.java   | 20 +++++++++++++-
 .../maven/plugin/plugin/report/PluginReport.java   | 32 ++++++++++++++--------
 .../src/site/apt/index.apt                         |  1 -
 5 files changed, 55 insertions(+), 23 deletions(-)

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 96eb7ae2..fb3fb75c 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
@@ -40,7 +40,6 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
-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;
@@ -241,9 +240,6 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
     @Parameter(property = "internalJavadocVersion", defaultValue = "${java.version}")
     protected String internalJavadocVersion;
 
-    @Component
-    private MavenSession mavenSession;
-
     /**
      * The required Java version to set in the plugin descriptor. This is evaluated by Maven 4 and ignored by earlier
      * Maven versions. Can be either one of the following formats:
@@ -280,6 +276,8 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
     @Parameter(defaultValue = VALUE_AUTO)
     String requiredMavenVersion;
 
+    private final MavenSession mavenSession;
+
     /**
      * The component used for scanning the source tree for mojos.
      */
@@ -288,8 +286,10 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
     protected final BuildContext buildContext;
 
     @Inject
-    public DescriptorGeneratorMojo(MavenProject project, MojoScanner mojoScanner, BuildContext buildContext) {
+    public DescriptorGeneratorMojo(
+            MavenProject project, MavenSession mavenSession, MojoScanner mojoScanner, BuildContext buildContext) {
         super(project);
+        this.mavenSession = mavenSession;
         this.mojoScanner = mojoScanner;
         this.buildContext = buildContext;
     }
diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java
index fe1d382d..3332c415 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java
@@ -18,10 +18,11 @@
  */
 package org.apache.maven.plugin.plugin.metadata;
 
+import javax.inject.Inject;
+
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
-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;
@@ -52,8 +53,7 @@ public class AddPluginArtifactMetadataMojo extends AbstractMojo {
     /**
      * The project artifact, which should have the <code>latest</code> metadata added to it.
      */
-    @Component
-    private MavenProject project;
+    private final MavenProject project;
 
     /**
      * The prefix for the plugin goal.
@@ -69,11 +69,16 @@ public class AddPluginArtifactMetadataMojo extends AbstractMojo {
     @Parameter(defaultValue = "false", property = "maven.plugin.skip")
     private boolean skip;
 
-    @Component
-    private RuntimeInformation runtimeInformation;
+    private final RuntimeInformation runtimeInformation;
 
     private final VersionScheme versionScheme = new GenericVersionScheme();
 
+    @Inject
+    public AddPluginArtifactMetadataMojo(MavenProject project, RuntimeInformation runtimeInformation) {
+        this.project = project;
+        this.runtimeInformation = runtimeInformation;
+    }
+
     /** {@inheritDoc} */
     @Override
     public void execute() throws MojoExecutionException {
diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginNoForkReport.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginNoForkReport.java
index 8b546697..1117639a 100644
--- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginNoForkReport.java
+++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginNoForkReport.java
@@ -18,9 +18,16 @@
  */
 package org.apache.maven.plugin.plugin.report;
 
+import javax.inject.Inject;
+
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugins.annotations.Execute;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.rtinfo.RuntimeInformation;
+import org.codehaus.plexus.i18n.I18N;
+import org.eclipse.aether.RepositorySystem;
 
 /**
  * Generates the plugin's report: the plugin details page at <code>plugin-info.html</code>,
@@ -31,4 +38,15 @@ import org.apache.maven.plugins.annotations.Mojo;
  */
 @Mojo(name = "report-no-fork", threadSafe = true)
 @Execute(phase = LifecyclePhase.NONE)
-public class PluginNoForkReport extends PluginReport {}
+public class PluginNoForkReport extends PluginReport {
+
+    @Inject
+    public PluginNoForkReport(
+            RuntimeInformation rtInfo,
+            I18N i18n,
+            MavenSession mavenSession,
+            RepositorySystem repositorySystem,
+            ProjectBuilder projectBuilder) {
+        super(rtInfo, i18n, mavenSession, repositorySystem, projectBuilder);
+    }
+}
diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java
index cc260b7d..5e35bb3a 100644
--- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java
+++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java
@@ -18,6 +18,8 @@
  */
 package org.apache.maven.plugin.plugin.report;
 
+import javax.inject.Inject;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
@@ -35,7 +37,6 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.building.ModelBuildingRequest;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Execute;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
@@ -118,14 +119,12 @@ public class PluginReport extends AbstractMavenReport {
     @Parameter(defaultValue = "[0,)")
     private String requirementsHistoryDetectionRange;
 
-    @Component
-    private RuntimeInformation rtInfo;
+    private final RuntimeInformation rtInfo;
 
     /**
      * Internationalization component.
      */
-    @Component
-    private I18N i18n;
+    private final I18N i18n;
 
     /**
      * Path to enhanced plugin descriptor to generate the report from (must contain some XHTML values)
@@ -148,14 +147,25 @@ public class PluginReport extends AbstractMavenReport {
     @Parameter(property = "maven.plugin.report.disableInternalJavadocLinkValidation")
     private boolean disableInternalJavadocLinkValidation;
 
-    @Component
-    private MavenSession mavenSession;
+    private final MavenSession mavenSession;
+
+    private final RepositorySystem repositorySystem;
 
-    @Component
-    private RepositorySystem repositorySystem;
+    private final ProjectBuilder projectBuilder;
 
-    @Component
-    private ProjectBuilder projectBuilder;
+    @Inject
+    public PluginReport(
+            RuntimeInformation rtInfo,
+            I18N i18n,
+            MavenSession mavenSession,
+            RepositorySystem repositorySystem,
+            ProjectBuilder projectBuilder) {
+        this.rtInfo = rtInfo;
+        this.i18n = i18n;
+        this.mavenSession = mavenSession;
+        this.repositorySystem = repositorySystem;
+        this.projectBuilder = projectBuilder;
+    }
 
     /**
      * {@inheritDoc}
diff --git a/maven-plugin-tools-annotations/src/site/apt/index.apt b/maven-plugin-tools-annotations/src/site/apt/index.apt
index 666af0ac..a4f156b3 100644
--- a/maven-plugin-tools-annotations/src/site/apt/index.apt
+++ b/maven-plugin-tools-annotations/src/site/apt/index.apt
@@ -40,7 +40,6 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Execute;
 import org.apache.maven.plugins.annotations.InstantiationStrategy;
 import org.apache.maven.plugins.annotations.LifecyclePhase;