Skip to content

Commit 87eb723

Browse files
Use JSR-330 for component injection
1 parent 1f1f596 commit 87eb723

28 files changed

Lines changed: 270 additions & 40 deletions

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/AbstractModelloGeneratorMojo.java‎

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
import java.util.HashMap;
3333
import java.util.List;
3434
import java.util.Map;
35+
import java.util.Objects;
3536
import java.util.stream.Collectors;
3637

3738
import org.apache.maven.model.Resource;
3839
import org.apache.maven.plugin.AbstractMojo;
3940
import org.apache.maven.plugin.MojoExecutionException;
40-
import org.apache.maven.plugins.annotations.Component;
4141
import org.apache.maven.plugins.annotations.Parameter;
4242
import org.apache.maven.project.MavenProject;
4343
import org.codehaus.modello.ModelloException;
@@ -80,12 +80,6 @@ public abstract class AbstractModelloGeneratorMojo extends AbstractMojo {
8080
@Parameter(property = "packageWithVersion", defaultValue = "false", required = true)
8181
private boolean packageWithVersion;
8282

83-
/**
84-
* <p>Note: This is passed by Maven and must not be configured by the user.</p>
85-
*/
86-
@Component
87-
private ModelloCore modelloCore;
88-
8983
/**
9084
* The Maven project instance for the executing project.
9185
*/
@@ -128,11 +122,14 @@ public abstract class AbstractModelloGeneratorMojo extends AbstractMojo {
128122
@Parameter
129123
private Map<String, String> pluralExceptions;
130124

131-
/**
132-
* @since 1.0.1
133-
*/
134-
@Component
135-
private BuildContext buildContext;
125+
private final BuildContext buildContext;
126+
127+
private final ModelloCore modelloCore;
128+
129+
protected AbstractModelloGeneratorMojo(BuildContext buildContext, ModelloCore modelloCore) {
130+
this.buildContext = Objects.requireNonNull(buildContext, "buildContext cannot be null");
131+
this.modelloCore = Objects.requireNonNull(modelloCore, "modelloCore cannot be null");
132+
}
136133

137134
// ----------------------------------------------------------------------
138135
// Overridables
@@ -366,18 +363,6 @@ public void setPackageWithVersion(boolean packageWithVersion) {
366363
this.packageWithVersion = packageWithVersion;
367364
}
368365

369-
public ModelloCore getModelloCore() {
370-
return modelloCore;
371-
}
372-
373-
public void setModelloCore(ModelloCore modelloCore) {
374-
this.modelloCore = modelloCore;
375-
}
376-
377-
public void setBuildContext(BuildContext context) {
378-
this.buildContext = context;
379-
}
380-
381366
public MavenProject getProject() {
382367
return project;
383368
}

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/AbstractModelloSourceGeneratorMojo.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.io.File;
2628
import java.util.Map;
2729
import java.util.Optional;
@@ -31,6 +33,8 @@
3133

3234
import org.apache.maven.plugins.annotations.Parameter;
3335
import org.codehaus.modello.ModelloParameterConstants;
36+
import org.codehaus.modello.core.ModelloCore;
37+
import org.codehaus.plexus.build.BuildContext;
3438

3539
/**
3640
* @author Hervé Boutemy
@@ -74,6 +78,11 @@ public abstract class AbstractModelloSourceGeneratorMojo extends AbstractModello
7478
@Parameter(defaultValue = "true")
7579
private boolean domAsXpp3;
7680

81+
@Inject
82+
public AbstractModelloSourceGeneratorMojo(BuildContext buildContext, ModelloCore modelloCore) {
83+
super(buildContext, modelloCore);
84+
}
85+
7786
@Override
7887
protected boolean producesCompilableResult() {
7988
return true;

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloConvertersMojo.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.codehaus.modello.maven;
22

3+
import javax.inject.Inject;
4+
35
import org.apache.maven.plugins.annotations.LifecyclePhase;
46
import org.apache.maven.plugins.annotations.Mojo;
7+
import org.codehaus.modello.core.ModelloCore;
8+
import org.codehaus.plexus.build.BuildContext;
59

610
/**
711
* Creates classes that can convert between different versions of the model.
@@ -10,6 +14,12 @@
1014
*/
1115
@Mojo(name = "converters", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
1216
public class ModelloConvertersMojo extends AbstractModelloSourceGeneratorMojo {
17+
18+
@Inject
19+
public ModelloConvertersMojo(BuildContext buildContext, ModelloCore modelloCore) {
20+
super(buildContext, modelloCore);
21+
}
22+
1323
protected String getGeneratorType() {
1424
return "converters";
1525
}

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jReaderMojo.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package org.codehaus.modello.maven;
22

3+
import javax.inject.Inject;
4+
35
import org.apache.maven.plugins.annotations.LifecyclePhase;
46
import org.apache.maven.plugins.annotations.Mojo;
7+
import org.codehaus.modello.core.ModelloCore;
8+
import org.codehaus.plexus.build.BuildContext;
59

610
/**
711
* Creates a DOM4J reader from the model.
812
*/
913
@Mojo(name = "dom4j-reader", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
1014
public class ModelloDom4jReaderMojo extends AbstractModelloSourceGeneratorMojo {
15+
16+
@Inject
17+
public ModelloDom4jReaderMojo(BuildContext buildContext, ModelloCore modelloCore) {
18+
super(buildContext, modelloCore);
19+
}
20+
1121
protected String getGeneratorType() {
1222
return "dom4j-reader";
1323
}

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jWriterMojo.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package org.codehaus.modello.maven;
22

3+
import javax.inject.Inject;
4+
35
import org.apache.maven.plugins.annotations.LifecyclePhase;
46
import org.apache.maven.plugins.annotations.Mojo;
7+
import org.codehaus.modello.core.ModelloCore;
8+
import org.codehaus.plexus.build.BuildContext;
59

610
/**
711
* Creates a DOM4J writer from the model.
812
*/
913
@Mojo(name = "dom4j-writer", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
1014
public class ModelloDom4jWriterMojo extends AbstractModelloSourceGeneratorMojo {
15+
16+
@Inject
17+
public ModelloDom4jWriterMojo(BuildContext buildContext, ModelloCore modelloCore) {
18+
super(buildContext, modelloCore);
19+
}
20+
1121
protected String getGeneratorType() {
1222
return "dom4j-writer";
1323
}

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloGenerateMojo.java‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.util.Map;
28+
import java.util.Objects;
2629

2730
import org.apache.maven.plugin.MojoExecutionException;
28-
import org.apache.maven.plugins.annotations.Component;
2931
import org.apache.maven.plugins.annotations.LifecyclePhase;
3032
import org.apache.maven.plugins.annotations.Mojo;
3133
import org.apache.maven.plugins.annotations.Parameter;
34+
import org.codehaus.modello.core.ModelloCore;
3235
import org.codehaus.modello.plugin.ModelloGenerator;
36+
import org.codehaus.plexus.build.BuildContext;
3337

3438
/**
3539
* <p>
@@ -85,12 +89,18 @@
8589
*/
8690
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
8791
public class ModelloGenerateMojo extends AbstractModelloSourceGeneratorMojo {
88-
@Component(role = ModelloGenerator.class)
89-
private Map<String, ModelloGenerator> generatorMap;
92+
private final Map<String, ModelloGenerator> generatorMap;
9093

9194
@Parameter(property = "modello.generator.id", defaultValue = "java")
9295
private String generatorId;
9396

97+
@Inject
98+
public ModelloGenerateMojo(
99+
BuildContext buildContext, ModelloCore modelloCore, Map<String, ModelloGenerator> generatorMap) {
100+
super(buildContext, modelloCore);
101+
this.generatorMap = Objects.requireNonNull(generatorMap, "generatorMap cannot be null");
102+
}
103+
94104
protected String getGeneratorType() {
95105
return generatorId;
96106
}

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloJDOMWriterMojo.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import org.apache.maven.plugins.annotations.LifecyclePhase;
2628
import org.apache.maven.plugins.annotations.Mojo;
29+
import org.codehaus.modello.core.ModelloCore;
30+
import org.codehaus.plexus.build.BuildContext;
2731

2832
/**
2933
* Creates a jdom writer from the model that is capable of preserving element ordering
@@ -33,6 +37,12 @@
3337
*/
3438
@Mojo(name = "jdom-writer", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
3539
public class ModelloJDOMWriterMojo extends AbstractModelloSourceGeneratorMojo {
40+
41+
@Inject
42+
public ModelloJDOMWriterMojo(BuildContext buildContext, ModelloCore modelloCore) {
43+
super(buildContext, modelloCore);
44+
}
45+
3646
protected String getGeneratorType() {
3747
return "jdom-writer";
3848
}

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloJacksonExtendedReaderMojo.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import org.apache.maven.plugins.annotations.LifecyclePhase;
2628
import org.apache.maven.plugins.annotations.Mojo;
29+
import org.codehaus.modello.core.ModelloCore;
30+
import org.codehaus.plexus.build.BuildContext;
2731

2832
/**
2933
* Creates an Jackson extended reader from the model. An extended reader populates the parsed model with metadata about
@@ -35,6 +39,11 @@
3539
@Mojo(name = "jackson-extended-reader", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
3640
public class ModelloJacksonExtendedReaderMojo extends ModelloXpp3ReaderMojo {
3741

42+
@Inject
43+
public ModelloJacksonExtendedReaderMojo(BuildContext buildContext, ModelloCore modelloCore) {
44+
super(buildContext, modelloCore);
45+
}
46+
3847
@Override
3948
protected String getGeneratorType() {
4049
return "jackson-extended-reader";

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloJacksonReaderMojo.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.util.Map;
2628

2729
import org.apache.maven.plugins.annotations.LifecyclePhase;
2830
import org.apache.maven.plugins.annotations.Mojo;
2931
import org.codehaus.modello.ModelloParameterConstants;
32+
import org.codehaus.modello.core.ModelloCore;
33+
import org.codehaus.plexus.build.BuildContext;
3034

3135
/**
3236
* Creates an Jackson reader from the model.
@@ -36,6 +40,12 @@
3640
*/
3741
@Mojo(name = "jackson-reader", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
3842
public class ModelloJacksonReaderMojo extends AbstractModelloSourceGeneratorMojo {
43+
44+
@Inject
45+
public ModelloJacksonReaderMojo(BuildContext buildContext, ModelloCore modelloCore) {
46+
super(buildContext, modelloCore);
47+
}
48+
3949
protected String getGeneratorType() {
4050
return "jackson-reader";
4151
}

‎modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloJacksonWriterMojo.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.util.Map;
2628

2729
import org.apache.maven.plugins.annotations.LifecyclePhase;
2830
import org.apache.maven.plugins.annotations.Mojo;
2931
import org.codehaus.modello.ModelloParameterConstants;
32+
import org.codehaus.modello.core.ModelloCore;
33+
import org.codehaus.plexus.build.BuildContext;
3034

3135
/**
3236
* Creates an Jackson writer from the model.
@@ -36,6 +40,12 @@
3640
*/
3741
@Mojo(name = "jackson-writer", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
3842
public class ModelloJacksonWriterMojo extends AbstractModelloSourceGeneratorMojo {
43+
44+
@Inject
45+
public ModelloJacksonWriterMojo(BuildContext buildContext, ModelloCore modelloCore) {
46+
super(buildContext, modelloCore);
47+
}
48+
3949
protected String getGeneratorType() {
4050
return "jackson-writer";
4151
}

0 commit comments

Comments
 (0)