]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java
First consistent version with JMS
[gpl/argeo-slc.git] / runtime / org.argeo.slc.launcher / src / main / java / org / argeo / slc / cli / SlcMain.java
index cf52581c87c86f799d35d03cf4edb8382f0125a1..8db1330a6e1d0106bce79bd381cde8b4fd30f3e7 100644 (file)
@@ -1,7 +1,6 @@
 package org.argeo.slc.cli;
 
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Properties;
 
@@ -16,9 +15,13 @@ import org.apache.commons.cli.ParseException;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.ant.AntConstants;
-import org.argeo.slc.core.SlcException;
+import org.argeo.slc.SlcException;
 import org.argeo.slc.logging.Log4jUtils;
+import org.argeo.slc.runtime.SlcExecutionContext;
+import org.argeo.slc.runtime.SlcRuntime;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
 
 public class SlcMain {
        public enum Mode {
@@ -28,6 +31,7 @@ public class SlcMain {
        private static Log log = null;
 
        private final static String BOOTSTRAP_LOG4J_CONFIG = "org/argeo/slc/cli/bootstrapLog4j.properties";
+       private final static String DEFAULT_AGENT_CONTEXT = "classpath:org/argeo/slc/activemq/spring-agent.xml";
 
        private final static Option modeOpt = OptionBuilder.withLongOpt("mode")
                        .withArgName("mode").hasArg().withDescription(
@@ -155,15 +159,34 @@ public class SlcMain {
                // Execution
                if (mode.equals(Mode.single)) {
                        try {
-                               DefaultSlcRuntime runtime = new DefaultSlcRuntime();
+                               // DefaultSlcRuntime runtime = new DefaultSlcRuntime();
+                               // FIXME: inject this more cleanly
+                               ClassLoader cl = Thread.currentThread().getContextClassLoader();
+                               Class clss = cl.loadClass("org.argeo.slc.ant.AntSlcRuntime");
+                               SlcRuntime<? extends SlcExecutionContext> runtime = (SlcRuntime<? extends SlcExecutionContext>) clss
+                                               .newInstance();
                                runtime.executeScript(runtimeStr, script, targets, properties,
                                                null, null);
-                               //System.exit(0);
-                       } catch (SlcException e) {
+                               // System.exit(0);
+                       } catch (Exception e) {
                                log.error("SLC client terminated with an error: ", e);
                                System.exit(1);
                        }
                }
+               // Agent
+               else if (mode.equals(Mode.agent)) {
+                       final ConfigurableApplicationContext applicationContext;
+                       if (runtimeStr == null) {
+                               applicationContext = new ClassPathXmlApplicationContext(
+                                               DEFAULT_AGENT_CONTEXT);
+                       } else {
+                               applicationContext = new FileSystemXmlApplicationContext(
+                                               runtimeStr);
+                       }
+                       applicationContext.registerShutdownHook();
+                       applicationContext.start();
+                       log.info("SLC Agent context started.");
+               }
        }
 
        public static void printUsage() {