Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferrazzutti2013-11-28 14:17:22 -0500
committerAndrew Ferrazzutti2013-12-02 15:30:01 -0500
commitb22b69aa6928a79167cbd3ff35b5a68b44a54105 (patch)
tree676dc7879545c7ce1a58262e970f36483f7e1881
parentfb6e8ebf97723eaaad2fba255febcbe33c9f5fab (diff)
downloadorg.eclipse.linuxtools-b22b69aa6928a79167cbd3ff35b5a68b44a54105.tar.gz
org.eclipse.linuxtools-b22b69aa6928a79167cbd3ff35b5a68b44a54105.tar.xz
org.eclipse.linuxtools-b22b69aa6928a79167cbd3ff35b5a68b44a54105.zip
Systemtap: Pre-run autosave for projectless scripts.
When a Systemtap script that lacks a parent project is run, have that script be immediately saved before the run begins. This adds to the functionality of fa6613e, which only saves scripts that belong to a project. This improvement also fixes a bug introduced in that patch which caused a NullPointerException when running a projectless script. This patch also fixes a bug in fa6613e that allowed non-*.stp files to be run as Systemtap scripts. Change-Id: Ib0cc475e882ad9775fdaca44b1119089ca65638c Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com> Reviewed-on: https://git.eclipse.org/r/19084 Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com> Reviewed-on: https://git.eclipse.org/r/19159 Tested-by: Hudson CI
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml17
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptHandler.java85
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationDelegate.java7
3 files changed, 86 insertions, 23 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml
index 7f7325e51d..e18337135f 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml
@@ -333,12 +333,17 @@
value="*.stp">
</test>
</and>
- <with
- variable="activeEditorId">
- <equals
- value="org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor">
- </equals>
- </with>
+ <and>
+ <instanceof
+ value="org.eclipse.ui.IPathEditorInput">
+ </instanceof>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor">
+ </equals>
+ </with>
+ </and>
</or>
</iterate>
</with>
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 a8a31adb34..3d7b8f81eb 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
@@ -45,10 +45,14 @@ import org.eclipse.linuxtools.systemtap.ui.systemtapgui.preferences.EnvironmentV
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.ResourceUtil;
-
import com.jcraft.jsch.JSchException;
/**
@@ -67,6 +71,8 @@ public class RunScriptHandler extends AbstractHandler {
*/
protected boolean continueRun = true;
private boolean runLocal = true;
+ private IEditorPart ed = null;
+ private Shell shell = null;
private String fileName = null;
private String tmpfileName = null;
private String serverfileName = null;
@@ -86,13 +92,60 @@ public class RunScriptHandler extends AbstractHandler {
}
/**
+ * 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).
+ */
+ private void findTargetEditor() {
+ ed = null;
+ shell = null;
+
+ if (path == null) {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ed = window.getActivePage().getActiveEditor();
+ shell = window.getShell();
+ return;
+ }
+
+ for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
+ IEditorPart ed_test = window.getActivePage().getActiveEditor();
+ if (matchesEditor(ed_test.getEditorInput(), ed_test, window.getShell())) {
+ return;
+ }
+ for (IEditorReference ref : window.getActivePage().getEditorReferences()) {
+ try {
+ if (matchesEditor(ref.getEditorInput(), ref.getEditor(false), window.getShell())) {
+ return;
+ }
+ } catch (PartInitException e) {
+ continue;
+ }
+ }
+ }
+ }
+
+ private boolean matchesEditor(IEditorInput input, IEditorPart editor, Shell shell) {
+ 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;
+ this.shell = shell;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
* The main body of this event. Starts by making sure the current editor is valid to run,
* then builds the command line arguments for stap and retrieves the environment variables.
* Finally, it gets an instance of <code>ScriptConsole</code> to run the script.
*/
@Override
public Object execute(ExecutionEvent event){
-
+ findTargetEditor();
if(isValid()) {
if(getRunLocal() == false) {
try{
@@ -156,7 +209,9 @@ public class RunScriptHandler extends AbstractHandler {
if (path != null){
return path.toOSString();
}
- IEditorPart ed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if (ed == null) {
+ return ""; //$NON-NLS-1$
+ }
if(ed.getEditorInput() instanceof PathEditorInput){
return ((PathEditorInput)ed.getEditorInput()).getPath().toString();
} else {
@@ -172,26 +227,30 @@ public class RunScriptHandler extends AbstractHandler {
private boolean isValid() {
// If the path is not set this action will run the script from
// the active editor
- if (this.path == null){
- IEditorPart ed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if(!isValidEditor(ed)){
+ if(!tryEditorSave()){
+ if (this.path == null){
+ 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$
return false;
}
}
-
- return this.getFilePath().endsWith(".stp") //$NON-NLS-1$
- && isValidDirectory(this.getFilePath());
+ String filePath = this.getFilePath();
+ return filePath.endsWith(".stp") //$NON-NLS-1$
+ && isValidDirectory(filePath);
}
- private boolean isValidEditor(IEditorPart ed) {
+ private boolean tryEditorSave() {
if(null == ed) {
- 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$
return false;
}
if(ed.isDirty()) {
- ed.doSave(new ProgressMonitorPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new FillLayout()));
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ ed.doSave(new ProgressMonitorPart(shell, new FillLayout()));
+ }
+ });
}
return true;
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 3915d68b81..4101453916 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
@@ -39,7 +39,7 @@ public class SystemTapScriptLaunchConfigurationDelegate extends
static final String CONFIGURATION_TYPE = "org.eclipse.linuxtools.systemtap.ui.ide.SystemTapLaunchConfigurationType"; //$NON-NLS-1$
- private IProject[] scriptProject = new IProject[1];
+ private IProject[] scriptProject;
/**
* Keep a reference to the target running script's parent project, so only that project
@@ -55,11 +55,10 @@ public class SystemTapScriptLaunchConfigurationDelegate extends
// Find the parent project of the target script.
IPath path = Path.fromOSString(configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.SCRIPT_PATH_ATTR, (String)null));
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
- IProject project = file == null ? null : file.getProject();
+ scriptProject = file == null ? null : new IProject[]{file.getProject()};
// Only save the target script's project if a project is found.
- if (project != null) {
- scriptProject[0] = project;
+ if (scriptProject != null) {
return super.preLaunchCheck(configuration, mode, monitor);
}
return true;

Back to the top