[Esbox-commits] r389 - in trunk: org.indt.esbox.launch org.indt.esbox.launch/icons org.indt.esbox.launch/src/org/indt/esbox/launch org.indt.esbox.launch/src/org/indt/esbox/launch/oprofile org.indt.esbox.launch/src/org/indt/esbox/launch/valgrind org.indt.esbox.python.launch org.indt.esbox.python.launch/src/org/indt/esbox/python/launch org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/oprofile org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/valgrind
raul at garage.maemo.org
raul at garage.maemo.org
Sat Jan 26 18:38:19 EET 2008
Author: raul
Date: 2008-01-26 18:38:10 +0200 (Sat, 26 Jan 2008)
New Revision: 389
Added:
trunk/org.indt.esbox.launch/icons/valgrind.png
trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/oprofile/
trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/oprofile/OProfileLaunchShortcut.java
trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/valgrind/
trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/valgrind/ValgrindLaunchShortcut.java
trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/oprofile/
trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/oprofile/OProfilePythonShortcut.java
trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/valgrind/
trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/valgrind/ValgrindPythonLaunchShortcut.java
Modified:
trunk/org.indt.esbox.launch/plugin.xml
trunk/org.indt.esbox.python.launch/plugin.xml
Log:
LaunchShortcuts for Valgrind and OProfile tools
Added: trunk/org.indt.esbox.launch/icons/valgrind.png
===================================================================
(Binary files differ)
Property changes on: trunk/org.indt.esbox.launch/icons/valgrind.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/org.indt.esbox.launch/plugin.xml
===================================================================
--- trunk/org.indt.esbox.launch/plugin.xml 2008-01-25 19:54:39 UTC (rev 388)
+++ trunk/org.indt.esbox.launch/plugin.xml 2008-01-26 16:38:10 UTC (rev 389)
@@ -132,6 +132,58 @@
<perspective id="org.eclipse.cdt.ui.CPerspective"/>
<perspective id="org.eclipse.debug.ui.DebugPerspective"/>
</shortcut>
+ <shortcut
+ class="org.indt.esbox.launch.oprofile.OProfileLaunchShortcut"
+ icon="icons/maemo_project.png"
+ id="org.indt.esbox.launch.shortcut1"
+ label="OProfile Profiler"
+ modes="run">
+ <contextualLaunch>
+ <enablement>
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <test
+ property="org.eclipse.cdt.launch.isExecutable">
+ </test></iterate>
+ </with></enablement>
+ <contextLabel
+ label="OProfile Profiler"
+ mode="run">
+ </contextLabel></contextualLaunch>
+ <perspective
+ id="org.indt.esbox.launch.perspective2">
+ </perspective>
+ </shortcut>
+ <shortcut
+ class="org.indt.esbox.launch.valgrind.ValgrindLaunchShortcut"
+ icon="icons/valgrind.png"
+ id="org.indt.esbox.launch.shortcut2"
+ label="Valgrind Memory Profiler"
+ modes="run">
+ <contextualLaunch>
+ <enablement>
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <test
+ property="org.eclipse.cdt.launch.isExecutable">
+ </test></iterate>
+ </with></enablement>
+ <contextLabel
+ label="Valgrind Memory Profiler"
+ mode="run">
+ </contextLabel></contextualLaunch>
+ <perspective
+ id="org.indt.esbox.launch.perspective4">
+ </perspective>
+ </shortcut>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
Added: trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/oprofile/OProfileLaunchShortcut.java
===================================================================
--- trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/oprofile/OProfileLaunchShortcut.java (rev 0)
+++ trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/oprofile/OProfileLaunchShortcut.java 2008-01-26 16:38:10 UTC (rev 389)
@@ -0,0 +1,409 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 INdT.
+ * 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:
+ * Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.launch.oprofile;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.debug.core.CDebugCorePlugin;
+import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
+import org.eclipse.cdt.debug.core.ICDebugConfiguration;
+import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
+import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
+import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
+import org.eclipse.cdt.ui.CElementLabelProvider;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugModelPresentation;
+import org.eclipse.debug.ui.ILaunchShortcut;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.dialogs.TwoPaneElementSelector;
+import org.indt.esbox.launch.remote.ESboxRemoteRunLaunchDelegate;
+
+/**
+ *
+ */
+public class OProfileLaunchShortcut implements ILaunchShortcut {
+
+ public void launch(IEditorPart editor, String mode) {
+ searchAndLaunch(new Object[] { editor.getEditorInput()}, mode);
+ }
+
+ public void launch(ISelection selection, String mode) {
+ if (selection instanceof IStructuredSelection) {
+ searchAndLaunch(((IStructuredSelection) selection).toArray(), mode);
+ }
+ }
+
+ public void launch(IBinary bin, String mode) {
+ // implementa aqui a execucao da ferramenta
+
+ }
+
+ /**
+ * Locate a configuration to relaunch for the given type. If one cannot be found, create one.
+ *
+ * @return a re-useable config or <code>null</code> if none
+ */
+ protected ILaunchConfiguration findLaunchConfiguration(IBinary bin, String mode) {
+ ILaunchConfiguration configuration = null;
+ ILaunchConfigurationType configType = getCLaunchConfigType();
+ List candidateConfigs = Collections.EMPTY_LIST;
+ try {
+ ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType);
+ candidateConfigs = new ArrayList(configs.length);
+ for (int i = 0; i < configs.length; i++) {
+ ILaunchConfiguration config = configs[i];
+ IPath programPath = AbstractCLaunchDelegate.getProgramPath(config);
+ String projectName = AbstractCLaunchDelegate.getProjectName(config);
+ IPath name = bin.getResource().getProjectRelativePath();
+ if (programPath != null && programPath.equals(name)) {
+ if (projectName != null && projectName.equals(bin.getCProject().getProject().getName())) {
+ candidateConfigs.add(config);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ LaunchUIPlugin.log(e);
+ }
+
+ // If there are no existing configs associated with the IBinary, create one.
+ // If there is exactly one config associated with the IBinary, return it.
+ // Otherwise, if there is more than one config associated with the IBinary, prompt the
+ // user to choose one.
+ int candidateCount = candidateConfigs.size();
+ if (candidateCount < 1) {
+ String programCPU = bin.getCPU();
+
+ // Prompt the user if more then 1 debugger.
+ ICDebugConfiguration debugConfig = null;
+ ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getDebugConfigurations();
+ List debugList = new ArrayList(debugConfigs.length);
+ String os = Platform.getOS();
+ for (int i = 0; i < debugConfigs.length; i++) {
+ String platform = debugConfigs[i].getPlatform();
+ if (debugConfigs[i].supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
+ if (platform.equals("*") || platform.equals(os)) { //$NON-NLS-1$
+ if (debugConfigs[i].supportsCPU(programCPU))
+ debugList.add(debugConfigs[i]);
+ }
+ }
+ }
+ debugConfigs = (ICDebugConfiguration[]) debugList.toArray(new ICDebugConfiguration[0]);
+ if (debugConfigs.length == 1) {
+ debugConfig = debugConfigs[0];
+ } else if (debugConfigs.length > 1) {
+ debugConfig = chooseDebugConfig(debugConfigs, mode);
+ }
+ if (debugConfig != null) {
+ configuration = createConfiguration(bin, debugConfig);
+ }
+ } else if (candidateCount == 1) {
+ configuration = (ILaunchConfiguration) candidateConfigs.get(0);
+ } else {
+ // Prompt the user to choose a config. A null result means the user
+ // cancelled the dialog, in which case this method returns null,
+ // since cancelling the dialog should also cancel launching anything.
+ configuration = chooseConfiguration(candidateConfigs, mode);
+ }
+ return configuration;
+ }
+
+ /**
+ * Method createConfiguration.
+ * @param bin
+ * @return ILaunchConfiguration
+ */
+ private ILaunchConfiguration createConfiguration(IBinary bin, ICDebugConfiguration debugConfig) {
+ ILaunchConfiguration config = null;
+ try {
+ String projectName = bin.getResource().getProjectRelativePath().toString();
+ ILaunchConfigurationType configType = getCLaunchConfigType();
+ ILaunchConfigurationWorkingCopy wc =
+ configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(bin.getElementName()));
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectName);
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, bin.getCProject().getElementName());
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true);
+ wc.setAttribute(
+ ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
+ ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, debugConfig.getID());
+ config = wc.doSave();
+ } catch (CoreException ce) {
+ LaunchUIPlugin.log(ce);
+ }
+ return config;
+ }
+
+ /**
+ * Method getCLaunchConfigType.
+ * @return ILaunchConfigurationType
+ */
+ protected ILaunchConfigurationType getCLaunchConfigType() {
+ return getLaunchManager().getLaunchConfigurationType(ESboxRemoteRunLaunchDelegate.ESBOX_CONFIG_TYPE); //the ID of the configuration type that we want to link with.
+ }
+
+ protected ILaunchManager getLaunchManager() {
+ return DebugPlugin.getDefault().getLaunchManager();
+ }
+
+ /**
+ * Convenience method to get the window that owns this action's Shell.
+ */
+ protected Shell getShell() {
+ return LaunchUIPlugin.getActiveWorkbenchShell();
+ }
+
+ /**
+ * Method chooseDebugConfig.
+ * @param debugConfigs
+ * @param mode
+ * @return ICDebugConfiguration
+ */
+ private ICDebugConfiguration chooseDebugConfig(ICDebugConfiguration[] debugConfigs, String mode) {
+ ILabelProvider provider = new LabelProvider() {
+ /**
+ * The <code>LabelProvider</code> implementation of this
+ * <code>ILabelProvider</code> method returns the element's <code>toString</code>
+ * string. Subclasses may override.
+ */
+ public String getText(Object element) {
+ if (element == null) {
+ return ""; //$NON-NLS-1$
+ } else if (element instanceof ICDebugConfiguration) {
+ return ((ICDebugConfiguration) element).getName();
+ }
+ return element.toString();
+ }
+ };
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), provider);
+ dialog.setElements(debugConfigs);
+ dialog.setTitle(getDebugConfigDialogTitleString(debugConfigs, mode));
+ dialog.setMessage(getDebugConfigDialogMessageString(debugConfigs, mode));
+ dialog.setMultipleSelection(false);
+ int result = dialog.open();
+ provider.dispose();
+ if (result == Window.OK) {
+ return (ICDebugConfiguration) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ protected String getDebugConfigDialogTitleString(ICDebugConfiguration [] configList, String mode) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.LaunchDebugConfigSelection"); //$NON-NLS-1$
+ }
+
+ protected String getDebugConfigDialogMessageString(ICDebugConfiguration [] configList, String mode) {
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseConfigToDebug"); //$NON-NLS-1$
+ } else if (mode.equals(ILaunchManager.RUN_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseConfigToRun"); //$NON-NLS-1$
+ }
+ return LaunchMessages.getString("CApplicationLaunchShortcut.Invalid_launch_mode_1"); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Show a selection dialog that allows the user to choose one of the specified
+ * launch configurations. Return the chosen config, or <code>null</code> if the
+ * user cancelled the dialog.
+ */
+ protected ILaunchConfiguration chooseConfiguration(List configList, String mode) {
+ IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
+ dialog.setElements(configList.toArray());
+ dialog.setTitle(getLaunchSelectionDialogTitleString(configList, mode));
+ dialog.setMessage(getLaunchSelectionDialogMessageString(configList, mode));
+ dialog.setMultipleSelection(false);
+ int result = dialog.open();
+ labelProvider.dispose();
+ if (result == Window.OK) {
+ return (ILaunchConfiguration) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ protected String getLaunchSelectionDialogTitleString(List configList, String mode) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.LaunchConfigSelection"); //$NON-NLS-1$
+ }
+
+ protected String getLaunchSelectionDialogMessageString(List binList, String mode) {
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLaunchConfigToDebug"); //$NON-NLS-1$
+ } else if (mode.equals(ILaunchManager.RUN_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLaunchConfigToRun"); //$NON-NLS-1$
+ }
+ return LaunchMessages.getString("CApplicationLaunchShortcut.Invalid_launch_mode_2"); //$NON-NLS-1$
+ }
+
+ /**
+ * Prompts the user to select a binary
+ *
+ * @return the selected binary or <code>null</code> if none.
+ */
+ protected IBinary chooseBinary(List binList, String mode) {
+ ILabelProvider programLabelProvider = new CElementLabelProvider() {
+ public String getText(Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ StringBuffer name = new StringBuffer();
+ name.append(bin.getPath().lastSegment());
+ return name.toString();
+ }
+ return super.getText(element);
+ }
+ };
+
+ ILabelProvider qualifierLabelProvider = new CElementLabelProvider() {
+ public String getText(Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ StringBuffer name = new StringBuffer();
+ name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be")); //$NON-NLS-1$ //$NON-NLS-2$
+ name.append(" - "); //$NON-NLS-1$
+ name.append(bin.getPath().toString());
+ return name.toString();
+ }
+ return super.getText(element);
+ }
+ };
+
+ TwoPaneElementSelector dialog = new TwoPaneElementSelector(getShell(), programLabelProvider, qualifierLabelProvider);
+ dialog.setElements(binList.toArray());
+ dialog.setTitle(getBinarySelectionDialogTitleString(binList, mode)); //$NON-NLS-1$
+ dialog.setMessage(getBinarySelectionDialogMessageString(binList, mode)); //$NON-NLS-1$
+ dialog.setUpperListLabel(LaunchMessages.getString("Launch.common.BinariesColon")); //$NON-NLS-1$
+ dialog.setLowerListLabel(LaunchMessages.getString("Launch.common.QualifierColon")); //$NON-NLS-1$
+ dialog.setMultipleSelection(false);
+ if (dialog.open() == Window.OK) {
+ return (IBinary) dialog.getFirstResult();
+ }
+
+ return null;
+ }
+
+ protected String getBinarySelectionDialogTitleString(List binList, String mode) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.CLocalApplication"); //$NON-NLS-1$
+ }
+
+ protected String getBinarySelectionDialogMessageString(List binList, String mode) {
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLocalAppToDebug"); //$NON-NLS-1$
+ } else if (mode.equals(ILaunchManager.RUN_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLocalAppToRun"); //$NON-NLS-1$
+ }
+ return LaunchMessages.getString("CApplicationLaunchShortcut.Invalid_launch_mode_3"); //$NON-NLS-1$
+ }
+
+ /**
+ * Method searchAndLaunch.
+ * @param objects
+ * @param mode
+ */
+ private void searchAndLaunch(final Object[] elements, String mode) {
+ if (elements != null && elements.length > 0) {
+ IBinary bin = null;
+ if (elements.length == 1 && elements[0] instanceof IBinary) {
+ bin = (IBinary)elements[0];
+ } else {
+ final List results = new ArrayList();
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ public void run(IProgressMonitor pm) throws InterruptedException {
+ int nElements = elements.length;
+ pm.beginTask("Looking for executables", nElements); //$NON-NLS-1$
+ try {
+ IProgressMonitor sub = new SubProgressMonitor(pm, 1);
+ for (int i = 0; i < nElements; i++) {
+ if (elements[i] instanceof IAdaptable) {
+ IResource r = (IResource) ((IAdaptable) elements[i]).getAdapter(IResource.class);
+ if (r != null) {
+ ICProject cproject = CoreModel.getDefault().create(r.getProject());
+ if (cproject != null) {
+ try {
+ IBinary[] bins = cproject.getBinaryContainer().getBinaries();
+
+ for (int j = 0; j < bins.length; j++) {
+ if (bins[j].isExecutable()) {
+ results.add(bins[j]);
+ }
+ }
+ } catch (CModelException e) {
+ }
+ }
+ }
+ }
+ if (pm.isCanceled()) {
+ throw new InterruptedException();
+ }
+ sub.done();
+ }
+ } finally {
+ pm.done();
+ }
+ }
+ };
+ try {
+ dialog.run(true, true, runnable);
+ } catch (InterruptedException e) {
+ return;
+ } catch (InvocationTargetException e) {
+ MessageDialog.openError(getShell(), LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), e.getMessage()); //$NON-NLS-1$
+ return;
+ }
+ int count = results.size();
+ if (count == 0) {
+ MessageDialog.openError(getShell(), LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (count > 1) {
+ bin = chooseBinary(results, mode);
+ } else {
+ bin = (IBinary)results.get(0);
+ }
+ }
+ if (bin != null) {
+ launch(bin, mode);
+ }
+ } else {
+ MessageDialog.openError(getShell(), LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+
+
+}
Added: trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/valgrind/ValgrindLaunchShortcut.java
===================================================================
--- trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/valgrind/ValgrindLaunchShortcut.java (rev 0)
+++ trunk/org.indt.esbox.launch/src/org/indt/esbox/launch/valgrind/ValgrindLaunchShortcut.java 2008-01-26 16:38:10 UTC (rev 389)
@@ -0,0 +1,410 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 INdT.
+ * 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:
+ * Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.launch.valgrind;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.debug.core.CDebugCorePlugin;
+import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
+import org.eclipse.cdt.debug.core.ICDebugConfiguration;
+import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
+import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
+import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
+import org.eclipse.cdt.ui.CElementLabelProvider;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugModelPresentation;
+import org.eclipse.debug.ui.ILaunchShortcut;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.dialogs.TwoPaneElementSelector;
+import org.indt.esbox.launch.remote.ESboxRemoteRunLaunchDelegate;
+
+/**
+ * @author raul
+ *
+ */
+public class ValgrindLaunchShortcut implements ILaunchShortcut {
+
+ public void launch(IEditorPart editor, String mode) {
+ searchAndLaunch(new Object[] { editor.getEditorInput()}, mode);
+ }
+
+ public void launch(ISelection selection, String mode) {
+ if (selection instanceof IStructuredSelection) {
+ searchAndLaunch(((IStructuredSelection) selection).toArray(), mode);
+ }
+ }
+
+ public void launch(IBinary bin, String mode) {
+ // implementa aqui a execucao da ferramenta
+
+ }
+
+ /**
+ * Locate a configuration to relaunch for the given type. If one cannot be found, create one.
+ *
+ * @return a re-useable config or <code>null</code> if none
+ */
+ protected ILaunchConfiguration findLaunchConfiguration(IBinary bin, String mode) {
+ ILaunchConfiguration configuration = null;
+ ILaunchConfigurationType configType = getCLaunchConfigType();
+ List candidateConfigs = Collections.EMPTY_LIST;
+ try {
+ ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType);
+ candidateConfigs = new ArrayList(configs.length);
+ for (int i = 0; i < configs.length; i++) {
+ ILaunchConfiguration config = configs[i];
+ IPath programPath = AbstractCLaunchDelegate.getProgramPath(config);
+ String projectName = AbstractCLaunchDelegate.getProjectName(config);
+ IPath name = bin.getResource().getProjectRelativePath();
+ if (programPath != null && programPath.equals(name)) {
+ if (projectName != null && projectName.equals(bin.getCProject().getProject().getName())) {
+ candidateConfigs.add(config);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ LaunchUIPlugin.log(e);
+ }
+
+ // If there are no existing configs associated with the IBinary, create one.
+ // If there is exactly one config associated with the IBinary, return it.
+ // Otherwise, if there is more than one config associated with the IBinary, prompt the
+ // user to choose one.
+ int candidateCount = candidateConfigs.size();
+ if (candidateCount < 1) {
+ String programCPU = bin.getCPU();
+
+ // Prompt the user if more then 1 debugger.
+ ICDebugConfiguration debugConfig = null;
+ ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getDebugConfigurations();
+ List debugList = new ArrayList(debugConfigs.length);
+ String os = Platform.getOS();
+ for (int i = 0; i < debugConfigs.length; i++) {
+ String platform = debugConfigs[i].getPlatform();
+ if (debugConfigs[i].supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
+ if (platform.equals("*") || platform.equals(os)) { //$NON-NLS-1$
+ if (debugConfigs[i].supportsCPU(programCPU))
+ debugList.add(debugConfigs[i]);
+ }
+ }
+ }
+ debugConfigs = (ICDebugConfiguration[]) debugList.toArray(new ICDebugConfiguration[0]);
+ if (debugConfigs.length == 1) {
+ debugConfig = debugConfigs[0];
+ } else if (debugConfigs.length > 1) {
+ debugConfig = chooseDebugConfig(debugConfigs, mode);
+ }
+ if (debugConfig != null) {
+ configuration = createConfiguration(bin, debugConfig);
+ }
+ } else if (candidateCount == 1) {
+ configuration = (ILaunchConfiguration) candidateConfigs.get(0);
+ } else {
+ // Prompt the user to choose a config. A null result means the user
+ // cancelled the dialog, in which case this method returns null,
+ // since cancelling the dialog should also cancel launching anything.
+ configuration = chooseConfiguration(candidateConfigs, mode);
+ }
+ return configuration;
+ }
+
+ /**
+ * Method createConfiguration.
+ * @param bin
+ * @return ILaunchConfiguration
+ */
+ private ILaunchConfiguration createConfiguration(IBinary bin, ICDebugConfiguration debugConfig) {
+ ILaunchConfiguration config = null;
+ try {
+ String projectName = bin.getResource().getProjectRelativePath().toString();
+ ILaunchConfigurationType configType = getCLaunchConfigType();
+ ILaunchConfigurationWorkingCopy wc =
+ configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(bin.getElementName()));
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectName);
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, bin.getCProject().getElementName());
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true);
+ wc.setAttribute(
+ ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
+ ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
+ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, debugConfig.getID());
+ config = wc.doSave();
+ } catch (CoreException ce) {
+ LaunchUIPlugin.log(ce);
+ }
+ return config;
+ }
+
+ /**
+ * Method getCLaunchConfigType.
+ * @return ILaunchConfigurationType
+ */
+ protected ILaunchConfigurationType getCLaunchConfigType() {
+ return getLaunchManager().getLaunchConfigurationType(ESboxRemoteRunLaunchDelegate.ESBOX_CONFIG_TYPE); //the ID of the configuration type that we want to link with.
+ }
+
+ protected ILaunchManager getLaunchManager() {
+ return DebugPlugin.getDefault().getLaunchManager();
+ }
+
+ /**
+ * Convenience method to get the window that owns this action's Shell.
+ */
+ protected Shell getShell() {
+ return LaunchUIPlugin.getActiveWorkbenchShell();
+ }
+
+ /**
+ * Method chooseDebugConfig.
+ * @param debugConfigs
+ * @param mode
+ * @return ICDebugConfiguration
+ */
+ private ICDebugConfiguration chooseDebugConfig(ICDebugConfiguration[] debugConfigs, String mode) {
+ ILabelProvider provider = new LabelProvider() {
+ /**
+ * The <code>LabelProvider</code> implementation of this
+ * <code>ILabelProvider</code> method returns the element's <code>toString</code>
+ * string. Subclasses may override.
+ */
+ public String getText(Object element) {
+ if (element == null) {
+ return ""; //$NON-NLS-1$
+ } else if (element instanceof ICDebugConfiguration) {
+ return ((ICDebugConfiguration) element).getName();
+ }
+ return element.toString();
+ }
+ };
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), provider);
+ dialog.setElements(debugConfigs);
+ dialog.setTitle(getDebugConfigDialogTitleString(debugConfigs, mode));
+ dialog.setMessage(getDebugConfigDialogMessageString(debugConfigs, mode));
+ dialog.setMultipleSelection(false);
+ int result = dialog.open();
+ provider.dispose();
+ if (result == Window.OK) {
+ return (ICDebugConfiguration) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ protected String getDebugConfigDialogTitleString(ICDebugConfiguration [] configList, String mode) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.LaunchDebugConfigSelection"); //$NON-NLS-1$
+ }
+
+ protected String getDebugConfigDialogMessageString(ICDebugConfiguration [] configList, String mode) {
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseConfigToDebug"); //$NON-NLS-1$
+ } else if (mode.equals(ILaunchManager.RUN_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseConfigToRun"); //$NON-NLS-1$
+ }
+ return LaunchMessages.getString("CApplicationLaunchShortcut.Invalid_launch_mode_1"); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Show a selection dialog that allows the user to choose one of the specified
+ * launch configurations. Return the chosen config, or <code>null</code> if the
+ * user cancelled the dialog.
+ */
+ protected ILaunchConfiguration chooseConfiguration(List configList, String mode) {
+ IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
+ dialog.setElements(configList.toArray());
+ dialog.setTitle(getLaunchSelectionDialogTitleString(configList, mode));
+ dialog.setMessage(getLaunchSelectionDialogMessageString(configList, mode));
+ dialog.setMultipleSelection(false);
+ int result = dialog.open();
+ labelProvider.dispose();
+ if (result == Window.OK) {
+ return (ILaunchConfiguration) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ protected String getLaunchSelectionDialogTitleString(List configList, String mode) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.LaunchConfigSelection"); //$NON-NLS-1$
+ }
+
+ protected String getLaunchSelectionDialogMessageString(List binList, String mode) {
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLaunchConfigToDebug"); //$NON-NLS-1$
+ } else if (mode.equals(ILaunchManager.RUN_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLaunchConfigToRun"); //$NON-NLS-1$
+ }
+ return LaunchMessages.getString("CApplicationLaunchShortcut.Invalid_launch_mode_2"); //$NON-NLS-1$
+ }
+
+ /**
+ * Prompts the user to select a binary
+ *
+ * @return the selected binary or <code>null</code> if none.
+ */
+ protected IBinary chooseBinary(List binList, String mode) {
+ ILabelProvider programLabelProvider = new CElementLabelProvider() {
+ public String getText(Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ StringBuffer name = new StringBuffer();
+ name.append(bin.getPath().lastSegment());
+ return name.toString();
+ }
+ return super.getText(element);
+ }
+ };
+
+ ILabelProvider qualifierLabelProvider = new CElementLabelProvider() {
+ public String getText(Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ StringBuffer name = new StringBuffer();
+ name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be")); //$NON-NLS-1$ //$NON-NLS-2$
+ name.append(" - "); //$NON-NLS-1$
+ name.append(bin.getPath().toString());
+ return name.toString();
+ }
+ return super.getText(element);
+ }
+ };
+
+ TwoPaneElementSelector dialog = new TwoPaneElementSelector(getShell(), programLabelProvider, qualifierLabelProvider);
+ dialog.setElements(binList.toArray());
+ dialog.setTitle(getBinarySelectionDialogTitleString(binList, mode)); //$NON-NLS-1$
+ dialog.setMessage(getBinarySelectionDialogMessageString(binList, mode)); //$NON-NLS-1$
+ dialog.setUpperListLabel(LaunchMessages.getString("Launch.common.BinariesColon")); //$NON-NLS-1$
+ dialog.setLowerListLabel(LaunchMessages.getString("Launch.common.QualifierColon")); //$NON-NLS-1$
+ dialog.setMultipleSelection(false);
+ if (dialog.open() == Window.OK) {
+ return (IBinary) dialog.getFirstResult();
+ }
+
+ return null;
+ }
+
+ protected String getBinarySelectionDialogTitleString(List binList, String mode) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.CLocalApplication"); //$NON-NLS-1$
+ }
+
+ protected String getBinarySelectionDialogMessageString(List binList, String mode) {
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLocalAppToDebug"); //$NON-NLS-1$
+ } else if (mode.equals(ILaunchManager.RUN_MODE)) {
+ return LaunchMessages.getString("CApplicationLaunchShortcut.ChooseLocalAppToRun"); //$NON-NLS-1$
+ }
+ return LaunchMessages.getString("CApplicationLaunchShortcut.Invalid_launch_mode_3"); //$NON-NLS-1$
+ }
+
+ /**
+ * Method searchAndLaunch.
+ * @param objects
+ * @param mode
+ */
+ private void searchAndLaunch(final Object[] elements, String mode) {
+ if (elements != null && elements.length > 0) {
+ IBinary bin = null;
+ if (elements.length == 1 && elements[0] instanceof IBinary) {
+ bin = (IBinary)elements[0];
+ } else {
+ final List results = new ArrayList();
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ public void run(IProgressMonitor pm) throws InterruptedException {
+ int nElements = elements.length;
+ pm.beginTask("Looking for executables", nElements); //$NON-NLS-1$
+ try {
+ IProgressMonitor sub = new SubProgressMonitor(pm, 1);
+ for (int i = 0; i < nElements; i++) {
+ if (elements[i] instanceof IAdaptable) {
+ IResource r = (IResource) ((IAdaptable) elements[i]).getAdapter(IResource.class);
+ if (r != null) {
+ ICProject cproject = CoreModel.getDefault().create(r.getProject());
+ if (cproject != null) {
+ try {
+ IBinary[] bins = cproject.getBinaryContainer().getBinaries();
+
+ for (int j = 0; j < bins.length; j++) {
+ if (bins[j].isExecutable()) {
+ results.add(bins[j]);
+ }
+ }
+ } catch (CModelException e) {
+ }
+ }
+ }
+ }
+ if (pm.isCanceled()) {
+ throw new InterruptedException();
+ }
+ sub.done();
+ }
+ } finally {
+ pm.done();
+ }
+ }
+ };
+ try {
+ dialog.run(true, true, runnable);
+ } catch (InterruptedException e) {
+ return;
+ } catch (InvocationTargetException e) {
+ MessageDialog.openError(getShell(), LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), e.getMessage()); //$NON-NLS-1$
+ return;
+ }
+ int count = results.size();
+ if (count == 0) {
+ MessageDialog.openError(getShell(), LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (count > 1) {
+ bin = chooseBinary(results, mode);
+ } else {
+ bin = (IBinary)results.get(0);
+ }
+ }
+ if (bin != null) {
+ launch(bin, mode);
+ }
+ } else {
+ MessageDialog.openError(getShell(), LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+
+
+}
Modified: trunk/org.indt.esbox.python.launch/plugin.xml
===================================================================
--- trunk/org.indt.esbox.python.launch/plugin.xml 2008-01-25 19:54:39 UTC (rev 388)
+++ trunk/org.indt.esbox.python.launch/plugin.xml 2008-01-26 16:38:10 UTC (rev 389)
@@ -117,6 +117,76 @@
id="org.python.pydev.plugin.PythonPerspective">
</perspective>
</shortcut>
+ <shortcut
+ class="org.indt.esbox.python.launch.LaunchShortcut4"
+ id="valgrindPythonShortcut"
+ label="Valgrind Profiler"
+ modes="run">
+ <contextualLaunch>
+ <enablement>
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <or>
+ <test
+ property="org.eclipse.debug.ui.matchesPattern"
+ value="*.py">
+ </test>
+ <test
+ property="org.eclipse.debug.ui.matchesPattern"
+ value="*.pyw">
+ </test>
+ </or>
+ </iterate>
+ </with>
+ </enablement>
+ <contextLabel
+ label="Valgrind Profiler"
+ mode="run">
+ </contextLabel>
+ </contextualLaunch>
+ <perspective
+ id="org.python.pydev.plugin.PythonPerspective">
+ </perspective>
+ </shortcut>
+ <shortcut
+ class="org.indt.esbox.python.launch.LaunchShortcut3"
+ id="oprofilePythonShortcut"
+ label="OProfile Profiler"
+ modes="run">
+ <contextualLaunch>
+ <enablement>
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate>
+ <or>
+ <test
+ property="org.eclipse.debug.ui.matchesPattern"
+ value="*.py">
+ </test>
+ <test
+ property="org.eclipse.debug.ui.matchesPattern"
+ value="*.pyw">
+ </test>
+ </or>
+ </iterate>
+ </with>
+ </enablement>
+ <contextLabel
+ label="Valgrind Profiler"
+ mode="run">
+ </contextLabel>
+ </contextualLaunch>
+ <perspective
+ id="org.python.pydev.plugin.PythonPerspective">
+ </perspective>
+ </shortcut>
</extension>
Added: trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/oprofile/OProfilePythonShortcut.java
===================================================================
--- trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/oprofile/OProfilePythonShortcut.java (rev 0)
+++ trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/oprofile/OProfilePythonShortcut.java 2008-01-26 16:38:10 UTC (rev 389)
@@ -0,0 +1,291 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 INdT.
+ * 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:
+ * Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.python.launch.oprofile;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.debug.ui.ILaunchShortcut;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.indt.esbox.python.launch.PythonLaunchActivator;
+import org.indt.esbox.python.launch.internal.core.ESboxPythonLaunchConstants;
+import org.python.pydev.ui.NotConfiguredInterpreterException;
+
+/**
+ *
+ */
+public class OProfilePythonShortcut implements ILaunchShortcut {
+
+ boolean fShowDialog = false; // show configuration dialog?
+
+ //=============================================================================================
+ // ILaunchShortcut IMPL
+ //=============================================================================================
+ public void launch(ISelection selection, String mode) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ Object object = structuredSelection.getFirstElement();
+ if (object instanceof IAdaptable) {
+
+ IFile resource = (IFile)((IAdaptable)object).getAdapter(IFile.class);
+ if (resource != null) {
+ launch(resource, mode, null);
+ return;
+ }
+
+ IFolder folder = (IFolder)((IAdaptable)object).getAdapter(IFolder.class);
+ if (folder != null) {
+ launch(folder, mode, null);
+ return;
+ }
+ }
+ }
+ fileNotFound();
+ }
+
+
+ public void launch(IEditorPart editor, String mode) {
+ //we have an editor to run
+ IEditorInput input = editor.getEditorInput();
+ IFile file = (IFile)input.getAdapter(IFile.class);
+ if (file != null) {
+ launch(file, mode, null);
+ return;
+ }
+ fileNotFound();
+ }
+ //=============================================================================================
+ // END ILaunchShortcut IMPL
+ //=============================================================================================
+
+ protected void fileNotFound() {
+ reportError("Unable to launch the file, not found??", null);
+ }
+
+ protected boolean verifyMode(String mode) {
+ boolean ok = mode.equals(ILaunchManager.RUN_MODE) || mode.equals(ILaunchManager.DEBUG_MODE);
+
+ if (!ok){
+ reportError("Unknown launch mode: " + mode, null);
+ }
+ return ok;
+ }
+
+
+ protected static void reportError(String message, Throwable throwable) {
+ if (message == null)
+ message = "Unexpected error";
+ IStatus status = null;
+ if (throwable instanceof CoreException) {
+ status = ((CoreException)throwable).getStatus();
+ } else {
+ status = new Status(IStatus.ERROR, "org.python.pydev.debug", 0, message, throwable);
+ }
+ ErrorDialog.openError(PythonLaunchActivator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "ESbox esbox.python.launch error", "ESbox launch failed", status);
+ }
+
+ /**
+ * COPIED/MODIFIED from AntLaunchShortcut
+ * Returns a list of existing launch configuration for the given file.
+ */
+ protected List findExistingLaunchConfigurations(IResource file) {
+ ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(getLaunchConfigurationType());
+ List validConfigs = new ArrayList();
+ if (type == null)
+ return validConfigs;
+ try {
+ ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
+ String defaultLocation = getDefaultLocation(file);
+ for (int i = 0; i < configs.length; i++) {
+ String configPath = configs[i].getAttribute(ESboxPythonLaunchConstants.ATTR_LOCATION, "");
+ if (defaultLocation.equals(configPath))
+ validConfigs.add(configs[i]);
+ }
+ } catch (CoreException e) {
+ reportError("Unexpected error", e);
+ }
+ return validConfigs;
+ }
+
+ /**
+ * @param file
+ * @return default string for the location field
+ */
+ public static String getDefaultLocation (IResource file) {
+ return file.getRawLocation().toString();
+ }
+
+ protected String getLaunchConfigurationType() {
+ return ESboxPythonLaunchConstants.ID_ESBOX_REMOTE_LAUNCH_CONFIGURATION_TYPE;
+ }
+
+ protected ILaunchConfiguration createDefaultLaunchConfiguration(IResource resource) {
+ String projName = resource.getProject().getName();
+ return createDefaultLaunchConfiguration(resource, getLaunchConfigurationType(), getDefaultLocation(resource), projName);
+ }
+
+ public static ILaunchConfiguration createDefaultLaunchConfiguration(IResource resource, String launchConfigurationType,
+ String location, String projName) {
+ return createDefaultLaunchConfiguration(resource, launchConfigurationType, location, projName, null);
+ }
+
+ /**
+ * COPIED/MODIFIED from AntLaunchShortcut
+ * @param location
+ * @param pythonInterpreterManager
+ */
+ public static ILaunchConfiguration createDefaultLaunchConfiguration(IResource resource, String launchConfigurationType,
+ String location, String projName, String vmargs) {
+
+
+ ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(launchConfigurationType);
+ if (type == null) {
+ reportError("ESbox launch configuration not found", null);
+ return null;
+ }
+
+ StringBuffer buffer = new StringBuffer(projName);
+ buffer.append(" ");
+ buffer.append(resource.getName());
+ String name = buffer.toString().trim();
+ name= manager.generateUniqueLaunchConfigurationNameFrom(name);
+
+ try {
+
+ ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name);
+ String baseDirectory = resource.getRawLocation().removeLastSegments(1).toString();
+ String arguments = "";
+
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_PROJECT_NAME,projName);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_RESOURCE_TYPE,resource.getType());
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_PROGRAM_NAME,location);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_INTERPRETER, ESboxPythonLaunchConstants.ATTR_INTERPRETER_DEFAULT);
+
+ workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_LOCATION,location);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_WORKING_DIRECTORY,baseDirectory);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_PROGRAM_ARGUMENTS,arguments);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_VM_ARGUMENTS, vmargs);
+
+ // Common Tab Arguments
+ CommonTab tab = new CommonTab();
+ tab.setDefaults(workingCopy);
+ tab.dispose();
+ return workingCopy.doSave();
+ } catch (NotConfiguredInterpreterException e) {
+ reportError(e.getMessage(), e);
+ throw e;
+ } catch (CoreException e) {
+ reportError(null, e);
+ return null;
+ }
+ }
+
+ /**
+ * COPIED/MODIFIED from AntLaunchShortcut
+ */
+ protected ILaunchConfiguration chooseConfig(List configs) {
+ if (configs.isEmpty()) {
+ return null;
+ }
+ ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(Display.getDefault().getActiveShell(), labelProvider);
+ dialog.setElements(configs.toArray(new ILaunchConfiguration[configs.size()]));
+ dialog.setTitle("Pick a Python configuration");
+ dialog.setMessage("Choose a python configuration to run");
+ dialog.setMultipleSelection(false);
+ int result = dialog.open();
+ labelProvider.dispose();
+ if (result == Window.OK)
+ return (ILaunchConfiguration) dialog.getFirstResult();
+ else
+ return null;
+ }
+
+ /**
+ * Launch the given targets in the given build file. The targets are
+ * launched in the given mode.
+ *
+ * @param file the build file to launch
+ * @param mode the mode in which the build file should be executed
+ * @param targetAttribute the targets to launch, in the form of the launch
+ * configuration targets attribute.
+ */
+ protected void launch(IResource file, String mode, String targetAttribute) {
+ if (!verifyMode(mode)){
+ reportError("Invalid mode " + mode, null);
+ return;
+ }
+
+ ILaunchConfiguration conf = null;
+ List configurations = findExistingLaunchConfigurations(file);
+ if (configurations.isEmpty())
+ conf = createDefaultLaunchConfiguration(file);
+ else {
+ if (configurations.size() == 1) {
+ conf = (ILaunchConfiguration)configurations.get(0);
+ } else {
+ conf = chooseConfig(configurations);
+ if (conf == null)
+ // User cancelled selection
+ return;
+ }
+ }
+
+ if (conf != null) {
+ if (fShowDialog) {
+ String groupID = "";
+
+ if(mode.equals("run")) {
+ groupID = ESboxPythonLaunchConstants.ESBOX_RUN_LAUNCH_GROUP;
+ }else if (mode.equals("debug")){
+ groupID = ESboxPythonLaunchConstants.ESBOX_DEBUG_LAUNCH_GROUP;
+ }
+
+ DebugUITools.openLaunchConfigurationDialog(PythonLaunchActivator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), conf, groupID, null);
+ } else {
+ DebugUITools.launch(conf, mode);
+ }
+ return;
+ }
+ fileNotFound();
+ }
+
+ public void setShowDialog(boolean showDialog) {
+ fShowDialog = showDialog;
+ }
+
+}
Added: trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/valgrind/ValgrindPythonLaunchShortcut.java
===================================================================
--- trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/valgrind/ValgrindPythonLaunchShortcut.java (rev 0)
+++ trunk/org.indt.esbox.python.launch/src/org/indt/esbox/python/launch/valgrind/ValgrindPythonLaunchShortcut.java 2008-01-26 16:38:10 UTC (rev 389)
@@ -0,0 +1,291 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 INdT.
+ * 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:
+ * Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.python.launch.valgrind;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.debug.ui.ILaunchShortcut;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.indt.esbox.python.launch.PythonLaunchActivator;
+import org.indt.esbox.python.launch.internal.core.ESboxPythonLaunchConstants;
+import org.python.pydev.ui.NotConfiguredInterpreterException;
+
+/**
+ *
+ */
+public class ValgrindPythonLaunchShortcut implements ILaunchShortcut {
+
+ boolean fShowDialog = false; // show configuration dialog?
+
+ //=============================================================================================
+ // ILaunchShortcut IMPL
+ //=============================================================================================
+ public void launch(ISelection selection, String mode) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ Object object = structuredSelection.getFirstElement();
+ if (object instanceof IAdaptable) {
+
+ IFile resource = (IFile)((IAdaptable)object).getAdapter(IFile.class);
+ if (resource != null) {
+ launch(resource, mode, null);
+ return;
+ }
+
+ IFolder folder = (IFolder)((IAdaptable)object).getAdapter(IFolder.class);
+ if (folder != null) {
+ launch(folder, mode, null);
+ return;
+ }
+ }
+ }
+ fileNotFound();
+ }
+
+
+ public void launch(IEditorPart editor, String mode) {
+ //we have an editor to run
+ IEditorInput input = editor.getEditorInput();
+ IFile file = (IFile)input.getAdapter(IFile.class);
+ if (file != null) {
+ launch(file, mode, null);
+ return;
+ }
+ fileNotFound();
+ }
+ //=============================================================================================
+ // END ILaunchShortcut IMPL
+ //=============================================================================================
+
+ protected void fileNotFound() {
+ reportError("Unable to launch the file, not found??", null);
+ }
+
+ protected boolean verifyMode(String mode) {
+ boolean ok = mode.equals(ILaunchManager.RUN_MODE) || mode.equals(ILaunchManager.DEBUG_MODE);
+
+ if (!ok){
+ reportError("Unknown launch mode: " + mode, null);
+ }
+ return ok;
+ }
+
+
+ protected static void reportError(String message, Throwable throwable) {
+ if (message == null)
+ message = "Unexpected error";
+ IStatus status = null;
+ if (throwable instanceof CoreException) {
+ status = ((CoreException)throwable).getStatus();
+ } else {
+ status = new Status(IStatus.ERROR, "org.python.pydev.debug", 0, message, throwable);
+ }
+ ErrorDialog.openError(PythonLaunchActivator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "ESbox esbox.python.launch error", "ESbox launch failed", status);
+ }
+
+ /**
+ * COPIED/MODIFIED from AntLaunchShortcut
+ * Returns a list of existing launch configuration for the given file.
+ */
+ protected List findExistingLaunchConfigurations(IResource file) {
+ ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(getLaunchConfigurationType());
+ List validConfigs = new ArrayList();
+ if (type == null)
+ return validConfigs;
+ try {
+ ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
+ String defaultLocation = getDefaultLocation(file);
+ for (int i = 0; i < configs.length; i++) {
+ String configPath = configs[i].getAttribute(ESboxPythonLaunchConstants.ATTR_LOCATION, "");
+ if (defaultLocation.equals(configPath))
+ validConfigs.add(configs[i]);
+ }
+ } catch (CoreException e) {
+ reportError("Unexpected error", e);
+ }
+ return validConfigs;
+ }
+
+ /**
+ * @param file
+ * @return default string for the location field
+ */
+ public static String getDefaultLocation (IResource file) {
+ return file.getRawLocation().toString();
+ }
+
+ protected String getLaunchConfigurationType() {
+ return ESboxPythonLaunchConstants.ID_ESBOX_REMOTE_LAUNCH_CONFIGURATION_TYPE;
+ }
+
+ protected ILaunchConfiguration createDefaultLaunchConfiguration(IResource resource) {
+ String projName = resource.getProject().getName();
+ return createDefaultLaunchConfiguration(resource, getLaunchConfigurationType(), getDefaultLocation(resource), projName);
+ }
+
+ public static ILaunchConfiguration createDefaultLaunchConfiguration(IResource resource, String launchConfigurationType,
+ String location, String projName) {
+ return createDefaultLaunchConfiguration(resource, launchConfigurationType, location, projName, null);
+ }
+
+ /**
+ * COPIED/MODIFIED from AntLaunchShortcut
+ * @param location
+ * @param pythonInterpreterManager
+ */
+ public static ILaunchConfiguration createDefaultLaunchConfiguration(IResource resource, String launchConfigurationType,
+ String location, String projName, String vmargs) {
+
+
+ ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(launchConfigurationType);
+ if (type == null) {
+ reportError("ESbox launch configuration not found", null);
+ return null;
+ }
+
+ StringBuffer buffer = new StringBuffer(projName);
+ buffer.append(" ");
+ buffer.append(resource.getName());
+ String name = buffer.toString().trim();
+ name= manager.generateUniqueLaunchConfigurationNameFrom(name);
+
+ try {
+
+ ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name);
+ String baseDirectory = resource.getRawLocation().removeLastSegments(1).toString();
+ String arguments = "";
+
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_PROJECT_NAME,projName);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_RESOURCE_TYPE,resource.getType());
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_PROGRAM_NAME,location);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_INTERPRETER, ESboxPythonLaunchConstants.ATTR_INTERPRETER_DEFAULT);
+
+ workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_LOCATION,location);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_WORKING_DIRECTORY,baseDirectory);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_PROGRAM_ARGUMENTS,arguments);
+ workingCopy.setAttribute(ESboxPythonLaunchConstants.ATTR_VM_ARGUMENTS, vmargs);
+
+ // Common Tab Arguments
+ CommonTab tab = new CommonTab();
+ tab.setDefaults(workingCopy);
+ tab.dispose();
+ return workingCopy.doSave();
+ } catch (NotConfiguredInterpreterException e) {
+ reportError(e.getMessage(), e);
+ throw e;
+ } catch (CoreException e) {
+ reportError(null, e);
+ return null;
+ }
+ }
+
+ /**
+ * COPIED/MODIFIED from AntLaunchShortcut
+ */
+ protected ILaunchConfiguration chooseConfig(List configs) {
+ if (configs.isEmpty()) {
+ return null;
+ }
+ ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(Display.getDefault().getActiveShell(), labelProvider);
+ dialog.setElements(configs.toArray(new ILaunchConfiguration[configs.size()]));
+ dialog.setTitle("Pick a Python configuration");
+ dialog.setMessage("Choose a python configuration to run");
+ dialog.setMultipleSelection(false);
+ int result = dialog.open();
+ labelProvider.dispose();
+ if (result == Window.OK)
+ return (ILaunchConfiguration) dialog.getFirstResult();
+ else
+ return null;
+ }
+
+ /**
+ * Launch the given targets in the given build file. The targets are
+ * launched in the given mode.
+ *
+ * @param file the build file to launch
+ * @param mode the mode in which the build file should be executed
+ * @param targetAttribute the targets to launch, in the form of the launch
+ * configuration targets attribute.
+ */
+ protected void launch(IResource file, String mode, String targetAttribute) {
+ if (!verifyMode(mode)){
+ reportError("Invalid mode " + mode, null);
+ return;
+ }
+
+ ILaunchConfiguration conf = null;
+ List configurations = findExistingLaunchConfigurations(file);
+ if (configurations.isEmpty())
+ conf = createDefaultLaunchConfiguration(file);
+ else {
+ if (configurations.size() == 1) {
+ conf = (ILaunchConfiguration)configurations.get(0);
+ } else {
+ conf = chooseConfig(configurations);
+ if (conf == null)
+ // User cancelled selection
+ return;
+ }
+ }
+
+ if (conf != null) {
+ if (fShowDialog) {
+ String groupID = "";
+
+ if(mode.equals("run")) {
+ groupID = ESboxPythonLaunchConstants.ESBOX_RUN_LAUNCH_GROUP;
+ }else if (mode.equals("debug")){
+ groupID = ESboxPythonLaunchConstants.ESBOX_DEBUG_LAUNCH_GROUP;
+ }
+
+ DebugUITools.openLaunchConfigurationDialog(PythonLaunchActivator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), conf, groupID, null);
+ } else {
+ DebugUITools.launch(conf, mode);
+ }
+ return;
+ }
+ fileNotFound();
+ }
+
+ public void setShowDialog(boolean showDialog) {
+ fShowDialog = showDialog;
+ }
+
+}
More information about the Esbox-commits
mailing list