Skip to content

Commit 252c901

Browse files
Use injection instead of Component annotation
(cherry picked from commit 95b748d)
1 parent 69c653a commit 252c901

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.maven.plugin.MojoExecutionException;
3636
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
3737
import org.apache.maven.plugin.descriptor.PluginDescriptor;
38-
import org.apache.maven.plugins.annotations.Component;
3938
import org.apache.maven.plugins.annotations.LifecyclePhase;
4039
import org.apache.maven.plugins.annotations.Mojo;
4140
import org.apache.maven.plugins.annotations.Parameter;
@@ -223,9 +222,6 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
223222
@Parameter(property = "internalJavadocVersion", defaultValue = "${java.version}")
224223
protected String internalJavadocVersion;
225224

226-
@Component
227-
private MavenSession mavenSession;
228-
229225
/**
230226
* The required Java version to set in the plugin descriptor. This is evaluated by Maven 4 and ignored by earlier
231227
* Maven versions. Can be either one of the following formats:
@@ -262,6 +258,8 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
262258
@Parameter(defaultValue = VALUE_AUTO)
263259
String requiredMavenVersion;
264260

261+
private final MavenSession mavenSession;
262+
265263
/**
266264
* The component used for scanning the source tree for mojos.
267265
*/
@@ -270,8 +268,10 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
270268
protected final BuildContext buildContext;
271269

272270
@Inject
273-
public DescriptorGeneratorMojo(MavenProject project, MojoScanner mojoScanner, BuildContext buildContext) {
271+
public DescriptorGeneratorMojo(
272+
MavenProject project, MavenSession mavenSession, MojoScanner mojoScanner, BuildContext buildContext) {
274273
super(project);
274+
this.mavenSession = mavenSession;
275275
this.mojoScanner = mojoScanner;
276276
this.buildContext = buildContext;
277277
}

maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919
package org.apache.maven.plugin.plugin.metadata;
2020

21+
import javax.inject.Inject;
22+
2123
import org.apache.maven.plugin.AbstractMojo;
2224
import org.apache.maven.plugin.MojoExecutionException;
2325
import org.apache.maven.plugin.descriptor.PluginDescriptor;
24-
import org.apache.maven.plugins.annotations.Component;
2526
import org.apache.maven.plugins.annotations.LifecyclePhase;
2627
import org.apache.maven.plugins.annotations.Mojo;
2728
import org.apache.maven.plugins.annotations.Parameter;
@@ -52,8 +53,7 @@ public class AddPluginArtifactMetadataMojo extends AbstractMojo {
5253
/**
5354
* The project artifact, which should have the <code>latest</code> metadata added to it.
5455
*/
55-
@Component
56-
private MavenProject project;
56+
private final MavenProject project;
5757

5858
/**
5959
* The prefix for the plugin goal.
@@ -69,11 +69,16 @@ public class AddPluginArtifactMetadataMojo extends AbstractMojo {
6969
@Parameter(defaultValue = "false", property = "maven.plugin.skip")
7070
private boolean skip;
7171

72-
@Component
73-
private RuntimeInformation runtimeInformation;
72+
private final RuntimeInformation runtimeInformation;
7473

7574
private final VersionScheme versionScheme = new GenericVersionScheme();
7675

76+
@Inject
77+
public AddPluginArtifactMetadataMojo(MavenProject project, RuntimeInformation runtimeInformation) {
78+
this.project = project;
79+
this.runtimeInformation = runtimeInformation;
80+
}
81+
7782
/** {@inheritDoc} */
7883
@Override
7984
public void execute() throws MojoExecutionException {

maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginNoForkReport.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@
1818
*/
1919
package org.apache.maven.plugin.plugin.report;
2020

21+
import javax.inject.Inject;
22+
23+
import org.apache.maven.execution.MavenSession;
2124
import org.apache.maven.plugins.annotations.Execute;
2225
import org.apache.maven.plugins.annotations.LifecyclePhase;
2326
import org.apache.maven.plugins.annotations.Mojo;
27+
import org.apache.maven.project.ProjectBuilder;
28+
import org.apache.maven.rtinfo.RuntimeInformation;
29+
import org.codehaus.plexus.i18n.I18N;
30+
import org.eclipse.aether.RepositorySystem;
2431

2532
/**
2633
* Generates the plugin's report: the plugin details page at <code>plugin-info.html</code>,
@@ -31,4 +38,15 @@
3138
*/
3239
@Mojo(name = "report-no-fork", threadSafe = true)
3340
@Execute(phase = LifecyclePhase.NONE)
34-
public class PluginNoForkReport extends PluginReport {}
41+
public class PluginNoForkReport extends PluginReport {
42+
43+
@Inject
44+
public PluginNoForkReport(
45+
RuntimeInformation rtInfo,
46+
I18N i18n,
47+
MavenSession mavenSession,
48+
RepositorySystem repositorySystem,
49+
ProjectBuilder projectBuilder) {
50+
super(rtInfo, i18n, mavenSession, repositorySystem, projectBuilder);
51+
}
52+
}

maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.maven.plugin.plugin.report;
2020

21+
import javax.inject.Inject;
22+
2123
import java.io.File;
2224
import java.io.IOException;
2325
import java.io.Reader;
@@ -36,7 +38,6 @@
3638
import org.apache.maven.plugin.descriptor.MojoDescriptor;
3739
import org.apache.maven.plugin.descriptor.PluginDescriptor;
3840
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
39-
import org.apache.maven.plugins.annotations.Component;
4041
import org.apache.maven.plugins.annotations.Execute;
4142
import org.apache.maven.plugins.annotations.LifecyclePhase;
4243
import org.apache.maven.plugins.annotations.Mojo;
@@ -118,14 +119,12 @@ public class PluginReport extends AbstractMavenReport {
118119
@Parameter(defaultValue = "[0,)")
119120
private String requirementsHistoryDetectionRange;
120121

121-
@Component
122-
private RuntimeInformation rtInfo;
122+
private final RuntimeInformation rtInfo;
123123

124124
/**
125125
* Internationalization component.
126126
*/
127-
@Component
128-
private I18N i18n;
127+
private final I18N i18n;
129128

130129
/**
131130
* Path to enhanced plugin descriptor to generate the report from (must contain some XHTML values)
@@ -148,14 +147,25 @@ public class PluginReport extends AbstractMavenReport {
148147
@Parameter(property = "maven.plugin.report.disableInternalJavadocLinkValidation")
149148
private boolean disableInternalJavadocLinkValidation;
150149

151-
@Component
152-
private MavenSession mavenSession;
150+
private final MavenSession mavenSession;
151+
152+
private final RepositorySystem repositorySystem;
153153

154-
@Component
155-
private RepositorySystem repositorySystem;
154+
private final ProjectBuilder projectBuilder;
156155

157-
@Component
158-
private ProjectBuilder projectBuilder;
156+
@Inject
157+
public PluginReport(
158+
RuntimeInformation rtInfo,
159+
I18N i18n,
160+
MavenSession mavenSession,
161+
RepositorySystem repositorySystem,
162+
ProjectBuilder projectBuilder) {
163+
this.rtInfo = rtInfo;
164+
this.i18n = i18n;
165+
this.mavenSession = mavenSession;
166+
this.repositorySystem = repositorySystem;
167+
this.projectBuilder = projectBuilder;
168+
}
159169

160170
/**
161171
* {@inheritDoc}

maven-plugin-tools-annotations/src/site/apt/index.apt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import org.apache.maven.execution.MavenSession;
4040
import org.apache.maven.plugin.AbstractMojo;
4141
import org.apache.maven.plugin.MojoExecution;
4242
import org.apache.maven.plugin.descriptor.PluginDescriptor;
43-
import org.apache.maven.plugins.annotations.Component;
4443
import org.apache.maven.plugins.annotations.Execute;
4544
import org.apache.maven.plugins.annotations.InstantiationStrategy;
4645
import org.apache.maven.plugins.annotations.LifecyclePhase;

0 commit comments

Comments
 (0)