]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/JschExecutor.java
Improve versioning driver
[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 if(workingDirectory!=null)
81 cmd = "cd "+workingDirectory.getPath()+" && "+cmd;
82 RemoteExec remoteExec = new RemoteExec();
83 remoteExec.setSshTarget(sshTarget);
84 remoteExec.setStreamHandler(streamHandler);
85 remoteExec.setCommand(cmd);
86 if (environment != null)
87 remoteExec.setEnv(environment);
88 remoteExec.run();
89 return remoteExec.getLastExitStatus() != null ? remoteExec
90 .getLastExitStatus() : Executor.INVALID_EXITVALUE;
91 }
92
93 public void execute(CommandLine command, ExecuteResultHandler handler)
94 throws ExecuteException, IOException {
95 // TODO Auto-generated method stub
96
97 }
98
99 public void execute(CommandLine command, Map environment,
100 ExecuteResultHandler handler) throws ExecuteException, IOException {
101
102 }
103
104 public SshTarget getSshTarget() {
105 return sshTarget;
106 }
107
108 public void setSshTarget(SshTarget sshTarget) {
109 this.sshTarget = sshTarget;
110 }
111
112 }