~ubuntu-branches/ubuntu/wily/eclipse-linuxtools/wily

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.structures/src/org/eclipse/linuxtools/systemtap/structures/process/SystemtapProcessFactory.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
package org.eclipse.linuxtools.systemtap.structures.process;
13
13
 
14
 
import java.io.IOException;
15
14
import java.io.OutputStream;
16
15
 
17
 
import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory;
 
16
import org.eclipse.linuxtools.tools.launch.core.factory.LinuxtoolsProcessFactory;
18
17
 
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;
24
20
 
25
21
/**
26
 
 * The {@link SystemtapProcessFactory} is responsible for creating process
27
 
 * objects.
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.
30
23
 */
 
24
@Deprecated
31
25
public class SystemtapProcessFactory {
32
26
 
33
 
        /**
34
 
         * Runs systemtap locally with the given arguments.
35
 
         *
36
 
         * @param args
37
 
         *            arguments to run systemtap with.
38
 
         * @param envVars
39
 
         *            environment variables.
40
 
         * @return The newly created process.
41
 
         * @throws IOException
42
 
         */
43
 
        public static Process exec(String[] args, String[] envVars) throws IOException {
44
 
                return RuntimeProcessFactory.getFactory().exec(args, envVars, null);
45
 
        }
46
 
 
47
 
        /**
48
 
         * Runs stap with the given arguments on the given host using the given
49
 
         * credentials.
50
 
         *
51
 
         * @param user
52
 
         *            the user name to use on the remote machine.
53
 
         * @param host
54
 
         *            the host where the systemtap process will be run.
55
 
         * @param password
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
60
 
         *             machine.
61
 
         */
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);
71
 
                session.connect();
72
 
 
73
 
                StringBuilder command = new StringBuilder();
74
 
                for (int i = 0; i < args.length; i++) {
75
 
                        command.append(args[i]);
76
 
                }
77
 
 
78
 
                Channel channel = session.openChannel("exec"); //$NON-NLS-1$
79
 
                ((ChannelExec) channel).setCommand(command.toString());
80
 
 
81
 
                channel.setInputStream(null, true);
82
 
                channel.setOutputStream(out, true);
83
 
                channel.setExtOutputStream(err, true);
84
 
 
85
 
                return channel;
86
 
        }
87
 
 
88
 
        /**
89
 
         * Runs stap with the given arguments on the given host using the given
90
 
         * credentials and waits for the process to finish executing.
91
 
         *
92
 
         * @param user
93
 
         *            the user name to use on the remote machine.
94
 
         * @param host
95
 
         *            the host where the systemtap process will be run.
96
 
         * @param password
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
101
 
         *             machine.
102
 
         */
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);
107
 
 
108
 
                while (!channel.isClosed()){
109
 
                        try {
110
 
                                Thread.sleep(250);
111
 
                        } catch (InterruptedException e) {
112
 
                                // Thread was interrupted just return.
113
 
                                return channel;
114
 
                        }
115
 
                }
116
 
 
117
 
                return channel;
118
 
        }
 
27
    /**
 
28
     * Runs stap with the given arguments on the given host using the given
 
29
     * credentials.
 
30
     *
 
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.
 
36
     */
 
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);
 
41
    }
 
42
 
 
43
    /**
 
44
     * Runs stap with the given arguments on the given host using the given
 
45
     * credentials.
 
46
     *
 
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.
 
54
     * @since 3.0
 
55
     */
 
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);
 
60
    }
 
61
 
 
62
    /**
 
63
     * Runs stap with the given arguments on the given host using the given
 
64
     * credentials and waits for the process to finish executing.
 
65
     *
 
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.
 
71
     */
 
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);
 
76
    }
 
77
 
 
78
    /**
 
79
     * Runs stap with the given arguments on the given host using the given
 
80
     * credentials and waits for the process to finish executing.
 
81
     *
 
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.
 
89
     * @since 3.0
 
90
     */
 
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);
 
95
    }
119
96
}