diff options
author | Andrew Overholt | 2009-08-11 15:34:33 +0000 |
---|---|---|
committer | Andrew Overholt | 2009-08-11 15:34:33 +0000 |
commit | d7ff177e92e641590c38bfb48579158b8a52a5ae (patch) | |
tree | 5a3f567b8d9beba635d1b39c71d112814fe9ba2b /systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog | |
parent | 5500323611c3d73e6a0795f9e23443b1cb1164a4 (diff) | |
download | org.eclipse.linuxtools-d7ff177e92e641590c38bfb48579158b8a52a5ae.tar.gz org.eclipse.linuxtools-d7ff177e92e641590c38bfb48579158b8a52a5ae.tar.xz org.eclipse.linuxtools-d7ff177e92e641590c38bfb48579158b8a52a5ae.zip |
Branch for 0.3
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog')
36 files changed, 3107 insertions, 0 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.classpath b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.classpath new file mode 100644 index 0000000000..64c5e31b7a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.project b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.project new file mode 100644 index 0000000000..166d553357 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.linuxtools.systemtap.ui.consolelog</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.settings/org.eclipse.jdt.core.prefs b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..e6130aa6a3 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Fri Feb 27 18:15:40 IST 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/ChangeLog b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/ChangeLog new file mode 100644 index 0000000000..9e11384b8d --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/ChangeLog @@ -0,0 +1,11 @@ +2009-08-07 Andrew Overholt <overholt@redhat.com> + + * META-INF/MANIFEST.MF: Make version 0.3.0.qualifier. + +2009-08-07 Andrew Overholt <overholt@redhat.com> + + * META-INF/MANIFEST.MF: Change provider from IBM to Eclipse. + +2009-07-07 Anithra P Janakiraman <anithra@linux.vnet.ibm.com> + + * ChangeLog: Refactoring. Renaming all packages directories from *.systemtapgui.* to *.systemtap.ui.*
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/META-INF/MANIFEST.MF b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..f421d48927 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ConsoleLog Plug-in +Bundle-SymbolicName: org.eclipse.linuxtools.systemtap.ui.consolelog;singleton:=true +Bundle-Version: 0.3.0.qualifier +Bundle-Activator: org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin +Bundle-Vendor: Eclipse +Bundle-Localization: plugin +Export-Package: org.eclipse.linuxtools.systemtap.ui.consolelog, + org.eclipse.linuxtools.systemtap.ui.consolelog.actions, + org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs, + org.eclipse.linuxtools.systemtap.ui.consolelog.internal, + org.eclipse.linuxtools.systemtap.ui.consolelog.preferences, + org.eclipse.linuxtools.systemtap.ui.consolelog.structures, + org.eclipse.linuxtools.systemtap.ui.consolelog.views +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.ui.console;visibility:=reexport, + org.eclipse.ui.workbench.texteditor, + org.eclipse.linuxtools.systemtap.ui.editor, + org.eclipse.linuxtools.systemtap.ui.structures, + com.jcraft.jsch;bundle-version="0.1.37" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/build.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/build.properties new file mode 100644 index 0000000000..fc993cec49 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/build.properties @@ -0,0 +1,9 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + plugin.properties,\ + .classpath +src.includes = .classpath diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/actions/save_log.gif b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/actions/save_log.gif Binary files differnew file mode 100644 index 0000000000..71ad510b41 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/actions/save_log.gif diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/views/error_obj.gif b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/views/error_obj.gif Binary files differnew file mode 100644 index 0000000000..b6922ac11c --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/views/error_obj.gif diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/views/error_st_obj.gif b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/views/error_st_obj.gif Binary files differnew file mode 100644 index 0000000000..0bc60689c6 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/icons/views/error_st_obj.gif diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/plugin.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/plugin.properties new file mode 100644 index 0000000000..afd8b0297e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/plugin.properties @@ -0,0 +1,6 @@ +view.error.name=Error Log + +action.saveLog.name=Save &Log +action.saveLog.desc=Save console log to file + +preference.consoleLog.name=RemoteServer
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/plugin.xml b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/plugin.xml new file mode 100644 index 0000000000..82a09c16b5 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/plugin.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin> + <extension + point="org.eclipse.ui.views"> + <view + name="%view.error.name" + allowMultiple="false" + icon="icons/views/error_obj.gif" + class="org.eclipse.linuxtools.systemtap.ui.consolelog.views.ErrorView" + id="org.eclipse.linuxtools.systemtap.ui.consolelog.views.ErrorView"/> + </extension> + + + <extension + point="org.eclipse.ui.viewActions"> + <viewContribution + id="org.eclipse.linuxtools.systemtap.ui.consolelog.consoleview.toolbar" + targetID="org.eclipse.ui.console.ConsoleView"> + <action + id="org.eclipse.linuxtools.systemtap.ui.consolelog.actions.SaveLogAction" + label="%action.saveLog.name" + tooltip="%action.saveLog.desc" + class="org.eclipse.linuxtools.systemtap.ui.consolelog.actions.SaveLogAction" + icon="icons/actions/save_log.gif" + toolbarPath="launchGroup" + state="false" + style="push"/> + + </viewContribution> + </extension> + + <extension + point="org.eclipse.core.runtime.preferences"> + <initializer class="org.eclipse.linuxtools.systemtap.ui.consolelog.preferences.PreferenceInitializer"/> + </extension> + + <extension + point="org.eclipse.ui.preferencePages"> + <page + name="%preference.consoleLog.name" + id="com.qualityeclipse.systemtap.prefs.consoleLog" + class="org.eclipse.linuxtools.systemtap.ui.consolelog.preferences.ConsoleLogPreferencePage" + category="com.qualityeclipse.systemtap.prefs.view"/> + </extension> +</plugin> diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ClientSession.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ClientSession.java new file mode 100644 index 0000000000..dc3db44111 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ClientSession.java @@ -0,0 +1,326 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.TreeMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.net.Socket; +import java.net.UnknownHostException; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs.ErrorMessage; +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; +import org.eclipse.linuxtools.systemtap.ui.consolelog.preferences.ConsoleLogPreferenceConstants; +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.DMRequest; +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.DMResponse; + + + + +/** + * Singleton thread. Maintains the communication between the + * data manager and the client (this). + * + * @author patrickm + * + */ +public final class ClientSession extends Thread { + + private static ClientSession instance = null; + private static int portnumber, clientID; + private static boolean connected; + private static String hostname; + private static int scriptnumber; + private static InputStream in; + private static TreeMap<Integer, LinkedBlockingQueue<byte[]>> mbox; + + private ClientSession () { + // only happens once + + hostname = ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.HOST_NAME); + portnumber = ConsoleLogPlugin.getDefault().getPluginPreferences().getInt(ConsoleLogPreferenceConstants.PORT_NUMBER); + mbox = new TreeMap<Integer, LinkedBlockingQueue<byte[]>> (); + connected = createConnection (); + scriptnumber = 15; + if (connected) this.start(); + } + + /** + * Send a request packet to the data manager. Synchronized, only + * one request can be sent at a time. + * + * @param req The filled in request packet to send over the socket. + * @return true if successfully sent, false otherwise. + */ + public synchronized boolean sendRequest (DMRequest req) { + + try { + // open perma-socket: + Socket tmp = new Socket(hostname, portnumber); + OutputStream out = tmp.getOutputStream(); + + out.write(req.getData()); + out.flush(); + out.flush(); + out.close(); + + return true; + + } catch (final UnknownHostException uhe) { + new ErrorMessage("Unknown host!", "Check if server is running").open(); + System.err.println("Unknown host: " + uhe.getMessage()); + connected = false; + return false; + } catch (final IOException ioe) { + new ErrorMessage("Unable to send request!", "Check if server is running").open(); + System.err.println("Req I/O error " + ioe.getMessage()); + connected = false; + return false; + } + } + + /** + * Read a response from the data manager and return the response packet. + * + * @return A response packet. Possibly invalid/incomplete. + */ + public DMResponse recvResponse (int scriptnum) { + + if (!mbox.containsKey(scriptnum)) { + return null; + } + try { + DMResponse dm = new DMResponse (mbox.get(scriptnum).take()); + + return dm; + } catch (InterruptedException ie) { + return null; + } + + } + + /** + * Read size bytes from the socket and return the result as a String. The + * size is most likely from DMResponse.packetsize . + * + * @param size The number of bytes to read from the open socket. + * @return A String of size characters long, or null if there was an error. + */ + public byte[] recvData (int scriptnum, int size) { + if (!mbox.containsKey(scriptnum)) { + + return null; + } + + try { + // maybe check that the sizes match? + return mbox.get(scriptnum).take(); + + } catch (InterruptedException ie) { +// subscription.interrupt() was probably called + System.err.println("Interruptedrecvdata"); + return null; + } + } + + public boolean addSubscription (int scriptnum) { + if (mbox.containsKey(scriptnum)) + { + return false; + } + mbox.put(scriptnum, new LinkedBlockingQueue<byte[]>()); + return true; + } + + public boolean delSubscription (int scriptnum) + { + if (!mbox.containsKey(scriptnum)) + return false; + + + mbox.get(scriptnum).clear(); + mbox.remove(scriptnum); + return true; + } + + public static synchronized ClientSession getInstance () { + // synchronized so everybody has the same session + if (instance == null) + instance = new ClientSession (); + else + { + if(!isConnected()) + { + connected=instance.createConnection(); + scriptnumber = 15; + if (connected) instance.start(); + } + } + return instance; + } + + public static int getNewScriptId() + { + return scriptnumber++; + } + + public static boolean isConnected () { + return connected; + } + + public int getcid () { + return clientID; + } + + public void run () { + + while (!Thread.interrupted()) { + + final byte[] headBuffer = new byte[DMResponse.packetsize]; + final byte[] bodyBuffer; + DMResponse header; + + try { + // Boolean first = new Boolean(true); + in.read(headBuffer, 0, headBuffer.length); + header = new DMResponse (headBuffer); + if(header.isValid()) + { + bodyBuffer = new byte[header.getsize()]; + in.read(bodyBuffer, 0, bodyBuffer.length); + if(header.getsource() == DMResponse.SUBSCRIPTION_MGR) + { + if(!mbox.containsKey(header.getscriptID())) + mbox.put(header.getscriptID (), new LinkedBlockingQueue<byte[]> ()); + mbox.get(header.getscriptID()).put(header.tobytes()); + mbox.get(header.getscriptID()).put(bodyBuffer); + + } + else + { + if(!mbox.containsKey(header.getscriptID())) + mbox.put(header.getscriptID (), new LinkedBlockingQueue<byte[]> ()); + mbox.get(header.getscriptID()).put(header.tobytes()); + mbox.get(header.getscriptID()).put(bodyBuffer); + + } + } + else { + // either the header was not valid, + // or the scriptid has not been seen before.. + + } + + } catch (InterruptedException ie) { + // probably shutting down + System.err.println ("Interrupted: " + ie.getMessage()); + break; + + } catch (IOException ioe) { + new ErrorMessage("I/O Error Check host!", "See stderr for more details").open(); + System.err.println ("i/o error: " + ioe.getMessage()); + return; + + } catch (Exception e) { + new ErrorMessage("Check if DMD is running", "See stderr for more details").open(); + System.err.println ("Server terminated unexpectedly?," + e.getMessage()); + return; + } + + + + } // while + this.destroyConnection(); + + } + + /** + * Grab hostname and port settings from the settings, attempt to open + * socket, and finally attempt to open a connection to the data manager + * and store a clientID. If anything fails the connection is left in an + * unknown state (see stderr). + * + * @return true if everything succeeded, false otherwise. + */ + public boolean createConnection () { + + final DMRequest ccpacket = new DMRequest (DMRequest.CREATE_CONN, 0, 0, 0); + final byte buffer[] = new byte[DMResponse.packetsize]; + final DMResponse respacket; + hostname = ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.HOST_NAME); + portnumber = ConsoleLogPlugin.getDefault().getPluginPreferences().getInt(ConsoleLogPreferenceConstants.PORT_NUMBER); + + OutputStream out = null; + try { + + Socket tmp = new Socket(hostname, portnumber); + out = tmp.getOutputStream(); + in = tmp.getInputStream(); + out.write(ccpacket.getData()); + out.flush(); + in.read(buffer, 0, buffer.length); + respacket = new DMResponse (buffer); + + } catch (final UnknownHostException uhe) { + new ErrorMessage("Unknown host!", "See stderr for more details").open(); + System.err.println("Unknown host: " + uhe.getMessage()); + return false; + } catch (final IOException ioe) { + new ErrorMessage("Connection I/O error!", "See stderr for more details").open(); + System.err.println("Con I/O error: " + ioe.getMessage()); + //ioe.printStackTrace(); + return false; + } + + if (!respacket.isValid()) + { + return false;} + + + clientID = respacket.getclientID(); + return true; + } + + /** + * Send a disconnection request to the data manager, and attempt to + * close the open socket to the data manager. If anything fails the + * connection is left in a unknown state (see stderr). + * + * @return true if successfully destroyed, false otherwise + */ + public boolean destroyConnection () { + + final DMRequest dcpacket = new DMRequest (DMRequest.DESTROY_CONN, 0, clientID, 0); + + try { + sendRequest (dcpacket); + in.close(); + connected = false; + return true; + } catch (final IOException e) { + new ErrorMessage("Connection close error!", "See stderr for more details").open(); + System.err.println("Close error: " + e.getMessage()); + return false; + } + +// Old code that actually checks the response and whatnot, +// removed because we can hang waiting for a response from +// (for example) a recently deceased Data Manager +// if (!sendRequest (dcpacket)) +// rc = false; +// +// final DMResponse respacket = recvResponse (); +// +// if (respacket.getreturnCode() != 0) +// rc = false; +// +// try { +// in.close(); +// } catch (final IOException e) { +// System.err.println("Close error: " + e.getMessage()); +// rc = false; +// } +// +// return rc; + } +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpClient.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpClient.java new file mode 100644 index 0000000000..757b719c5e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpClient.java @@ -0,0 +1,232 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog; + +import com.jcraft.jsch.*; +import java.awt.*; +import javax.swing.*; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs.ErrorMessage; +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; +import org.eclipse.linuxtools.systemtap.ui.consolelog.preferences.ConsoleLogPreferenceConstants; + + +import java.io.*; + +public class ScpClient{ + + private Session session; + + public ScpClient() { + //public static void main(String[] arg){ + + + String user=ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_USER); + String host=ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.HOST_NAME); + + + //System.out.println(lfile + " " + rfile); + + try{ + JSch jsch=new JSch(); + + session=jsch.getSession(user, host, 22); + + // username and password will be given via UserInfo interface. + //UserInfo ui=new MyUserInfo(); + //session.setUserInfo(ui); + session.setPassword(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_PASSWORD)); + java.util.Properties config = new java.util.Properties(); + config.put("StrictHostKeyChecking", "no"); + session.setConfig(config); + session.connect(); + }catch(Exception e) + { + e.printStackTrace(System.err); + new ErrorMessage("Error in connection", "File Transfer failed.\n See stderr for more details").open(); + } + } + + public void transfer(String fromFile, String toFile) { + // exec 'scp -t rfile' remotely + FileInputStream fis=null; + String rfile=toFile; + String lfile=fromFile; + String command="scp -t "+rfile; + try { + Channel channel=session.openChannel("exec"); + ((ChannelExec)channel).setCommand(command); + + // get I/O streams for remote scp + OutputStream out=channel.getOutputStream(); + InputStream in=channel.getInputStream(); + + channel.connect(); + + + if(checkAck(in)!=0){ + System.out.println("err"); + } + + // send "C0644 filesize filename", where filename should not include '/' + long filesize=(new File(lfile)).length(); + command="C0644 "+filesize+" "; + if(lfile.lastIndexOf('/')>0){ + command+=lfile.substring(lfile.lastIndexOf('/')+1); + } + else{ + command+=lfile; + } + command+="\n"; + + out.write(command.getBytes()); out.flush(); + if(checkAck(in)!=0){ + System.out.println("err"); + } + + + + // send a content of lfile + fis=new FileInputStream(lfile); + byte[] buf=new byte[1024]; + while(true){ + int len=fis.read(buf, 0, buf.length); + if(len<=0) break; + out.write(buf, 0, len); //out.flush(); + + } + fis.close(); + fis=null; + // send '\0' + buf[0]=0; out.write(buf, 0, 1); out.flush(); + if(checkAck(in)!=0){ + System.out.println("err"); + } + out.close(); + + channel.disconnect(); + session.disconnect(); + + } + catch(Exception e){ + try{if(fis!=null)fis.close();}catch(Exception ee){} + + } + } + + static int checkAck(InputStream in) throws IOException{ + int b=in.read(); + // b may be 0 for success, + // 1 for error, + // 2 for fatal error, + // -1 + if(b==0) return b; + if(b==-1) return b; + + if(b==1 || b==2){ + StringBuffer sb=new StringBuffer(); + int c; + do { + c=in.read(); + sb.append((char)c); + } + while(c!='\n'); + if(b==1){ // error + //System.out.print(sb.toString()); + } + if(b==2){ // fatal error + //System.out.print(sb.toString()); + } + } + return b; + } + + public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{ + public String getPassword(){ return passwd; } + public boolean promptYesNo(String str){ + Object[] options={ "yes", "no" }; + int foo=JOptionPane.showOptionDialog(null, + str, + "Warning", + JOptionPane.DEFAULT_OPTION, + JOptionPane.WARNING_MESSAGE, + null, options, options[0]); + return foo==0; + } + + String passwd; + JTextField passwordField=(JTextField)new JPasswordField(20); + + public String getPassphrase(){ return null; } + public boolean promptPassphrase(String message){ return true; } + public boolean promptPassword(String message){ + Object[] ob={passwordField}; + int result= + JOptionPane.showConfirmDialog(null, ob, message, + JOptionPane.OK_CANCEL_OPTION); + if(result==JOptionPane.OK_OPTION){ + passwd=passwordField.getText(); + return true; + } + else{ return false; } + } + public void showMessage(String message){ + JOptionPane.showMessageDialog(null, message); + } + final GridBagConstraints gbc = + new GridBagConstraints(0,0,1,1,1,1, + GridBagConstraints.NORTHWEST, + GridBagConstraints.NONE, + new Insets(0,0,0,0),0,0); + private Container panel; + public String[] promptKeyboardInteractive(String destination, + String name, + String instruction, + String[] prompt, + boolean[] echo){ + panel = new JPanel(); + panel.setLayout(new GridBagLayout()); + + gbc.weightx = 1.0; + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.gridx = 0; + panel.add(new JLabel(instruction), gbc); + gbc.gridy++; + + gbc.gridwidth = GridBagConstraints.RELATIVE; + + JTextField[] texts=new JTextField[prompt.length]; + for(int i=0; i<prompt.length; i++){ + gbc.fill = GridBagConstraints.NONE; + gbc.gridx = 0; + gbc.weightx = 1; + panel.add(new JLabel(prompt[i]),gbc); + + gbc.gridx = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.weighty = 1; + if(echo[i]){ + texts[i]=new JTextField(20); + } + else{ + texts[i]=new JPasswordField(20); + } + panel.add(texts[i], gbc); + gbc.gridy++; + } + + if(JOptionPane.showConfirmDialog(null, panel, + destination+": "+name, + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE) + ==JOptionPane.OK_OPTION){ + String[] response=new String[prompt.length]; + for(int i=0; i<prompt.length; i++){ + response[i]=texts[i].getText(); + } + return response; + } + else{ + return null; // cancel + } + } + } +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/Subscription.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/Subscription.java new file mode 100644 index 0000000000..aabb2ac17b --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/Subscription.java @@ -0,0 +1,420 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog; + + +//import com.trilead.ssh2.SCPClient; +//import com.trilead.ssh2.Connection; +//import com.jcraft.jsch.*; + + +import java.io.File; +import java.io.PipedOutputStream; +import java.io.PipedInputStream; +import java.util.ArrayList; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs.ErrorMessage; +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.DMRequest; +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.DMResponse; +import org.eclipse.linuxtools.systemtap.ui.structures.LoggingStreamDaemon; +import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IGobblerListener; +import org.eclipse.linuxtools.systemtap.ui.structures.runnable.StreamGobbler; + + + +public class Subscription extends Thread { + private int scriptid; + private boolean running; + private final ClientSession session; + private final String filename; + private final boolean isGuru; + private boolean disposed = false; + private PipedOutputStream pos = null; + private PipedInputStream pis = null; + private StreamGobbler inputGobbler = null; + private StreamGobbler errorGobbler = null; + private ArrayList<IGobblerListener> inputListeners = new ArrayList<IGobblerListener>(); //Only used to allow adding listeners before creating the StreamGobbler + private ArrayList<IGobblerListener> errorListeners = new ArrayList<IGobblerListener>(); //Only used to allow adding listeners before creating the StreamGobbler + private LoggingStreamDaemon logger; + + public Subscription(final int scriptid) { + this.scriptid = scriptid; + this.filename = null; + this.running = false; + this.session = ClientSession.getInstance(); + this.isGuru = false; + + } + + public Subscription(final String filename,boolean isGuru) { + this.filename = filename; + this.scriptid = -1; + this.running = false; + this.session = ClientSession.getInstance(); + this.isGuru = isGuru; + } + + public boolean init() { + // send subscription request packet + // check if response is OK + + if (!ClientSession.isConnected()) { + return false; + } + + + // BusyIndicator.showWhile(null, new Runnable() { + // public void run() { + try{ + ScpClient scpclient = new ScpClient(); + scpclient.transfer(filename,"/tmp/"+ filename.substring(filename.lastIndexOf('/')+1)); + }catch(Exception e){e.printStackTrace();} + scriptid = ClientSession.getNewScriptId(); + final DMRequest subreq = new DMRequest(DMRequest.SUBSCRIBE,scriptid, filename,session.getcid(), 0, isGuru); + if (!session.sendRequest(subreq)) { + //System.out.println("sent subscription"); + // return false; + } + + + session.addSubscription(scriptid); + // FIXME: horrible hack. I think there is some sort of deadlock issue + // when starting up, either way this fixes it. + try { Thread.sleep(500); } + catch (InterruptedException ie) {} + + final DMResponse subrep = session.recvResponse(scriptid); + if (subrep.isValid()) { + scriptid = subrep.getscriptID(); + + + logger = new LoggingStreamDaemon(); + inputListeners.add(logger); + + try{ + pos = new PipedOutputStream(); + pis = new PipedInputStream(pos); + pos.flush(); + }catch(Exception e) + { + new ErrorMessage("Could not subscribe!", "See stderr for more details").open(); + } + + inputGobbler = new StreamGobbler(pis); + addInputStreamListener(logger); + + return true; + } + else { + session.delSubscription(scriptid); + new ErrorMessage("Could not subscribe!", "Response from Server not valid \n See stderr for more details").open(); + return false; + } + } + + /** + * Gather data from a previously started script and do stuff with it. + * Contains blocking reads. + * + */ + public void run () { + running = true; + DMResponse subrep = null; + //long timeToRemove = 0; + inputGobbler.start(); + while (!Thread.interrupted() && ClientSession.isConnected()) { + subrep = session.recvResponse(scriptid); + //timeToRemove = System.currentTimeMillis() - (1000 * ConsoleLogPlugin.getDefault().getPluginPreferences().getInt(ConsoleLogPreferenceConstants.SAVE_LENGTH)); + if (subrep == null) { + // Interrupting this thread cause recvResponse to return + // from its blocking read, leaving subrep null + break; + } + + if (subrep.isValid() && (subrep.getsource() == DMResponse.STDERR)) { + // log the err output?, maybe pop up a dialog? ignore for now.. + final String outp = new String (session.recvData(scriptid, subrep.getsize())); + final String[] lines = outp.trim().split("\n"); + for (final String str : lines) { + try{ + inputGobbler.fireNewDataEvent(str + "\n"); + }catch(Exception e) + { + System.err.println(e.toString()); + } + + } + return; + } + else if (subrep.isValid()) { + + final String outp = new String (session.recvData(scriptid, subrep.getsize())); + + final String[] lines = outp.trim().split("\n"); + for (final String str : lines) { + try{ + inputGobbler.fireNewDataEvent(str + "\n"); + }catch(Exception e) + { + System.err.println(e.toString()); + } + + } + + } + } + + final DMRequest unsub = new DMRequest (DMRequest.UNSUBSCRIBE, scriptid, session.getcid(), 0); + if (!session.sendRequest (unsub)) + System.err.println ("Failed Unsubscribing: " + session.getcid()); + + subrep = session.recvResponse(scriptid); + delSubscription(); + + running = false; + } + + public boolean isRunning() { + return running; + } + + public String getScriptName(final int script) { + return "table" + script; + } + + public String getOutput() + { + return logger.getOutput(); + } + + public boolean saveLog(File file) { + return logger.saveLog(file); + } + + + + public void dispose() { + if(!disposed) { + disposed = true; + inputListeners = null; + errorListeners = null; + + if(null != inputGobbler){ + inputGobbler.dispose(); + inputGobbler.stop(); + } + inputGobbler = null; + + if(null != errorGobbler){ + errorGobbler.dispose(); + errorGobbler.stop(); + } + errorGobbler = null; + } + } + + /** + * Registers the provided <code>IGobblerListener</code> with the InputStream + * @param listener A listener to monitor the InputStream from the Process + */ + public void addInputStreamListener(IGobblerListener listener) { + if(null != inputGobbler) + { + inputGobbler.addDataListener(listener); + } + else + inputListeners.add(listener); + } + + /** + * Registers the provided <code>IGobblerListener</code> with the ErrorStream + * @param listener A listener to monitor the ErrorStream from the Process + */ + public void addErrorStreamListener(IGobblerListener listener) { + if(null != errorGobbler) + errorGobbler.addDataListener(listener); + else + errorListeners.add(listener); + } + + /** + * Returns the list of everything that is listening the the InputStream + * @return List of all <code>IGobblerListeners</code> that are monitoring the stream. + */ + public ArrayList<IGobblerListener> getInputStreamListeners() { + if(null != inputGobbler) + return inputListeners; + else + return inputGobbler.getDataListeners(); + } + + /** + * Returns the list of everything that is listening the the ErrorStream + * @return List of all <code>IGobblerListeners</code> that are monitoring the stream. + */ + public ArrayList<IGobblerListener> getErrorStreamListeners() { + if(null != errorGobbler) + return errorListeners; + else + return errorGobbler.getDataListeners(); + } + + /** + * Removes the provided listener from those monitoring the InputStream. + * @param listener An </code>IGobblerListener</code> that is monitoring the stream. + */ + public void removeInputStreamListener(IGobblerListener listener) { + if(null != inputGobbler) + inputGobbler.removeDataListener(listener); + else + inputListeners.remove(listener); + } + + /** + * Removes the provided listener from those monitoring the ErrorStream. + * @param listener An </code>IGobblerListener</code> that is monitoring the stream. + */ + public void removeErrorStreamListener(IGobblerListener listener) { + if(null != errorGobbler) + errorGobbler.removeDataListener(listener); + else + errorListeners.remove(listener); + } + + public void delSubscription() + { + session.delSubscription(scriptid); + } + + /*private boolean sendFile() + { + /*try + { + Connection conn = new Connection(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.HOST_NAME)); + conn.connect(); + boolean isAuthenticated = conn.authenticateWithPassword(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_USER),ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_PASSWORD)); + if (isAuthenticated == false) + { + new ErrorMessage("Could not send script!", "Authentication failure").open(); + return false; + } + SCPClient scpclient = conn.createSCPClient(); + scpclient.put(filename, "/tmp"); + // return true; + }catch(Exception Ex) + { + new ErrorMessage("Could not send script!", "Check if scp is enabled on server").open(); + return false; + } + FileInputStream fis=null; + try{ + String osname=(String)(System.getProperties().get("os.name")); + System.out.println(osname); + JSch jsch = new JSch(); + System.out.println("1"); + Session session = jsch.getSession(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_USER), ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.HOST_NAME), 22); + System.out.println("1"); + session.setPassword(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_PASSWORD)); + System.out.println("1"); + session.connect(); + System.out.println("1"); + String command="scp -p -t /tmp/"+ filename; + Channel channel=session.openChannel("exec"); + ((ChannelExec)channel).setCommand(command); + OutputStream out=channel.getOutputStream(); + InputStream in=channel.getInputStream(); + System.out.println("2"); + channel.connect(); + System.out.println("3"); + if(checkAck(in)!=0){ + //System.exit(0); + } + System.out.println("4"); + // send "C0644 filesize filename", where filename should not include '/' + long filesize=(new File(filename)).length(); + command="C0644 "+filesize+" "; + if(filename.lastIndexOf('/')>0){ + command+=filename.substring(filename.lastIndexOf('/')+1); + } + else{ + command+=filename; + } + command+="\n"; + System.out.println("5"); + out.write(command.getBytes()); out.flush(); + System.out.println("6"); + if(checkAck(in)!=0){ + //System.exit(0); + } + System.out.println("7"); + // send a content of lfile + fis=new FileInputStream(filename); + byte[] buf=new byte[1024]; + while(true){ + int len=fis.read(buf, 0, buf.length); + if(len<=0) break; + out.write(buf, 0, len); //out.flush(); + } + fis.close(); + fis=null; + // send '\0' + System.out.println("8"); + buf[0]=0; out.write(buf, 0, 1); out.flush(); + System.out.println("9"); + if(checkAck(in)!=0){ + //System.exit(0); + } + System.out.println("10"); + out.close(); + + channel.disconnect(); + session.disconnect(); + + return true; + } + catch(Exception e){ + System.out.println(e); + try{if(fis!=null)fis.close();}catch(Exception ee){} + } + return true; + } + + + static int checkAck(InputStream in) throws IOException{ + int b=in.read(); + // b may be 0 for success, + // 1 for error, + // 2 for fatal error, + // -1 + if(b==0) return b; + if(b==-1) return b; + + if(b==1 || b==2){ + StringBuffer sb=new StringBuffer(); + int c; + do { + c=in.read(); + sb.append((char)c); + } + while(c!='\n'); + if(b==1){ // error + System.out.print(sb.toString()); + } + if(b==2){ // fatal error + System.out.print(sb.toString()); + } + } + return b; + } + */ + /** + * Removes the provided listener from those monitoring the ErrorStream. + * @param listener An </code>IGobblerListener</code> that is monitoring the stream. + *//* + public void removeInputStreamListeners() { + if(null != inputGobbler) + inputGobbler.r removeDataListener(listener); + else + inputListeners.remove + } + */ + +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/ConsoleAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/ConsoleAction.java new file mode 100644 index 0000000000..0cbeb7d137 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/ConsoleAction.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.ScriptConsole; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleView; + + + + +/** + * A basic core class that provides common methods that are needed by any + * action that makes use of the Console. + * @author Ryan Morse + */ +public abstract class ConsoleAction extends Action implements IWorkbenchWindowActionDelegate, IViewActionDelegate { + public void init(IWorkbenchWindow window) {} + + public void init(IViewPart part) {} + + public void run(IAction action) { + run(); + } + + public abstract void run(); + + + /** + * Finds and returns the active console. + * @return The active <code>ScriptConsole<code> in the ConsoleView + */ + protected ScriptConsole getActive() { + IConsoleView ivp = (IConsoleView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(IConsoleConstants.ID_CONSOLE_VIEW); + return (ScriptConsole)ivp.getConsole(); + } + + /** + * Updates whether the action should be enabled when the user changes their ViewPart selection + */ + public void selectionChanged(IAction act, ISelection select) { + this.setAct(act); + buildEnablementChecks(); + } + + /** + * Builds the checks to see if the action should be enabled or not + */ + private void buildEnablementChecks() { + IViewPart ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(IConsoleConstants.ID_CONSOLE_VIEW); + if(null != ivp) { + setEnablement(isRunning((IConsoleView)ivp)); + ivp.addPropertyListener(listener); + } + } + + /** + * Checks to see if the active console is still running + */ + private boolean isRunning(IConsoleView cv) { + ScriptConsole console = (ScriptConsole)cv.getConsole(); + return (console != null && console.isRunning()); + } + + /** + * Changes whether or not this action is enabled + */ + private void setEnablement(boolean enabled) { + //act.setEnabled(enabled); //TODO: This is disabled until we figure out how to get it to realize script is running. + } + + /** + * Disposes of all internal references held by this class. No method should be called after + * calling this. + */ + public void dispose() { + setAct(null); + //Unable to findView when disposed is called, as a result null pointer exception is thrown + //PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(IConsoleConstants.ID_CONSOLE_VIEW).removePropertyListener(listener); + listener = null; + } + + public void setAct(IAction act) { + this.act = act; + } + + public IAction getAct() { + return act; + } + + private IAction act; + private IPropertyListener listener = new IPropertyListener() { + public void propertyChanged(Object o, int i) { + if(o instanceof IConsoleView) + setEnablement(isRunning((IConsoleView)o)); + } + }; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/SaveLogAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/SaveLogAction.java new file mode 100644 index 0000000000..e2b1b30774 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/SaveLogAction.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.actions; + +import java.io.File; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.ScriptConsole; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.ui.PlatformUI; + + + +/** + * This class is used to allow the user to save the log generated from an active console + * @author Ryan Morse + */ +public class SaveLogAction extends ConsoleAction { + /** + * The main method of this class. Handles getting the currnet <code>ScriptConsole</code> + * and telling it to save the output to the selected file. + */ + public void run() { + ScriptConsole console = getActive(); + if(null != console && console.isRunning()) { + File file = getFile(); + + if(null != file) + console.saveStream(file); + } + } + + /** + * Brings up a dialog box for the user to select a place to save the log output. + * @return File representing the desired destination for the log. + */ + private File getFile() { + String path = null; + FileDialog dialog= new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE); + dialog.setText(Localization.getString("SaveLogAction.OutputFile")); + + path = dialog.open(); + + if(null == path) + return null; + + return new File(path); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/StopScriptAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/StopScriptAction.java new file mode 100644 index 0000000000..ed7ed07c1a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/actions/StopScriptAction.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.actions; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.ScriptConsole; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; + + + +/** + * A class that handles stopping the <code>ScriptConsole</code>. + * @author Ryan Morse + */ +public class StopScriptAction extends ConsoleAction { + /** + * This is the main method of the class. It handles stopping the + * currently active <code>ScriptConsole</code>. + */ + public void run() { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + boolean stop = false; + public void run() { + if(stop) return; + try { + ScriptConsole console = getActive(); + if(null != console && console.isRunning()) + console.stop(); + } catch (Exception e) { + stop = true; + } + } + }); + } + + /** + * This method will stop the i'th <code>ScriptConsole</code> if it is running. + * @param i The index value of the console that will be stopped. + */ + public void run(int i) { + IConsole ic[] = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + ScriptConsole console = (ScriptConsole)ic[i]; + + if(console.isRunning()) + console.stop(); + + } + + /** + * This method will stop all consoles that are running. + */ + public void stopAll() { + IConsole ic[] = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + ScriptConsole console; + + for(int i=0; i<ic.length; i++) { + console = (ScriptConsole)ic[i]; + if(console.isRunning()) + console.stop(); + } + } + + /** + * This method will check to see if any scripts are currently running. + * @return - boolean indicating whether any scripts are running + */ + public boolean anyRunning() { + IConsole ic[] = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + ScriptConsole console; + + for(int i=0; i<ic.length; i++) { + console = (ScriptConsole)ic[i]; + if(console.isRunning()) + return true; + } + return false; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/ErrorMessage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/ErrorMessage.java new file mode 100644 index 0000000000..40de170e1c --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/ErrorMessage.java @@ -0,0 +1,31 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.ui.PlatformUI; + +/** + * Creates and displays an error message box that runs in the UI thread. + * + */ +public class ErrorMessage { + private String title; + private String error; + + public ErrorMessage(String title, String error) { + this.title = title; + this.error = error; + } + + public void open() { + Display.getDefault().syncExec(new Runnable() { + public void run() { + MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_ERROR | SWT.OK); + messageBox.setMessage(error); + messageBox.setText(title); + messageBox.open(); + } // end run + }); // end new Runnable + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/SCPDetails.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/SCPDetails.java new file mode 100644 index 0000000000..7800389b77 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/SCPDetails.java @@ -0,0 +1,110 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; +import org.eclipse.linuxtools.systemtap.ui.consolelog.preferences.ConsoleLogPreferenceConstants; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.SelectionEvent; + + + +public class SCPDetails extends Dialog { + private Text userText; + private Text passwordText; +// private Button rememberButton; + private Button sendButton; + private Button cancelButton; + + public SCPDetails(Shell parent) { + super(parent); + } + + public void open() { + + Shell parent = getParent(); + final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); + shell.setText("Enter SCP details"); + shell.setSize(350, 160); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + shell.setLayout(layout); + + GridData data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label userLabel = new Label(shell, SWT.NONE); + userLabel.setText("User: "); + userLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + userText = new Text(shell, SWT.SINGLE | SWT.BORDER); + userText.setLayoutData(data); + userText.setText(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_USER)); + + data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label passwordLabel = new Label(shell, SWT.NONE); + passwordLabel.setText("Password: "); + passwordLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + passwordText = new Text(shell, SWT.SINGLE | SWT.BORDER); + passwordText.setEchoChar('*'); + passwordText.setLayoutData(data); + passwordText.setText(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_PASSWORD)); + + + data = new GridData(); + data.horizontalAlignment = SWT.RIGHT; + cancelButton = new Button(shell, SWT.PUSH); + cancelButton.setLayoutData(data); + cancelButton.setSize(50, 100); + cancelButton.setText("Cancel"); + cancelButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + shell.dispose(); + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + data = new GridData(); + data.horizontalAlignment = SWT.RIGHT; + sendButton = new Button(shell, SWT.PUSH); + sendButton.setLayoutData(data); + sendButton.setSize(50, 100); + sendButton.setText("Send"); + sendButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + // FIXME: no error handling is done, should probably be + // pushed down to the connection level + // Set the preferences to this new info. + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.SCP_PASSWORD, passwordText.getText()); + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.SCP_USER, userText.getText()); + + shell.close(); + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + shell.open(); + Display display = parent.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/SelectServerDialog.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/SelectServerDialog.java new file mode 100644 index 0000000000..2cfbbebe93 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/dialogs/SelectServerDialog.java @@ -0,0 +1,165 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; +import org.eclipse.linuxtools.systemtap.ui.consolelog.preferences.ConsoleLogPreferenceConstants; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.SelectionEvent; + + + +public class SelectServerDialog extends Dialog { + private Text hostText; + private Text portText; + private Text userText; + private Text passwordText; + private Button rememberButton; + private Button connectButton; + private Button cancelButton; + + public SelectServerDialog(Shell parent) { + super(parent); + } + + public void open() { + if (ConsoleLogPlugin.getDefault().getPluginPreferences().getBoolean(ConsoleLogPreferenceConstants.REMEMBER_SERVER)) { + return; + } + + Shell parent = getParent(); + final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); + shell.setText("Remote Server Details"); + shell.pack(); + //shell.setSize(350, 220); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + shell.setLayout(layout); + + GridData data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label hostLabel = new Label(shell, SWT.NONE); + hostLabel.setText("Host: "); + hostLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + hostText = new Text(shell, SWT.SINGLE | SWT.BORDER); + hostText.setLayoutData(data); + hostText.setText(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.HOST_NAME)); + + data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label portLabel = new Label(shell, SWT.NONE); + portLabel.setText("Port: "); + portLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + portText = new Text(shell, SWT.SINGLE | SWT.BORDER); + portText.setLayoutData(data); + portText.setText(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.PORT_NUMBER)); + + data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label userLabel = new Label(shell, SWT.NONE); + userLabel.setText("User: "); + userLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + userText = new Text(shell, SWT.SINGLE | SWT.BORDER); + userText.setLayoutData(data); + userText.setText(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_USER)); + + data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.horizontalAlignment = SWT.LEFT; + Label passwordLabel = new Label(shell, SWT.NONE); + passwordLabel.setText("Password: "); + passwordLabel.setLayoutData(data); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + passwordText = new Text(shell, SWT.SINGLE | SWT.BORDER); + passwordText.setEchoChar('*'); + passwordText.setLayoutData(data); + passwordText.setText(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_PASSWORD)); + + + data = new GridData(); + data.horizontalAlignment = SWT.LEFT; + data.horizontalSpan = 2; + rememberButton = new Button(shell, SWT.CHECK); + rememberButton.setLayoutData(data); + rememberButton.setText("Always connect to this host."); + rememberButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + data = new GridData(); + data.horizontalAlignment = SWT.RIGHT; + cancelButton = new Button(shell, SWT.PUSH); + cancelButton.setLayoutData(data); + cancelButton.setSize(50, 100); + cancelButton.setText("Cancel"); + cancelButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.CANCELLED, true); + shell.dispose(); + + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + data = new GridData(); + data.horizontalAlignment = SWT.RIGHT; + connectButton = new Button(shell, SWT.PUSH); + connectButton.setLayoutData(data); + connectButton.setSize(50, 100); + connectButton.setText("Connect"); + connectButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + // FIXME: no error handling is done, should probably be + // pushed down to the connection level + // Set the preferences to this new info. + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.PORT_NUMBER, portText.getText()); + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.HOST_NAME, hostText.getText()); + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.REMEMBER_SERVER, rememberButton.getSelection()); + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.SCP_PASSWORD, passwordText.getText()); + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.SCP_USER, userText.getText()); + ConsoleLogPlugin.getDefault().getPreferenceStore().setValue(ConsoleLogPreferenceConstants.CANCELLED, false); + + shell.close(); + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + shell.pack(); + shell.open(); + Display display = parent.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/ConsoleLogPlugin.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/ConsoleLogPlugin.java new file mode 100644 index 0000000000..9e7e40f2af --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/ConsoleLogPlugin.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.internal; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class ConsoleLogPlugin extends AbstractUIPlugin { + + //The shared instance. + private static ConsoleLogPlugin plugin; + + /** + * The constructor. + */ + public ConsoleLogPlugin() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + this.internalInitializeDefaultPluginPreferences(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static ConsoleLogPlugin getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path. + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.linuxtools.systemtap.ui.consolelog", path); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/Localization.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/Localization.java new file mode 100644 index 0000000000..24f6d52101 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/Localization.java @@ -0,0 +1,22 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.internal; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Localization { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.systemtap.ui.consolelog.internal.localization"; + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle(BUNDLE_NAME); + + private Localization() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/localization.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/localization.properties new file mode 100644 index 0000000000..7d933a4fd0 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/internal/localization.properties @@ -0,0 +1,13 @@ +SaveLogAction.OutputFile=Output File + +ErrorStreamDaemon.Password=Password: + +ErrorView.Description=Description + +ScriptConsole.Problem=Problem +ScriptConsole.ErrorSavingLog=Error saving the log file. +ScriptConsole.Terminated=<terminated> + +ErrorView.Type=Type +ErrorView.Saw=Saw +ErrorView.Line=Line diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/ConsoleLogPreferenceConstants.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/ConsoleLogPreferenceConstants.java new file mode 100644 index 0000000000..65d5bf547c --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/ConsoleLogPreferenceConstants.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.preferences; + +public class ConsoleLogPreferenceConstants { + //ide + public static final String HOST_NAME = "host"; + public static final String PORT_NUMBER = "port"; + public static final String DB_COMMIT = "commit"; + public static final String SAVE_LENGTH = "saveLength"; + public static final String REMEMBER_SERVER = "rememberServer"; + public static final String SCP_USER = "scpuser"; + public static final String SCP_PASSWORD = "scppassword"; + public static final String REMEMBER_SCPUSER = "rememberscpuser"; + public static final String CANCELLED = "cancel"; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/ConsoleLogPreferencePage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/ConsoleLogPreferencePage.java new file mode 100644 index 0000000000..8cc1e47b32 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/ConsoleLogPreferencePage.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.preferences; + +import org.eclipse.jface.preference.*; +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.IWorkbench; + + + + + +public class ConsoleLogPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + public ConsoleLogPreferencePage() { + super(GRID); + // LogManager.logDebug("Start ConsoleLogPreferencePage:", this); + setPreferenceStore(ConsoleLogPlugin.getDefault().getPreferenceStore()); + setDescription("Preferences when accessing a remote server"); + //LogManager.logDebug("End ConsoleLogPreferencePage:", this); + } + + public void createFieldEditors() { + + addField(new StringFieldEditor(ConsoleLogPreferenceConstants.HOST_NAME, + "Host Name: ", getFieldEditorParent())); + + addField(new IntegerFieldEditor(ConsoleLogPreferenceConstants.PORT_NUMBER, + "Port: ", getFieldEditorParent())); + + addField(new StringFieldEditor(ConsoleLogPreferenceConstants.SCP_USER, + "User Name: ", getFieldEditorParent())); + + StringFieldEditor passwordField = new StringFieldEditor( + ConsoleLogPreferenceConstants.SCP_PASSWORD, "Password: ", + getFieldEditorParent()); + passwordField.getTextControl(getFieldEditorParent()).setEchoChar('*'); + addField(passwordField); + + // addField(new StringFieldEditor(ConsoleLogPreferenceConstants.SCP_PASSWORD, + // "Password: ", getFieldEditorParent())); + + addField(new BooleanFieldEditor(ConsoleLogPreferenceConstants.REMEMBER_SERVER, + "Always connect to this host.", getFieldEditorParent())); + + addField(new IntegerFieldEditor(ConsoleLogPreferenceConstants.SAVE_LENGTH, + "Seconds to Save Data: ", getFieldEditorParent())); + + } + + public void init(IWorkbench workbench) { + + } + + public void dispose() { + + super.dispose(); + } +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/PreferenceInitializer.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/PreferenceInitializer.java new file mode 100644 index 0000000000..5d2b1b775f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/preferences/PreferenceInitializer.java @@ -0,0 +1,38 @@ + /* Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.preferences; + + + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; + + + +public class PreferenceInitializer extends AbstractPreferenceInitializer { + public void initializeDefaultPreferences() { + IPreferenceStore store = ConsoleLogPlugin.getDefault().getPreferenceStore(); + + //ide + store.setDefault(ConsoleLogPreferenceConstants.HOST_NAME, "localhost"); + store.setDefault(ConsoleLogPreferenceConstants.PORT_NUMBER, 22462); + store.setDefault(ConsoleLogPreferenceConstants.DB_COMMIT, false); + store.setDefault(ConsoleLogPreferenceConstants.SAVE_LENGTH, 5); + store.setDefault(ConsoleLogPreferenceConstants.REMEMBER_SERVER, false); + store.setDefault(ConsoleLogPreferenceConstants.SCP_USER, "guest"); + store.setDefault(ConsoleLogPreferenceConstants.SCP_PASSWORD, "welcome"); + store.setDefault(ConsoleLogPreferenceConstants.REMEMBER_SCPUSER, false); + store.setDefault(ConsoleLogPreferenceConstants.CANCELLED, false); + + + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ConsoleStreamDaemon.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ConsoleStreamDaemon.java new file mode 100644 index 0000000000..18432e74ce --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ConsoleStreamDaemon.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IGobblerListener; +import org.eclipse.ui.console.MessageConsoleStream; + + + +/** + * A class push data to a ScriptConsole. + * @author Ryan Morse + */ +public class ConsoleStreamDaemon implements IGobblerListener { + public ConsoleStreamDaemon(ScriptConsole console) { + this.console = console; + if(null != console) + msgConsole = console.newMessageStream(); + disposed = false; + } + + /** + * Prints out the new output data to the console + */ + protected void pushData() { + if(null != msgConsole) + msgConsole.print(output); + } + + /** + * Captures data events and pushes the data to the console + */ + public void handleDataEvent(String line) { + output = line; + this.pushData(); + } + + /** + * Checks to see if the class has been disposed already + * @return boolean representing whether or not the class has been disposed + */ + public boolean isDisposed() { + return disposed; + } + + /** + * Disposes of all internal references in the class. No method should be called after this. + */ + public void dispose() { + if(!disposed) { + disposed = true; + output = null; + console = null; + msgConsole = null; + } + } + + protected String output; + protected ScriptConsole console; + protected MessageConsoleStream msgConsole; + private boolean disposed; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMError.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMError.java new file mode 100644 index 0000000000..504aa75498 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMError.java @@ -0,0 +1,62 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +/** + * Turn error codes into text. Taken from include/staperror.hpp + * from the data manager's source. + * + * @author patrickm + * + */ +public final class DMError { + + private static String errtext; + + public DMError (int errcode) { + + if (errcode >= 0) { + errtext = "Success"; + return; + } + + switch (errcode) { + case 0x82100001: + errtext = "Invalid/Unknown request type"; + break; + case 0x81100002: + errtext = "Error running script, or script unexpectedly died"; + break; + case 0x82100003: + errtext = "Unknown / unused !?"; + break; + case 0x81100004: + errtext = "Unused?"; + break; + case 0x81200005: + errtext = "Invalid mailbox number requested"; + break; + case 0x82200006: + errtext = "Duplicate/invalid un- or subscription request"; + break; + case 0x82200007: + errtext = "Failed to release or aquire a mutex lock"; + break; + case 0x82200009: + errtext = "Malformed or unrecognizable packet"; + break; + case 0x8220000A: + errtext = "Invalid client ID"; + break; + case 0x8220000B: + errtext = "Attemting to use unopen or bad channel"; + break; + default: + errtext = "Unknown Error: " + errcode; + } + return; + } + + public String toString() { + return new String(errtext); + } + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMPacket.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMPacket.java new file mode 100644 index 0000000000..9eeeca569b --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMPacket.java @@ -0,0 +1,65 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +/** + * A class to represent a data packet. This abstract class just has all of the + * common fields and associated get-methods. + * + * @author patrickm + * + */ +public abstract class DMPacket { + + // TODO?: replace with java enums + + // header ID + protected final int BEGINSTR = 0xa1b2c3d4; + public int packetsize; + + // common packet fields + protected int clientID; + protected int size; + protected int scriptID; + protected String filename; + + /** + * Return the client ID number from this packet. This needs to be included + * in all outgoing packets (so the DM can tell who is sending what). + * + * @return The clientID of this packet. + */ + public int getclientID() { + return clientID; + } + /** + * Return the filename from this packet. This needs to be included + * in all outgoing packets (so the DM can tell who is sending what). + * + * @return The filename. + */ + + public String getfilename() { + return filename; + } + + /** + * Return the script number of this packet. Consult the data manager package + * for what these map to. + * + * @return The script number of this packet. + */ + public int getscriptID() { + return scriptID; + } + + /** + * Return the size field of this packet. This is not the size of the packet + * but the size of the following stream. All request packets this will be + * zero, most response packets will be non negative. + * + * @return The size in bytes of this packets "size" field + */ + public int getsize() { + return size; + } + +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMRequest.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMRequest.java new file mode 100644 index 0000000000..44abd3bfb2 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMRequest.java @@ -0,0 +1,197 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs.ErrorMessage; +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; +import org.eclipse.linuxtools.systemtap.ui.consolelog.preferences.ConsoleLogPreferenceConstants; + + + + + +/** + * The request packet class. This class is used to construct a "packet", which + * is just a stream of bytes with specific properties. Normally a DMRequest + * object is constructed, and then its byte-stream is sent over a socket to the + * data manager. + * + * @author patrickm + * + */ +public class DMRequest extends DMPacket { + + // packet size + public static final int packetsize = 28; // bytes + + // request types + public static final int CREATE_CONN = 1; + public static final int SUBSCRIBE = 2; + public static final int UNSUBSCRIBE = 3; + public static final int GET_STATUS = 4; + public static final int SUBSCRIPTION_MODIFY = 5; + public static final int DESTROY_CONN = 6; + public static final int FILE = 7; + + // request specific + private final int reqType; + private final boolean isGuru; + + /** + * Construct a request packet. There is no error checking, if you construct + * a bad packet then send it to the data manager to see what is wrong with + * it. + * + * @param reqType + * One of the public REQ_* fields of this packet, the "request" / + * command of this packet. + * @param scriptID + * The script ID associated with this packet, right now only + * valid for un/subscribe. + * @param clientID + * The client ID of this packet. Every packet must have the + * correct client ID, or 0 if they are requesting one. + * @param size + * The size of the succeeding body. Always 0 for now, may change + * in the future. + */ + public DMRequest(final int reqType, final int scriptID, final int clientID, + final int size) { + this.reqType = reqType; + this.scriptID = scriptID; + this.filename = ""; + this.clientID = clientID; + this.size = size; + this.isGuru = false; + } + + public DMRequest(final int reqType, final int scriptnum,final String filename, final int clientID, + final int size, final boolean isGuru) { + this.reqType = reqType; + this.filename = filename; + this.scriptID = scriptnum; + this.clientID = clientID; + this.size = size; + this.isGuru = isGuru; + + } + + + /** + * Convert all of this packet's fields into a stream of bytes of length + * packetsize. Any errors would leave the packet in an unknown state, so + * null is returned. + * + * @return A stream of bytes representing the packet or null. + */ + public byte[] getData() { + // TODO: close these open streams, if needed + if (reqType == SUBSCRIBE) + return getFile(); + else + return getMessage(); + } + + public int getReqtype() + { + return reqType; + } + + private byte[] getMessage() + { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final DataOutputStream dos = new DataOutputStream(baos); + char a[] = new char[20]; + for (int i = 0; i < 20 ; i++) + a[i] = ' '; + String b= ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_USER); + b.getChars(0, b.length(), a, 0); + + b = null; + b = String.copyValueOf(a); + + //String b = String.copyValueOf(a, 0, 20); + //System.out.println(a.toString() + " " + b + " " + b.length()); + try { + dos.writeInt(BEGINSTR); + dos.writeInt(reqType); + dos.writeInt(scriptID); + dos.writeInt(clientID); + dos.writeInt(0); + dos.writeInt(ConsoleLogPlugin.getDefault().getPluginPreferences().getString(ConsoleLogPreferenceConstants.SCP_USER).length()); + dos.writeBytes(b); + // System.out.println(a.length + " " + a.toString().length() + " " + filename.substring(filename.lastIndexOf('/')).length()); + dos.flush(); + } catch (final IOException ioe) { + new ErrorMessage("Request packet error!", "See stderr for more details").open(); + System.err.println("Packet Error: " + ioe.getMessage()); + // baos.close(); + // dos.close(); + return null; + } + return baos.toByteArray(); + } + + + private byte[] getFile() + { + + try { + /* int len = 0; + File f = new File(filename); + FileReader fr = new FileReader(f); + + BufferedReader br = new BufferedReader(fr); + StringBuilder sb = new StringBuilder(); + String line; + while(null != (line=br.readLine())) { + sb.append(line + "\n"); + } + File tmpfile = new File("/home/anithra/eclipse/tmp.stp"); + tmpfile.createNewFile(); + FileWriter tmpfilewriter = new FileWriter(tmpfile); + tmpfilewriter.write(sb.toString()); + tmpfilewriter.flush(); + tmpfilewriter.close(); + + // System.out.println("file:" + sb.toString()); + // BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename)); + // byte[] buffer = new byte[in.available()];*/ + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + final DataOutputStream dos = new DataOutputStream(baos); + // System.out.println("file:" + sb.length()); + dos.writeInt(BEGINSTR); + dos.writeInt(reqType); + dos.writeInt(scriptID); + dos.writeInt(clientID); + if(isGuru) + dos.writeInt(1); + else + dos.writeInt(0); + dos.writeInt(filename.length()); + dos.writeBytes(filename.substring(filename.lastIndexOf('/'))); + dos.flush(); + return baos.toByteArray(); + + } catch (final Exception ioe) { + new ErrorMessage("Request packet error!", "See stderr for more details").open(); + System.err.println("Packet Error: " + ioe.getMessage()); + // baos.close(); + // dos.close(); + return null; + } + + } + + /** + * For debugging, dump the packet contents to a formatted string + */ + public String toString() { + return "ID String:\t" + BEGINSTR + "\nRequest Type:\t" + reqType + + "\nScript #:\t" + scriptID + "\nFilename:\t" + filename + "\nClient ID:\t" + clientID + + "\nData Size:\t" + size + "\n"; + } +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMResponse.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMResponse.java new file mode 100644 index 0000000000..93cdf1036f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/DMResponse.java @@ -0,0 +1,136 @@ +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.EOFException; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.dialogs.ErrorMessage; + + + +/** + * A class to represent a response packet. A response packet prefaces all data + * sent from the data manager, even the DM is not sending any data (ie shutting + * down now). + * + * @author patrickm + * + */ +public class DMResponse extends DMPacket { + + // packet size + public static final int packetsize = 24; // bytes + + // data sources + public static final int STDOUT = 1; + public static final int STDERR = 2; + public static final int SUBSCRIPTION_MGR = 3; + public static final int DATA_MGR = 4; + public static final int MAILBOX = 5; + + // response specific + private int returnCode; + private int source; + private boolean valid; + + // for adding to ClientSession's buffer + private byte[] bacopy; + + /** + * Construct a response object from a stream of bytes. If there are any + * errors, the valid flag is set to false. + * + * @param ba + * The array of bytes from the data manager, of length + * packetsize. + */ + public DMResponse(final byte[] ba) { + + if (ba.length != packetsize) { + // usually happens when reading garbage data + // ignore for now, but can be useful +// System.err.println("Invalid packet length: " + ba.length); + valid = false; + return; + } + + bacopy = ba; + + final ByteArrayInputStream bais = new ByteArrayInputStream(ba); + final DataInputStream dis = new DataInputStream(bais); + int headerID = 0; + + try { + headerID = dis.readInt(); + source = dis.readInt(); + scriptID = dis.readInt(); + clientID = dis.readInt(); + returnCode = dis.readInt(); + size = dis.readInt(); + // void ptr? + } catch (final EOFException eofe) { + valid = false; + new ErrorMessage("Response packet error!", "See stderr for more details").open(); + System.err.println("response packet Error: " + eofe.getMessage()); + } catch (final IOException ioe) { + valid = false; + new ErrorMessage("Response packet error!", "See stderr for more details").open(); + System.err.println("response packet Error: " + ioe.getMessage()); + } + + valid = (headerID == BEGINSTR); + return; + + } + + /** + * The "source" of this packet, unused right now. + * + * @return An integer corresponding to the data manager, the subscription + * manager, or the mailbox, etc. + */ + public int getsource() { + return source; + } + + /** + * The return code. This does not apply to all responses. + * + * @return An integer: zero on success, non zero otherwise. + */ + public int getreturnCode() { + return returnCode; + } + + /** + * A packet is marked invalid if the size is wrong, there was any errors + * converting the stream of bytes to individual integers, or the header's + * magic number is wrong. + * + * @return True if the packet appears to be sane, false otherwise. + */ + public boolean isValid() { + return valid; + } + + /** + * For debugging, dump the packet contents to a formatted string + */ + public String toString() { + return "ID String:\t" + BEGINSTR + "\nSource:\t" + source + + "\nScript #:\t" + scriptID + "\nClient ID:\t" + clientID + + "\nData Size:\t" + size + "\nReturn Code:\t" + returnCode + + "\n"; + } + + /** + * Hackish function to retrieve the original byte array. <ay be removed in + * the future. + * + * @return The original array of bytes this packet was constructed from. + */ + public byte[] tobytes() { + return bacopy; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ErrorStreamDaemon.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ErrorStreamDaemon.java new file mode 100644 index 0000000000..6754502191 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ErrorStreamDaemon.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.consolelog.views.ErrorView; + +/** + * A class push data to both the </code>ScriptConsole</code> and the ErrorView + * @author Ryan Morse + */ +public class ErrorStreamDaemon extends ConsoleStreamDaemon { + public ErrorStreamDaemon(ScriptConsole console, ErrorView errorWindow, IErrorParser parser) { + super(console); + + outputData = new StringBuilder(); + this.parser = parser; + + errorView = errorWindow; + errorView.clear(); + } + + /** + * Prints out the new output data to the console and parses it and sends it to the + * ErrorView. + */ + protected void pushData() { + if(output.startsWith(Localization.getString("ErrorStreamDaemon.Password"))) + output = output.substring(Localization.getString("ErrorStreamDaemon.Password").length()); + + super.pushData(); + + outputData.append(output); + + /* Since we never know when the last set of data is comming we don't clear the + * errorStream in the hope of getting a more complete error message. As a result + * the parser will always return what we already had. Clear removes anything + * that was added before. + */ + if(null != errorView) { + String[][] errors = parser.parseOutput(outputData.toString()); + + if(null != errors) { + errorView.clear(); + for(int i=0; i<errors.length; i++) + errorView.add(errors[i]); + } + } + } + + /** + * Disposes of all internal references in the class. No method should be called after this. + */ + public void dispose() { + if(!isDisposed()) { + super.dispose(); + errorView = null; + outputData.delete(0, outputData.length()); + outputData = null; + parser = null; + } + } + + private ErrorView errorView; + private StringBuilder outputData; + private IErrorParser parser; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ErrorTableDisplay.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ErrorTableDisplay.java new file mode 100644 index 0000000000..ddeaeb47fc --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ErrorTableDisplay.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.ConsoleLogPlugin; +import org.eclipse.linuxtools.systemtap.ui.editor.SimpleEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; + + + +/** + * A class push data to a ScriptConsole. + * @author Ryan Morse + */ +public class ErrorTableDisplay { + public ErrorTableDisplay(Composite parent, String[] titles) { + this.titles = titles; + createControl(parent); + } + + /** + * Creates the table for displaying error messages in. + * @param parent The container for the new error table. + */ + public void createControl(Composite parent) { + table = new Table(parent, SWT.SINGLE); + table.setHeaderVisible(true); + table.getVerticalBar().setVisible(true); + table.setLinesVisible(true); + table.addMouseListener(mouseListener); + + TableColumn column; + for(int i = 0; i < titles.length; i++) { + column = new TableColumn(table, SWT.NONE); + column.setText(titles[i]); + } + + updateColumns(); + } + + /** + * Clears all items from the table. + */ + public void clear() { + table.getDisplay().syncExec(new Runnable() { + boolean stop = false; + public void run() { + if(stop) return; + try { + table.removeAll(); + } catch (Exception e) { + stop = true; + } + } + + }); + } + + /** + * Adds a new row to the table with an error icon. + * @param row The pre-divied sections of the error message. + */ + public void addRow(final String[] row) { + addRow(row, ConsoleLogPlugin.getImageDescriptor("icons/views/error_st_obj.gif").createImage()); + } + + /** + * Adds a new row to the table. + * @param row The pre-divied sections of the error message. + * @param img The image to display with the error. + */ + public void addRow(final String[] row, final Image img) { + table.getDisplay().syncExec(new Runnable() { + boolean stop = false; + public void run() { + if(stop) return; + try { + item = new TableItem(table, SWT.NULL); + for(int i=0; i<row.length; i++) + item.setText(i+1, row[i]); + item.setImage(img); + updateColumns(); + } catch (Exception e) { + stop = true; + } + } + + }); + } + + /** + * Updates each of the columns in the table to ensure that the entries all fit + * as well as possible. + */ + private void updateColumns() { + TableColumn[] columns = table.getColumns(); + for (int i = 0; i < columns.length; i++) { + columns[i].pack(); + columns[i].setMoveable(true); + } + } + + public Control getControl() { + return table; + } + + /** + * Disposes of all internal references in the class. No method should be called after this. + */ + public void dispose() { + if(null != table && !table.isDisposed()) { + table.removeMouseListener(mouseListener); + table.dispose(); + table = null; + } + + if(titles != null) + for(int i=0; i<titles.length; i++) + titles[i] = null; + titles = null; + + if(null != item) + item.dispose(); + item = null; + } + + /** + * MouseListener that is used to detect when the user clicks on a row in the table. + * When clicked it will find the line number the error occured on and then set the + * cursor location to that location in the active editor. + */ + private final MouseListener mouseListener = new MouseListener() { + public void mouseDown(MouseEvent me) {} + public void mouseUp(MouseEvent me) {} + + public void mouseDoubleClick(MouseEvent me) { + try { + String location = table.getSelection()[0].getText(4); + + if(location.length() > 0) { + int line = 0; + if(location.indexOf(':') > 0) { + String[] pos = location.split(":"); + line = Integer.parseInt(pos[0]); + } else + line = Integer.parseInt(location); + + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IEditorPart ed = page.getActiveEditor(); + + if(ed instanceof SimpleEditor) { + SimpleEditor editor = ((SimpleEditor)ed); + editor.selectLine(line); + editor.setFocus(); + } + } + } catch(Exception e) {} + } + }; + + private Table table; + private String[] titles; + private TableItem item; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/IErrorParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/IErrorParser.java new file mode 100644 index 0000000000..9ee962367b --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/IErrorParser.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +public interface IErrorParser { + public String[][] parseOutput(String data); +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java new file mode 100644 index 0000000000..3f0e6f3072 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java @@ -0,0 +1,288 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.structures; + +import java.io.File; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.linuxtools.systemtap.ui.consolelog.Subscription; +import org.eclipse.linuxtools.systemtap.ui.consolelog.actions.StopScriptAction; +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.consolelog.views.ErrorView; +import org.eclipse.linuxtools.systemtap.ui.structures.IPasswordPrompt; +import org.eclipse.linuxtools.systemtap.ui.structures.runnable.LoggedCommand; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.MessageConsole; + + + +/** + * This class serves as a pain in the ConsoleView. It is used to create a new Command that, + * through ConsoleDaemons will print all the output the the console. In order to stop the + * running Command <code>StopScriptAction</code> should be used to stop this console from + * running. + * @author Ryan Morse + */ +public class ScriptConsole extends MessageConsole { + /** + * This method is used to get a reference to a <code>ScriptConsole</code>. If there + * is already an console that has the same name as that provided it will be stopped, + * cleared and returned to the caller to use. If there is no console matching the + * provided name then a new <code>ScriptConsole</code> will be created for use. + * @param name The name of the console that should be returned if available. + * @return The console with the provided name, or a new instance if none exist. + */ + public static ScriptConsole getInstance(String name) { + ScriptConsole console = null; + try { + IConsole ic[] = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + + //Prevent running the same script twice + if(null != ic) { + ScriptConsole activeConsole; + StopScriptAction ssa = new StopScriptAction(); + ssa.init(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + for(int i=0; i<ic.length; i++) { + activeConsole = (ScriptConsole)ic[i]; + if(activeConsole.getName().endsWith(name)) { + //Stop any script currently running + ssa.run(i); + //Remove output from last run + activeConsole.clearConsole(); + activeConsole.setName(name); + console = activeConsole; + } + } + } + + if(null == console) { + console = new ScriptConsole(name, null); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console}); + } + } catch(NullPointerException npe) { + console = null; + } + return console; + } + + public static ScriptConsole getInstance(String name,Subscription sub) { + ScriptConsole console = null; + try { + IConsole ic[] = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + + //Prevent running the same script twice + if(null != ic) { + ScriptConsole activeConsole; + StopScriptAction ssa = new StopScriptAction(); + ssa.init(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + for(int i=0; i<ic.length; i++) { + activeConsole = (ScriptConsole)ic[i]; + if(activeConsole.getName().endsWith(name)) { + //Stop any script currently running + ssa.run(i); + + //Remove output from last run + activeConsole.clearConsole(); + activeConsole.setName(name); + console = activeConsole; + } + } + } + + if(null == console) { + console = new ScriptConsole(name, null, sub); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console}); + } + } catch(NullPointerException npe) { + console = null; + } + return console; + } + private ScriptConsole(String name, ImageDescriptor imageDescriptor) { + super(name, imageDescriptor); + cmd = null; + } + + private ScriptConsole(String name, ImageDescriptor imageDescriptor, Subscription sub) { + super(name, imageDescriptor); + this.subscription = sub; + cmd = null; + } + + /** + * Creates the <code>ConsoleStreamDaemon</code> for passing data from the + * <code>LoggedCommand</code>'s InputStream to the Console. + */ + protected void createConsoleDaemon() { + consoleDaemon = new ConsoleStreamDaemon(this); + } + + /** + * Creates the <code>ErrorStreamDaemon</code> for passing data from the + * <code>LoggedCommand</code>'s ErrorStream to the Console and ErrorView. + */ + protected void createErrorDaemon(IErrorParser parser) { + ErrorView errorView = null; + try { + IViewPart ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ErrorView.ID); + if(null != ivp && ivp instanceof ErrorView) + errorView = ((ErrorView)ivp); + } catch(Exception e) {} + + errorDaemon = new ErrorStreamDaemon(this, errorView, parser); + } + + /** + * Runs the provied command in this ScriptConsole instance. + * @param command The command and arguments to run. + * @param envVars The environment variables to use while running + * @param prompt The prompt to get the users password if needed. + * @param errorParser The parser to handle error messages generated by the command + */ + public void run(String[] command, String[] envVars, IPasswordPrompt prompt, IErrorParser errorParser) { + if(subscription.init()) + { + createConsoleDaemon(); + createErrorDaemon(errorParser); + subscription.addErrorStreamListener(errorDaemon); + subscription.addInputStreamListener(consoleDaemon); + + if (!subscription.isRunning()) + { + subscription.start(); + } + ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this); + } + else + { + setName(Localization.getString("ScriptConsole.Terminated") + super.getName()); + subscription.interrupt(); + subscription.delSubscription(); + ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {this}); + } + } + + public void run() { + if(subscription.init()) + { + createConsoleDaemon(); + subscription.addInputStreamListener(consoleDaemon); + subscription.addErrorStreamListener(consoleDaemon); + + if (!subscription.isRunning()) + { + subscription.start(); + } + ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this); + //ConsolePlugin.getDefault().getConsoleManager(). + //activate(); + } + else + { + setName(Localization.getString("ScriptConsole.Terminated") + super.getName()); + subscription.interrupt(); + subscription.delSubscription(); + ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {this}); + } + + } + + /** + * Check to see if the Command is still running + * @return boolean representing if the command is running + */ + public boolean isRunning() { + return subscription.isRunning(); + } + + /** + * Check to see if this class has already been disposed. + * @return boolean represneting whether or not the class has been disposed. + */ + public boolean isDisposed() { + return cmd.isDisposed(); + } + + /** + * Method to allow the user to save the Commands output to a file for use latter. + * @param file The new file to save the output to. + */ + public void saveStream(File file) { + if(isRunning()) + if(!subscription.saveLog(file)) + MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Localization.getString("ScriptConsole.Problem"), Localization.getString("ScriptConsole.ErrorSavingLog")); + } + + /** + * Gets the command that is running in this console, or null if there is no running command. + * @return The <code>LoggedCommand</code> that is running in this console. + */ + public LoggedCommand getCommand() { + return cmd; + } + + public String getOutput() { + return subscription.getOutput(); + } + + /** + * Stops the running command and the associated listeners. + */ + public synchronized void stop() { + if(isRunning()) { + setName(Localization.getString("ScriptConsole.Terminated") + super.getName()); + subscription.interrupt(); + subscription.delSubscription(); + ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {this}); + + } + } + + /** + * Disposes of all internal references in the class. No method should be called after this. + */ + public void dispose() { + if(!isDisposed()) { + if(null != subscription) + subscription.dispose(); + subscription = null; + if(null != errorDaemon) + errorDaemon.dispose(); + errorDaemon = null; + if(null != consoleDaemon) + consoleDaemon.dispose(); + consoleDaemon = null; + } + } + + /** + * Changes the name displayed on this console. + * @param name The new name to display on the console. + */ + public void setName(String name) { + try { + super.setName(name); + if(null != ConsolePlugin.getDefault()) + ConsolePlugin.getDefault().getConsoleManager().refresh(this); + } catch(Exception e) {} + } + + private LoggedCommand cmd; + + private ErrorStreamDaemon errorDaemon; + private ConsoleStreamDaemon consoleDaemon; + private Subscription subscription; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/views/ErrorView.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/views/ErrorView.java new file mode 100644 index 0000000000..1606b00b59 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/views/ErrorView.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM 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: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.consolelog.views; + +import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.ErrorTableDisplay; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; + + + +/** + * A view to list error messages generated from trying to run a script in the editor. + * @author Ryan Morse + */ +public class ErrorView extends ViewPart { + public ErrorView() { + super(); + } + + /** + * Greates a new table to contain all of the error messages. + * @param parent The composite to draw all content to. + */ + public void createPartControl(Composite parent) { + Composite c = new Composite(parent, SWT.NONE); + + GridLayout grid = new GridLayout(); + c.setLayout(grid); + + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + table = new ErrorTableDisplay(c, new String[] {"", Localization.getString("ErrorView.Type"), Localization.getString("ErrorView.Description"), Localization.getString("ErrorView.Saw"), Localization.getString("ErrorView.Line")}); + table.getControl().setLayoutData(gd); + } + + /** + * Adds the log details to the table of errors. + * @param log The details for an error message to display in the table. + */ + public void add(final String[] log) { + table.getControl().getDisplay().syncExec(new Runnable() { + boolean stop = false; + public void run() { + if(stop) return; + try { + table.addRow(log); + + try { + PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().showView(ID); + } catch(PartInitException pie) { + } catch(NullPointerException npe) {} + } catch (Exception e) { + stop = true; + } + } + + }); + } + + /** + * Clears the entire table of error messages. + */ + public void clear() { + table.clear(); + } + + public void setFocus() {} + + /** + * Disposes of everything in this class. + */ + public void dispose() { + if(null != table) + table.dispose(); + table = null; + super.dispose(); + } + + private volatile ErrorTableDisplay table; + public static final String ID = "org.eclipse.linuxtools.systemtap.ui.consolelog.views.ErrorView"; +} |