Skip to content

Commit 90352d3

Browse files
committed
Fix ModelloCli after moving from Plexus to JSR330
1 parent ef562b0 commit 90352d3

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

modello-core/src/main/java/org/codehaus/modello/Modello.java

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

25-
import javax.inject.Inject;
26-
2725
import java.io.Reader;
2826
import java.io.Writer;
2927
import java.util.Properties;
3028

3129
import org.codehaus.modello.core.ModelloCore;
3230
import org.codehaus.modello.model.Model;
3331
import org.codehaus.modello.model.ModelValidationException;
32+
import org.codehaus.plexus.ContainerConfiguration;
33+
import org.codehaus.plexus.DefaultContainerConfiguration;
34+
import org.codehaus.plexus.DefaultPlexusContainer;
35+
import org.codehaus.plexus.PlexusConstants;
36+
import org.codehaus.plexus.PlexusContainer;
3437

3538
/**
3639
* @author <a href="mailto:[email protected]">Jason van Zyl</a>
3740
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
3841
*/
3942
public class Modello {
40-
private final ModelloCore core;
43+
private PlexusContainer container;
44+
45+
private ModelloCore core;
46+
47+
public Modello() throws ModelloException {
48+
try {
49+
ContainerConfiguration configuration = new DefaultContainerConfiguration();
50+
configuration.setAutoWiring(true);
51+
configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);
52+
53+
container = new DefaultPlexusContainer(configuration);
4154

42-
@Inject
43-
public Modello(ModelloCore core) {
44-
this.core = core;
55+
core = (ModelloCore) container.lookup(ModelloCore.ROLE);
56+
} catch (Exception ex) {
57+
throw new ModelloException("Error while starting plexus.", ex);
58+
}
4559
}
4660

4761
public void generate(Reader modelReader, String outputType, Properties parameters)

modello-core/src/main/java/org/codehaus/modello/ModelloCli.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.File;
2626
import java.util.Properties;
2727

28-
import org.codehaus.plexus.DefaultPlexusContainer;
2928
import org.codehaus.plexus.util.StringUtils;
3029
import org.codehaus.plexus.util.xml.XmlStreamReader;
3130

@@ -40,7 +39,7 @@ public class ModelloCli {
4039
private static Properties parameters;
4140

4241
public static void main(String[] args) throws Exception {
43-
Modello modello = new DefaultPlexusContainer().lookup(Modello.class);
42+
Modello modello = new Modello();
4443

4544
parseArgumentsFromCommandLine(args);
4645

0 commit comments

Comments
 (0)