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