X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;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=8c0bfebe95a58393d6cf17bd70606b59cc1d3542;hb=8eb028e332cb2be50ed311a0501f7efce5849d44;hp=ba1d67eb558ac0296e46d9dba4ddbb0ec7a979b6;hpb=5bb64c4c0e3b263f7d6c8f41efa11d8588c3ded8;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 index ba1d67eb5..8c0bfebe9 100644 --- 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 @@ -1,6 +1,8 @@ package org.argeo.slc.core.execution.tasks; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -8,10 +10,15 @@ import java.util.Map; import java.util.Properties; import org.apache.commons.exec.CommandLine; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; import org.springframework.core.io.Resource; public class JvmProcess extends SystemCall { + private final static Log log = LogFactory.getLog(JvmProcess.class); + private Properties systemProperties = new Properties(); private List classpath = new ArrayList(); private List pBootClasspath = new ArrayList(); @@ -29,10 +36,9 @@ public class JvmProcess extends SystemCall { cl = new CommandLine("java"); if (pBootClasspath.size() > 0) { - StringBuffer buf = new StringBuffer("-Xbootclasspath/p:"); + StringBuffer buf = new StringBuffer("-Xbootclasspath/p"); for (Resource res : pBootClasspath) { - if (buf.length() != 0) - buf.append(File.pathSeparatorChar); + buf.append(File.pathSeparatorChar); buf.append(asFile(res)); } cl.addArgument(buf.toString()); @@ -62,19 +68,38 @@ public class JvmProcess extends SystemCall { cl.addArgument(arg); } + if (log.isDebugEnabled()) + log.debug("Command line:\n" + cl.toString() + "\n"); + return cl; } protected File asFile(Resource res) { - // TODO: implements local copy try { return res.getFile().getCanonicalFile(); + } catch (FileNotFoundException e) { + return copyToTempFile(res); } catch (IOException e) { throw new SlcException("Cannot convert resource to file", e); } } + protected File copyToTempFile(Resource res) { + File tempFile; + FileOutputStream fos; + try { + tempFile = File.createTempFile("slcJvmProcess-", res.getFilename()); + tempFile.deleteOnExit(); + fos = new FileOutputStream(tempFile); + IOUtils.copy(res.getInputStream(), fos); + } catch (IOException e) { + throw new SlcException("Cannot copy " + res + " to temp file.", e); + } + IOUtils.closeQuietly(fos); + return tempFile; + } + public Properties getSystemProperties() { return systemProperties; }