summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCamilo Bernal2012-07-05 14:17:55 (EDT)
committer Camilo Bernal2012-07-13 10:21:41 (EDT)
commit8ea9dcf8a28f570eb67754749bef09f0cfc78dde (patch)
treecec33596bbb530b931ad637b2f0b5f4aab4363bf
parentaacacfb1d8f0a44389975fd31e33ddf39c33c923 (diff)
downloadorg.eclipse.linuxtools-8ea9dcf8a28f570eb67754749bef09f0cfc78dde.zip
org.eclipse.linuxtools-8ea9dcf8a28f570eb67754749bef09f0cfc78dde.tar.gz
org.eclipse.linuxtools-8ea9dcf8a28f570eb67754749bef09f0cfc78dde.tar.bz2
Add priority attribute to launch provider schema.refs/changes/40/6640/5
The launch provider schema has a priority attribute, which allows for the best selection of available launch provider choices. Change-Id: I1ac873c9b0c07a72621eb49ae2524a87272d82c8
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd8
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchShortcut.java55
2 files changed, 56 insertions, 7 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd b/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd
index 2d79eb2..c9035f7 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd
@@ -83,6 +83,14 @@
</appinfo>
</annotation>
</attribute>
+ <attribute name="priority" type="string" use="required">
+ <annotation>
+ <documentation>
+ Positive integer stating priorty over launch provider&apos;s of the same type.
+Invalid values will be assigned the lowest priority to the extension.
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchShortcut.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchShortcut.java
index 1ed7dac..58c43fc 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchShortcut.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchShortcut.java
@@ -15,6 +15,7 @@ package org.eclipse.linuxtools.profiling.launch;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
@@ -89,24 +90,64 @@ public abstract class ProfileLaunchShortcut implements ILaunchShortcut {
IExtensionPoint extPoint = Platform.getExtensionRegistry()
.getExtensionPoint(ProfileLaunchPlugin.PLUGIN_ID, "launchProvider"); //$NON-NLS-1$
IConfigurationElement[] configs = extPoint.getConfigurationElements();
+ ArrayList<IConfigurationElement> configList = new ArrayList<IConfigurationElement>();
+
for (IConfigurationElement config : configs) {
if (config.getName().equals("provider")) { //$NON-NLS-1$
String currentType = config.getAttribute("type"); //$NON-NLS-1$
String shortcut = config.getAttribute("shortcut"); //$NON-NLS-1$
- if (currentType != null && shortcut != null
+ if (currentType != null && shortcut != null
&& currentType.equals(type)) {
- try {
- Object obj = config.createExecutableExtension("shortcut"); //$NON-NLS-1$
- if (obj instanceof ProfileLaunchShortcut) {
- return (ProfileLaunchShortcut) obj;
+
+ String priority = config.getAttribute("priority");
+ if (priority != null) {
+ try {
+ Integer.parseInt(priority);
+ configList.add(config);
+ } catch (NumberFormatException e) {
+ // continue
}
- } catch (CoreException e) {
- // continue, perhaps another configuration will succeed
}
}
}
}
+ Collections.sort(configList, new Comparator<IConfigurationElement>() {
+ public int compare(IConfigurationElement c1,
+ IConfigurationElement c2) {
+ int p1, p2;
+ // If priority is not an int or is < 0, corresponding config has
+ // lowest priority.
+ try {
+ p1 = Integer.parseInt(c1.getAttribute("priority"));
+ if (p1 <= 0) {
+ return 1;
+ }
+ } catch (NumberFormatException e) {
+ return 1;
+ }
+ try {
+ p2 = Integer.parseInt(c2.getAttribute("priority"));
+ if (p2 <= 0) {
+ return -1;
+ }
+ } catch (NumberFormatException e) {
+ return -1;
+ }
+ return p1 < p2 ? -1 : 1;
+ }
+ });
+
+ for (IConfigurationElement config : configList) {
+ try {
+ Object obj = config.createExecutableExtension("shortcut"); //$NON-NLS-1$
+ if (obj instanceof ProfileLaunchShortcut) {
+ return (ProfileLaunchShortcut) obj;
+ }
+ } catch (CoreException e) {
+ // continue, other configuration may succeed
+ }
+ }
return null;
}