</dependency>
<!--
- Unit Tests <dependency> <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.unit</artifactId> <scope>test</scope>
- </dependency>
- -->
+ Unit Tests -->
+ <dependency>
+ <groupId>org.argeo.slc.runtime</groupId>
+ <artifactId>org.argeo.slc.unit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="detachedTest" parent="slcTemplate.simpleFlow">
- <property name="path" value="/autoui/testcases" />
+ <property name="path" value="/detached" />
<property name="executables">
<list>
<bean parent="task.echo" scope="execution">
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+ <bean id="launch" parent="slcTemplate.simpleFlow">
+ <constructor-arg>
+ <bean parent="slcTemplate.simpleSpec">
+ <property name="attributes">
+ <map>
+ <entry key="spartaDist">
+ <bean parent="specAttr.primitive"
+ p:value="${user.home}/Desktop/sparta-dist-0.9.3-SNAPSHOT" />
+ </entry>
+ <entry key="detachedLauncherJar">
+ <bean parent="specAttr.primitive"
+ p:value="${user.home}/.m2/repository/org/argeo/slc/runtime/org.argeo.slc.detached.launcher/0.11.4-SNAPSHOT/org.argeo.slc.detached.launcher-0.11.4-SNAPSHOT.jar" />
+ </entry>
+ </map>
+ </property>
+ </bean>
+ </constructor-arg>
+ <property name="executables">
+ <list>
+
+ <bean parent="task.echo" p:message="osgi.install.area=${osgi.install.area}" />
+ <bean parent="task.echo" p:message="osgi.framework=${osgi.framework}" />
+
+ <ref local="jvmProcess" />
+ </list>
+ </property>
+ </bean>
+
+ <bean id="jvmProcess" class="org.argeo.slc.core.execution.tasks.JvmProcess">
+ <property name="mainClass" value="org.argeo.slc.detached.launcher.Main" />
+ <property name="classpath">
+ <list>
+ <value>${osgi.framework}</value>
+ <value>file:@{detachedLauncherJar}</value>
+ </list>
+ </property>
+ </bean>
+
+</beans>
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.core.execution.tasks;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.exec.CommandLine;
+import org.argeo.slc.SlcException;
+import org.springframework.core.io.Resource;
+
+public class JvmProcess extends SystemCall {
+ private Properties systemProperties = new Properties();
+ private List<Resource> classpath = new ArrayList<Resource>();
+ private List<Resource> pBootClasspath = new ArrayList<Resource>();
+ private Resource jvm = null;
+ private String mainClass;
+ private List<String> jvmArgs = new ArrayList<String>();
+ private List<String> args = new ArrayList<String>();
+
+ @Override
+ protected CommandLine createCommandLine() {
+ final CommandLine cl;
+ if (jvm != null)
+ cl = new CommandLine(asFile(jvm));
+ else
+ cl = new CommandLine("java");
+
+ if (pBootClasspath.size() > 0) {
+ StringBuffer buf = new StringBuffer("-Xbootclasspath/p:");
+ for (Resource res : pBootClasspath) {
+ if (buf.length() != 0)
+ buf.append(File.pathSeparatorChar);
+ buf.append(asFile(res));
+ }
+ cl.addArgument(buf.toString());
+ }
+
+ for (String jvmArg : jvmArgs) {
+ cl.addArgument(jvmArg);
+ }
+
+ cl.addArgument("-cp");
+ StringBuffer buf = new StringBuffer("");
+ for (Resource res : classpath) {
+ if (buf.length() != 0)
+ buf.append(File.pathSeparatorChar);
+ buf.append(asFile(res));
+ }
+ cl.addArgument(buf.toString());
+
+ for (Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
+ cl.addArgument("-D" + entry.getKey() + "=" + entry.getValue());
+ }
+
+ // Program
+ cl.addArgument(mainClass);
+
+ for (String arg : args) {
+ cl.addArgument(arg);
+ }
+
+ return cl;
+ }
+
+ protected File asFile(Resource res) {
+ // TODO: implements local copy
+ try {
+ return res.getFile().getCanonicalFile();
+ } catch (IOException e) {
+ throw new SlcException("Cannot convert resource to file", e);
+ }
+
+ }
+
+ public Properties getSystemProperties() {
+ return systemProperties;
+ }
+
+ public void setSystemProperties(Properties systemProperties) {
+ this.systemProperties = systemProperties;
+ }
+
+ public List<Resource> getClasspath() {
+ return classpath;
+ }
+
+ public void setClasspath(List<Resource> classpath) {
+ this.classpath = classpath;
+ }
+
+ public List<Resource> getPBootClasspath() {
+ return pBootClasspath;
+ }
+
+ public void setPBootClasspath(List<Resource> bootClasspath) {
+ pBootClasspath = bootClasspath;
+ }
+
+ public Resource getJvm() {
+ return jvm;
+ }
+
+ public void setJvm(Resource jvm) {
+ this.jvm = jvm;
+ }
+
+ public String getMainClass() {
+ return mainClass;
+ }
+
+ public void setMainClass(String mainClass) {
+ this.mainClass = mainClass;
+ }
+
+ public List<String> getJvmArgs() {
+ return jvmArgs;
+ }
+
+ public void setJvmArgs(List<String> jvmArgs) {
+ this.jvmArgs = jvmArgs;
+ }
+
+ public List<String> getArgs() {
+ return args;
+ }
+
+ public void setArgs(List<String> args) {
+ this.args = args;
+ }
+
+}
dir = new File(execDir).getCanonicalFile();
}
- // Check if an OS specific command overrides
- String osName = System.getProperty("os.name");
- List<Object> commandToUse = null;
- if (osCommands.containsKey(osName))
- commandToUse = osCommands.get(osName);
- else
- commandToUse = command;
- String cmdToUse = null;
- if (osCmds.containsKey(osName))
- cmdToUse = osCmds.get(osName);
- else
- cmdToUse = cmd;
-
// Prepare executor
if (dir == null)
dir = new File(getUsedDir(dir));
if (!dir.exists())
dir.mkdirs();
+ // Watchdog to check for lost processes
Executor executor = new DefaultExecutor();
executor.setWatchdog(new ExecuteWatchdog(watchdogTimeout));
+ // Redirect standard streams
PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(
new LogOutputStream() {
protected void processLine(String line, int level) {
executor.setStreamHandler(pumpStreamHandler);
executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
executor.setWorkingDirectory(dir);
- final CommandLine commandLine;
-
- // Which command definition to use
- if (commandToUse == null && cmdToUse == null)
- throw new SlcException("Please specify a command.");
- else if (commandToUse != null && cmdToUse != null)
- throw new SlcException(
- "Specify the command either as a line or as a list.");
- else if (cmdToUse != null) {
- if (log.isTraceEnabled())
- log.trace("Execute '" + cmdToUse + "' in "
- + getUsedDir(dir));
-
- commandLine = CommandLine.parse(cmdToUse);
- } else if (commandToUse != null) {
- if (log.isTraceEnabled())
- log.trace("Execute '" + commandToUse + "' in "
- + getUsedDir(dir));
- if (commandToUse.size() == 0)
- throw new SlcException("Command line is empty.");
-
- commandLine = new CommandLine(commandToUse.get(0).toString());
- for (int i = 1; i < commandToUse.size(); i++)
- commandLine.addArgument(commandToUse.get(i).toString());
- } else {
- // all cases covered previously
- throw new UnsupportedOperationException();
- }
+
+ // Command line to use
+ final CommandLine commandLine = createCommandLine();
// Env variables
Map<String, String> environmentVariablesToUse = environmentVariables
}
+ /** Can be overridden by specific command wrapper*/
+ protected CommandLine createCommandLine() {
+ // Check if an OS specific command overrides
+ String osName = System.getProperty("os.name");
+ List<Object> commandToUse = null;
+ if (osCommands.containsKey(osName))
+ commandToUse = osCommands.get(osName);
+ else
+ commandToUse = command;
+ String cmdToUse = null;
+ if (osCmds.containsKey(osName))
+ cmdToUse = osCmds.get(osName);
+ else
+ cmdToUse = cmd;
+
+ final CommandLine commandLine;
+
+ // Which command definition to use
+ if (commandToUse == null && cmdToUse == null)
+ throw new SlcException("Please specify a command.");
+ else if (commandToUse != null && cmdToUse != null)
+ throw new SlcException(
+ "Specify the command either as a line or as a list.");
+ else if (cmdToUse != null) {
+ commandLine = CommandLine.parse(cmdToUse);
+ } else if (commandToUse != null) {
+ if (commandToUse.size() == 0)
+ throw new SlcException("Command line is empty.");
+
+ commandLine = new CommandLine(commandToUse.get(0).toString());
+ for (int i = 1; i < commandToUse.size(); i++)
+ commandLine.addArgument(commandToUse.get(i).toString());
+ } else {
+ // all cases covered previously
+ throw new UnsupportedOperationException();
+ }
+ return commandLine;
+ }
+
/**
* Shortcut method returning the current exec dir if the specified one is
* null.
startApp(config);
// Start OSGi framework
- try {
- startEquinox(config);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ startEquinox(config);
info("Argeo SLC Detached launcher started.");
} catch (Exception e) {
e.printStackTrace();