summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCamilo Bernal2012-10-29 16:35:26 (EDT)
committer Roland Grunberg2012-10-31 15:42:03 (EDT)
commitb4641e3580ffc0818167ea021c3030b242a4a0d4 (patch)
tree1dc3e97eefabb3119a5885a7cbdf07215f886d9e
parent6fe3c9b24685a39436871b71c387625e0972c261 (diff)
downloadorg.eclipse.linuxtools-b4641e3580ffc0818167ea021c3030b242a4a0d4.zip
org.eclipse.linuxtools-b4641e3580ffc0818167ea021c3030b242a4a0d4.tar.gz
org.eclipse.linuxtools-b4641e3580ffc0818167ea021c3030b242a4a0d4.tar.bz2
Incorporate name of backend tool with provider launch configuration name.
To inform the user what the underlying tool of a particular provider launch configuration is, the tool name is appended to the original configuration name. Change-Id: I878ca85c9f937fce663ba50ae30794e198b810d6 Reviewed-on: https://git.eclipse.org/r/8239 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/ProviderOptionsTab.java50
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderProfileConstants.java5
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderFramework.java24
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java41
4 files changed, 116 insertions, 4 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderOptionsTab.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderOptionsTab.java
index eb3e2af..fe66599 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderOptionsTab.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderOptionsTab.java
@@ -13,7 +13,7 @@ package org.eclipse.linuxtools.internal.profiling.launch.provider;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
-
+import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
@@ -22,6 +22,7 @@ import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.linuxtools.internal.profiling.launch.provider.launch.Messages;
import org.eclipse.linuxtools.internal.profiling.launch.provider.launch.ProviderFramework;
import org.eclipse.linuxtools.internal.profiling.launch.provider.launch.ProviderLaunchConfigurationDelegate;
+import org.eclipse.linuxtools.internal.profiling.launch.provider.launch.ProviderLaunchShortcut;
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTab;
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup;
import org.eclipse.swt.SWT;
@@ -119,6 +120,9 @@ public class ProviderOptionsTab extends ProfileLaunchConfigurationTab {
int itemIndex = getComboItemIndexFromId(curProviderId);
providerCombo.select(itemIndex);
+ // Set name of configuration.
+ setConfigurationName(providerCombo.getText());
+
// create the tab item, and load the specified tab inside
for (ILaunchConfigurationTab tab : tabs) {
tab.setLaunchConfigurationDialog(getLaunchConfigurationDialog());
@@ -319,4 +323,48 @@ public class ProviderOptionsTab extends ProfileLaunchConfigurationTab {
public String getName() {
return name;
}
+
+ /**
+ * Set name of the launch configuration.
+ *
+ * @param newToolName String tool name to be appended to configuration name,
+ */
+ private void setConfigurationName(String newToolName) {
+ try {
+ String currentToolName = initial.getAttribute(
+ ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, "");
+
+ // Append the new tool name as long as the current and new tool
+ // names are different.
+ if (newToolName != null && !newToolName.equals("")
+ && !currentToolName.equals(newToolName)) {
+
+ String projectName = initial.getAttribute(
+ ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
+
+ // String of the form <project name> [<tool name>].
+ String newConfigurationName = ProviderLaunchShortcut
+ .generateProviderConfigurationName(projectName,
+ newToolName);
+
+ // Unique name of the form <project name> [<tool name>]{(<number>)}.
+ String newUniqueToolName = getLaunchManager()
+ .generateLaunchConfigurationName(newConfigurationName);
+
+ // Save changes in current configuration.
+ ILaunchConfigurationWorkingCopy wc = initial.getWorkingCopy();
+ wc.rename(newUniqueToolName);
+ wc.setAttribute(
+ ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT,
+ newToolName);
+ initial = wc.doSave();
+
+ // Set name field in launch configuration dialog to avoid the
+ // new configuration name from being overwritten.
+ getLaunchConfigurationDialog().setName(newUniqueToolName);
+ }
+ } catch (CoreException e) {
+ // If unable to set the name, leave the original name as is.
+ }
+ }
}
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderProfileConstants.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderProfileConstants.java
index 4de521c..24faf15 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderProfileConstants.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/ProviderProfileConstants.java
@@ -52,4 +52,9 @@ public class ProviderProfileConstants {
* Key to acquire the provider launch configuration attribute.
*/
public static final String PROVIDER_CONFIG_ATT = "provider"; //$NON-NLS-1$
+
+ /**
+ * Key to acquire the tool name launch configuration attribute.
+ */
+ public static final String PROVIDER_CONFIG_TOOLNAME_ATT = "toolname"; //$NON-NLS-1$
}
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderFramework.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderFramework.java
index 28ea0c7..8ad2082 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderFramework.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderFramework.java
@@ -247,4 +247,28 @@ public class ProviderFramework {
return extPoint.getConfigurationElements();
}
+ /**
+ * Get name of tool with plug-in id <code>id</code>. This looks through
+ * extensions of the
+ * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code>
+ * extensions point.
+ *
+ * @since 1.2
+ */
+ public static String getProviderToolNameFromId(String id) {
+ IExtensionPoint extPoint = Platform.getExtensionRegistry()
+ .getExtensionPoint(ProfileLaunchPlugin.PLUGIN_ID,
+ "launchProvider"); //$NON-NLS-1$
+ IConfigurationElement[] configs = extPoint.getConfigurationElements();
+ for (IConfigurationElement config : configs) {
+ if (config.getName().equals("provider")) { //$NON-NLS-1$
+ String currentId = config.getAttribute("id"); //$NON-NLS-1$
+ if (currentId != null && currentId.equals(id)) {
+ return config.getAttribute("name");
+ }
+ }
+ }
+ return null;
+ }
+
}
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 7605599..ccb06fe 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
@@ -13,6 +13,8 @@ package org.eclipse.linuxtools.internal.profiling.launch.provider.launch;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
@@ -147,10 +149,13 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
protected void setDefaultProfileAttributes(ILaunchConfigurationWorkingCopy wc) {
// acquire a provider id to run.
- String providerId = ProviderLaunchConfigurationDelegate.getProviderIdToRun(wc, getProfilingType());
+ final String providerId = ProviderLaunchConfigurationDelegate.getProviderIdToRun(wc, getProfilingType());
+
+ // get tool name from id.
+ final String providerToolName = ProviderFramework.getProviderToolNameFromId(providerId);
// get tab group associated with provider id.
- ProfileLaunchConfigurationTabGroup tabgroup = ProfileLaunchConfigurationTabGroup.getTabGroupProviderFromId(providerId);
+ final ProfileLaunchConfigurationTabGroup tabgroup = ProfileLaunchConfigurationTabGroup.getTabGroupProviderFromId(providerId);
/**
* Certain tabs' setDefaults(ILaunchConfigurationWorkingCopy) may
@@ -203,7 +208,8 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
if (name == null) {
name = "";
}
- return getLaunchManager().generateLaunchConfigurationName(name);
+ String providerConfigutationName = generateProviderConfigurationName(name, providerToolName);
+ return getLaunchManager().generateLaunchConfigurationName(providerConfigutationName);
}
};
@@ -222,6 +228,21 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
wc.setAttribute(ProviderProfileConstants.PROVIDER_CONFIG_ATT,
providerId);
+
+ // set tool name in configuration.
+ wc.setAttribute(ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, providerToolName);
+
+ /**
+ * To avoid renaming an already renamed launch configuration, we can
+ * check the expected format of the name using regular expressions and
+ * skip on matches.
+ */
+ String curConfigName = wc.getName();
+ Pattern configNamePattern = Pattern.compile(".+\\s\\[.+\\](\\s\\(\\d+\\))?$"); //$NON-NLS-1$
+ Matcher match = configNamePattern.matcher(curConfigName);
+ if (!match.find()) {
+ wc.rename(dialog.generateName(curConfigName));
+ }
}
/**
@@ -254,4 +275,18 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
return type;
}
+ /**
+ * Generate a string that can be used as a name for a provider launch configuration.
+ * It combines <code>configName</code> and <code>toolName</code> into a String of
+ * consistent format: <configuration name> [<tool name>].
+ *
+ * @param configName
+ * @param toolName
+ * @return String tool name appended to original configuration name.
+ * @since 1.2
+ */
+ public static String generateProviderConfigurationName(String configName, String toolName){
+ return configName + " " + "[" + toolName + "]"; //$NON-NLS-1$
+ }
+
}