X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Ftasks%2FJvmProcess.java;fp=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Ftasks%2FJvmProcess.java;h=ba1d67eb558ac0296e46d9dba4ddbb0ec7a979b6;hb=09ab1aca27488e1feef6c8f46b34b7d27284be9a;hp=0000000000000000000000000000000000000000;hpb=2ef825e48090ee698863e3af4d2dd918e6a19c55;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/JvmProcess.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/JvmProcess.java new file mode 100644 index 000000000..ba1d67eb5 --- /dev/null +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/JvmProcess.java @@ -0,0 +1,134 @@ +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 classpath = new ArrayList(); + private List pBootClasspath = new ArrayList(); + private Resource jvm = null; + private String mainClass; + private List jvmArgs = new ArrayList(); + private List args = new ArrayList(); + + @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 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 getClasspath() { + return classpath; + } + + public void setClasspath(List classpath) { + this.classpath = classpath; + } + + public List getPBootClasspath() { + return pBootClasspath; + } + + public void setPBootClasspath(List 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 getJvmArgs() { + return jvmArgs; + } + + public void setJvmArgs(List jvmArgs) { + this.jvmArgs = jvmArgs; + } + + public List getArgs() { + return args; + } + + public void setArgs(List args) { + this.args = args; + } + +}