]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/JvmProcess.java
Fix bootclasspath prepend
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / JvmProcess.java
index ba1d67eb558ac0296e46d9dba4ddbb0ec7a979b6..2be9e8ceaeaaba51b5981b015aa9cbe60d9d1878 100644 (file)
@@ -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<Resource> classpath = new ArrayList<Resource>();
        private List<Resource> pBootClasspath = new ArrayList<Resource>();
@@ -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;
        }