diff options
author | Uwe Stieber | 2012-04-27 05:08:50 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-04-27 05:09:31 +0000 |
commit | 027bdcf9bf128d05e257d653fc67f158cedfad99 (patch) | |
tree | 13204b5e76b51af4aa1673b92721d411a42d2d95 /plugins/org.eclipse.tcf | |
parent | 410992c7f7b771c8cd54d2ed71f1d65ba7b89acb (diff) | |
download | org.eclipse.tcf-027bdcf9bf128d05e257d653fc67f158cedfad99.tar.gz org.eclipse.tcf-027bdcf9bf128d05e257d653fc67f158cedfad99.tar.xz org.eclipse.tcf-027bdcf9bf128d05e257d653fc67f158cedfad99.zip |
TCF Core: Fix Bug 377619 - [eclipse] Simplify handling of "serviceProviders" extension point
Diffstat (limited to 'plugins/org.eclipse.tcf')
7 files changed, 33 insertions, 460 deletions
diff --git a/plugins/org.eclipse.tcf/META-INF/MANIFEST.MF b/plugins/org.eclipse.tcf/META-INF/MANIFEST.MF index de66a4c64..18f1f8b82 100644 --- a/plugins/org.eclipse.tcf/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.tcf/META-INF/MANIFEST.MF @@ -12,5 +12,4 @@ Require-Bundle: org.eclipse.core.runtime Bundle-Activator: org.eclipse.tcf.Activator Import-Package: org.eclipse.tcf.core;version="1.0.0", org.eclipse.tcf.protocol;version="1.0.0" -Export-Package: org.eclipse.tcf.extensions;version="1.0.0", - org.eclipse.tcf.ssl;version="1.0.0" +Export-Package: org.eclipse.tcf.ssl;version="1.0.0" diff --git a/plugins/org.eclipse.tcf/schema/serviceProviders.exsd b/plugins/org.eclipse.tcf/schema/serviceProviders.exsd index 5067d631b..4fe6f1c55 100644 --- a/plugins/org.eclipse.tcf/schema/serviceProviders.exsd +++ b/plugins/org.eclipse.tcf/schema/serviceProviders.exsd @@ -54,11 +54,14 @@ </documentation>
</annotation>
<complexType>
- <attribute name="id" type="string" use="required">
+ <attribute name="id" type="string">
<annotation>
<documentation>
- The unique id of the service provider.
+ The unique id of the service provider (deprecated).
</documentation>
+ <appInfo>
+ <meta.attribute deprecated="true"/>
+ </appInfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java index 35684a48d..978da4652 100644 --- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java +++ b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java @@ -10,16 +10,20 @@ *******************************************************************************/ package org.eclipse.tcf; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; 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.tcf.internal.extensions.TcfServiceProvidersExtensionPointManager; +import org.eclipse.osgi.util.NLS; import org.eclipse.tcf.core.ChannelTCP; +import org.eclipse.tcf.internal.nls.TcfPluginMessages; import org.eclipse.tcf.protocol.ILogger; +import org.eclipse.tcf.protocol.IServiceProvider; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.ssl.TCFSecurityManager; import org.osgi.framework.Bundle; @@ -154,6 +158,27 @@ public class Activator extends Plugin { } // Register service providers contributed via Eclipse extension point - TcfServiceProvidersExtensionPointManager.getInstance().registerServiceProviders(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint point = registry.getExtensionPoint("org.eclipse.tcf.serviceProviders"); //$NON-NLS-1$ + if (point != null) { + IExtension[] extensions = point.getExtensions(); + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + if ("serviceProvider".equals(element.getName())) { //$NON-NLS-1$ + try { + // Create the service provider instance + IServiceProvider provider = (IServiceProvider)element.createExecutableExtension("class"); //$NON-NLS-1$ + if (provider != null) Protocol.addServiceProvider(provider); + } catch (CoreException e) { + IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, + NLS.bind(TcfPluginMessages.Extension_error_invalidExtensionPoint, element.getDeclaringExtension().getUniqueIdentifier()), + e); + Activator.getDefault().getLog().log(status); + } + } + } + } + } } } diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfAbstractExtensionPointManager.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfAbstractExtensionPointManager.java deleted file mode 100644 index 3bf010fdd..000000000 --- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfAbstractExtensionPointManager.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.extensions; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.osgi.util.NLS; -import org.eclipse.tcf.Activator; -import org.eclipse.tcf.internal.nls.TcfPluginMessages; - - -/** - * Abstract extension point manager base implementation. - */ -public abstract class TcfAbstractExtensionPointManager<V> { - // Flag to mark the extension point manager initialized (extensions loaded). - private boolean fInitialized = false; - // The map of loaded extension listed by their unique ids - private Map<String, TcfExtensionProxy<V>> fExtensions = new LinkedHashMap<String, TcfExtensionProxy<V>>(); - // The extension point comparator - private TcfExtensionPointComparator fComparator = null; - - /** - * Constructor. - */ - public TcfAbstractExtensionPointManager() { - } - - /** - * Returns if or if not the service provider extension point manager - * got initialized. Initialized means that the manager read the - * contributions for the managed extension point. - * - * @return <code>True</code> if already initialized, <code>false</code> otherwise. - */ - protected boolean isInitialized() { - return fInitialized; - } - - /** - * Sets if or if not the service provider extension point manager - * is initialized. Initialized means that the manager has read - * the contributions for the managed extension point. - * - * @return <code>True</code> to set the extension point manager is initialized, <code>false</code> otherwise. - */ - protected void setInitialized(boolean initialized) { - fInitialized = initialized; - } - - /** - * Returns the map of managed extensions. If not loaded before, - * this methods trigger the loading of the extensions to the managed - * extension point. - * - * @return The map of contributions. - */ - protected Map<String, TcfExtensionProxy<V>> getExtensions() { - if (!isInitialized()) { loadExtensions(); setInitialized(true); } - return fExtensions; - } - - /** - * Returns the extensions of the specified extension point sorted. - * For the order of the extensions, see {@link WRLaunchExtensionPointComparator}. - * - * @param point The extension point. Must be not <code>null</code>. - * @return The extensions in sorted order or an empty array if the extension point has no extensions. - */ - protected IExtension[] getExtensionsSorted(IExtensionPoint point) { - assert point != null; - - List<IExtension> extensions = new ArrayList<IExtension>(Arrays.asList(point.getExtensions())); - if (extensions.size() > 0) { - Collections.sort(extensions, getExtensionPointComparator()); - } - - return extensions.toArray(new IExtension[extensions.size()]); - } - - /** - * Returns the extension point comparator instance. If not available, - * {@link #doCreateExtensionPointComparator()} is called to create a new instance. - * - * @return The extension point comparator or <code>null</code> if the instance creation fails. - */ - protected final TcfExtensionPointComparator getExtensionPointComparator() { - if (fComparator == null) { - fComparator = doCreateExtensionPointComparator(); - } - return fComparator; - } - - /** - * Creates a new extension point comparator instance. - * - * @return The extension point comparator instance. Must never be <code>null</code>. - */ - protected TcfExtensionPointComparator doCreateExtensionPointComparator() { - return new TcfExtensionPointComparator(); - } - - /** - * Returns the extension point id to read. The method - * must return never <code>null</code>. - * - * @return The extension point id. - */ - protected abstract String getExtensionPointId(); - - /** - * Returns the configuration element name. The method - * must return never <code>null</code>. - * - * @return The configuration element name. - */ - protected abstract String getConfigurationElementName(); - - /** - * Creates the extension proxy instance. - * - * @param element The configuration element of the extension. Must be not <code>null</code>. - * @return The extension proxy instance. - * - * @throws CoreException If the extension proxy instantiation failed. - */ - protected TcfExtensionProxy<V> doCreateExtensionProxy(IConfigurationElement element) throws CoreException { - assert element != null; - return new TcfExtensionProxy<V>(element); - } - - /** - * Loads the extensions for the managed extenions point. - */ - protected void loadExtensions() { - // If already initialized, this method will do nothing. - if (isInitialized()) return; - - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint point = registry.getExtensionPoint(getExtensionPointId()); - if (point != null) { - IExtension[] extensions = getExtensionsSorted(point); - for (IExtension extension : extensions) { - IConfigurationElement[] elements = extension.getConfigurationElements(); - for (IConfigurationElement element : elements) { - if (getConfigurationElementName().equals(element.getName())) { - try { - TcfExtensionProxy<V> candidate = doCreateExtensionProxy(element); - if (candidate.getId() != null) { - // If no contribution with this id had been registered before, register now. - if (!fExtensions.containsKey(candidate.getId())) { - fExtensions.put(candidate.getId(), candidate); - } - else { - throw new CoreException(new Status(IStatus.ERROR, - Activator.PLUGIN_ID, - 0, - NLS.bind(TcfPluginMessages.Extension_error_duplicateExtension, candidate.getId(), element.getContributor().getName()), - null)); - } - } - else { - throw new CoreException(new Status(IStatus.ERROR, - Activator.PLUGIN_ID, - 0, - NLS.bind(TcfPluginMessages.Extension_error_missingRequiredAttribute, "id", element.getAttribute("label")), //$NON-NLS-1$ //$NON-NLS-2$ - null)); - } - } - catch (CoreException e) { - IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, - NLS.bind(TcfPluginMessages.Extension_error_invalidExtensionPoint, element.getDeclaringExtension().getUniqueIdentifier()), - e); - Activator.getDefault().getLog().log(status); - } - } - } - } - } - } -} diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java deleted file mode 100644 index fd5b2108e..000000000 --- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2012 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.extensions; - -import java.io.Serializable; -import java.util.Comparator; - -import org.eclipse.core.runtime.IExtension; - -/** - * TCF extension point comparator. Used to ensure that extension are - * always read in the same order. - * <p> - * The order of the extensions is defined as following:<br> - * <ul><li>Extensions contributed by the TCF core plug-ins (<code>org.eclipse.tcf.*</code>) - * in ascending alphabetic order and</li> - * <li>Extensions contributed by any other plug-in in ascending alphabetic order.</li> - * <li>Extensions contributed by the same plug-in in ascending alphabetic order by the - * extensions unique id</li> - * </ul> - */ -public class TcfExtensionPointComparator implements Comparator<IExtension>, Serializable { - - private static final long serialVersionUID = 488904870541301084L; - private final static String TCF_PLUGIN_PATTERN = "org.eclipse.tcf.*"; //$NON-NLS-1$ - - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(IExtension o1, IExtension o2) { - // We ignore any comparison with null and - if (o1 == null || o2 == null) return 0; - // Check if it is the exact same element - if (o1 == o2) return 0; - - // The extensions are compared by the unique id of the contributing plugin first - String contributor1 = o1.getContributor().getName(); - String contributor2 = o2.getContributor().getName(); - - // Contributions from TCF core plugins comes before 3rdParty Plugins - if (contributor1.startsWith(TCF_PLUGIN_PATTERN) && !contributor2.startsWith(TCF_PLUGIN_PATTERN)) - return -1; - if (!contributor1.startsWith(TCF_PLUGIN_PATTERN) && contributor2.startsWith(TCF_PLUGIN_PATTERN)) - return 1; - if (contributor1.startsWith(TCF_PLUGIN_PATTERN) && contributor2.startsWith(TCF_PLUGIN_PATTERN)) { - int value = contributor1.compareTo(contributor2); - // Within the same plugins, the extension are sorted by their unique id (if available) - if (value == 0 && o1.getUniqueIdentifier() != null && o2.getUniqueIdentifier() != null) - return o1.getUniqueIdentifier().compareTo(o2.getUniqueIdentifier()); - // Otherwise, just return the comparison result from the contributors - return value; - } - - // Contributions from all other plugins are sorted alphabetical - int value = contributor1.compareTo(contributor2); - // Within the same plugins, the extension are sorted by thier unique id (if available) - if (value == 0 && o1.getUniqueIdentifier() != null && o2.getUniqueIdentifier() != null) - return o1.getUniqueIdentifier().compareTo(o2.getUniqueIdentifier()); - // Otherwise, just return the comparison result from the contributors - return value; - } -} diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java deleted file mode 100644 index 77cd6f75d..000000000 --- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2012 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.extensions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.osgi.util.NLS; -import org.eclipse.tcf.Activator; -import org.eclipse.tcf.internal.nls.TcfPluginMessages; - -/** - * TCF extension proxy implementation. The use of the proxy ensures the - * lazy plug-in activation policy for the contributing plug-in. - */ -public class TcfExtensionProxy<V> { - // The extension instance. Create on first access - private V instance; - // The configuration element - private final IConfigurationElement element; - // The unique id of the extension. - private final String id; - - /** - * Constructor. - * - * @param element The configuration element. Must be not <code>null</code>. - * - * @throws CoreException In case the configuration element attribute <i>id</i> is <code>null</code> or empty. - */ - public TcfExtensionProxy(IConfigurationElement element) throws CoreException { - assert element != null; - this.element = element; - - // The <id> attribute is mandatory. - id = element.getAttribute("id"); //$NON-NLS-1$ - if (id == null || id.trim().length() == 0) { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, - NLS.bind(TcfPluginMessages.Extension_error_missingRequiredAttribute, "id", element.getContributor().getName()), //$NON-NLS-1$ - null)); - } - } - - /** - * Returns the extensions unique id. - * - * @return The unique id. - */ - public final String getId() { - return id; - } - - /** - * Returns the configuration element for this extension. - * - * @return The configuration element. - */ - protected final IConfigurationElement getConfigurationElement() { - return element; - } - - /** - * Returns the extension class instance. The contributing - * plug-in will be activated if not yet activated anyway. - * - * @return The extension class instance. Might be <code>null</code> if the instantiation fails. - */ - @SuppressWarnings("unchecked") - public V getInstance() { - if (instance == null && element.getAttribute("class") != null) { //$NON-NLS-1$ - try { - instance = (V)element.createExecutableExtension("class"); //$NON-NLS-1$ - } - catch (Exception e) { - // Possible exceptions: CoreException, ClassCastException. - IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, - NLS.bind(TcfPluginMessages.Extension_error_invalidExtensionPoint, element.getDeclaringExtension().getUniqueIdentifier()), - e); - Activator.getDefault().getLog().log(status); - } - } - return instance; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - // Proxies are equal if they have encapsulate an element - // with the same unique id - if (obj instanceof TcfExtensionProxy<?>) { - return id.equals(((TcfExtensionProxy<?>)obj).id); - } - return super.equals(obj); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - // The hash code of a proxy is the one from the id - return id.hashCode(); - } -} diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/internal/extensions/TcfServiceProvidersExtensionPointManager.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/internal/extensions/TcfServiceProvidersExtensionPointManager.java deleted file mode 100644 index c84950c55..000000000 --- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/internal/extensions/TcfServiceProvidersExtensionPointManager.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.internal.extensions; - -import java.util.Map; - -import org.eclipse.tcf.extensions.TcfAbstractExtensionPointManager; -import org.eclipse.tcf.extensions.TcfExtensionProxy; -import org.eclipse.tcf.protocol.IServiceProvider; -import org.eclipse.tcf.protocol.Protocol; - -/** - * Extension point manager implementation for "org.eclipse.tcf.serviceProviders". - */ -public class TcfServiceProvidersExtensionPointManager extends TcfAbstractExtensionPointManager<IServiceProvider> { - /* - * Thread save singleton instance creation. - */ - private static class LazyInstanceHolder { - public static TcfServiceProvidersExtensionPointManager fInstance = new TcfServiceProvidersExtensionPointManager(); - } - - /** - * Returns the singleton instance for the manager. - */ - public static TcfServiceProvidersExtensionPointManager getInstance() { - return LazyInstanceHolder.fInstance; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.extensions.TcfAbstractExtensionPointManager#getExtensionPointId() - */ - @Override - protected String getExtensionPointId() { - return "org.eclipse.tcf.serviceProviders"; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.extensions.TcfAbstractExtensionPointManager#getConfigurationElementName() - */ - @Override - protected String getConfigurationElementName() { - return "serviceProvider"; //$NON-NLS-1$ - } - - /** - * Register the contributed service provider extensions with the framework. - */ - public void registerServiceProviders() { - // Load the extensions - Map<String, TcfExtensionProxy<IServiceProvider>> extensions = getExtensions(); - // Loop the extensions and get the service provider instance. - // This will activate the contributing plugin. - for (TcfExtensionProxy<IServiceProvider> proxy : extensions.values()) { - IServiceProvider provider = proxy.getInstance(); - if (provider != null) Protocol.addServiceProvider(provider); - } - } -} |