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;
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>();
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());
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;
}