diff options
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java new file mode 100644 index 0000000..bb2fa2d --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java | |||
@@ -0,0 +1,88 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.File; | ||
14 | import java.lang.reflect.InvocationTargetException; | ||
15 | |||
16 | import org.eclipse.core.runtime.IProgressMonitor; | ||
17 | import org.eclipse.swt.widgets.Display; | ||
18 | import org.eclipse.ui.console.ConsolePlugin; | ||
19 | import org.eclipse.ui.console.IConsole; | ||
20 | import org.eclipse.ui.console.IConsoleManager; | ||
21 | import org.eclipse.ui.console.MessageConsole; | ||
22 | import org.yocto.remote.utils.ShellSession; | ||
23 | |||
24 | public class SystemtapModel extends BaseModel { | ||
25 | protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env"; | ||
26 | protected static final String SYSTEMTAP_CONSOLE = "Systemtap Console"; | ||
27 | |||
28 | private static final String TASK_NAME = "systemtap command"; | ||
29 | |||
30 | protected MessageConsole sessionConsole; | ||
31 | private String metadata_location; | ||
32 | private String builddir_location; | ||
33 | private String remote_host; | ||
34 | private String user_id; | ||
35 | private String systemtap_script; | ||
36 | private String systemtap_args; | ||
37 | |||
38 | Display display; | ||
39 | |||
40 | public SystemtapModel(String metadata_location, String builddir_location, String remote_host, String user_id, String systemtap_script, String systemtap_args, Display display) { | ||
41 | super(null, TASK_NAME, "", ""); | ||
42 | this.metadata_location = metadata_location; | ||
43 | this.builddir_location = builddir_location; | ||
44 | this.remote_host = remote_host; | ||
45 | this.user_id = user_id; | ||
46 | this.systemtap_script = systemtap_script; | ||
47 | this.systemtap_args = systemtap_args; | ||
48 | this.display = display; | ||
49 | if (sessionConsole == null) { | ||
50 | IConsoleManager conMan = ConsolePlugin.getDefault().getConsoleManager(); | ||
51 | IConsole[] existing = conMan.getConsoles(); | ||
52 | for (int i = 0; i < existing.length; i++) | ||
53 | if (SYSTEMTAP_CONSOLE.equals(existing[i].getName())) { | ||
54 | sessionConsole = (MessageConsole) existing[i]; | ||
55 | break; | ||
56 | } | ||
57 | if (sessionConsole == null) { | ||
58 | sessionConsole = new MessageConsole(SYSTEMTAP_CONSOLE, null); | ||
59 | conMan.addConsoles(new IConsole[] { sessionConsole }); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | ConsolePlugin.getDefault().getConsoleManager().showConsoleView(sessionConsole); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public void preProcess(IProgressMonitor monitor) | ||
68 | throws InvocationTargetException, InterruptedException {} | ||
69 | |||
70 | @Override | ||
71 | public void process(IProgressMonitor monitor) | ||
72 | throws InvocationTargetException, InterruptedException { | ||
73 | try { | ||
74 | ShellSession shell = new ShellSession(ShellSession.SHELL_TYPE_BASH, | ||
75 | new File(this.metadata_location), new File(this.builddir_location), | ||
76 | DEFAULT_INIT_SCRIPT, sessionConsole.newOutputStream()); | ||
77 | boolean acceptedKey = shell.ensureKnownHostKey(user_id, remote_host); | ||
78 | if (acceptedKey) { | ||
79 | String crosstapCmd = "crosstap " + user_id + "@" + remote_host + " " + systemtap_script; | ||
80 | if (systemtap_args != null) | ||
81 | crosstapCmd = crosstapCmd + " " + systemtap_args; | ||
82 | shell.execute(crosstapCmd); | ||
83 | } | ||
84 | } catch (Exception e) { | ||
85 | throw new InvocationTargetException(e,e.getMessage()); | ||
86 | } | ||
87 | } | ||
88 | } | ||