package org.argeo.slc.cli;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
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 {
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/cli/spring-agent-default.xml";
private final static Option modeOpt = OptionBuilder.withLongOpt("mode")
.withArgName("mode").hasArg().withDescription(
// 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() {