Introduce script call
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 22 May 2010 19:16:15 +0000 (19:16 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 22 May 2010 19:16:15 +0000 (19:16 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3589 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/ScriptCall.java [new file with mode: 0644]

diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/ScriptCall.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/ScriptCall.java
new file mode 100644 (file)
index 0000000..38c209a
--- /dev/null
@@ -0,0 +1,45 @@
+package org.argeo.slc.lib.linux;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FilenameUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.core.execution.tasks.SystemCall;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.Resource;
+
+public class ScriptCall extends SystemCall implements InitializingBean {
+       private Resource script;
+       private List<Object> scriptArgs = new ArrayList<Object>();
+
+       public void afterPropertiesSet() throws Exception {
+               initInterpreter();
+               for (Object obj : scriptArgs) {
+                       arg(obj.toString());
+               }
+               setStdInFile(script);
+       }
+
+       protected void initInterpreter() {
+               String ext = FilenameUtils.getExtension(script.getFilename());
+               if ("sh".equals(ext))
+                       arg("/bin/sh").arg("-s");
+               else if ("pl".equals(ext))
+                       arg("/usr/bin/perl").arg("/dev/stdin");
+               else if ("py".equals(ext))
+                       arg("/usr/bin/python").arg("-");
+               else
+                       throw new SlcException("Cannot initialize script intepreter for "
+                                       + script);
+       }
+
+       public void setScript(Resource script) {
+               this.script = script;
+       }
+
+       public void setScriptArgs(List<Object> scriptArgs) {
+               this.scriptArgs = scriptArgs;
+       }
+
+}