aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2012-10-31 13:39:58 (EDT)
committerRoland Grunberg2012-11-02 16:01:49 (EDT)
commit23b1b5d8572888b1ec24b7cbfea3976fec3155d4 (patch)
tree62537579fb22f67d8a3c70c40015f5cd2fe748f1
parent3760bf646fb9ddcbe45fe6e749c6cdc100c6c87d (diff)
downloadorg.eclipse.linuxtools-23b1b5d8572888b1ec24b7cbfea3976fec3155d4.zip
org.eclipse.linuxtools-23b1b5d8572888b1ec24b7cbfea3976fec3155d4.tar.gz
org.eclipse.linuxtools-23b1b5d8572888b1ec24b7cbfea3976fec3155d4.tar.bz2
Bug 392790: Prompt user to create a new launch configuration.
When a proper launch configuration cannot be found for a specific type and tool , when launching from a shortcut, prompt the user on whether they want to create such a configuration. Change-Id: If17907521c31e8efa0838ec45d54b3ca564cbb94 Reviewed-on: https://git.eclipse.org/r/8469 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/Messages.java3
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java111
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/messages.properties3
3 files changed, 68 insertions, 49 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/Messages.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/Messages.java
index c3c1a33..95037ee 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/Messages.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/Messages.java
@@ -21,7 +21,8 @@ public class Messages extends NLS {
public static String UseProjectSetting_0;
public static String ProjectSettings_0;
public static String PreferenceLink_0;
-
+ public static String ProviderLaunchConfigurationPrompt_0;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java
index ccb06fe..7917c20 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java
@@ -10,8 +10,7 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.profiling.launch.provider.launch;
-import java.util.Arrays;
-import java.util.List;
+import java.text.MessageFormat;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -24,13 +23,14 @@ import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.linuxtools.internal.profiling.launch.provider.ProviderProfileConstants;
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup;
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IExecutableExtension {
@@ -66,85 +66,100 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
@Override
protected ILaunchConfiguration findLaunchConfiguration(IBinary bin, String mode) {
- String type = getProfilingType();
+
+ // create a default launch configuration based on the shortcut
+ ILaunchConfiguration config = createConfiguration(bin, false);
+
+ String providerId = null;
+ try {
+ providerId = ProviderLaunchConfigurationDelegate.getProviderIdToRun(config.getWorkingCopy(), type);
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
// check that there exists a provider for the given profiling type
- if (ProviderLaunchConfigurationDelegate.getProviderIdToRun(null, type) == null) {
+ if (providerId == null) {
handleFail(Messages.ProviderLaunchShortcut_0 + " " + type);
return null;
}
- // create a launch configuration based on the shortcut
- ILaunchConfiguration config = createConfiguration(bin, false);
- boolean exists = false;
+ boolean exists = false;
+ ILaunchConfiguration[] configs = null;
try {
- for (ILaunchConfiguration cfg : getLaunchManager().getLaunchConfigurations(getLaunchConfigType())){
- if (areEqual(config, cfg)){
+ configs = getLaunchManager().getLaunchConfigurations(getLaunchConfigType());
+
+ // attributes for which a configuration can be considered valid for
+ // the current tool and profiling type
+ String[] relevantAttributes = new String[] {
+ ProviderProfileConstants.PROVIDER_CONFIG_ATT,
+ ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
+ ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME };
+
+ // check that there a exists a valid configuration for the current
+ // tool and profiling type
+ for (ILaunchConfiguration cfg : configs) {
+ if (equalAttributes(config, cfg, relevantAttributes)) {
exists = true;
+ break;
}
}
} catch (CoreException e) {
exists = true;
}
- // only save the configuration if it does not exist
- if (! exists) {
+ // automatically create a configuration if there are none available
+ if (configs == null || configs.length == 0) {
createConfiguration(bin);
- }
+ } else if (!exists) {
+ String provider = ProviderFramework
+ .getProviderToolNameFromId(providerId);
+
+ String profileType = Character.toUpperCase(type.charAt(0))
+ + type.substring(1);
+
+ // prompt message
+ String promptMsg = MessageFormat.format(
+ Messages.ProviderLaunchConfigurationPrompt_0, new String[] {
+ profileType, provider });
+ MessageBox prompt = new MessageBox(getActiveWorkbenchShell(),
+ SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+ prompt.setMessage(promptMsg);
+
+ // prompt user for configuration creation
+ if (prompt.open() == SWT.YES) {
+ return createConfiguration(bin);
+ }
+ }
return super.findLaunchConfiguration(bin, mode);
}
/**
+ * Check whether configurations <code>cfg1</code> and <code>cfg2</code>
+ * share specified attributes <code>attributes</code>
+ *
* @param cfg1 a launch configuration
* @param cfg2 a launch configuration
- * @return true if the launch configurations contain the exact
- * same attributes, and false otherwise.
+ * @param attributes attributes to compare
+ * @return <code>true</code> if specified attributes are equal on both configuration, <code>false</code> otherwise.
*/
- private boolean areEqual(ILaunchConfiguration cfg1,
- ILaunchConfiguration cfg2) {
-
- // We don't care about these attributes.
- final List<String> IGNORED_ATTRS = Arrays.asList(new String [] {
- ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH,
- ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH,
- IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE });
-
+ private boolean equalAttributes(ILaunchConfiguration cfg1,
+ ILaunchConfiguration cfg2, String[] attributes) {
try {
- Map<?, ?> attrs1 = cfg1.getAttributes();
- Map<?, ?> attrs2 = cfg2.getAttributes();
-
- for (Object key1 : attrs1.keySet()) {
- if (! attrs2.containsKey(key1)
- && ! IGNORED_ATTRS.contains(key1.toString())) {
+ for (String attribute : attributes) {
+ String cfg1Attribute = cfg1.getAttribute(attribute, "");
+ String cfg2Attribute = cfg2.getAttribute(attribute, "");
+ if (!cfg1Attribute.equals(cfg2Attribute)) {
return false;
}
}
-
- for (Object key2 : attrs2.keySet()) {
- if (! attrs1.containsKey(key2)
- && ! IGNORED_ATTRS.contains(key2.toString())) {
- return false;
- }
- }
-
- for (Object key1 : attrs1.keySet()) {
- for (Object key2 : attrs2.keySet()) {
- if (key1.toString().equals(key2.toString())
- && ! attrs1.get(key1).toString().equals(attrs2.get(key2).toString())) {
- return false;
- }
- }
- }
} catch (CoreException e) {
return false;
}
-
return true;
}
-
@Override
protected void setDefaultProfileAttributes(ILaunchConfigurationWorkingCopy wc) {
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/messages.properties b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/messages.properties
index 9386581..8308d81 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/messages.properties
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/messages.properties
@@ -5,3 +5,6 @@ ProviderOptionsTab_0=No plug-in provider found in launch configuration
UseProjectSetting_0=Enable project-specific settings
ProjectSettings_0=Project Settings
PreferenceLink_0=<a>Configure Workspace Settings...</a>
+ProviderLaunchConfigurationPrompt_0=This project has one or more Profile {0} configurations set up for the executable selected, \
+but none of these profiling configurations use the current default tool for Profile {0} which is set to use {1}. \n\n\
+Do you want to create and use a new profiling configuration that uses {1}? \ No newline at end of file