From 29c15b16bb731817b8e1df0ea715f19c1dba42ed Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Tue, 28 Jul 2009 18:07:00 +0000 Subject: [PATCH] Add generate script git-svn-id: https://svn.argeo.org/slc/trunk@2825 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../slc/core/execution/tasks/SystemCall.java | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java index 93a467a1d..87a45905a 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java @@ -20,6 +20,7 @@ import org.apache.commons.exec.Executor; import org.apache.commons.exec.LogOutputStream; import org.apache.commons.exec.PumpStreamHandler; import org.apache.commons.exec.ShutdownHookProcessDestroyer; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -58,6 +59,7 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable, private Boolean logCommand = false; private Boolean redirectStreams = true; private String osConsole = null; + private String generateScript = null; private Long watchdogTimeout = 24 * 60 * 60 * 1000l; @@ -165,7 +167,7 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable, else cmdToUse = cmd; - final CommandLine commandLine; + CommandLine commandLine = null; // Which command definition to use if (commandToUse == null && cmdToUse == null) @@ -174,27 +176,39 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable, throw new SlcException( "Specify the command either as a line or as a list."); else if (cmdToUse != null) { - if (osConsole != null) - cmdToUse = osConsole + " " + cmdToUse; commandLine = CommandLine.parse(cmdToUse); } else if (commandToUse != null) { if (commandToUse.size() == 0) throw new SlcException("Command line is empty."); - if (osConsole != null) { - commandLine = CommandLine.parse(osConsole); - } else { - commandLine = new CommandLine(commandToUse.get(0).toString()); - } + commandLine = new CommandLine(commandToUse.get(0).toString()); - for (int i = (osConsole != null ? 0 : 1); i < commandToUse.size(); i++) { - log.debug(commandToUse.get(i)); + for (int i = 1; i < commandToUse.size(); i++) { + if (log.isTraceEnabled()) + log.debug(commandToUse.get(i)); commandLine.addArgument(commandToUse.get(i).toString()); } } else { // all cases covered previously throw new UnsupportedException(); } + + if (osConsole != null) + commandLine = CommandLine.parse(osConsole + " " + + commandLine.toString()); + + if (generateScript != null) { + File scriptFile = new File(getExecDirToUse() + File.separator + + generateScript); + try { + FileUtils.writeStringToFile(scriptFile, commandLine.toString()); + } catch (IOException e) { + throw new SlcException("Could not generate script " + + scriptFile, e); + } + commandLine = new CommandLine(scriptFile); + } + return commandLine; } @@ -370,6 +384,10 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable, this.osConsole = osConsole; } + public void setGenerateScript(String generateScript) { + this.generateScript = generateScript; + } + private class DummyexecuteStreamHandler implements ExecuteStreamHandler { public void setProcessErrorStream(InputStream is) throws IOException { -- 2.39.2