diff --git a/cli/src/main/java/ca/weblite/jdeploy/DIContext.java b/cli/src/main/java/ca/weblite/jdeploy/DIContext.java index 933cc5c7..80154b05 100644 --- a/cli/src/main/java/ca/weblite/jdeploy/DIContext.java +++ b/cli/src/main/java/ca/weblite/jdeploy/DIContext.java @@ -5,16 +5,33 @@ import ca.weblite.jdeploy.openai.di.OpenAiModule; import org.codejargon.feather.Feather; +import java.util.Arrays; + public class DIContext { - private final Feather feather = Feather.with(new JDeployModule(), new OpenAiModule(), new JDeployCliModule()); + private final Feather feather; private static DIContext instance; + public DIContext(Object ...modules) { + java.util.List args = new java.util.ArrayList(); + args.add(new JDeployModule()); + args.add(new OpenAiModule()); + args.add(new JDeployCliModule()); + args.addAll(Arrays.asList(modules)); + feather = Feather.with(args); + } + public T getInstance(Class clazz) { return feather.instance(clazz); } + public static void initialize(Object ...modules) { + synchronized (DIContext.class) { + instance = new DIContext(modules); + } + } + public static DIContext getInstance() { if (instance == null) { synchronized (DIContext.class) { @@ -27,4 +44,8 @@ public static DIContext getInstance() { return instance; } + + public static T get(Class clazz) { + return getInstance().getInstance(clazz); + } } diff --git a/cli/src/main/java/ca/weblite/jdeploy/JDeploy.java b/cli/src/main/java/ca/weblite/jdeploy/JDeploy.java index b2a13be1..3c0119ef 100644 --- a/cli/src/main/java/ca/weblite/jdeploy/JDeploy.java +++ b/cli/src/main/java/ca/weblite/jdeploy/JDeploy.java @@ -2538,7 +2538,6 @@ private void _run() { */ public static void main(String[] args) { try { - Feather feather = Feather.with(new JDeployModule()); JDeploy prog = new JDeploy(new File(".").getAbsoluteFile()); if (args.length > 0 && "generate".equals(args[0])) { String[] generateArgs = new String[args.length-1]; diff --git a/cli/src/main/java/ca/weblite/jdeploy/services/ProjectTemplateCatalog.java b/cli/src/main/java/ca/weblite/jdeploy/services/ProjectTemplateCatalog.java index dbd196a1..ea2d3535 100644 --- a/cli/src/main/java/ca/weblite/jdeploy/services/ProjectTemplateCatalog.java +++ b/cli/src/main/java/ca/weblite/jdeploy/services/ProjectTemplateCatalog.java @@ -70,6 +70,14 @@ public File getExtensionTemplate(String name) throws Exception { return f; } + public File[] getProjectTemplates() { + return getProjectsDir().listFiles(); + } + + public boolean isCatalogInitialized() { + return new File(localPath).exists(); + } + private File getProjectsDir() { return new File(localPath, "projects"); }