1 package org
.argeo
.slc
.jsch
;
4 import java
.io
.IOException
;
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
;
15 /** A Commons Exec executor executing remotely via SSH */
16 public class JschExecutor
implements Executor
{
17 private File workingDirectory
;
18 private ExecuteStreamHandler streamHandler
;
20 private SshTarget sshTarget
;
22 public void setExitValue(int value
) {
23 // TODO Auto-generated method stub
27 public void setExitValues(int[] values
) {
28 // TODO Auto-generated method stub
32 public boolean isFailure(int exitValue
) {
33 return Executor
.INVALID_EXITVALUE
== exitValue
;
36 public ExecuteStreamHandler
getStreamHandler() {
40 public void setStreamHandler(ExecuteStreamHandler streamHandler
) {
41 this.streamHandler
= streamHandler
;
44 public ExecuteWatchdog
getWatchdog() {
45 // TODO Auto-generated method stub
49 public void setWatchdog(ExecuteWatchdog watchDog
) {
50 // TODO Auto-generated method stub
54 public ProcessDestroyer
getProcessDestroyer() {
55 // TODO Auto-generated method stub
59 public void setProcessDestroyer(ProcessDestroyer processDestroyer
) {
60 // TODO Auto-generated method stub
64 public File
getWorkingDirectory() {
65 return workingDirectory
;
68 public void setWorkingDirectory(File workingDirectory
) {
69 this.workingDirectory
= workingDirectory
;
72 public int execute(CommandLine command
) throws ExecuteException
,
74 return execute(command
, (Map
) null);
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
);
89 return remoteExec
.getLastExitStatus() != null ? remoteExec
90 .getLastExitStatus() : Executor
.INVALID_EXITVALUE
;
93 public void execute(CommandLine command
, ExecuteResultHandler handler
)
94 throws ExecuteException
, IOException
{
95 // TODO Auto-generated method stub
99 public void execute(CommandLine command
, Map environment
,
100 ExecuteResultHandler handler
) throws ExecuteException
, IOException
{
104 public SshTarget
getSshTarget() {
108 public void setSshTarget(SshTarget sshTarget
) {
109 this.sshTarget
= sshTarget
;