]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java
Improve killing of system calls
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / SystemCall.java
index 9d8ebdcf8785920a459be223eed70596ea693e5c..5046abb0a3bd2f47d178488ab777fe5dbd356829 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.argeo.slc.core.execution.tasks;
 
 import java.io.File;
@@ -30,14 +46,13 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.UnsupportedException;
 import org.argeo.slc.core.execution.ExecutionResources;
-import org.argeo.slc.core.structure.tree.TreeSRelatedHelper;
 import org.argeo.slc.core.test.SimpleResultPart;
 import org.argeo.slc.test.TestResult;
 import org.argeo.slc.test.TestStatus;
 import org.springframework.core.io.Resource;
 
 /** Execute an OS specific system call. */
-public class SystemCall extends TreeSRelatedHelper implements Runnable {
+public class SystemCall implements Runnable {
        public final static String LOG_STDOUT = "System.out";
 
        private final Log log = LogFactory.getLog(getClass());
@@ -185,7 +200,7 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
 
                //
                // THE EXECUTION PROPER
-               // 
+               //
                try {
                        if (synchronous)
                                try {
@@ -193,6 +208,10 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
                                                        environmentVariablesToUse);
                                        executeResultHandler.onProcessComplete(exitValue);
                                } catch (ExecuteException e1) {
+                                       if (e1.getExitValue() == Executor.INVALID_EXITVALUE) {
+                                               Thread.currentThread().interrupt();
+                                               return;
+                                       }
                                        executeResultHandler.onProcessFailed(e1);
                                }
                        else
@@ -341,7 +360,7 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
                                if (log.isTraceEnabled())
                                        log.trace(msg);
                                if (testResult != null) {
-                                       forwardPath(testResult, null);
+                                       forwardPath(testResult);
                                        testResult.addResultPart(new SimpleResultPart(
                                                        TestStatus.PASSED, msg));
                                }
@@ -350,7 +369,7 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
                        public void onProcessFailed(ExecuteException e) {
                                String msg = "System call '" + commandLine + "' failed.";
                                if (testResult != null) {
-                                       forwardPath(testResult, null);
+                                       forwardPath(testResult);
                                        testResult.addResultPart(new SimpleResultPart(
                                                        TestStatus.ERROR, msg, e));
                                } else {
@@ -363,6 +382,10 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
                };
        }
 
+       protected void forwardPath(TestResult testResult) {
+               // TODO: allocate a TreeSPath
+       }
+
        /**
         * Shortcut method getting the execDir to use
         */
@@ -463,12 +486,16 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
 
        /** Append the argument (for chaining) */
        public SystemCall arg(String arg) {
+               if (command == null)
+                       command = new ArrayList<Object>();
                command.add(arg);
                return this;
        }
 
        /** Append the argument (for chaining) */
        public SystemCall arg(String arg, String value) {
+               if (command == null)
+                       command = new ArrayList<Object>();
                command.add(arg);
                command.add(value);
                return this;