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%2FSystemCall.java;h=f3314ac7f46616b9b84334e1a60e4dec6410d335;hb=8c0984b6c89376160effcaa5cb73ec6a1f59208c;hp=a14e550bf85eb39455fec181ff517e562c395641;hpb=ee6c3543a0ff9403420ce6a9c647723269f14331;p=gpl%2Fargeo-slc.git 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 a14e550bf..f3314ac7f 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 @@ -96,28 +96,17 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable, dir = new File(execDir).getCanonicalFile(); } - // Check if an OS specific command overrides - String osName = System.getProperty("os.name"); - List commandToUse = null; - if (osCommands.containsKey(osName)) - commandToUse = osCommands.get(osName); - else - commandToUse = command; - String cmdToUse = null; - if (osCmds.containsKey(osName)) - cmdToUse = osCmds.get(osName); - else - cmdToUse = cmd; - // Prepare executor if (dir == null) dir = new File(getUsedDir(dir)); if (!dir.exists()) dir.mkdirs(); + // Watchdog to check for lost processes Executor executor = new DefaultExecutor(); executor.setWatchdog(new ExecuteWatchdog(watchdogTimeout)); + // Redirect standard streams PumpStreamHandler pumpStreamHandler = new PumpStreamHandler( new LogOutputStream() { protected void processLine(String line, int level) { @@ -135,34 +124,9 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable, executor.setStreamHandler(pumpStreamHandler); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); executor.setWorkingDirectory(dir); - final CommandLine commandLine; - - // Which command definition to use - if (commandToUse == null && cmdToUse == null) - throw new SlcException("Please specify a command."); - else if (commandToUse != null && cmdToUse != null) - throw new SlcException( - "Specify the command either as a line or as a list."); - else if (cmdToUse != null) { - if (log.isTraceEnabled()) - log.trace("Execute '" + cmdToUse + "' in " - + getUsedDir(dir)); - - commandLine = CommandLine.parse(cmdToUse); - } else if (commandToUse != null) { - if (log.isTraceEnabled()) - log.trace("Execute '" + commandToUse + "' in " - + getUsedDir(dir)); - if (commandToUse.size() == 0) - throw new SlcException("Command line is empty."); - - commandLine = new CommandLine(commandToUse.get(0).toString()); - for (int i = 1; i < commandToUse.size(); i++) - commandLine.addArgument(commandToUse.get(i).toString()); - } else { - // all cases covered previously - throw new UnsupportedOperationException(); - } + + // Command line to use + final CommandLine commandLine = createCommandLine(); // Env variables Map environmentVariablesToUse = environmentVariables @@ -216,6 +180,45 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable, } + /** Can be overridden by specific command wrapper*/ + protected CommandLine createCommandLine() { + // Check if an OS specific command overrides + String osName = System.getProperty("os.name"); + List commandToUse = null; + if (osCommands.containsKey(osName)) + commandToUse = osCommands.get(osName); + else + commandToUse = command; + String cmdToUse = null; + if (osCmds.containsKey(osName)) + cmdToUse = osCmds.get(osName); + else + cmdToUse = cmd; + + final CommandLine commandLine; + + // Which command definition to use + if (commandToUse == null && cmdToUse == null) + throw new SlcException("Please specify a command."); + else if (commandToUse != null && cmdToUse != null) + throw new SlcException( + "Specify the command either as a line or as a list."); + else if (cmdToUse != null) { + commandLine = CommandLine.parse(cmdToUse); + } else if (commandToUse != null) { + if (commandToUse.size() == 0) + throw new SlcException("Command line is empty."); + + commandLine = new CommandLine(commandToUse.get(0).toString()); + for (int i = 1; i < commandToUse.size(); i++) + commandLine.addArgument(commandToUse.get(i).toString()); + } else { + // all cases covered previously + throw new UnsupportedOperationException(); + } + return commandLine; + } + /** * Shortcut method returning the current exec dir if the specified one is * null.