File tree Expand file tree Collapse file tree 5 files changed +37
-15
lines changed
main/java/org/apache/maven/plugin/plugin
test/java/org/apache/maven/plugin/plugin Expand file tree Collapse file tree 5 files changed +37
-15
lines changed Original file line number Diff line number Diff line change 130130 <artifactId >maven-resolver-util</artifactId >
131131 <version >${resolverVersion} </version >
132132 </dependency >
133+ <dependency >
134+ <groupId >javax.inject</groupId >
135+ <artifactId >javax.inject</artifactId >
136+ <version >1</version >
137+ <scope >provided</scope >
138+ </dependency >
133139
134140 <!-- plexus -->
135141 <dependency >
Original file line number Diff line number Diff line change 2323
2424import org .apache .maven .plugin .AbstractMojo ;
2525import org .apache .maven .plugin .MojoExecutionException ;
26- import org .apache .maven .plugins .annotations .Component ;
2726import org .apache .maven .plugins .annotations .Parameter ;
2827import org .apache .maven .project .MavenProject ;
2928
3433 *
3534 */
3635public abstract class AbstractGeneratorMojo extends AbstractMojo {
37- /**
38- * The project currently being built.
39- */
40- @ Component
41- protected MavenProject project ;
4236
4337 /**
4438 * The goal prefix that will appear before the ":".
@@ -67,6 +61,15 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
6761 */
6862 protected static final String LS = System .lineSeparator ();
6963
64+ /**
65+ * The project currently being built.
66+ */
67+ protected final MavenProject project ;
68+
69+ protected AbstractGeneratorMojo (MavenProject project ) {
70+ this .project = project ;
71+ }
72+
7073 protected abstract void generate () throws MojoExecutionException ;
7174
7275 @ Override
Original file line number Diff line number Diff line change 1818 */
1919package org .apache .maven .plugin .plugin ;
2020
21+ import javax .inject .Inject ;
22+
2123import java .io .File ;
2224import java .net .URI ;
2325import java .util .Arrays ;
3840import org .apache .maven .plugins .annotations .Mojo ;
3941import org .apache .maven .plugins .annotations .Parameter ;
4042import org .apache .maven .plugins .annotations .ResolutionScope ;
43+ import org .apache .maven .project .MavenProject ;
4144import org .apache .maven .tools .plugin .DefaultPluginToolsRequest ;
4245import org .apache .maven .tools .plugin .ExtendedPluginDescriptor ;
4346import org .apache .maven .tools .plugin .PluginToolsRequest ;
@@ -262,11 +265,16 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
262265 /**
263266 * The component used for scanning the source tree for mojos.
264267 */
265- @ Component
266- private MojoScanner mojoScanner ;
268+ private final MojoScanner mojoScanner ;
267269
268- @ Component
269- protected BuildContext buildContext ;
270+ protected final BuildContext buildContext ;
271+
272+ @ Inject
273+ public DescriptorGeneratorMojo (MavenProject project , MojoScanner mojoScanner , BuildContext buildContext ) {
274+ super (project );
275+ this .mojoScanner = mojoScanner ;
276+ this .buildContext = buildContext ;
277+ }
270278
271279 public void generate () throws MojoExecutionException {
272280
Original file line number Diff line number Diff line change 1818 */
1919package org .apache .maven .plugin .plugin ;
2020
21+ import javax .inject .Inject ;
2122import javax .lang .model .SourceVersion ;
2223
2324import java .io .File ;
2425import java .util .Arrays ;
2526import java .util .stream .Collectors ;
2627
2728import org .apache .maven .plugin .MojoExecutionException ;
28- import org .apache .maven .plugins .annotations .Component ;
2929import org .apache .maven .plugins .annotations .LifecyclePhase ;
3030import org .apache .maven .plugins .annotations .Mojo ;
3131import org .apache .maven .plugins .annotations .Parameter ;
3232import org .apache .maven .plugins .annotations .ResolutionScope ;
33+ import org .apache .maven .project .MavenProject ;
3334import org .apache .maven .tools .plugin .generator .GeneratorException ;
3435import org .apache .maven .tools .plugin .generator .PluginHelpGenerator ;
3536import org .codehaus .plexus .util .StringUtils ;
@@ -71,8 +72,13 @@ public class HelpGeneratorMojo extends AbstractGeneratorMojo {
7172 /**
7273 * Velocity component.
7374 */
74- @ Component
75- private VelocityComponent velocity ;
75+ private final VelocityComponent velocity ;
76+
77+ @ Inject
78+ public HelpGeneratorMojo (MavenProject project , VelocityComponent velocity ) {
79+ super (project );
80+ this .velocity = velocity ;
81+ }
7682
7783 String getHelpPackageName () {
7884 String packageName = null ;
Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ public static Stream<Arguments> packageNameShouldBeCorrect() {
4040 @ ParameterizedTest
4141 @ MethodSource
4242 void packageNameShouldBeCorrect (MavenProject project , String expectedPackageName ) {
43- HelpGeneratorMojo mojo = new HelpGeneratorMojo ();
44- mojo .project = project ;
43+ HelpGeneratorMojo mojo = new HelpGeneratorMojo (project , null );
4544
4645 String packageName = mojo .getHelpPackageName ();
4746 assertEquals (expectedPackageName , packageName );
You can’t perform that action at this time.
0 commit comments