Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorbjörn Svensson2020-01-31 20:51:09 +0000
committerSarika Sinha2020-11-20 10:09:05 +0000
commit79dc434a6073a2650bc8c82335dbd8849d6bb625 (patch)
treeb2e3e14f96afb013e8a49e487764d29efefffc8f
parent1e760d286525d9efe492edf362ef64d8b4be684b (diff)
downloadeclipse.platform.debug-Y20201120-1200.tar.gz
eclipse.platform.debug-Y20201120-1200.tar.xz
eclipse.platform.debug-Y20201120-1200.zip
Bug 559758 - Only present unique launch configurationsY20201120-1200I20201120-1800
Try to identify unique launch configurations based on kind and name and return the unique set of configurations. To avoid comparing every launch configuration with all others, map the name of the configuration to the configuration itself and then as a second step if there are duplicated names, do a another pass and verify that there are only one configuration with the same attribute set (both keys and values are compared) in the resulting list of configurations. Change-Id: Id72d2842b096332fa73b3cc23e1c94531f6df28e Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java
index 524c34202..ae4c31c4a 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java
@@ -18,7 +18,12 @@ package org.eclipse.debug.internal.ui.launchConfigurations;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -93,6 +98,8 @@ public class LaunchConfigurationTreeContentProvider implements ITreeContentProvi
configs.add(launchConfig);
}
}
+ configs = filterUniqueLaunchConfigurations(configs);
+
ILaunchConfiguration[] prototypes = getLaunchManager().getLaunchConfigurations(type, ILaunchConfiguration.PROTOTYPE);
Collections.addAll(configs, prototypes);
return configs.toArray(new ILaunchConfiguration[0]);
@@ -223,4 +230,56 @@ public class LaunchConfigurationTreeContentProvider implements ITreeContentProvi
private Shell getShell() {
return fShell;
}
+
+ /**
+ * Returns unique launch configurations from the input list Launch
+ * configurations are unique if the following criteria are fulfilled:
+ * <ol>
+ * <li>The name is unique within the list</li>
+ * <li>The set of attributes (key and value) for the launch configuration is
+ * unique within the list</li>
+ * </ol>
+ *
+ * @param launchConfigurations The list of launch configurations to filter
+ * @return List of unique launch configurations based on criteria above
+ * @throws CoreException If unable to fetch attributes for launch configuration
+ */
+ private List<ILaunchConfiguration> filterUniqueLaunchConfigurations(List<ILaunchConfiguration> launchConfigurations) throws CoreException {
+ List<ILaunchConfiguration> configs = new ArrayList<>();
+
+ // Create map between name and list of launch configurations with same
+ // name
+ Map<String, List<ILaunchConfiguration>> configNameMap = new HashMap<>();
+
+ for (ILaunchConfiguration launchConfig : launchConfigurations) {
+ String name = launchConfig.getName();
+ if (!configNameMap.containsKey(name)) {
+ configNameMap.put(name, new ArrayList<>());
+ }
+ configNameMap.get(name).add(launchConfig);
+ }
+
+ // Identify unique configurations
+ for (Entry<String, List<ILaunchConfiguration>> entry : configNameMap.entrySet()) {
+ List<ILaunchConfiguration> configsWithSameName = entry.getValue();
+ if (configsWithSameName.size() == 1) {
+ // Only one configuration, add it
+ configs.add(configsWithSameName.get(0));
+ } else if (configsWithSameName.size() > 1) {
+ // More than one configuration detected with same name,
+ // verify that they are unique
+ Set<Map<String, Object>> seenConfigContent = new HashSet<>();
+ for (ILaunchConfiguration config : configsWithSameName) {
+ Map<String, Object> content = config.getAttributes();
+ if (!seenConfigContent.contains(content)) {
+ // Only add the first one with the same content
+ seenConfigContent.add(content);
+ configs.add(config);
+ }
+ }
+ }
+ }
+
+ return configs;
+ }
}

Back to the top