| author | Sebastian Schmidt | 2012-05-21 13:15:14 (EDT) |
|---|---|---|
| committer | Sebastian Schmidt | 2012-05-21 13:15:14 (EDT) |
| commit | 2e1ea1a3fd1cae9466befe11b9870d8981ea2921 (patch) (side-by-side diff) | |
| tree | 1a4b9a472d64267b8a6b3c889ffeacdbac1eb6e8 | |
| parent | e8a53673bf36d66d72bbc9498d6ca37feff37c68 (diff) | |
| download | org.eclipse.mylyn.context-2e1ea1a3fd1cae9466befe11b9870d8981ea2921.zip org.eclipse.mylyn.context-2e1ea1a3fd1cae9466befe11b9870d8981ea2921.tar.gz org.eclipse.mylyn.context-2e1ea1a3fd1cae9466befe11b9870d8981ea2921.tar.bz2 | |
expose IContextContributor as extension pointrefs/changes/53/6053/8
This changes exposes IContextContributor registrations
as an org.eclipse.mylyn.context.core extension point.
Bug: 378399
Change-Id: I62b2c4c3400d951b8dc800cd98b993bdcb03df85
6 files changed, 147 insertions, 7 deletions
diff --git a/org.eclipse.mylyn.context.core/plugin.xml b/org.eclipse.mylyn.context.core/plugin.xml index 6d7e01b..bf7733b 100644 --- a/org.eclipse.mylyn.context.core/plugin.xml +++ b/org.eclipse.mylyn.context.core/plugin.xml @@ -8,9 +8,11 @@ Contributors: Tasktop Technologies - initial API and implementation + Sebastian Schmidt - added contributor extension point --> <plugin> + <extension-point id="contributor" name="contributor" schema="schema/contributor.exsd"/> <extension-point id="bridges" name="bridges" schema="schema/bridges.exsd"/> <extension-point id="internalBridges" name="Internal Bridges" schema="schema/internalBridges.exsd"/> <extension-point id="relationProviders" name="relationProviders" schema="schema/relationProviders.exsd"/> diff --git a/org.eclipse.mylyn.context.core/schema/contributor.exsd b/org.eclipse.mylyn.context.core/schema/contributor.exsd new file mode 100644 index 0000000..ee0c1f7 --- a/dev/null +++ b/org.eclipse.mylyn.context.core/schema/contributor.exsd @@ -0,0 +1,95 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.mylyn.context.core" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.mylyn.context.core" id="contributor" name="contributor"/> + </appInfo> + <documentation> + ContextContributor are allowed to persist arbitrary data in context. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence> + <element ref="contextContributor" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <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="contextContributor"> + <complexType> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn="org.eclipse.mylyn.context.core.AbstractContextContributor:"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + 3.8 + </documentation> + </annotation> + + + + + +</schema> diff --git a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/AbstractContextContributor.java b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/AbstractContextContributor.java new file mode 100644 index 0000000..93abac3 --- a/dev/null +++ b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/AbstractContextContributor.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Sebastian Schmidt - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.context.core; + +/** + * Clients should extend this class instead of implementing {@link IContextContributor}. + * + * @since 3.9 + */ +public abstract class AbstractContextContributor implements IContextContributor { + +}
\ No newline at end of file diff --git a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/ContextCore.java b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/ContextCore.java index 2ae4613..8a0d572 100644 --- a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/ContextCore.java +++ b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/context/core/ContextCore.java @@ -59,6 +59,9 @@ public final class ContextCore { } /** + * Returns a list of all {@link IContextContributor} registered with Mylyn context. Please refer to the + * org.eclipse.mylyn.context.core.contributor extension point. + * * @since 3.9 */ public static List<IContextContributor> getContextContributor() { diff --git a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/ContextCorePlugin.java b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/ContextCorePlugin.java index fe7ecf8..ce46d9f 100644 --- a/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/ContextCorePlugin.java +++ b/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/ContextCorePlugin.java @@ -31,7 +31,9 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; +import org.eclipse.mylyn.commons.core.ExtensionPointReader; import org.eclipse.mylyn.commons.core.StatusHandler; +import org.eclipse.mylyn.context.core.AbstractContextContributor; import org.eclipse.mylyn.context.core.AbstractContextStructureBridge; import org.eclipse.mylyn.context.core.ContextCore; import org.eclipse.mylyn.context.core.IContextContributor; @@ -52,7 +54,7 @@ public class ContextCorePlugin extends Plugin { private final Map<String, Set<String>> childContentTypeMap = new ConcurrentHashMap<String, Set<String>>(); - private final List<IContextContributor> contextContributor = new CopyOnWriteArrayList<IContextContributor>(); + private List<IContextContributor> contextContributor = new CopyOnWriteArrayList<IContextContributor>(); // specifies that one content type should shadow another // the <value> content type shadows the <key> content typee @@ -70,6 +72,8 @@ public class ContextCorePlugin extends Plugin { private final InteractionContextScaling commonContextScaling = new InteractionContextScaling(); + private boolean contextContributorInitialized = false; + private static final AbstractContextStructureBridge DEFAULT_BRIDGE = new AbstractContextStructureBridge() { @Override @@ -133,6 +137,10 @@ public class ContextCorePlugin extends Plugin { } }; + private static final String EXTENSION_ELEMENT_CONTRIBUTOR = "contextContributor"; //$NON-NLS-1$ + + private static final String EXTENSION_ID_CONTRIBUTOR = "contributor"; //$NON-NLS-1$ + public ContextCorePlugin() { INSTANCE = this; } @@ -215,15 +223,26 @@ public class ContextCorePlugin extends Plugin { } public List<IContextContributor> getContextContributor() { + initContextContributor(); return contextContributor; } - // TODO: add extension point to register context provider - public void addContextContributor(IContextContributor contributor) { + private void initContextContributor() { + if (!contextContributorInitialized) { + ExtensionPointReader<IContextContributor> extensionPointReader = new ExtensionPointReader<IContextContributor>( + ContextCorePlugin.ID_PLUGIN, ContextCorePlugin.EXTENSION_ID_CONTRIBUTOR, + ContextCorePlugin.EXTENSION_ELEMENT_CONTRIBUTOR, IContextContributor.class); + extensionPointReader.read(); + contextContributor = extensionPointReader.getItems(); + contextContributorInitialized = true; + } + } + + public void addContextContributor(AbstractContextContributor contributor) { contextContributor.add(contributor); } - public void removeContextContributor(IContextContributor contributor) { + public void removeContextContributor(AbstractContextContributor contributor) { contextContributor.remove(contributor); } diff --git a/org.eclipse.mylyn.context.tests/src/org/eclipse/mylyn/context/tests/ContextExternalizerTest.java b/org.eclipse.mylyn.context.tests/src/org/eclipse/mylyn/context/tests/ContextExternalizerTest.java index e5eb933..3a48531 100644 --- a/org.eclipse.mylyn.context.tests/src/org/eclipse/mylyn/context/tests/ContextExternalizerTest.java +++ b/org.eclipse.mylyn.context.tests/src/org/eclipse/mylyn/context/tests/ContextExternalizerTest.java @@ -24,8 +24,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil; +import org.eclipse.mylyn.context.core.AbstractContextContributor; import org.eclipse.mylyn.context.core.ContextCore; -import org.eclipse.mylyn.context.core.IContextContributor; import org.eclipse.mylyn.context.core.IInteractionContext; import org.eclipse.mylyn.context.core.IInteractionContextScaling; import org.eclipse.mylyn.context.core.IInteractionElement; @@ -314,7 +314,7 @@ public class ContextExternalizerTest extends AbstractContextTest { public void testAddContextContributor() throws Exception { InteractionContextExternalizer externalizer = new InteractionContextExternalizer(); ContextCorePlugin contextCorePlugin = ContextCorePlugin.getDefault(); - IContextContributor contributor = mock(IContextContributor.class); + AbstractContextContributor contributor = mock(AbstractContextContributor.class); when(contributor.getDataAsStream(context)).thenReturn(null); contextCorePlugin.addContextContributor(contributor); @@ -330,7 +330,7 @@ public class ContextExternalizerTest extends AbstractContextTest { public void testWriteAdditionalContextData() throws Exception { InteractionContextExternalizer externalizer = new InteractionContextExternalizer(); - IContextContributor contributor = mock(IContextContributor.class); + AbstractContextContributor contributor = mock(AbstractContextContributor.class); InteractionEvent event = mockNavigation("InteractionEvent"); context.parseEvent(event); |

