diff options
author | Andrew Ferrazzutti | 2014-04-30 20:58:14 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2014-05-02 08:00:11 +0000 |
commit | b49974f099c89f5ddc4c6f5b11c8f4db4c820459 (patch) | |
tree | 501bf5e1bb725dfe9d20f770e2e5924bc77d04f4 | |
parent | 8c7ff68fd027ea1dc6983f625c0db4f3ebca04ce (diff) | |
download | org.eclipse.linuxtools-b49974f099c89f5ddc4c6f5b11c8f4db4c820459.tar.gz org.eclipse.linuxtools-b49974f099c89f5ddc4c6f5b11c8f4db4c820459.tar.xz org.eclipse.linuxtools-b49974f099c89f5ddc4c6f5b11c8f4db4c820459.zip |
Systemtap: Assorted cleanup/fixes.
-Ensure that ExceptionErrorDialog.openError always operates
in the display thread.
-Make improvements to running stap scripts.
-Perform some general syntax cleanup.
Change-Id: I714f3bdba26b12feccedff5d14eba20614eb741b
Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com>
Reviewed-on: https://git.eclipse.org/r/25824
Tested-by: Hudson CI
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
18 files changed, 331 insertions, 451 deletions
diff --git a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java index fd8eaa4956..0f8c3a8289 100644 --- a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java +++ b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java @@ -203,7 +203,7 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { * @since 1.1 */ private Process exec(String cmd, String[] envp, IFileStore dir, IProject project) - throws IOException { + throws IOException { return exec(tokenizeCommand(cmd), envp, dir, project); } @@ -237,10 +237,10 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { * @param pty PTY for use with Eclipse Console. * @return The process started by exec. * - * @since 2.1 + * @since 3.0 */ public Process exec(String cmdarray[], String[] envp, IFileStore dir, IProject project, PTY pty) - throws IOException { + throws IOException { Process p = null; try { diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.core/src/org/eclipse/linuxtools/systemtap/graphing/core/structures/GraphData.java b/systemtap/org.eclipse.linuxtools.systemtap.graphing.core/src/org/eclipse/linuxtools/systemtap/graphing/core/structures/GraphData.java index 12c73a1c57..555d081a84 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.core/src/org/eclipse/linuxtools/systemtap/graphing/core/structures/GraphData.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.core/src/org/eclipse/linuxtools/systemtap/graphing/core/structures/GraphData.java @@ -11,15 +11,21 @@ package org.eclipse.linuxtools.systemtap.graphing.core.structures; -public class GraphData implements Cloneable { +import java.util.Arrays; + +public class GraphData { public int xSeries; public int[] ySeries; public String key; public String graphID; public String title; - @Override - public GraphData clone() { + /** + * Creates and returns a copy of this GraphData instance. + * @return A copy of this GraphData. + * @since 1.1 + */ + public GraphData getCopy() { GraphData gd = new GraphData(); gd.xSeries = this.xSeries; gd.ySeries = this.ySeries == null ? null : this.ySeries.clone(); @@ -29,41 +35,35 @@ public class GraphData implements Cloneable { return gd; } - /** - * Indicates whether all properties of this GraphData are the same as another GraphData. - * @param gd The GraphData to compare with. - * @return <code>true</code> if all properties are equal, or <code>false</code> otherwise. - * @since 1.1 - */ - public boolean equals(GraphData gd) { - if (gd.ySeries != null && this.ySeries != null) { - if (gd.ySeries.length != this.ySeries.length) { + public boolean isCopyOf(GraphData gd) { + if (graphID == null) { + if (gd.graphID != null) { return false; } - for (int i = 0; i < this.ySeries.length; i++) { - if (gd.ySeries[i] != this.ySeries[i]) { - return false; - } + } else if (!graphID.equals(gd.graphID)) { + return false; + } + if (key == null) { + if (gd.key != null) { + return false; } - } else if (gd.ySeries != this.ySeries) { + } else if (!key.equals(gd.key)) { return false; } - - if ((gd.key != this.key) - && (gd.key != null && this.key != null && !gd.key.equals(this.key))) { + if (title == null) { + if (gd.title != null) { + return false; + } + } else if (!title.equals(gd.title)) { return false; } - - if ((gd.graphID != this.graphID) - && (gd.graphID != null && this.graphID != null && !gd.graphID.equals(this.graphID))) { + if (xSeries != gd.xSeries) { return false; } - - if ((gd.title != this.title) - && (gd.title != null && this.title != null && !gd.title.equals(this.title))) { + if (!Arrays.equals(ySeries, gd.ySeries)) { return false; } - - return gd.xSeries == this.xSeries; + return true; } + } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/systemtap/graphing/ui/widgets/ExceptionErrorDialog.java b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/systemtap/graphing/ui/widgets/ExceptionErrorDialog.java index f17f7c0755..9abd225037 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/systemtap/graphing/ui/widgets/ExceptionErrorDialog.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/systemtap/graphing/ui/widgets/ExceptionErrorDialog.java @@ -16,23 +16,33 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.linuxtools.internal.systemtap.graphing.ui.GraphingUIPlugin; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; /** * A convenience class for showing error dialogs which display the full stack * trace in the details section. * @since 2.0 - * */ public class ExceptionErrorDialog { - public static int openError(String message, Exception e){ - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - Status status = new Status(IStatus.ERROR, GraphingUIPlugin.PLUGIN_ID, e.toString(), new Throwable(writer.toString())); - return ErrorDialog.openError(PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getShell(), message, - message, status); + public static void openError(final String message, final Exception e) { + openError(message, message, e); + } + + public static void openError(final String title, final String message, final Exception e) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + Status status = new Status(IStatus.ERROR, GraphingUIPlugin.PLUGIN_ID, + e.toString(), new Throwable(writer.toString())); + ErrorDialog.openError(PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(), + title, message, status); + } + }); } } 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 index a9d730feff..cf085ae356 100644 --- 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 @@ -34,19 +34,19 @@ public class ScpClient { */ public ScpClient(RemoteScriptOptions remoteOptions) throws JSchException { - JSch jsch=new JSch(); + JSch jsch = new JSch(); - session=jsch.getSession(remoteOptions.getUserName(), remoteOptions.getHostName(), 22); + session = jsch.getSession(remoteOptions.userName, remoteOptions.hostName, 22); - session.setPassword(remoteOptions.getPassword()); - java.util.Properties config = new java.util.Properties(); - config.put("StrictHostKeyChecking", "no"); //$NON-NLS-1$ //$NON-NLS-2$ - session.setConfig(config); - session.connect(); + session.setPassword(remoteOptions.password); + java.util.Properties config = new java.util.Properties(); + config.put("StrictHostKeyChecking", "no"); //$NON-NLS-1$ //$NON-NLS-2$ + session.setConfig(config); + session.connect(); } public void transfer(String fromFile, String toFile) throws IOException, - JSchException { + JSchException { String rfile = toFile; String lfile = fromFile; String command = "scp -t " + rfile; //$NON-NLS-1$ diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java index 399ddeb913..697b8bd899 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java @@ -30,8 +30,11 @@ import com.jcraft.jsch.JSchException; public class ScpExec extends Command { + public static final int INPUT_STREAM = 1; + private Channel channel; private RemoteScriptOptions remoteOptions; + private String command; /** * @since 3.0 @@ -49,7 +52,7 @@ public class ScpExec extends Command { protected IStatus init() { try { channel = SystemtapProcessFactory.execRemote( - new String[] { command }, System.out, System.err, remoteOptions.getUserName(), remoteOptions.getHostName(), remoteOptions.getPassword()); + new String[] { command }, System.out, System.err, remoteOptions.userName, remoteOptions.hostName, remoteOptions.password); errorGobbler = new StreamGobbler(channel.getExtInputStream()); inputGobbler = new StreamGobbler(channel.getInputStream()); @@ -107,8 +110,4 @@ public class ScpExec extends Command { notifyAll(); } } - - private String command; - - public static final int INPUT_STREAM = 1; } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/RemoteScriptOptions.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/RemoteScriptOptions.java index 1191b6205c..c81f2a6544 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/RemoteScriptOptions.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/RemoteScriptOptions.java @@ -20,21 +20,9 @@ import org.eclipse.linuxtools.internal.systemtap.ui.consolelog.structures.Messag */ public class RemoteScriptOptions { - private String userName = null; - private String password = null; - private String hostName = null; - - public String getUserName() { - return userName; - } - - public String getPassword() { - return password; - } - - public String getHostName() { - return hostName; - } + public final String userName; + public final String password; + public final String hostName; public RemoteScriptOptions(String userName, String password, String hostName) { if (userName == null || password == null || hostName == null) { @@ -44,20 +32,4 @@ public class RemoteScriptOptions { this.password = password; this.hostName = hostName; } - - @Override - public boolean equals(Object obj) { - if (obj instanceof RemoteScriptOptions) { - return false; - } - RemoteScriptOptions other = (RemoteScriptOptions) obj; - return this.userName.equals(other.userName) - && this.password.equals(other.password) - && this.hostName.equals(other.hostName); - } - - @Override - public int hashCode() { - return super.hashCode(); - } } 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 index 30b2a2b4f2..debc559514 100644 --- 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 @@ -350,12 +350,7 @@ public class ScriptConsole extends IOConsole { try { cmd.start(); } catch (final CoreException e) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - ExceptionErrorDialog.openError(e.getMessage(), e); - } - }); + ExceptionErrorDialog.openError(e.getMessage(), e); cmd.dispose(); return; } @@ -449,11 +444,10 @@ public class ScriptConsole extends IOConsole { public void saveStream(File file) { if (isRunning()) { if (!cmd.saveLog(file)) { - MessageDialog - .openWarning( - PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getShell(), - Localization.getString("ScriptConsole.Problem"), Localization.getString("ScriptConsole.ErrorSavingLog")); //$NON-NLS-1$//$NON-NLS-2$ + MessageDialog.openWarning( + PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(), + Localization.getString("ScriptConsole.Problem"), Localization.getString("ScriptConsole.ErrorSavingLog")); //$NON-NLS-1$//$NON-NLS-2$ } } @@ -505,7 +499,7 @@ public class ScriptConsole extends IOConsole { } private String getStopString(){ - return "pkill -SIGINT -f stapio.*"+ getModuleName(); //$NON-NLS-1$ + return "pkill -SIGINT -f stapio.*"+ getModuleName(); //$NON-NLS-1$ } /** * Disposes of all internal references in the class. No method should be called after this. diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/Messages.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/Messages.java index ee86c74c1e..f9d168a4d9 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/Messages.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/Messages.java @@ -19,7 +19,7 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.systemtap.ui.ide.actions.messages"; //$NON-NLS-1$ public static String ScriptRunAction_InvalidScriptTitle; - public static String ScriptRunAction_InvalidScriptTMessage; + public static String ScriptRunAction_InvalidScriptMessage; public static String ScriptRunAction_errorDialogTitle; public static String RunScriptAction_alreadyRunningDialogTitle; public static String RunScriptAction_alreadyRunningDialogMessage; diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptChartHandler.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptChartHandler.java index 62ba6d47b0..fcf6508625 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptChartHandler.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptChartHandler.java @@ -55,10 +55,10 @@ public class RunScriptChartHandler extends RunScriptHandler { } try { String name = console.getName(); - String title = name.substring(name.lastIndexOf('/')+1); + String title = name.substring(name.lastIndexOf('/') + 1); IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); - GraphSelectorEditor ivp = (GraphSelectorEditor)p.openEditor(new GraphSelectorEditorInput(title), GraphSelectorEditor.ID); + GraphSelectorEditor ivp = (GraphSelectorEditor) p.openEditor(new GraphSelectorEditorInput(title), GraphSelectorEditor.ID); String scriptName = console.getName(); ivp.createScriptSets(scriptName, names, dataSets); @@ -68,7 +68,7 @@ public class RunScriptChartHandler extends RunScriptHandler { ivp.getDisplaySet(i).addGraph(graph); } } - } catch(WorkbenchException we) { + } catch (WorkbenchException we) { ExceptionErrorDialog.openError(Messages.RunScriptChartAction_couldNotSwitchToGraphicPerspective, we); } super.scriptConsoleInitialized(console); diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptHandler.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptHandler.java index dbd976ab5e..e317b06737 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptHandler.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptHandler.java @@ -24,28 +24,23 @@ import java.util.regex.Pattern; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandlerListener; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.ProgressMonitorPart; import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; -import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDESessionSettings; import org.eclipse.linuxtools.internal.systemtap.ui.ide.Localization; import org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor; import org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher.SystemTapScriptLaunch; import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.EnvironmentVariablesPreferencePage; import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants; import org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.StapErrorParser; -import org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.TapsetLibrary; import org.eclipse.linuxtools.systemtap.graphing.ui.widgets.ExceptionErrorDialog; import org.eclipse.linuxtools.systemtap.ui.consolelog.ScpClient; import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.RemoteScriptOptions; @@ -58,9 +53,11 @@ import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IPathEditorInput; +import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.ide.ResourceUtil; import com.jcraft.jsch.JSchException; @@ -81,24 +78,19 @@ public class RunScriptHandler extends AbstractHandler { */ protected boolean continueRun = true; private RemoteScriptOptions remoteOptions = null; - private IEditorPart ed = null; + private IEditorPart targetEditor = null; private String fileName = null; private String tmpfileName = null; private String serverfileName = null; - private IPath path; - private IProject project; - private SystemTapScriptLaunch launch; - private final List<String> cmdList; - - - public RunScriptHandler(){ - this.cmdList = new ArrayList<>(); - } + private IPath path = null; + private IProject project = null; + private SystemTapScriptLaunch launch = null; + private final List<String> cmdList = new ArrayList<>(); /** * @since 2.0 */ - public void setPath(IPath path){ + public void setPath(IPath path) { this.path = path; URI uri = URIUtil.toURI(path); IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri); @@ -108,61 +100,41 @@ public class RunScriptHandler extends AbstractHandler { } /** - * @since 2.1 + * @since 2.3 */ - public IProject getProject() { - return project; + public void setLaunch(SystemTapScriptLaunch launch) { + this.launch = launch; } /** - * @since 2.3 + * Adds the given String to the list of commands to be + * passed to systemtap when running the command + * @param option */ - public void setLaunch(SystemTapScriptLaunch launch){ - this.launch = launch; + public void addComandLineOptions(String option) { + this.cmdList.add(option); } /** - * Finds the editor containing the target script to run, so the script can be saved - * when it is run, if appropriate. - * The script is saved when it is run with the "simple" run button on the toolbar (path == null), - * or if the script is outside of a project (working with a PathEditorInput). + * Set the options for running the script remotely. If the script is to be run locally, + * pass <code>null</code> as the only parameter. + * @param remoteOptions The remote options of the script run, or <code>null</code> if the script + * is to be run locally. + * @since 3.0 */ - private void findTargetEditor() { - ed = null; - - if (path == null) { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - ed = window.getActivePage().getActiveEditor(); - return; - } + public void setRemoteScriptOptions(RemoteScriptOptions remoteOptions) { + this.remoteOptions = remoteOptions; + } - for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) { - IEditorPart edTest = window.getActivePage().getActiveEditor(); - if (edTest != null && matchesEditor(edTest.getEditorInput(), edTest)) { - return; - } - for (IEditorReference ref : window.getActivePage().getEditorReferences()) { - try { - if (matchesEditor(ref.getEditorInput(), ref.getEditor(false))) { - return; - } - } catch (PartInitException e) { - continue; - } - } - } + public boolean getRunLocal() { + return remoteOptions == null; } - private boolean matchesEditor(IEditorInput input, IEditorPart editor) { - if (input instanceof IPathEditorInput && ((IPathEditorInput) (input)).getPath().equals(this.path)) { - // Only save the editor when working with a file without a project (PathEditorInput), - // otherwise the editor isn't needed at all (saving is handled elsewhere in that case). - if (input instanceof PathEditorInput) { - this.ed = editor; - } - return true; - } - return false; + /** + * @since 2.1 + */ + public IProject getProject() { + return project; } /** @@ -172,89 +144,58 @@ public class RunScriptHandler extends AbstractHandler { */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { - findTargetEditor(); - final boolean local = getRunLocal(); - if(isValid()) { - if(!local && !prepareNonLocalScript()) { - return null; - } - final String[] script = buildStandardScript(); - final String[] envVars = EnvironmentVariablesPreferencePage.getEnvironmentVariables(); - if (continueRun) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - String name = !local ? serverfileName : fileName; - if (ScriptConsole.instanceIsRunning(name)) { - MessageDialog dialog = new MessageDialog( - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), - Messages.RunScriptAction_alreadyRunningDialogTitle, null, - MessageFormat.format(Messages.RunScriptAction_alreadyRunningDialogMessage, fileName), - MessageDialog.QUESTION, new String[]{"Yes", "No"}, 0); //$NON-NLS-1$ //$NON-NLS-2$ - if (dialog.open() != Window.OK) { - if (launch != null) { - launch.forceRemove(); - } - return; - } - } - final ScriptConsole console; - if (!local) { - console = ScriptConsole.getInstance(serverfileName); - } else { - console = ScriptConsole.getInstance(fileName); - } - synchronized (console) { - if (!local) { - console.run(script, envVars, remoteOptions, new StapErrorParser()); - } else { - console.runLocally(script, envVars, new StapErrorParser(), getProject()); - } - scriptConsoleInitialized(console); - } - } - }); + try { + executeAction(event); + } catch (ExecutionException e) { + // If the event isn't null, an error dialog must be displayed now. + if (event != null) { + ExceptionErrorDialog.openError( + Localization.getString("RunScriptHandler.Error"), //$NON-NLS-1$ + Localization.getString("RunScriptHandler.ErrorMessage"), e); //$NON-NLS-1$ } + throw e; } - return null; } - /** - * Attempts to set up a channel for a script that runs on a non-local host or user. - * @return <code>true</code> on success, <code>false</code> on failure. - * @throws ExecutionException If failure occurs during a (non-simple) launch, - * this will throw an exception instead of returning <code>false</code>. - */ - private boolean prepareNonLocalScript() throws ExecutionException { - try { - ScpClient scpclient = new ScpClient(remoteOptions); - serverfileName = fileName.substring(fileName.lastIndexOf('/')+1); - tmpfileName="/tmp/"+ serverfileName; //$NON-NLS-1$ - scpclient.transfer(fileName,tmpfileName); - } catch (final JSchException | IOException e) { - final String message = e instanceof JSchException ? Localization.getString("RunScriptHandler.checkCredentials") //$NON-NLS-1$ - : Localization.getString("RunScriptHandler.ioError"); //$NON-NLS-1$ - if (launch == null) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - if (e instanceof JSchException) { - ErrorDialog.openError(PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getShell(), - Localization.getString("RunScriptHandler.serverError"), Localization.getString("RunScriptHandler.serverError"), //$NON-NLS-1$ //$NON-NLS-2$ - new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, message)); - } else { - ExceptionErrorDialog.openError(Localization.getString("RunScriptHandler.ioError"), e); //$NON-NLS-1$ + private void executeAction(ExecutionEvent event) throws ExecutionException { + final boolean local = getRunLocal(); + findTargetEditor(event); + findFilePath(); + tryEditorSave(event); + if (!local) { + prepareNonLocalScript(); + } + final String[] script = buildStandardScript(); + final String[] envVars = getEnvironmentVariables(); + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + String name = !local ? serverfileName : fileName; + if (ScriptConsole.instanceIsRunning(name)) { + MessageDialog dialog = new MessageDialog( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + Messages.RunScriptAction_alreadyRunningDialogTitle, null, + MessageFormat.format(Messages.RunScriptAction_alreadyRunningDialogMessage, fileName), + MessageDialog.QUESTION, new String[]{"Yes", "No"}, 0); //$NON-NLS-1$ //$NON-NLS-2$ + if (dialog.open() != Window.OK) { + if (launch != null) { + launch.forceRemove(); } + return; + } + } + final ScriptConsole console = ScriptConsole.getInstance(name); + synchronized (console) { + if (!local) { + console.run(script, envVars, remoteOptions, new StapErrorParser()); + } else { + console.runLocally(script, envVars, new StapErrorParser(), getProject()); } - }); - return false; - } else { - throw new ExecutionException(message, e); + scriptConsoleInitialized(console); + } } - } - return true; + }); } /** @@ -263,73 +204,39 @@ public class RunScriptHandler extends AbstractHandler { * @param console * @since 2.0 */ - protected void scriptConsoleInitialized(ScriptConsole console){ + protected void scriptConsoleInitialized(ScriptConsole console) { if (launch != null && path != null) { launch.setConsole(console); } } - /** - * Returns the path that was set for this action. If one was not set it - * returns the path of the current editor in the window this action is - * associated with. - * - * @return The string representation of the path of the script to run. - */ - protected String getFilePath() { - if (path != null){ - return path.toOSString(); - } - if (ed == null) { - return ""; //$NON-NLS-1$ - } - if(ed.getEditorInput() instanceof PathEditorInput){ - return ((PathEditorInput)ed.getEditorInput()).getPath().toString(); + private void findTargetEditor(ExecutionEvent event) { + if (event != null) { + targetEditor = HandlerUtil.getActiveEditor(event); } else { - return ResourceUtil.getFile(ed.getEditorInput()).getLocation().toString(); - } - } - - /** - * Checks if the current editor is operating on a file that actually exists and can be - * used as an argument to stap (as opposed to an unsaved buffer). - * @return True if the file is valid. - */ - private boolean isValid() { - // If the path is not set this action will run the script from - // the active editor - if(!tryEditorSave()){ - if (this.path == null){ - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - String msg = MessageFormat.format(Localization.getString("RunScriptAction.NoScriptFile"),(Object[]) null); //$NON-NLS-1$ - MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Localization.getString("RunScriptAction.Problem"), msg); //$NON-NLS-1$ + for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) { + IWorkbenchPage activePage = window.getActivePage(); + IEditorPart edTest = activePage.getActiveEditor(); + if (edTest != null && editorMatchesPath(edTest.getEditorInput())) { + targetEditor = edTest; + } else { + for (IEditorReference ref : activePage.getEditorReferences()) { + try { + if (editorMatchesPath(ref.getEditorInput())) { + targetEditor = ref.getEditor(false); + break; + } + } catch (PartInitException e) { + continue; + } } - }); - return false; + } } } - String filePath = this.getFilePath(); - return filePath.endsWith(".stp") //$NON-NLS-1$ - && isValidDirectory(filePath); } - private boolean tryEditorSave() { - if(null == ed) { - return false; - } - - if(ed.isDirty()) { - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - ed.doSave(new ProgressMonitorPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new FillLayout())); - } - }); - } - - return true; + private boolean editorMatchesPath(IEditorInput input) { + return input instanceof IPathEditorInput && ((IPathEditorInput) (input)).getPath().equals(this.path); } /** @@ -341,32 +248,63 @@ public class RunScriptHandler extends AbstractHandler { * @return true if the given path is valid false otherwise. * @since 1.2 */ - private boolean isValidDirectory(String fileName) { - this.fileName = fileName; - if(0 == IDESessionSettings.tapsetLocation.trim().length()){ - TapsetLibrary.getTapsetLocation(IDEPlugin.getDefault().getPreferenceStore()); + private void findFilePath() throws ExecutionException { + if (path != null) { + fileName = path.toOSString(); + } else if (targetEditor == null) { + // Cannot have neither a path nor an editor. + throw new ExecutionException(Localization.getString("RunScriptHandler.noScriptFile")); //$NON-NLS-1$ + } else if (targetEditor.getEditorInput() instanceof PathEditorInput) { + fileName = ((PathEditorInput) targetEditor.getEditorInput()).getPath().toString(); + } else { + fileName = ResourceUtil.getFile(targetEditor.getEditorInput()).getLocation().toString(); } + } - if(fileName.contains(IDESessionSettings.tapsetLocation)) { - Display.getDefault().asyncExec(new Runnable() { + /** + * If an editor containing the file to be run is open & dirty, save it, if appropriate. + * @param event + */ + private void tryEditorSave(final ExecutionEvent event) { + // No need to save if the script will already be saved with its project when launched. + if (project != null) { + return; + } + + if (targetEditor != null && targetEditor.isDirty()) { + Display.getDefault().syncExec(new Runnable() { @Override public void run() { - String msg = MessageFormat.format(Localization.getString("RunScriptAction.TapsetDirectoryRun"),(Object []) null); //$NON-NLS-1$ - MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Localization.getString("RunScriptAction.Error"), msg); //$NON-NLS-1$ + Shell shell = event != null ? HandlerUtil.getActiveShell(event) + : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + targetEditor.doSave(new ProgressMonitorPart(shell, new FillLayout())); } }); - return false; } - return true; } /** - * Adds the given String to the list of commands to be - * passed to systemtap when running the command - * @param option + * Attempts to set up a channel for a script that runs on a non-local host or user. + * @return <code>true</code> on success, <code>false</code> on failure. + * @throws ExecutionException If failure occurs during a (non-simple) launch, + * this will throw an exception instead of returning <code>false</code>. */ - public void addComandLineOptions(String option){ - this.cmdList.add(option); + private void prepareNonLocalScript() throws ExecutionException { + try { + ScpClient scpclient = new ScpClient(remoteOptions); + serverfileName = getFileName(fileName); + tmpfileName = new Path("/tmp").append(serverfileName).toOSString(); //$NON-NLS-1$ + scpclient.transfer(fileName, tmpfileName); + } catch (final JSchException | IOException e) { + String message = e instanceof JSchException + ? Localization.getString("RunScriptHandler.checkCredentials") //$NON-NLS-1$ + : Localization.getString("RunScriptHandler.ioError"); //$NON-NLS-1$ + throw new ExecutionException(message, e); + } + } + + private String getFileName(String fileName) { + return new File(fileName).getName(); } /** @@ -376,14 +314,14 @@ public class RunScriptHandler extends AbstractHandler { * @return The command to invoke to start the script running in stap. * @since 2.0 */ - private String[] buildStandardScript() { - getImportedTapsets(cmdList); + private String[] buildStandardScript() throws ExecutionException { + getImportedTapsets(); - if(isGuru()) { + if (isGuru()) { cmdList.add("-g"); //$NON-NLS-1$ } - return finalizeScript(cmdList); + return finalizeScript(); } /** @@ -392,13 +330,13 @@ public class RunScriptHandler extends AbstractHandler { * @since 2.0 */ - private void getImportedTapsets(List<String> cmdList) { + private void getImportedTapsets() { IPreferenceStore preferenceStore = IDEPlugin.getDefault().getPreferenceStore(); String[] tapsets = preferenceStore.getString(IDEPreferenceConstants.P_TAPSETS).split(File.pathSeparator); //Get all imported tapsets - if(tapsets.length > 0 && tapsets[0].trim().length() > 0) { - for(int i=0; i<tapsets.length; i++) { + if (tapsets.length > 0 && tapsets[0].trim().length() > 0) { + for (int i = 0; i < tapsets.length; i++) { cmdList.add("-I"); //$NON-NLS-1$ cmdList.add(tapsets[i]); } @@ -410,40 +348,39 @@ public class RunScriptHandler extends AbstractHandler { * by the presence of embedded C. * @return True if the script contains embedded C code. */ - private boolean isGuru() { + private boolean isGuru() throws ExecutionException { File f = new File(fileName); - try (FileReader fr = new FileReader(f)){ + try (FileReader fr = new FileReader(f)) { int curr = 0; int prev = 0; boolean front = false; - boolean imbedded = false; + boolean embedded = false; boolean inLineComment = false; boolean inBlockComment = false; - while(-1 != (curr = fr.read())) { - if(!inLineComment && !inBlockComment && '%' == prev && '{' == curr) { + while (-1 != (curr = fr.read())) { + if (!inLineComment && !inBlockComment && prev == '%' && curr == '{') { front = true; - } else if(!inLineComment && !inBlockComment && '%' == prev && '}' == curr && front) { - imbedded = true; + } else if (!inLineComment && !inBlockComment && prev == '%' && curr == '}' && front) { + embedded = true; break; - } else if(!inBlockComment && (('/' == prev && '/' == curr) || '#' == curr)) { + } else if (!inBlockComment && ((prev == '/' && curr == '/') || curr == '#')) { inLineComment = true; - } else if(!inLineComment && '/' == prev && '*' == curr) { + } else if (!inLineComment && prev == '/' && curr == '*') { inBlockComment = true; - } else if('\n' == curr) { + } else if (curr == '\n') { inLineComment = false; - } else if('*' == prev && '/' == curr) { + } else if (prev == '*' && curr == '/') { inBlockComment = false; } prev = curr; } - fr.close(); - if(imbedded) { + if (embedded) { return true; } } catch (FileNotFoundException fnfe) { - ExceptionErrorDialog.openError(Localization.getString("RunScriptHandler.couldNotOpenScriptFile"), fnfe); //$NON-NLS-1$ + throw new ExecutionException(Localization.getString("RunScriptHandler.couldNotOpenScriptFile"), fnfe); //$NON-NLS-1$ } catch (IOException ie) { - ExceptionErrorDialog.openError(Localization.getString("RunScriptHandler.fileIOError"), ie); //$NON-NLS-1$ + throw new ExecutionException(Localization.getString("RunScriptHandler.fileIOError"), ie); //$NON-NLS-1$ } return false; } @@ -453,39 +390,21 @@ public class RunScriptHandler extends AbstractHandler { * as the first entry, and the filename as the last entry. Used to convert the arguments generated * earlier in <code>buildStandardScript</code> such as tapset locations and guru mode into an actual * command line argument array that can be passed to <code>Runtime.exec</code>. - * @param cmdList The list of arguments for stap for this script * @return An array suitable to pass to <code>Runtime.exec</code> to start stap on this file. * @since 2.0 */ - private String[] finalizeScript(List<String> cmdList) { - - String[] script; - - script = new String[cmdList.size() + 4]; - script[0] = "stap"; //$NON-NLS-1$ - - if(getRunLocal() == false) { - script[script.length-1] = tmpfileName; - } else { - script[script.length-1] = fileName; - } - - for(int i=0; i< cmdList.size(); i++) { - script[i+1] = cmdList.get(i); - } - script[script.length-3]="-m"; //$NON-NLS-1$ - + private String[] finalizeScript() throws ExecutionException { + boolean local = getRunLocal(); String modname; - if(getRunLocal() == false) { - modname = serverfileName.substring(0, serverfileName.lastIndexOf(".stp")); //$NON-NLS-1$ + if (!local) { + modname = getFileNameWithoutExtension(serverfileName); } /* We need to remove the directory prefix here because in the case of * running the script remotely, this is already done. Not doing so * causes a modname error. */ else { - modname = fileName.substring(fileName.lastIndexOf('/')+1); - modname = modname.substring(0, modname.lastIndexOf(".stp")); //$NON-NLS-1$ + modname = getFileNameWithoutExtension(getFileName(fileName)); } // Make sure script name only contains underscores and/or alphanumeric characters. @@ -493,54 +412,36 @@ public class RunScriptHandler extends AbstractHandler { Matcher modNameMatch = validModName.matcher(modname); if (!modNameMatch.matches()) { continueRun = false; - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - - Shell parent = PlatformUI.getWorkbench().getDisplay() - .getActiveShell(); - MessageDialog.openError(parent, - Messages.ScriptRunAction_InvalidScriptTitle, - Messages.ScriptRunAction_InvalidScriptTMessage); - } - }); - return new String[0]; + throw new ExecutionException(Messages.ScriptRunAction_InvalidScriptMessage); } - script[script.length-2]=modname; - return script; - } + String[] script = new String[cmdList.size() + 4]; + script[0] = "stap"; //$NON-NLS-1$ + script[script.length - 1] = !local ? tmpfileName : fileName; - @Override - public boolean isEnabled() { - return (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() instanceof STPEditor); - } + for (int i = 0; i < cmdList.size(); i++) { + script[i + 1] = cmdList.get(i); + } + script[script.length - 3] = "-m"; //$NON-NLS-1$ - /** - * Set the options for running the script remotely. If the script is to be run locally, - * pass <code>null</code> as the only parameter. - * @param remoteOptions The remote options of the script run, or <code>null</code> if the script - * is to be run locally. - * @since 3.0 - */ - public void setRemoteScriptOptions(RemoteScriptOptions remoteOptions) { - this.remoteOptions = remoteOptions; + script[script.length - 2] = modname; + return script; } - private boolean getRunLocal() { - return remoteOptions == null; + private String getFileNameWithoutExtension(String fileName) { + int dotIndex = fileName.lastIndexOf('.'); + return dotIndex != -1 ? fileName.substring(0, dotIndex) : fileName; } - @Override - public void addHandlerListener(IHandlerListener handlerListener) { - // TODO Auto-generated method stub - + private String[] getEnvironmentVariables() { + String[] envVars = EnvironmentVariablesPreferencePage.getEnvironmentVariables(); + // TODO update these with vals? If project is null & PATH not set? + return envVars; } @Override - public void removeHandlerListener(IHandlerListener handlerListener) { - // TODO Auto-generated method stub - + public boolean isEnabled() { + return (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() instanceof STPEditor); } } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/messages.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/messages.properties index cc81c654d6..a4e4312444 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/messages.properties +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/messages.properties @@ -10,7 +10,7 @@ ############################################################################### ScriptRunAction_InvalidScriptTitle=Invalid Script Name -ScriptRunAction_InvalidScriptTMessage=Script name must only contain characters 'a'-'z','A'-'Z', '0'-'9' and '_' +ScriptRunAction_InvalidScriptMessage=Script name must only contain characters 'a'-'z','A'-'Z', '0'-'9' and '_' ScriptRunAction_errorDialogTitle=Unable to open editor RunScriptAction_alreadyRunningDialogTitle=Script Already Running diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/AddStapProbeHandler.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/AddStapProbeHandler.java index 1f92e17abd..0d0cc88c6b 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/AddStapProbeHandler.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/AddStapProbeHandler.java @@ -31,6 +31,9 @@ public class AddStapProbeHandler extends AbstractHandler { try { editor = (ITextEditor) HandlerUtil.getActiveEditor(event); } catch (ClassCastException e) { + ExceptionErrorDialog.openError( + Messages.AddStapProbe_unableToInsertProbe, + Messages.AddStapProbe_editorError, e); throw new ExecutionException(Messages.AddStapProbe_editorError, e); } IVerticalRulerInfo rulerInfo = (IVerticalRulerInfo) editor.getAdapter(IVerticalRulerInfo.class); @@ -92,10 +95,10 @@ public class AddStapProbeHandler extends AbstractHandler { } } catch (BadLocationException excp) { ExceptionErrorDialog.openError(Messages.AddStapProbe_unableToInsertProbe, excp); + return null; } if (die) { - MessageDialog - .openError( + MessageDialog.openError( PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getShell(), @@ -119,7 +122,7 @@ public class AddStapProbeHandler extends AbstractHandler { sb.append("\n{\n\t\n}\n"); //$NON-NLS-1$ STPEditor activeSTPEditor = IDESessionSettings.getOrAskForActiveSTPEditor(false); - if (null != activeSTPEditor) { + if (activeSTPEditor != null) { activeSTPEditor.insertText(sb.toString()); } } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java index 4b325e5e3f..d0b2977767 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptGraphOptionsTab.java @@ -857,7 +857,7 @@ public class SystemTapScriptGraphOptionsTab extends GraphData gd = wizard.getGraphData(); - if (null != gd) { + if (gd != null) { TableItem item = new TableItem(graphsTable, SWT.NONE); graphsData.add(gd); setUpGraphTableItem(item, gd, false); @@ -870,7 +870,7 @@ public class SystemTapScriptGraphOptionsTab extends duplicateGraphButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - GraphData gd = ((GraphData) selectedTableItem.getData()).clone(); + GraphData gd = ((GraphData) selectedTableItem.getData()).getCopy(); TableItem item = new TableItem(graphsTable, SWT.NONE); graphsData.add(gd); @@ -900,11 +900,11 @@ public class SystemTapScriptGraphOptionsTab extends dialog.open(); GraphData gd = wizard.getGraphData(); - if (null == gd) { + if (gd == null) { return; } GraphData old_gd = (GraphData) selectedTableItem.getData(); - if (!gd.equals(old_gd)) { + if (!gd.isCopyOf(old_gd)) { badGraphs.remove(old_gd); setUpGraphTableItem(selectedTableItem, gd, false); graphsData.set(graphsTable.indexOf(selectedTableItem), gd); diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationDelegate.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationDelegate.java index 8f95f5c435..1f40271e80 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationDelegate.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationDelegate.java @@ -44,6 +44,7 @@ import org.eclipse.linuxtools.systemtap.ui.consolelog.structures.RemoteScriptOpt public class SystemTapScriptLaunchConfigurationDelegate extends LaunchConfigurationDelegate { + private static String LOCALHOST = "localhost"; //$NON-NLS-1$ static final String CONFIGURATION_TYPE = "org.eclipse.linuxtools.systemtap.ui.ide.SystemTapLaunchConfigurationType"; //$NON-NLS-1$ private IProject[] scriptProject; @@ -108,13 +109,13 @@ public class SystemTapScriptLaunchConfigurationDelegate extends // If runWithChart is true there must be at least one graph, but this isn't guaranteed // to be true for outdated Launch Configurations. So for safety, make sure there are graphs. int numGraphs = configuration.getAttribute(SystemTapScriptGraphOptionsTab.NUMBER_OF_REGEXS, 0); - if (runWithChart && numGraphs > 0){ + if (runWithChart && numGraphs > 0) { List<IDataSetParser> parsers = SystemTapScriptGraphOptionsTab.createDatasetParsers(configuration); List<IFilteredDataSet> dataSets = SystemTapScriptGraphOptionsTab.createDataset(configuration); List<String> names = SystemTapScriptGraphOptionsTab.createDatasetNames(configuration); List<LinkedList<GraphData>> graphs = SystemTapScriptGraphOptionsTab.createGraphsFromConfiguration(configuration); action = new RunScriptChartHandler(parsers, dataSets, names, graphs); - }else{ + } else { action = new RunScriptHandler(); } @@ -132,38 +133,38 @@ public class SystemTapScriptLaunchConfigurationDelegate extends action.setPath(scriptPath); // Run locally and/or as current user. - boolean runAsCurrentUser = configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.CURRENT_USER_ATTR, true); - boolean runLocal = configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.LOCAL_HOST_ATTR, true); - - action.setRemoteScriptOptions(runLocal && runAsCurrentUser ? null : new RemoteScriptOptions( + action.setRemoteScriptOptions( + configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.CURRENT_USER_ATTR, true) ? null + : new RemoteScriptOptions( configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.USER_NAME_ATTR, ""), //$NON-NLS-1$ configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.USER_PASS_ATTR, ""), //$NON-NLS-1$ - configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.HOST_NAME_ATTR, "localhost"))); //$NON-NLS-1$ + configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.LOCAL_HOST_ATTR, true) ? LOCALHOST : + configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.HOST_NAME_ATTR, LOCALHOST))); String value = configuration.getAttribute(IDEPreferenceConstants.STAP_CMD_OPTION[IDEPreferenceConstants.KEY], ""); //$NON-NLS-1$ - if (!value.isEmpty()){ + if (!value.isEmpty()) { action.addComandLineOptions(IDEPreferenceConstants.STAP_CMD_OPTION[IDEPreferenceConstants.FLAG] + " " + value); //$NON-NLS-1$ } // Add command line options - for(int i=0; i<IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS.length; i++) { + for (int i = 0; i < IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS.length; i++) { boolean flag = configuration.getAttribute( IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.KEY], false); - if (flag){ + if (flag) { action.addComandLineOptions(IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.FLAG]); } } - for(int i=0; i<IDEPreferenceConstants.STAP_STRING_OPTIONS.length; i++) { + for (int i = 0; i < IDEPreferenceConstants.STAP_STRING_OPTIONS.length; i++) { value = configuration.getAttribute(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.KEY],""); //$NON-NLS-1$ - if (!value.isEmpty()){ + if (!value.isEmpty()) { action.addComandLineOptions(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.FLAG] + " " + value); //$NON-NLS-1$ } } value = configuration.getAttribute(SystemTapScriptOptionsTab.MISC_COMMANDLINE_OPTIONS,""); //$NON-NLS-1$ - if (!value.isEmpty()){ + if (!value.isEmpty()) { action.addComandLineOptions(value); } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationTab.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationTab.java index 5640440fdb..8c612f2a88 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationTab.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationTab.java @@ -62,6 +62,7 @@ public class SystemTapScriptLaunchConfigurationTab extends private Text userNameText; private Text userPasswordText; private Button localHostCheckButton; + private Group hostSettingsGroup; private Text hostNameText; private Label userNameLabel; private Label userPasswordLabel; @@ -115,7 +116,7 @@ public class SystemTapScriptLaunchConfigurationTab extends @Override public void widgetSelected(SelectionEvent e) { String path = fileDialog.open(); - if (path != null){ + if (path != null) { scriptPathText.setText(path); } } @@ -163,7 +164,7 @@ public class SystemTapScriptLaunchConfigurationTab extends update(); } - private void update(){ + private void update() { boolean enable = !currentUserCheckButton.getSelection(); setUserGroupEnablement(enable); updateLaunchConfigurationDialog(); @@ -184,10 +185,8 @@ public class SystemTapScriptLaunchConfigurationTab extends } }); - setUserGroupEnablement(false); - // Host settings - Group hostSettingsGroup = new Group(top, SWT.SHADOW_ETCHED_IN); + hostSettingsGroup = new Group(top, SWT.SHADOW_ETCHED_IN); hostSettingsGroup.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, false)); hostSettingsGroup.setText(Messages.SystemTapScriptLaunchConfigurationTab_host); layout = new GridLayout(); @@ -215,7 +214,7 @@ public class SystemTapScriptLaunchConfigurationTab extends update(); } - private void update(){ + private void update() { updateLaunchConfigurationDialog(); } }); @@ -227,14 +226,17 @@ public class SystemTapScriptLaunchConfigurationTab extends }); } - private void setUserGroupEnablement(boolean enable){ + private void setUserGroupEnablement(boolean enable) { userNameText.setEnabled(enable); userNameLabel.setEnabled(enable); userPasswordText.setEnabled(enable); userPasswordLabel.setEnabled(enable); + + hostSettingsGroup.setEnabled(enable); + localHostCheckButton.setEnabled(enable); } - private void setHostGroupEnablement(boolean enable){ + private void setHostGroupEnablement(boolean enable) { hostNamelabel.setEnabled(enable); hostNameText.setEnabled(enable); } @@ -275,7 +277,7 @@ public class SystemTapScriptLaunchConfigurationTab extends boolean enable = !currentUserCheckButton.getSelection(); setUserGroupEnablement(enable); - enable = !localHostCheckButton.getSelection(); + enable &= !localHostCheckButton.getSelection(); setHostGroupEnablement(enable); } @@ -302,7 +304,7 @@ public class SystemTapScriptLaunchConfigurationTab extends return Messages.SystemTapScriptLaunchConfigurationTab_general; } - private String getSelectedScriptPath(){ + private String getSelectedScriptPath() { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); String pathString = ""; //$NON-NLS-1$ @@ -312,7 +314,7 @@ public class SystemTapScriptLaunchConfigurationTab extends ISelection selection = window.getSelectionService().getSelection(); // Figure out the selected systemtap script - if (selection instanceof TreeSelection){ + if (selection instanceof TreeSelection) { Object selectedElement = ((TreeSelection)selection).getFirstElement(); if (selectedElement instanceof IFile) { @@ -322,7 +324,7 @@ public class SystemTapScriptLaunchConfigurationTab extends } // If it is a text selection use the path from the active editor. - if (selection instanceof TextSelection){ + if (selection instanceof TextSelection) { IEditorPart ed = window.getActivePage().getActiveEditor(); if(ed.getEditorInput() instanceof PathEditorInput) { pathString = ((PathEditorInput)ed.getEditorInput()).getPath().toString(); diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/localization.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/localization.properties index dcece1c435..f1f822d9c1 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/localization.properties +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/localization.properties @@ -1,11 +1,9 @@ -AddStapProbe.UnableToInsertProbe=Unable to Insert Probe -RunScriptAction.NoScriptFile=No Script File\! -RunScriptAction.Problem=Problem -RunScriptAction.TapsetDirectoryRun=Can not run files in tapset directory\! -RunScriptAction.Error=Error +RunScriptAction.NoScriptFile=No script file found. +RunScriptAction.TapsetDirectoryRun=Scripts in tapset directories cannot be run. +RunScriptHandler.Error=Error +RunScriptHandler.ErrorMessage=The script file could not be run. RunScriptHandler.couldNotOpenScriptFile=Could not open script file. -RunScriptHandler.serverError=Error Connecting To Server -RunScriptHandler.checkCredentials=Please check the supplied username, password and server address. +RunScriptHandler.checkCredentials=Error connecting to server. Please check the supplied username, password and server address. RunScriptHandler.ioError=IO Error with remote server. RunScriptHandler.fileIOError=Error reading script file. diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/preferences/EnvironmentVariablesPreferencePage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/preferences/EnvironmentVariablesPreferencePage.java index c5f1af46e2..6cdc93774e 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/preferences/EnvironmentVariablesPreferencePage.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/preferences/EnvironmentVariablesPreferencePage.java @@ -28,6 +28,8 @@ import org.eclipse.ui.IWorkbenchPreferencePage; public class EnvironmentVariablesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + private static StringFieldEditor[] envVariables; + /** * Set the description of the page. */ @@ -58,7 +60,7 @@ public class EnvironmentVariablesPreferencePage extends PreferencePage implement sc.setContent(c); envVariables = new StringFieldEditor[PreferenceConstants.P_ENV.length]; - for(int i=0; i<envVariables.length; i++) { + for (int i = 0; i < envVariables.length; i++) { envVariables[i] = createStringFieldEditor(PreferenceConstants.P_ENV[i][0], PreferenceConstants.P_ENV[i][1], c); } @@ -120,18 +122,18 @@ public class EnvironmentVariablesPreferencePage extends PreferencePage implement String var; int i; - if(null == IDEPlugin.getDefault() || null == IDEPlugin.getDefault().getPreferenceStore()) { + if (IDEPlugin.getDefault() == null || IDEPlugin.getDefault().getPreferenceStore() == null) { return null; } IPreferenceStore p = IDEPlugin.getDefault().getPreferenceStore(); - for(i=0; i<PreferenceConstants.P_ENV.length; i++) { + for (i = 0; i < PreferenceConstants.P_ENV.length; i++) { var = p.getString(PreferenceConstants.P_ENV[i][0]).trim(); - if(!var.isEmpty()) { - vars.add(PreferenceConstants.P_ENV[i][0] + "=" + var); //$NON-NLS-1$ + if (!var.isEmpty()) { + vars.add(PreferenceConstants.P_ENV[i][1] + "=" + var); //$NON-NLS-1$ } } - if(vars.size() > 0) { + if (vars.size() > 0) { envVars = new String[vars.size()]; for (i = 0; i < vars.size(); i++) { envVars[i] = vars.get(i); @@ -148,12 +150,10 @@ public class EnvironmentVariablesPreferencePage extends PreferencePage implement public void dispose() { super.dispose(); - for(int i=0; i<envVariables.length; i++) { + for (int i = 0; i < envVariables.length; i++) { envVariables[i].dispose(); envVariables[i] = null; } envVariables = null; } - - private static StringFieldEditor[] envVariables; } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java index c89c9857ff..a7c2f48d8b 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java @@ -204,17 +204,14 @@ public final class TapsetLibrary { String[] tapsets = p.getString(IDEPreferenceConstants.P_TAPSETS).split(File.pathSeparator); File f = getTapsetLocation(p); - - if (!checkIsCurrentFolder(treesDate, f)) { + if (f == null || !checkIsCurrentFolder(treesDate, f)) { return false; } - for(int i=0; i<tapsets.length; i++) { + for (int i = 0; i < tapsets.length; i++) { f = new File(tapsets[i]); - if (f.lastModified() > treesDate) { - return false; - } - if (f.canRead() && !checkIsCurrentFolder(treesDate, f)) { + if (!f.exists() || f.lastModified() > treesDate + || f.canRead() && !checkIsCurrentFolder(treesDate, f)) { return false; } } @@ -229,24 +226,27 @@ public final class TapsetLibrary { public static File getTapsetLocation(IPreferenceStore p) { File f; String path = p.getString(PreferenceConstants.P_ENV[2][0]); - if(path.trim().isEmpty()) { + if (path.trim().isEmpty()) { f = new File("/usr/share/systemtap/tapset"); //$NON-NLS-1$ - if(!f.exists()) { + if (!f.exists()) { f = new File("/usr/local/share/systemtap/tapset"); //$NON-NLS-1$ - if(!f.exists()) { + if (!f.exists()) { InputDialog i = new InputDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Localization.getString("TapsetBrowserView.TapsetLocation"), Localization.getString("TapsetBrowserView.WhereDefaultTapset"), "", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ i.open(); p.setValue(PreferenceConstants.P_ENV[2][0], i.getValue()); - f = new File( i.getValue() ); + f = new File(i.getValue()); } } } else { - f = new File( p.getString(path) ); + f = new File(path); + } + if (f.exists()) { + IDESessionSettings.tapsetLocation = f.getAbsolutePath(); + return f; } - IDESessionSettings.tapsetLocation = f.getAbsolutePath(); - return f; + return null; } /** @@ -259,7 +259,7 @@ public final class TapsetLibrary { private static boolean checkIsCurrentFolder(long time, File folder) { File[] fs = folder.listFiles(); - for(int i=0; i<fs.length; i++) { + for (int i = 0; i < fs.length; i++) { if (fs[i].lastModified() > time) { return false; } |