summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-02-17 19:12:38 (EST)
committerSteffen Pingel2012-02-17 19:12:38 (EST)
commit8d6c3a820bb821f852afd8c3cbe16a4b87c45998 (patch)
treed2aa44cffe55d2e9e8836957f3ad0015e8eb29d6
parent7f053963ca33912045bdd9c15ecd3e76fdba97b8 (diff)
downloadorg.eclipse.mylyn.commons-8d6c3a820bb821f852afd8c3cbe16a4b87c45998.zip
org.eclipse.mylyn.commons-8d6c3a820bb821f852afd8c3cbe16a4b87c45998.tar.gz
org.eclipse.mylyn.commons-8d6c3a820bb821f852afd8c3cbe16a4b87c45998.tar.bz2
REOPENED - bug 370620: renamed extensionPriority to priority
https://bugs.eclipse.org/bugs/show_bug.cgi?id=370620 Change-Id: Ica3c63f09ad244aeacc4076760cb445bb9b7a805
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java108
-rw-r--r--org.eclipse.mylyn.commons.tests/plugin.xml21
-rw-r--r--org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd38
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/ExtensionPointReaderTest.java39
4 files changed, 142 insertions, 64 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 68d88e4..5a8b3db 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
@@ -33,22 +33,20 @@ import org.eclipse.osgi.util.NLS;
*/
public class ExtensionPointReader<T> {
- private static final String ATTRIBUTE_EXTENSION_PRIORITY = "extensionPriority"; //$NON-NLS-1$
-
private static final class PriorityComparator implements Comparator<IConfigurationElement> {
public int compare(IConfigurationElement arg0, IConfigurationElement arg1) {
double p0 = 0;
double p1 = 0;
try {
- String priorityAttribute = arg0.getAttribute(ATTRIBUTE_EXTENSION_PRIORITY);
+ String priorityAttribute = arg0.getAttribute(DEFAULT_ATTRIBUTE_ID_PRIORITY);
if (priorityAttribute != null) {
p0 = Double.parseDouble(priorityAttribute);
}
} catch (NumberFormatException e) {
}
try {
- String priorityAttribute = arg1.getAttribute(ATTRIBUTE_EXTENSION_PRIORITY);
+ String priorityAttribute = arg1.getAttribute(DEFAULT_ATTRIBUTE_ID_PRIORITY);
if (priorityAttribute != null) {
p1 = Double.parseDouble(priorityAttribute);
}
@@ -61,34 +59,39 @@ public class ExtensionPointReader<T> {
}
return 0;
}
+
}
+ private static final String DEFAULT_ATTRIBUTE_ID_CLASS = "class"; //$NON-NLS-1$
+
+ private static final String DEFAULT_ATTRIBUTE_ID_PRIORITY = "priority"; //$NON-NLS-1$
+
private static final PriorityComparator PRIORITY_COMPARATOR = new PriorityComparator();
- private final String extensionId;
+ private String classAttributeId;
+
+ private final Class<T> clazz;
private final String elementId;
- private final Class<T> clazz;
+ private final String extensionId;
- private String classAttributeId;
+ private String filterAttributeId;
- private final String pluginId;
+ private String filterAttributeValue;
private final List<T> items;
- private String filterAttributeId;
+ private final String pluginId;
- private String filterAttributeValue;
+ private String priorityAttributeId;
- public ExtensionPointReader(String pluginId, String extensionId, String elementId, Class<T> clazz,
- String filterAttributeId, String filterAttributeValue) {
- this(pluginId, extensionId, elementId, clazz);
- this.filterAttributeId = filterAttributeId;
- this.filterAttributeValue = filterAttributeValue;
+ public ExtensionPointReader(String pluginId, String extensionId, String elementId, Class<T> clazz) {
+ this(pluginId, extensionId, elementId, clazz, null, null);
}
- public ExtensionPointReader(String pluginId, String extensionId, String elementId, Class<T> clazz) {
+ public ExtensionPointReader(String pluginId, String extensionId, String elementId, Class<T> clazz,
+ String filterAttributeId, String filterAttributeValue) {
Assert.isNotNull(pluginId);
Assert.isNotNull(extensionId);
Assert.isNotNull(elementId);
@@ -97,24 +100,35 @@ public class ExtensionPointReader<T> {
this.extensionId = extensionId;
this.elementId = elementId;
this.clazz = clazz;
- this.classAttributeId = "class"; //$NON-NLS-1$
+ this.filterAttributeId = filterAttributeId;
+ this.filterAttributeValue = filterAttributeValue;
+ this.classAttributeId = DEFAULT_ATTRIBUTE_ID_CLASS;
+ this.priorityAttributeId = DEFAULT_ATTRIBUTE_ID_PRIORITY;
this.items = new ArrayList<T>();
}
- public final String getPluginId() {
- return pluginId;
+ public final String getClassAttributeId() {
+ return classAttributeId;
}
public final String getElementId() {
return elementId;
}
- public final void setClassAttributeId(String classAttributeId) {
- this.classAttributeId = classAttributeId;
+ public T getItem() {
+ return (items.isEmpty()) ? null : items.get(0);
}
- public final String getClassAttributeId() {
- return classAttributeId;
+ public List<T> getItems() {
+ return new ArrayList<T>(items);
+ }
+
+ public final String getPluginId() {
+ return pluginId;
+ }
+
+ public String getPriorityAttributeId() {
+ return priorityAttributeId;
}
public IStatus read() {
@@ -150,32 +164,26 @@ public class ExtensionPointReader<T> {
return result;
}
- /**
- * Determines whether the element should be instantiated by this ExtensionPointReader. This implementation checks
- * whether the element defines an attribute with id and value matching filterAttributeId and filterAttributeValue.
- * If filterAttributeValue is the empty string, an element is also considered to match if it does not define the
- * attribute.
- * <p>
- * Subclasses may override.
- */
- protected boolean shouldRead(IConfigurationElement element) {
- return filterAttributeId == null || filterAttributeValue == null
- || filterAttributeValue.equals(element.getAttribute(filterAttributeId))
- || (filterAttributeValue.length() == 0 && element.getAttribute(filterAttributeId) == null);
+ public final void setClassAttributeId(String classAttributeId) {
+ this.classAttributeId = classAttributeId;
}
- protected void handleResult(IStatus result) {
- if (!result.isOK()) {
- StatusHandler.log(result);
- }
+ public void setFilterAttributeId(String filterAttributeId) {
+ this.filterAttributeId = filterAttributeId;
}
- public T getItem() {
- return (items.isEmpty()) ? null : items.get(0);
+ public void setFilterAttributeValue(String filterAttributeValue) {
+ this.filterAttributeValue = filterAttributeValue;
}
- public List<T> getItems() {
- return new ArrayList<T>(items);
+ public void setPriorityAttributeId(String priorityAttributeId) {
+ this.priorityAttributeId = priorityAttributeId;
+ }
+
+ protected void handleResult(IStatus result) {
+ if (!result.isOK()) {
+ StatusHandler.log(result);
+ }
}
protected T readElement(IConfigurationElement element, MultiStatus result) {
@@ -195,4 +203,18 @@ public class ExtensionPointReader<T> {
return null;
}
+ /**
+ * Determines whether the element should be instantiated by this ExtensionPointReader. This implementation checks
+ * whether the element defines an attribute with id and value matching filterAttributeId and filterAttributeValue.
+ * If filterAttributeValue is the empty string, an element is also considered to match if it does not define the
+ * attribute.
+ * <p>
+ * Subclasses may override.
+ */
+ protected boolean shouldRead(IConfigurationElement element) {
+ return filterAttributeId == null || filterAttributeValue == null
+ || filterAttributeValue.equals(element.getAttribute(filterAttributeId))
+ || (filterAttributeValue.length() == 0 && element.getAttribute(filterAttributeId) == null);
+ }
+
}
diff --git a/org.eclipse.mylyn.commons.tests/plugin.xml b/org.eclipse.mylyn.commons.tests/plugin.xml
index 714a8cf..d2ae3ab 100644
--- a/org.eclipse.mylyn.commons.tests/plugin.xml
+++ b/org.eclipse.mylyn.commons.tests/plugin.xml
@@ -26,20 +26,23 @@
point="org.eclipse.mylyn.commons.tests.extensionPointReaderTest">
<extensionElement
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$ExtensionPointReaderExtensionImplementation"></extensionElement>
- <extensionElement
+ <extensionElementWithPriority
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$P5ExtensionPointReaderExtensionImplementation"
- extensionPriority="5"
+ priority="5"
testFilterAttribute="value1">
- </extensionElement>
- <extensionElement
+ </extensionElementWithPriority>
+ <extensionElementWithPriority
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$PNegative5ExtensionPointReaderExtensionImplementation"
- extensionPriority="-5"
+ priority="-5"
testFilterAttribute="value2">
- </extensionElement>
- <extensionElement
+ </extensionElementWithPriority>
+ <extensionElementWithPriority
class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$P10ExtensionPointReaderExtensionImplementation"
- extensionPriority="10">
- </extensionElement>
+ priority="10">
+ </extensionElementWithPriority>
+ <extensionElementWithPriority
+ class="org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest$P0ExtensionPointReaderExtensionImplementation">
+ </extensionElementWithPriority>
</extension>
</plugin>
diff --git a/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd b/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd
index 3929cf5..a08c2c2 100644
--- a/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd
+++ b/org.eclipse.mylyn.commons.tests/schema/extensionPointReaderTest.exsd
@@ -17,9 +17,10 @@
</appinfo>
</annotation>
<complexType>
- <sequence>
- <element ref="extensionElement" minOccurs="1" maxOccurs="unbounded"/>
- </sequence>
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element ref="extensionElement"/>
+ <element ref="extensionElementWithPriority"/>
+ </choice>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
@@ -73,7 +74,36 @@
</documentation>
</annotation>
</attribute>
- <attribute name="extensionPriority" type="string">
+ </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>
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 93585b8..f553508 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
@@ -31,7 +31,7 @@ public class ExtensionPointReaderTest extends TestCase {
public static class ExtensionPointReaderExtensionImplementation implements ExtensionPointReaderExtension {
- String id;
+ String id = getClass().getName();
@Override
public int hashCode() {
@@ -76,6 +76,10 @@ public class ExtensionPointReaderTest extends TestCase {
ExtensionPointReaderExtensionImplementation {
}
+ public static class P0ExtensionPointReaderExtensionImplementation extends
+ ExtensionPointReaderExtensionImplementation {
+ }
+
private static final String ID_PLUGIN = "org.eclipse.mylyn.commons.tests";
public void testRead() {
@@ -84,20 +88,39 @@ public class ExtensionPointReaderTest extends TestCase {
IStatus status = reader.read();
assertEquals(IStatus.OK, status.getSeverity());
assertEquals(
- Arrays.asList(new ExtensionPointReaderExtension[] {
- new P10ExtensionPointReaderExtensionImplementation(),
- new P5ExtensionPointReaderExtensionImplementation(),
- new ExtensionPointReaderExtensionImplementation(),
- new PNegative5ExtensionPointReaderExtensionImplementation() }), reader.getItems());
+ Arrays.asList(new ExtensionPointReaderExtension[] { new ExtensionPointReaderExtensionImplementation(), }),
+ reader.getItems());
+ assertEquals(new ExtensionPointReaderExtensionImplementation(), reader.getItem());
}
public void testReadWithFiltering() {
ExtensionPointReader<ExtensionPointReaderExtension> reader = new ExtensionPointReader<ExtensionPointReaderExtension>(
- ID_PLUGIN, "extensionPointReaderTest", "extensionElement", ExtensionPointReaderExtension.class,
- "testFilterAttribute", "value1");
+ ID_PLUGIN, "extensionPointReaderTest", "extensionElementWithPriority",
+ ExtensionPointReaderExtension.class, "testFilterAttribute", "value1");
IStatus status = reader.read();
assertEquals(IStatus.OK, status.getSeverity());
assertEquals(Collections.singletonList(new P5ExtensionPointReaderExtensionImplementation()), reader.getItems());
+ assertEquals(new P5ExtensionPointReaderExtensionImplementation(), reader.getItem());
+
+ reader.setFilterAttributeValue("nomatch");
+ status = reader.read();
+ assertEquals(IStatus.OK, status.getSeverity());
+ assertEquals(Collections.emptyList(), reader.getItems());
+ assertNull(reader.getItem());
+ }
+
+ public void testReadWithPriority() {
+ ExtensionPointReader<ExtensionPointReaderExtension> reader = new ExtensionPointReader<ExtensionPointReaderExtension>(
+ ID_PLUGIN, "extensionPointReaderTest", "extensionElementWithPriority",
+ ExtensionPointReaderExtension.class);
+ IStatus status = reader.read();
+ assertEquals(IStatus.OK, status.getSeverity());
+ assertEquals(
+ Arrays.asList(new ExtensionPointReaderExtension[] {
+ new P10ExtensionPointReaderExtensionImplementation(),
+ new P5ExtensionPointReaderExtensionImplementation(),
+ new P0ExtensionPointReaderExtensionImplementation(),
+ new PNegative5ExtensionPointReaderExtensionImplementation() }), reader.getItems());
}
}