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;h=2be9e8ceaeaaba51b5981b015aa9cbe60d9d1878;hb=8c0984b6c89376160effcaa5cb73ec6a1f59208c;hp=ba1d67eb558ac0296e46d9dba4ddbb0ec7a979b6;hpb=09ab1aca27488e1feef6c8f46b34b7d27284be9a;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..2be9e8cea 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(); @@ -30,9 +37,13 @@ public class JvmProcess extends SystemCall { if (pBootClasspath.size() > 0) { StringBuffer buf = new StringBuffer("-Xbootclasspath/p:"); + Boolean first = true; for (Resource res : pBootClasspath) { - if (buf.length() != 0) + if (first) + first = false; + else buf.append(File.pathSeparatorChar); + buf.append(asFile(res)); } cl.addArgument(buf.toString()); @@ -62,19 +73,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; }