Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ModelloCli broken after moving from Plexus to JSR330 #435

Closed
wants to merge 7 commits into from
Closed
26 changes: 20 additions & 6 deletions modello-core/src/main/java/org/codehaus/modello/Modello.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,40 @@
* SOFTWARE.
*/

import javax.inject.Inject;

import java.io.Reader;
import java.io.Writer;
import java.util.Map;

import org.codehaus.modello.core.ModelloCore;
import org.codehaus.modello.model.Model;
import org.codehaus.modello.model.ModelValidationException;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;

/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*/
public class Modello {
private final ModelloCore core;
private PlexusContainer container;

private ModelloCore core;

public Modello() throws ModelloException {
try {
ContainerConfiguration configuration = new DefaultContainerConfiguration();
configuration.setAutoWiring(true);
configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);

container = new DefaultPlexusContainer(configuration);

@Inject
public Modello(ModelloCore core) {
this.core = core;
core = (ModelloCore) container.lookup(ModelloCore.ROLE);
} catch (Exception ex) {
throw new ModelloException("Error while starting plexus.", ex);
}
}

public void generate(Reader modelReader, String outputType, Map<String, Object> parameters)
Expand Down
14 changes: 9 additions & 5 deletions modello-core/src/main/java/org/codehaus/modello/ModelloCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.HashMap;
import java.util.Map;

import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.XmlStreamReader;

Expand All @@ -40,12 +39,17 @@ public class ModelloCli {

private static Map<String, Object> parameters;

public static void main(String[] args) throws Exception {
Modello modello = new DefaultPlexusContainer().lookup(Modello.class);
public static void main(String[] args) {
try {
Modello modello = new Modello();

parseArgumentsFromCommandLine(args);
parseArgumentsFromCommandLine(args);

modello.generate(new XmlStreamReader(modelFile), outputType, parameters);
modello.generate(new XmlStreamReader(modelFile), outputType, parameters);

} catch (Exception e) {
e.printStackTrace();
}
}

public static void parseArgumentsFromCommandLine(String[] args) throws Exception {
Expand Down