12
12
package org.eclipse.linuxtools.systemtap.structures.process;
14
import java.io.IOException;
15
14
import java.io.OutputStream;
17
import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory;
16
import org.eclipse.linuxtools.tools.launch.core.factory.LinuxtoolsProcessFactory;
19
18
import com.jcraft.jsch.Channel;
20
import com.jcraft.jsch.ChannelExec;
21
import com.jcraft.jsch.JSch;
22
19
import com.jcraft.jsch.JSchException;
23
import com.jcraft.jsch.Session;
26
* The {@link SystemtapProcessFactory} is responsible for creating process
28
* When executing systemtap operations you must always use this factory so that
29
* mock objects can be provided during testing.
22
* @deprecated Use {@link LinuxtoolsProcessFactory} instead.
31
25
public class SystemtapProcessFactory {
34
* Runs systemtap locally with the given arguments.
37
* arguments to run systemtap with.
39
* environment variables.
40
* @return The newly created process.
43
public static Process exec(String[] args, String[] envVars) throws IOException {
44
return RuntimeProcessFactory.getFactory().exec(args, envVars, null);
48
* Runs stap with the given arguments on the given host using the given
52
* the user name to use on the remote machine.
54
* the host where the systemtap process will be run.
56
* password for authenticating with the given host.
57
* @return a {@link Channel} connected to the remotely running process.
58
* @throws JSchException
59
* thrown if there are problems connecting to the remote
62
public static Channel execRemote(String[] args,
63
OutputStream out, OutputStream err, String user, String host,
64
String password) throws JSchException {
65
JSch jsch = new JSch();
66
Session session = jsch.getSession(user, host, 22);
67
session.setPassword(password);
68
java.util.Properties config = new java.util.Properties();
69
config.put("StrictHostKeyChecking", "no"); //$NON-NLS-1$//$NON-NLS-2$
70
session.setConfig(config);
73
StringBuilder command = new StringBuilder();
74
for (int i = 0; i < args.length; i++) {
75
command.append(args[i]);
78
Channel channel = session.openChannel("exec"); //$NON-NLS-1$
79
((ChannelExec) channel).setCommand(command.toString());
81
channel.setInputStream(null, true);
82
channel.setOutputStream(out, true);
83
channel.setExtOutputStream(err, true);
89
* Runs stap with the given arguments on the given host using the given
90
* credentials and waits for the process to finish executing.
93
* the user name to use on the remote machine.
95
* the host where the systemtap process will be run.
97
* password for authenticating with the given host.
98
* @return a {@link Channel} connected to the remotely running process.
99
* @throws JSchException
100
* thrown if there are problems connecting to the remote
103
public static Channel execRemoteAndWait(String[] args,
104
OutputStream out, OutputStream err, String user, String host,
105
String password) throws JSchException {
106
Channel channel = execRemote(args, out, err, user, host, password);
108
while (!channel.isClosed()){
111
} catch (InterruptedException e) {
112
// Thread was interrupted just return.
28
* Runs stap with the given arguments on the given host using the given
31
* @param user the user name to use on the remote machine.
32
* @param host the host where the systemtap process will be run.
33
* @param password password for authenticating with the given host.
34
* @return a {@link Channel} connected to the remotely running process.
35
* @throws JSchException thrown if there are problems connecting to the remote machine.
37
public static Channel execRemote(String[] args,
38
OutputStream out, OutputStream err, String user, String host,
39
String password) throws JSchException {
40
return LinuxtoolsProcessFactory.execRemote(args, out, err, user, host, password);
44
* Runs stap with the given arguments on the given host using the given
47
* @param user the user name to use on the remote machine.
48
* @param host the host where the systemtap process will be run.
49
* @param password password for authenticating with the given host.
50
* @param envp an array with extra enviroment variables to be used when running
51
* the command. Set to <code>null</code> if none are needed.
52
* @return a {@link Channel} connected to the remotely running process.
53
* @throws JSchException thrown if there are problems connecting to the remote machine.
56
public static Channel execRemote(String[] args, OutputStream out,
57
OutputStream err, String user, String host, String password, int port, String[] envp)
58
throws JSchException {
59
return LinuxtoolsProcessFactory.execRemote(args, out, err, user, host, password, port, envp);
63
* Runs stap with the given arguments on the given host using the given
64
* credentials and waits for the process to finish executing.
66
* @param user the user name to use on the remote machine.
67
* @param host the host where the systemtap process will be run.
68
* @param password password for authenticating with the given host.
69
* @return a {@link Channel} connected to the remotely running process.
70
* @throws JSchException thrown if there are problems connecting to the remote machine.
72
public static Channel execRemoteAndWait(String[] args,
73
OutputStream out, OutputStream err, String user, String host,
74
String password) throws JSchException {
75
return LinuxtoolsProcessFactory.execRemoteAndWait(args, out, err, user, host, password);
79
* Runs stap with the given arguments on the given host using the given
80
* credentials and waits for the process to finish executing.
82
* @param user the user name to use on the remote machine.
83
* @param host the host where the systemtap process will be run.
84
* @param password password for authenticating with the given host.
85
* @param envp an array with extra enviroment variables to be used when running
86
* the command. Set to <code>null</code> if none are needed.
87
* @return a {@link Channel} connected to the remotely running process.
88
* @throws JSchException thrown if there are problems connecting to the remote machine.
91
public static Channel execRemoteAndWait(String[] args, OutputStream out,
92
OutputStream err, String user, String host, String password, int port, String[] envp)
93
throws JSchException {
94
return LinuxtoolsProcessFactory.execRemoteAndWait(args, out, err, user, host, password, port, envp);