diff options
author | Sami Wagiaalla | 2012-10-10 16:04:46 +0000 |
---|---|---|
committer | Roland Grunberg | 2012-10-22 18:01:27 +0000 |
commit | aa8b9a164095235ec4840ac34c4401bf4ee8f25d (patch) | |
tree | ca0b35295972eb251d4e517de57775c4230737d0 /systemtap/org.eclipse.linuxtools.systemtap.ui.ide | |
parent | 11410d07625ea5eaa4d56dc3cbebf32252e0ea96 (diff) | |
download | org.eclipse.linuxtools-aa8b9a164095235ec4840ac34c4401bf4ee8f25d.tar.gz org.eclipse.linuxtools-aa8b9a164095235ec4840ac34c4401bf4ee8f25d.tar.xz org.eclipse.linuxtools-aa8b9a164095235ec4840ac34c4401bf4ee8f25d.zip |
Create a Launch Shortuct for SystemTap scripts
This enables running SystemTap scripts through 'Run As'
from the context menu.
Change-Id: I57d4470f346c46f322fef4e61c33861de955ad59
Reviewed-on: https://git.eclipse.org/r/8148
Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
IP-Clean: Roland Grunberg <rgrunber@redhat.com>
Tested-by: Roland Grunberg <rgrunber@redhat.com>
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.ide')
6 files changed, 180 insertions, 3 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/META-INF/MANIFEST.MF b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/META-INF/MANIFEST.MF index 042494e595..a7cd4183e7 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/META-INF/MANIFEST.MF +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/META-INF/MANIFEST.MF @@ -18,7 +18,9 @@ Require-Bundle: org.eclipse.linuxtools.systemtap.ui.logging, org.eclipse.linuxtools.systemtap.ui.structures, org.eclipse.core.resources;bundle-version="3.4.1", org.eclipse.linuxtools.profiling.launch;bundle-version="0.11.0", - org.eclipse.ui.ide + org.eclipse.ui.ide, + org.eclipse.debug.ui;bundle-version="3.8.0", + org.eclipse.core.expressions;bundle-version="3.4.400" Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.core.filesystem, org.eclipse.linuxtools.systemtap.ui.structures, diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml index 4ada4bc457..7da709bf84 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml @@ -281,4 +281,37 @@ name="%wizard.name"> </wizard> </extension> + <extension + point="org.eclipse.debug.ui.launchShortcuts"> + <shortcut + class="org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher.SystemTapScriptLaunchShortcut" + id="org.eclipse.linuxtools.systemtap.ui.ide.StapLaunchShortcut" + label="Systemtap Script" + modes="run"> + <contextualLaunch> + <enablement> + <with + variable="selection"> + <count + value="1"> + </count> + <test + forcePluginActivation="true" + property="org.eclipse.linuxtools.systemtap.ui.ide.property.systemtap"> + </test> + </with> + </enablement> + </contextualLaunch> + </shortcut> + </extension> + <extension + point="org.eclipse.core.expressions.propertyTesters"> + <propertyTester + class="org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher.SystemTapScriptTester" + id="org.eclipse.linuxtools.systemtap.ui.ide.propertyTester1" + namespace="org.eclipse.linuxtools.systemtap.ui.ide.property" + properties="systemtap" + type="java.util.Arrays$ArrayList"> + </propertyTester> + </extension> </plugin> diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptByPathAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptByPathAction.java new file mode 100644 index 0000000000..3d2a152c1f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/actions/RunScriptByPathAction.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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: + * Sami Wagiaalla + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.systemtap.ui.ide.actions; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher.SystemTapScriptTester; +import org.eclipse.linuxtools.systemtap.ui.ide.actions.RunScriptAction; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * This is a child of {@link RunScriptAction} which alloes callers to run a + * script by only passing in the path to the script. An active editor is not + * needed + * + * @author Sami Wagiaalla + * + */ +public class RunScriptByPathAction extends RunScriptAction { + + IPath path; + + public void init(IWorkbenchWindow window, IPath path) { + super.init(window); + this.path = path; + } + + @Override + protected boolean isValid() { + return this.getFilePath().endsWith(SystemTapScriptTester.STP_SUFFIX) + && isValidDirectory(this.getFilePath()); + } + + @Override + protected String getFilePath() { + return this.path.toOSString(); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchShortcut.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchShortcut.java new file mode 100644 index 0000000000..cd78eea2bf --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchShortcut.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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: + * Sami Wagiaalla + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IPath; +import org.eclipse.debug.ui.ILaunchShortcut; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.linuxtools.internal.systemtap.ui.ide.actions.RunScriptByPathAction; +import org.eclipse.linuxtools.systemtap.ui.ide.actions.RunScriptAction; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PlatformUI; + +public class SystemTapScriptLaunchShortcut implements ILaunchShortcut { + + public void launch(IEditorPart editor, String mode) { + RunScriptAction action = new RunScriptAction(); + action.init(editor.getSite().getWorkbenchWindow()); + action.run(); + } + + public void launch(ISelection selection, String mode) { + RunScriptByPathAction action = new RunScriptByPathAction(); + IPath path = ((IFile)((TreeSelection)selection).getFirstElement()).getLocation(); + action.init(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), path); + action.run(); + } + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptTester.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptTester.java new file mode 100644 index 0000000000..253c47e40c --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptTester.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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: + * Sami Wagiaalla + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher; + +import java.util.AbstractList; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IFile; +import org.eclipse.linuxtools.systemtap.ui.editor.PathEditorInput; +import org.eclipse.ui.part.FileEditorInput; + +public class SystemTapScriptTester extends PropertyTester { + + public static final String STP_SUFFIX = ".stp"; + + public SystemTapScriptTester() { + // TODO Auto-generated constructor stub + } + + public boolean test(Object receiver, String property, Object[] args, + Object expectedValue) { + + @SuppressWarnings("unchecked") + AbstractList<Object> list = (AbstractList<Object>) receiver; + Object selectedObject = list.get(0); + + if (selectedObject instanceof FileEditorInput){ + return ((FileEditorInput) selectedObject).getPath().toString().endsWith(STP_SUFFIX); + } + + if (selectedObject instanceof IFile){ + return ((IFile)selectedObject).getName().endsWith(STP_SUFFIX); + } + + if (selectedObject instanceof PathEditorInput){ + return ((PathEditorInput)selectedObject).getPath().toString().endsWith(STP_SUFFIX); + } + + return false; + } + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptAction.java index 822c27e826..89356145eb 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptAction.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptAction.java @@ -156,8 +156,17 @@ public class RunScriptAction extends Action implements IWorkbenchWindowActionDel return true; } - - private boolean isValidDirectory(String fileName) { + + /** + * Checks whether the directory to which the given file + * belongs is a valid directory. Currently this function just + * checks if the given file does not belong to the tapset + * directory. + * @param fileName + * @return true if the given path is valid false otherwise. + * @since 1.2 + */ + protected boolean isValidDirectory(String fileName) { this.fileName = fileName; if(0 == IDESessionSettings.tapsetLocation.trim().length()) TapsetLibrary.getTapsetLocation(IDEPlugin.getDefault().getPreferenceStore()); |