]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/JschExecutor.java
dbf62721a08778fc15bf3b59a7e006d20677437f
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / jsch / JschExecutor.java
1 package org.argeo.slc.jsch;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.Map;
6
7 import org.apache.commons.exec.CommandLine;
8 import org.apache.commons.exec.ExecuteException;
9 import org.apache.commons.exec.ExecuteResultHandler;
10 import org.apache.commons.exec.ExecuteStreamHandler;
11 import org.apache.commons.exec.ExecuteWatchdog;
12 import org.apache.commons.exec.Executor;
13 import org.apache.commons.exec.ProcessDestroyer;
14
15 /** A Commons Exec executor executing remotely via SSH */
16 public class JschExecutor implements Executor {
17 private File workingDirectory;
18 private ExecuteStreamHandler streamHandler;
19
20 private SshTarget sshTarget;
21
22 public void setExitValue(int value) {
23 // TODO Auto-generated method stub
24
25 }
26
27 public void setExitValues(int[] values) {
28 // TODO Auto-generated method stub
29
30 }
31
32 public boolean isFailure(int exitValue) {
33 return Executor.INVALID_EXITVALUE == exitValue;
34 }
35
36 public ExecuteStreamHandler getStreamHandler() {
37 return streamHandler;
38 }
39
40 public void setStreamHandler(ExecuteStreamHandler streamHandler) {
41 this.streamHandler = streamHandler;
42 }
43
44 public ExecuteWatchdog getWatchdog() {
45 // TODO Auto-generated method stub
46 return null;
47 }
48
49 public void setWatchdog(ExecuteWatchdog watchDog) {
50 // TODO Auto-generated method stub
51
52 }
53
54 public ProcessDestroyer getProcessDestroyer() {
55 // TODO Auto-generated method stub
56 return null;
57 }
58
59 public void setProcessDestroyer(ProcessDestroyer processDestroyer) {
60 // TODO Auto-generated method stub
61
62 }
63
64 public File getWorkingDirectory() {
65 return workingDirectory;
66 }
67
68 public void setWorkingDirectory(File workingDirectory) {
69 this.workingDirectory = workingDirectory;
70 }
71
72 public int execute(CommandLine command) throws ExecuteException,
73 IOException {
74 return execute(command, (Map) null);
75 }
76
77 public int execute(CommandLine command, Map environment)
78 throws ExecuteException, IOException {
79 String cmd = command.toString();
80 RemoteExec remoteExec = new RemoteExec();
81 remoteExec.setSshTarget(sshTarget);
82 remoteExec.setStreamHandler(streamHandler);
83 remoteExec.setCommand(cmd);
84 if (environment != null)
85 remoteExec.setEnv(environment);
86 remoteExec.run();
87 return remoteExec.getLastExitStatus() != null ? remoteExec
88 .getLastExitStatus() : Executor.INVALID_EXITVALUE;
89 }
90
91 public void execute(CommandLine command, ExecuteResultHandler handler)
92 throws ExecuteException, IOException {
93 // TODO Auto-generated method stub
94
95 }
96
97 public void execute(CommandLine command, Map environment,
98 ExecuteResultHandler handler) throws ExecuteException, IOException {
99
100 }
101
102 public SshTarget getSshTarget() {
103 return sshTarget;
104 }
105
106 public void setSshTarget(SshTarget sshTarget) {
107 this.sshTarget = sshTarget;
108 }
109
110 }