X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.agent%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcli%2FSlcMain.java;h=a2ffd17efe939d88e5862c34fabfba4f6f158fbb;hb=5ac335634ca09f980e452051dd41bc1ce1ea8c16;hp=39ff6aa411ec11ec949e7a73dd83f487c2f21c8c;hpb=c64c55c639fa256f85d498d958f78dfd0d6f10c6;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java index 39ff6aa41..a2ffd17ef 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java @@ -15,7 +15,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.core.SlcException; import org.argeo.slc.logging.Log4jUtils; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; public class SlcMain { public enum Mode { @@ -37,8 +39,17 @@ public class SlcMain { "use value for given property").create('p'); private final static Option scriptOpt = OptionBuilder.withLongOpt("script") - .withArgName("script").hasArg().withType(File.class) - .withDescription("SLC script to execute").create('s'); + .withArgName("script").hasArg().withDescription( + "SLC script to execute").create('s'); + + private final static Option targetsOpt = OptionBuilder.withLongOpt( + "targets").withArgName("targets").hasArg().withDescription( + "Targets to execute").create('t'); + + private final static Option runtimeOpt = OptionBuilder.withLongOpt( + "runtime").withArgName("runtime").hasArg().withDescription( + "Runtime to use, either a full path or relative to slc app conf dir: " + + "/runtime//.xml").create('r'); private final static Options options; @@ -48,13 +59,17 @@ public class SlcMain { options = new Options(); options.addOption(modeOpt); options.addOption(scriptOpt); + options.addOption(targetsOpt); options.addOption(propertyOpt); + options.addOption(runtimeOpt); } public static void main(String[] args) { Mode mode = null; Properties properties = new Properties(); - File script = null; + String script = null; + String targets = null; + String runtimeStr = null; try { @@ -75,7 +90,11 @@ public class SlcMain { throw new SlcException("Mode " + Mode.single + " requires option '" + scriptOpt.getLongOpt() + "'"); - script = (File) cl.getOptionObject(scriptOpt.getOpt()); + script = cl.getOptionValue(scriptOpt.getOpt()); + + // Targets + if (cl.hasOption(targetsOpt.getOpt())) + targets = cl.getOptionValue(targetsOpt.getOpt()); } // Properties @@ -85,6 +104,13 @@ public class SlcMain { } } + // Runtime + if (cl.hasOption(runtimeOpt.getOpt())) { + runtimeStr = cl.getOptionValue(runtimeOpt.getOpt()); + } else { + runtimeStr = "default"; + } + } catch (ParseException e) { System.err.println("Problem with command line arguments. " + e.getMessage()); @@ -102,15 +128,26 @@ public class SlcMain { initLogging(properties); if (log.isDebugEnabled()) { log.debug("Mode: " + mode); + log.debug("Runtime: " + runtimeStr); log.debug("User properties: " + properties); if (script != null) - log.debug("Script: " + script.getAbsolutePath()); + log.debug("Script: " + script); + if (targets != null) + log.debug("Targets: " + targets); } // Execution if (mode.equals(Mode.single)) { + Resource scriptRes; + if (new File(script).exists()) { + scriptRes = new FileSystemResource(script); + } else { + scriptRes = new DefaultResourceLoader(SlcMain.class + .getClassLoader()).getResource(script); + } + DefaultSlcRuntime runtime = new DefaultSlcRuntime(); - runtime.executeScript(new FileSystemResource(script), properties, + runtime.executeScript(runtimeStr, scriptRes, targets, properties, null); } } @@ -146,14 +183,14 @@ public class SlcMain { } private static void initLogging(Properties userProperties) { + System.setProperty("log4j.defaultInitOverride", "true"); + // Add log4j user properties to System properties for (String key : userProperties.stringPropertyNames()) { if (key.startsWith("log4j.")) { - System.setProperty(key, userProperties.getProperty(key)); + System.setProperty(key, userProperties.getProperty(key)); } } - - System.setProperty("log4j.defaultInitOverride", "true"); Log4jUtils.initLog4j(System.getProperty("log4j.configuration", "classpath:" + BOOTSTRAP_LOG4J_CONFIG)); log = LogFactory.getLog(SlcMain.class);