summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorLukas Berk2012-10-03 13:02:37 (EDT)
committer Sami Wagiaalla2012-10-04 15:52:55 (EDT)
commit0cd2c8f4a2cbe2f9459daeb780d6a966e457afdc (patch)
treee2cb894e8084a99ce81b421d602fa170434ded14
parentd0b6cedf6155f870b206a1dcdafa5c9044b5512f (diff)
downloadorg.eclipse.linuxtools-0cd2c8f4a2cbe2f9459daeb780d6a966e457afdc.zip
org.eclipse.linuxtools-0cd2c8f4a2cbe2f9459daeb780d6a966e457afdc.tar.gz
org.eclipse.linuxtools-0cd2c8f4a2cbe2f9459daeb780d6a966e457afdc.tar.bz2
Add new Systemtap Wizard for new scripts
This patch adds the initial systemtap wizard implementation. The manifest and plugin.xml file have been modified for this extention. The use is prompted for script name (must end in .stp) and can broswer to their desired folder. '#!/usr/bin/env stap' is applied automatically to the beginning of the new file and the proper perspective is automatically shown. Strings have been externalized as required. Change-Id: I46414863af975f2299e22ba112c216b11f47ade7 Reviewed-on: https://git.eclipse.org/r/8039 Tested-by: Hudson CI Reviewed-by: Sami Wagiaalla <swagiaal@redhat.com> IP-Clean: Sami Wagiaalla <swagiaal@redhat.com> Tested-by: Sami Wagiaalla <swagiaal@redhat.com>
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/messages.properties2
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/META-INF/MANIFEST.MF7
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/icons/smileytap.gifbin0 -> 19046 bytes
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml14
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizard.java152
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizardPage.java196
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/stap_strings.properties17
7 files changed, 386 insertions, 2 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/messages.properties b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/messages.properties
index 0366697..8e17300 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/messages.properties
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/messages.properties
@@ -8,4 +8,4 @@ ProfileLaunchShortcut.no_project_selected=Launch failed no project selected
ProfileLaunchShortcut.Profile=Profile
ProfileLaunchShortcut.Qualifier=Qualifer:
ProfileLaunchShortcut.Launcher=Profiling Launcher
-RemoteProxyManager_unrecognized_scheme=Unrecognized scheme:
+RemoteProxyManager_unrecognized_scheme=Unrecognized scheme: \ No newline at end of file
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 e5a1ad2..3afd7c4 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
@@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.linuxtools.systemtap.ui.logging,
org.eclipse.linuxtools.systemtap.ui.consolelog,
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.linuxtools.profiling.launch;bundle-version="0.11.0",
+ org.eclipse.ui.ide
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.core.filesystem,
org.eclipse.linuxtools.systemtap.ui.structures,
@@ -25,6 +26,10 @@ Import-Package: org.eclipse.core.filesystem,
org.eclipse.linuxtools.systemtap.ui.structures.runnable,
org.eclipse.linuxtools.systemtap.ui.structures.ui,
org.eclipse.linuxtools.systemtap.ui.structures.validators,
+ org.eclipse.linuxtools.tmf.core,
+ org.eclipse.linuxtools.tmf.ui.project.wizards,
+ org.eclipse.ui,
+ org.eclipse.ui.dialogs,
org.eclipse.ui.ide,
org.eclipse.ui.part
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/icons/smileytap.gif b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/icons/smileytap.gif
new file mode 100644
index 0000000..0e9b263
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/icons/smileytap.gif
Binary files differ
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml
index 575c4fa..4ada4bc 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/plugin.xml
@@ -267,4 +267,18 @@
<actionSet id="org.eclipse.linuxtools.systemtap.ui.ide.RunActionSet"/>
</perspectiveExtension>
</extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ id="org.eclipse.linuxtools.systemtap.ui.ide"
+ name="%category.name">
+ </category>
+ <wizard
+ category="org.eclipse.linuxtools.systemtap.ui.ide"
+ class="org.eclipse.linuxtools.systemtap.ui.ide.wizards.StapNewWizard"
+ icon="icons/smileytap.gif"
+ id="org.eclipse.linuxtools.systemtap.ui.ide.wizards.StapNewWizard"
+ name="%wizard.name">
+ </wizard>
+ </extension>
</plugin>
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizard.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizard.java
new file mode 100644
index 0000000..9f0a080
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizard.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat Inc. and others.
+ * 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:
+ * Red Hat Inc. - Initial Wizard and related API
+ *******************************************************************************/
+package org.eclipse.linuxtools.systemtap.ui.ide.wizards;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.operation.*;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ResourceBundle;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.linuxtools.systemtap.ui.ide.IDEPerspective;
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.ui.*;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * This is a sample new wizard. Its role is to create a new file
+ * resource in the provided container. If the container resource
+ * (a folder or a project) is selected in the workspace
+ * when the wizard is opened, it will accept it as the target
+ * container. The wizard creates one file with the extension
+ * "mpe". If a sample multi-page editor (also available
+ * as a template) is registered for the same extension, it will
+ * be able to open it.
+ */
+
+public class StapNewWizard extends Wizard implements INewWizard {
+ private StapNewWizardPage page;
+ private ISelection selection;
+ private static final ResourceBundle resourceBundle = ResourceBundle.getBundle("org.eclipse.linuxtools.systemtap.ui.ide.wizards.stap_strings");
+
+ /**
+ * Constructor for StapNewWizard.
+ */
+ public StapNewWizard() {
+ super();
+ setNeedsProgressMonitor(true);
+ }
+
+ /**
+ * Adding the page to the wizard.
+ */
+
+ public void addPages() {
+ page = new StapNewWizardPage(selection);
+ addPage(page);
+ }
+
+ /**
+ * This method is called when 'Finish' button is pressed in
+ * the wizard. We will create an operation and run it
+ * using wizard as execution context.
+ */
+ public boolean performFinish() {
+ final String containerName = page.getContainerName();
+ final String fileName = page.getFileName();
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ doFinish(containerName, fileName, monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ getContainer().run(true, false, op);
+ } catch (InterruptedException e) {
+ MessageDialog.openError(getShell(), "Error", e.getLocalizedMessage());
+ return false;
+ } catch (InvocationTargetException e) {
+ Throwable realException = e.getTargetException();
+ MessageDialog.openError(getShell(), "Error", realException.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * The worker method. It will find the container, create the
+ * file if missing or just replace its contents, and open
+ * the editor on the newly created file.
+ */
+
+ private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException {
+ // create a .stp file
+
+ monitor.beginTask(resourceBundle.getString("StapNewWizard.BeginTask") + fileName, 2);
+ final File newFile = new File(containerName, fileName);
+ try {
+ String envString = "#!/usr/bin/env stap";
+ FileOutputStream FOS = new FileOutputStream(newFile);
+ newFile.createNewFile();
+ FOS.write(envString.getBytes());
+ FOS.close();
+ } catch (IOException e) {
+ throwCoreException("Error: " + e);
+ }
+ monitor.worked(1);
+ monitor.setTaskName(resourceBundle.getString("StapNewWizard.SetTask"));
+ getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ try {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getWorkbench()
+ .showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ IDE.openEditorOnFileStore(page, EFS.getLocalFileSystem().fromLocalFile(newFile));
+ } catch (WorkbenchException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ });
+ monitor.worked(1);
+ }
+
+ private void throwCoreException(String message) throws CoreException {
+ IStatus status =
+ new Status(IStatus.ERROR, "org.eclipse.linuxtools.systemtap.ui.ide", IStatus.OK, message, null);
+ throw new CoreException(status);
+ }
+
+ /**
+ * We will accept the selection in the workbench to see if
+ * we can initialize from it.
+ * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ }
+} \ No newline at end of file
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizardPage.java
new file mode 100644
index 0000000..3ad2211
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/StapNewWizardPage.java
@@ -0,0 +1,196 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat Inc. and others.
+ * 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:
+ * Red Hat Inc. - Initial Wizard and related API
+ *******************************************************************************/
+package org.eclipse.linuxtools.systemtap.ui.ide.wizards;
+
+import java.util.ResourceBundle;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * The "New" wizard page allows setting the container for the new file as well
+ * as the file name. The page will only accept file name without the extension
+ * OR with the extension that matches the expected one (mpe).
+ */
+
+public class StapNewWizardPage extends WizardPage {
+ private Text fileText;
+
+ private Text containerText;
+
+ private ISelection selection;
+
+ private static final ResourceBundle resourceBundle = ResourceBundle.getBundle("org.eclipse.linuxtools.systemtap.ui.ide.wizards.stap_strings");
+
+ /**
+ * Constructor for StapNewWizardPage.
+ *
+ * @param pageName
+ */
+ public StapNewWizardPage(ISelection selection) {
+ super(resourceBundle.getString("StapNewWizardPage.WizardPage"));
+ setTitle(resourceBundle.getString("StapNewWizardPage.Title"));
+ setDescription(resourceBundle.getString("StapNewWizardPage.setDescription"));
+ this.selection = selection;
+ }
+
+ /**
+ * @see IDialogPage#createControl(Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 3;
+ layout.verticalSpacing = 9;
+
+ Label label = new Label(container, SWT.NULL);
+ label.setText(resourceBundle.getString("StapNewWizardPage.ScriptName")); //$NON-NLS-1$
+
+ fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ fileText.setLayoutData(gd);
+ fileText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+ label = new Label(container, SWT.NULL); // XXX just create a new layout with different width
+
+ label = new Label(container, SWT.NULL);
+ label.setText(resourceBundle.getString("StapNewWizardPage.Directory")); //$NON-NLS-1$
+
+ containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ containerText.setLayoutData(gd);
+ containerText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+
+ Button button = new Button(container, SWT.PUSH);
+ button.setText(resourceBundle.getString("StapNewWizardPage.Browse"));
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleBrowse();
+ }
+ });
+ initialize();
+ dialogChanged();
+ setControl(container);
+ }
+
+ /**
+ * Tests if the current workbench selection is a suitable container to use.
+ */
+
+ private void initialize() {
+ if (selection != null && selection.isEmpty() == false
+ && selection instanceof IStructuredSelection) {
+ IStructuredSelection ssel = (IStructuredSelection) selection;
+ if (ssel.size() > 1)
+ return;
+ Object obj = ssel.getFirstElement();
+ if (obj instanceof IResource) {
+ IContainer container;
+ if (obj instanceof IContainer)
+ container = (IContainer) obj;
+ else
+ container = ((IResource) obj).getParent();
+ containerText.setText(container.getFullPath().toString());
+ }
+ }
+ fileText.setText(".stp");
+ }
+
+ /**
+ * Uses the standard container selection dialog to choose the new value for
+ * the container field.
+ */
+
+ private void handleBrowse() {
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ try {
+ dialog.open();
+ String result = dialog.getFilterPath();
+ containerText.setText(result);
+ } catch (Exception e) {
+ System.out.println("Error: " + e);
+ }
+ }
+
+ /**
+ * Ensures that both text fields are set.
+ */
+
+ private void dialogChanged() {
+ IPath container = Path.fromOSString(getContainerName());
+ String fileName = getFileName();
+ container.isValidPath(getContainerName());
+ if (fileName.length() == 0 || fileName.equals(".stp")) {
+ updateStatus(resourceBundle.getString("StapNewWizardPage.UpdateStatus1"));
+ return;
+ }
+ if (getContainerName().length() == 0) {
+ updateStatus(resourceBundle.getString("StapNewWizardPage.UpdateStatus2"));
+ return;
+ }
+ if (container == null
+ || !container.isValidPath(getContainerName())) {
+ updateStatus(resourceBundle.getString("StapNewWizardPage.UpdateStatus3"));
+ return;
+ }
+ if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
+ updateStatus(resourceBundle.getString("StapNewWizardPage.UpdateStatus4"));
+ return;
+ }
+ int dotLoc = fileName.lastIndexOf('.');
+ if (dotLoc != -1) {
+ String ext = fileName.substring(dotLoc + 1);
+ if (ext.equalsIgnoreCase("stp") == false) {
+ updateStatus(resourceBundle.getString("StapNewWizardPage.UpdateStatus.5"));
+ return;
+ }
+ }
+ updateStatus(null);
+ }
+
+ private void updateStatus(String message) {
+ setErrorMessage(message);
+ setPageComplete(message == null);
+ }
+
+ public String getContainerName() {
+ return containerText.getText();
+ }
+
+ public String getFileName() {
+ return fileText.getText();
+ }
+} \ No newline at end of file
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/stap_strings.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/stap_strings.properties
new file mode 100644
index 0000000..7df2c45
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/wizards/stap_strings.properties
@@ -0,0 +1,17 @@
+StapNewWizardPage.Directory=&Directory:
+StapNewWizardPage.ScriptName=&Script Name:
+StapNewWizardPage.WizardPage=WizardPage
+StapNewWizardPage.Title=Systemtap Script
+StapNewWizardPage.setDescription=This wizard creates a new systemtap script.
+StapNewWizardPage.Browse=Browse
+StapNewWizardPage.UpdateStatus1=Script name must be specified
+StapNewWizardPage.UpdateStatus2=Script directory must be specified
+StapNewWizardPage.UpdateStatus3=Script directory must exist
+StapNewWizardPage.UpdateStatus4=Script name must be valid
+StapNewWizardPage.UpdateStatus5=Script extension must be \\"stp\\"
+
+StapNewWizard.BeginTask=Creating
+StapNewWizard.SetTask=Opening file for editing...
+
+category.name = Systemtap
+wizard.name = Systemtap Script \ No newline at end of file