summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2012-09-24 18:47:13 (EDT)
committerSteffen Pingel2012-10-06 05:40:24 (EDT)
commitd398d25d6d2342652b9637850334abef48fa39f5 (patch)
tree613b07098e0a789f503efd9b51a8822eda636ddb
parent9ca41a88ac078defb074f51a737c0f94c358874b (diff)
downloadorg.eclipse.mylyn.commons-d398d25d6d2342652b9637850334abef48fa39f5.zip
org.eclipse.mylyn.commons-d398d25d6d2342652b9637850334abef48fa39f5.tar.gz
org.eclipse.mylyn.commons-d398d25d6d2342652b9637850334abef48fa39f5.tar.bz2
389946: ExtensionPointReader ignores priorityAttributeId valuerefs/changes/03/7903/3
Change-Id: I4c657e6131ca26bc9ad07e426ab40a9095ed2b23 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=389946
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java12
-rw-r--r--org.eclipse.mylyn.commons.tests/plugin.xml5
-rw-r--r--org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd289
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/ExtensionPointReaderTest.java15
4 files changed, 172 insertions, 149 deletions
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java
index 467589d..06e6c2b 100644
--- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java
@@ -32,21 +32,19 @@ import org.eclipse.osgi.util.NLS;
* @since 3.7
*/
public class ExtensionPointReader<T> {
-
- private static final class PriorityComparator implements Comparator<IConfigurationElement> {
-
+ private final class PriorityComparator implements Comparator<IConfigurationElement> {
public int compare(IConfigurationElement arg0, IConfigurationElement arg1) {
double p0 = 0;
double p1 = 0;
try {
- String priorityAttribute = arg0.getAttribute(DEFAULT_ATTRIBUTE_ID_PRIORITY);
+ String priorityAttribute = arg0.getAttribute(getPriorityAttributeId());
if (priorityAttribute != null) {
p0 = Double.parseDouble(priorityAttribute);
}
} catch (NumberFormatException e) {
}
try {
- String priorityAttribute = arg1.getAttribute(DEFAULT_ATTRIBUTE_ID_PRIORITY);
+ String priorityAttribute = arg1.getAttribute(getPriorityAttributeId());
if (priorityAttribute != null) {
p1 = Double.parseDouble(priorityAttribute);
}
@@ -66,7 +64,7 @@ public class ExtensionPointReader<T> {
private static final String DEFAULT_ATTRIBUTE_ID_PRIORITY = "priority"; //$NON-NLS-1$
- private static final PriorityComparator PRIORITY_COMPARATOR = new PriorityComparator();
+ private final PriorityComparator priorityComparator = new PriorityComparator();
private String classAttributeId;
@@ -147,7 +145,7 @@ public class ExtensionPointReader<T> {
IExtension[] extensions = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] elements = extension.getConfigurationElements();
- Arrays.sort(elements, PRIORITY_COMPARATOR);
+ Arrays.sort(elements, priorityComparator);
for (IConfigurationElement element : elements) {
if (element.getName().equals(elementId) && shouldRead(element)) {
T item = readElement(element, result);
diff --git a/org.eclipse.mylyn.commons.tests/plugin.xml b/org.eclipse.mylyn.commons.tests/plugin.xml
index d2ae3ab..02022ac 100644
--- a/org.eclipse.mylyn.commons.tests/plugin.xml
+++ b/org.eclipse.mylyn.commons.tests/plugin.xml
@@ -29,16 +29,19 @@
<extensionElementWithPriority
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$P5ExtensionPointReaderExtensionImplementation"
priority="5"
+ customPriority="-5"
testFilterAttribute="value1">
</extensionElementWithPriority>
<extensionElementWithPriority
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$PNegative5ExtensionPointReaderExtensionImplementation"
priority="-5"
+ customPriority="5"
testFilterAttribute="value2">
</extensionElementWithPriority>
<extensionElementWithPriority
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$P10ExtensionPointReaderExtensionImplementation"
- priority="10">
+ priority="10"
+ customPriority="10">
</extensionElementWithPriority>
<extensionElementWithPriority
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$P0ExtensionPointReaderExtensionImplementation">
diff --git a/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd b/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd
index a08c2c2..7d8d7a7 100644
--- a/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd
+++ b/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd
@@ -1,141 +1,148 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.mylyn.commons.tests" xmlns="http://www.w3.org/2001/XMLSchema">
-<annotation>
- <appinfo>
- <meta.schema plugin="org.eclipse.mylyn.commons.tests" id="extensionPointReaderTest" name="ExtensionPointReader Test"/>
- </appinfo>
- <documentation>
- Test extenstion point for ExtensionPointReader.
- </documentation>
- </annotation>
-
- <element name="extension">
- <annotation>
- <appinfo>
- <meta.element internal="true" />
- </appinfo>
- </annotation>
- <complexType>
- <choice minOccurs="1" maxOccurs="unbounded">
- <element ref="extensionElement"/>
- <element ref="extensionElementWithPriority"/>
- </choice>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute translatable="true"/>
- </appinfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="extensionElement">
- <complexType>
- <attribute name="class" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute kind="java" basedOn=":org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$ExtensionPointReaderExtension"/>
- </appinfo>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="testFilterAttribute" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="extensionElementWithPriority">
- <complexType>
- <attribute name="class" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute kind="java" basedOn=":org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$ExtensionPointReaderExtension"/>
- </appinfo>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="testFilterAttribute" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="priority" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appinfo>
- <meta.section type="since"/>
- </appinfo>
- <documentation>
- 3.7
- </documentation>
- </annotation>
-
-
-
-
- <annotation>
- <appinfo>
- <meta.section type="copyright"/>
- </appinfo>
- <documentation>
- Copyright (c) 2012 Tasktop Technologies and others.
-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
- </documentation>
- </annotation>
-
-</schema>
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.mylyn.commons.tests" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.mylyn.commons.tests" id="extensionPointReaderTest" name="ExtensionPointReader Test"/>
+ </appinfo>
+ <documentation>
+ Test extenstion point for ExtensionPointReader.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element internal="true" />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element ref="extensionElement"/>
+ <element ref="extensionElementWithPriority"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="extensionElement">
+ <complexType>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$ExtensionPointReaderExtension"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="testFilterAttribute" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="extensionElementWithPriority">
+ <complexType>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$ExtensionPointReaderExtension"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="testFilterAttribute" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="priority" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="customPriority" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 3.7
+ </documentation>
+ </annotation>
+
+
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2012 Tasktop Technologies and others.
+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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/ExtensionPointReaderTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/ExtensionPointReaderTest.java
index f553508..cfe282f 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/ExtensionPointReaderTest.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/ExtensionPointReaderTest.java
@@ -123,4 +123,19 @@ public class ExtensionPointReaderTest extends TestCase {
new PNegative5ExtensionPointReaderExtensionImplementation() }), reader.getItems());
}
+ public void testReadWithCustomPriority() {
+ ExtensionPointReader<ExtensionPointReaderExtension> reader = new ExtensionPointReader<ExtensionPointReaderExtension>(
+ ID_PLUGIN, "extensionPointReaderTest", "extensionElementWithPriority",
+ ExtensionPointReaderExtension.class);
+ reader.setPriorityAttributeId("customPriority");
+ IStatus status = reader.read();
+ assertEquals(IStatus.OK, status.getSeverity());
+ assertEquals(
+ Arrays.asList(new ExtensionPointReaderExtension[] {
+ new P10ExtensionPointReaderExtensionImplementation(),
+ new PNegative5ExtensionPointReaderExtensionImplementation(),
+ new P0ExtensionPointReaderExtensionImplementation(),
+ new P5ExtensionPointReaderExtensionImplementation() }), reader.getItems());
+ }
+
}