From 90352d3cd8de0382be73d5ce16b5f9d96469e39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fridrich=20=C5=A0trba?= Date: Sat, 13 Apr 2024 15:14:24 +0200 Subject: [PATCH] Fix ModelloCli after moving from Plexus to JSR330 --- .../java/org/codehaus/modello/Modello.java | 26 ++++++++++++++----- .../java/org/codehaus/modello/ModelloCli.java | 3 +-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/modello-core/src/main/java/org/codehaus/modello/Modello.java b/modello-core/src/main/java/org/codehaus/modello/Modello.java index 2b73884f..9e3f8072 100644 --- a/modello-core/src/main/java/org/codehaus/modello/Modello.java +++ b/modello-core/src/main/java/org/codehaus/modello/Modello.java @@ -22,8 +22,6 @@ package org.codehaus.modello; * SOFTWARE. */ -import javax.inject.Inject; - import java.io.Reader; import java.io.Writer; import java.util.Properties; @@ -31,17 +29,33 @@ import java.util.Properties; 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 Jason van Zyl * @author Trygve Laugstøl */ 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, Properties parameters) diff --git a/modello-core/src/main/java/org/codehaus/modello/ModelloCli.java b/modello-core/src/main/java/org/codehaus/modello/ModelloCli.java index ba8f029f..e9c9e079 100644 --- a/modello-core/src/main/java/org/codehaus/modello/ModelloCli.java +++ b/modello-core/src/main/java/org/codehaus/modello/ModelloCli.java @@ -25,7 +25,6 @@ package org.codehaus.modello; import java.io.File; import java.util.Properties; -import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.XmlStreamReader; @@ -40,7 +39,7 @@ public class ModelloCli { private static Properties parameters; public static void main(String[] args) throws Exception { - Modello modello = new DefaultPlexusContainer().lookup(Modello.class); + Modello modello = new Modello(); parseArgumentsFromCommandLine(args); -- 2.44.0