summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-06-26 16:26:27 (EDT)
committer Steffen Pingel2013-06-28 05:16:20 (EDT)
commit6f2fb1fab8edcec43f683dda4e5e96f722d3daa6 (patch)
tree66decaf9947887382fbf6388591942dd1aa89372
parent97b3af427feb039f8e55d273ab09852effaff025 (diff)
downloadorg.eclipse.mylyn.tasks-6f2fb1fab8edcec43f683dda4e5e96f722d3daa6.zip
org.eclipse.mylyn.tasks-6f2fb1fab8edcec43f683dda4e5e96f722d3daa6.tar.gz
org.eclipse.mylyn.tasks-6f2fb1fab8edcec43f683dda4e5e96f722d3daa6.tar.bz2
408511: [api] move connector extension point reader into corerefs/changes/90/14090/2
Change-Id: I28c285f9ab9f7d0e3b4e80ad79dec9cb148f7db9 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=408511
-rw-r--r--org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java333
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryConnectorDescriptor.java25
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java229
4 files changed, 370 insertions, 218 deletions
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
index b449a9c..6c8d85a 100644
--- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
@@ -20,6 +20,7 @@ Export-Package: org.eclipse.mylyn.internal.provisional.tasks.core;x-internal:=tr
org.eclipse.mylyn.internal.tasks.core.data;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
org.eclipse.mylyn.internal.tasks.core.externalization;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
org.eclipse.mylyn.internal.tasks.core.sync;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
+ org.eclipse.mylyn.internal.tasks.core.util;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
org.eclipse.mylyn.tasks.core,
org.eclipse.mylyn.tasks.core.activity,
org.eclipse.mylyn.tasks.core.context,
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java
new file mode 100644
index 0000000..d4103c7
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java
@@ -0,0 +1,333 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.core.util;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+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.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
+import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
+import org.eclipse.mylyn.internal.tasks.core.externalization.TaskListExternalizer;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryMigrator;
+import org.eclipse.mylyn.tasks.core.AbstractTaskListMigrator;
+import org.eclipse.mylyn.tasks.core.RepositoryConnectorDescriptor;
+import org.eclipse.osgi.util.NLS;
+
+public class RepositoryConnectorExtensionReader {
+
+ public static final String ELMNT_MIGRATOR = "taskListMigrator"; //$NON-NLS-1$
+
+ public static final String ELMNT_REPOSITORY_MIGRATOR = "repositoryMigrator"; //$NON-NLS-1$
+
+ public static final String ELMNT_REPOSITORY_CONNECTOR = "connectorCore"; //$NON-NLS-1$
+
+ public static final String ATTR_ID = "id"; //$NON-NLS-1$
+
+ public static final String ATTR_CLASS = "class"; //$NON-NLS-1$
+
+ private static class ConnectorFactory {
+
+ private AbstractRepositoryConnector connector;
+
+ private AbstractTaskListMigrator taskListMigrator;
+
+ private AbstractRepositoryMigrator repositoryMigrator;
+
+ private final RepositoryConnectorDescriptor descriptor;
+
+ private final String pluginId;
+
+ public ConnectorFactory(RepositoryConnectorDescriptor descriptor, String pluginId) {
+ this.descriptor = descriptor;
+ this.pluginId = pluginId;
+ }
+
+ public String getConnectorKind() {
+ return (getConnector() != null) ? getConnector().getConnectorKind() : null;
+ }
+
+ public AbstractRepositoryConnector getConnector() {
+ return connector;
+ }
+
+ public String getPluginId() {
+ return pluginId;
+ }
+
+ public AbstractTaskListMigrator getTaskListMigrator() {
+ return taskListMigrator;
+ }
+
+ public AbstractRepositoryMigrator getRepositoryMigrator() {
+ return repositoryMigrator;
+ }
+
+ public IStatus createConnector() {
+ Assert.isTrue(connector == null);
+ try {
+ connector = descriptor.createRepositoryConnector();
+ if (connector != null) {
+ return Status.OK_STATUS;
+ } else {
+ return new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, NLS.bind(
+ "Could not load connector core contributed by ''{0}''", getPluginId())); //$NON-NLS-1$
+ }
+ } catch (Throwable e) {
+ return new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, NLS.bind(
+ "Could not load connector core contributed by ''{0}''", getPluginId()), e); //$NON-NLS-1$
+ }
+ }
+
+ public IStatus createTaskListMigrator() {
+ try {
+ taskListMigrator = descriptor.createTaskListMigrator();
+ if (taskListMigrator != null) {
+ return Status.OK_STATUS;
+ } else {
+ return Status.CANCEL_STATUS;
+ }
+ } catch (Throwable e) {
+ return new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, NLS.bind(
+ "Could not load task list migrator extension contributed by ''{0}''", getPluginId()), e); //$NON-NLS-1$
+ }
+ }
+
+ public IStatus createRepositoryMigrator() {
+ Assert.isTrue(repositoryMigrator == null);
+ try {
+ repositoryMigrator = descriptor.createRepositoryMigrator();
+ if (repositoryMigrator != null) {
+ return Status.OK_STATUS;
+ } else {
+ return Status.CANCEL_STATUS;
+ }
+ } catch (Throwable e) {
+ return new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, NLS.bind(
+ "Could not load repository migrator extension contributed by ''{0}''", getPluginId()), e); //$NON-NLS-1$
+ }
+ }
+
+ }
+
+ private static class ExtensionPointBasedConnectorDescriptor extends RepositoryConnectorDescriptor {
+
+ IConfigurationElement element;
+
+ IConfigurationElement taskListMigratorElement;
+
+ IConfigurationElement repositoryMigratorElement;
+
+ public ExtensionPointBasedConnectorDescriptor(IConfigurationElement element) {
+ this.element = element;
+ }
+
+ @Override
+ public AbstractRepositoryConnector createRepositoryConnector() {
+ try {
+ return (AbstractRepositoryConnector) element.createExecutableExtension(ATTR_CLASS);
+ } catch (CoreException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public AbstractTaskListMigrator createTaskListMigrator() {
+ if (taskListMigratorElement == null) {
+ return null;
+ }
+ try {
+ return (AbstractTaskListMigrator) taskListMigratorElement.createExecutableExtension(ATTR_CLASS);
+ } catch (CoreException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public AbstractRepositoryMigrator createRepositoryMigrator() {
+ if (repositoryMigratorElement == null) {
+ return null;
+ }
+ try {
+ return (AbstractRepositoryMigrator) repositoryMigratorElement.createExecutableExtension(ATTR_CLASS);
+ } catch (CoreException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getPluginId() {
+ return element.getContributor().getName();
+ }
+
+ public String getId() {
+ return element.getAttribute(ATTR_ID);
+ }
+
+ }
+
+ /**
+ * Plug-in ids of connector extensions that failed to load.
+ */
+ private final Set<String> disabledContributors = new HashSet<String>();
+
+ private final TaskListExternalizer taskListExternalizer;
+
+ private final TaskRepositoryManager repositoryManager;
+
+ public RepositoryConnectorExtensionReader(TaskListExternalizer taskListExternalizer,
+ TaskRepositoryManager repositoryManager) {
+ this.taskListExternalizer = taskListExternalizer;
+ this.repositoryManager = repositoryManager;
+ }
+
+ public void registerConnectors(IExtensionPoint repositoriesExtensionPoint) {
+ List<ConnectorFactory> descriptors = new ArrayList<ConnectorFactory>();
+ MultiStatus result = new MultiStatus(ITasksCoreConstants.ID_PLUGIN, 0,
+ "Repository connectors failed to load.", null); //$NON-NLS-1$
+
+ Map<String, List<ConnectorFactory>> factoryById = readFromRepositoriesExtensionPoint(
+ repositoriesExtensionPoint, descriptors);
+ checkForConflicts(descriptors, result, factoryById);
+
+ Map<String, List<ConnectorFactory>> factoryByConnectorKind = createConnectorInstances(descriptors, result);
+ checkForConflicts(descriptors, result, factoryByConnectorKind);
+
+ registerConnectorInstances(descriptors, result);
+
+ if (!result.isOK()) {
+ StatusHandler.log(result);
+ }
+ }
+
+ public Map<String, List<ConnectorFactory>> createConnectorInstances(List<ConnectorFactory> descriptors,
+ MultiStatus result) {
+ Map<String, List<ConnectorFactory>> factoryByConnectorKind = new LinkedHashMap<String, List<ConnectorFactory>>();
+ for (ConnectorFactory descriptor : descriptors) {
+ IStatus status = descriptor.createConnector();
+ if (status.isOK() && descriptor.getConnector() != null) {
+ add(factoryByConnectorKind, descriptor.getConnectorKind(), descriptor);
+ } else {
+ result.add(status);
+ }
+ }
+ return factoryByConnectorKind;
+ }
+
+ private void registerConnectorInstances(List<ConnectorFactory> descriptors, MultiStatus result) {
+ List<AbstractTaskListMigrator> taskListmigrators = new ArrayList<AbstractTaskListMigrator>();
+ List<AbstractRepositoryMigrator> repositoryMigrators = new ArrayList<AbstractRepositoryMigrator>();
+
+ for (ConnectorFactory descriptor : descriptors) {
+ if (descriptor.getConnector() != null) {
+ repositoryManager.addRepositoryConnector(descriptor.getConnector());
+
+ IStatus status = descriptor.createTaskListMigrator();
+ if (status.isOK() && descriptor.getTaskListMigrator() != null) {
+ taskListmigrators.add(descriptor.getTaskListMigrator());
+ } else if (status.getSeverity() == IStatus.CANCEL) {
+ // ignore
+ } else {
+ result.add(status);
+ }
+
+ status = descriptor.createRepositoryMigrator();
+ if (status.isOK() && descriptor.getRepositoryMigrator() != null) {
+ repositoryMigrators.add(descriptor.getRepositoryMigrator());
+ } else if (status.getSeverity() == IStatus.CANCEL) {
+ // ignore
+ } else {
+ result.add(status);
+ }
+ }
+ }
+
+ repositoryManager.initialize(repositoryMigrators);
+ taskListExternalizer.initialize(taskListmigrators);
+ }
+
+ private Map<String, List<ConnectorFactory>> readFromRepositoriesExtensionPoint(
+ IExtensionPoint repositoriesExtensionPoint, List<ConnectorFactory> descriptors) {
+ // read core and migrator extensions to check for id conflicts
+ Map<String, List<ConnectorFactory>> factoryById = new LinkedHashMap<String, List<ConnectorFactory>>();
+
+ IExtension[] repositoryExtensions = repositoriesExtensionPoint.getExtensions();
+ for (IExtension repositoryExtension : repositoryExtensions) {
+ IConfigurationElement[] elements = repositoryExtension.getConfigurationElements();
+ ExtensionPointBasedConnectorDescriptor descriptor = null;
+ IConfigurationElement tasklistMigratorElement = null;
+ IConfigurationElement repositoryMigratorElement = null;
+ for (IConfigurationElement element : elements) {
+ if (element.getName().equals(ELMNT_REPOSITORY_CONNECTOR)) {
+ descriptor = new ExtensionPointBasedConnectorDescriptor(element);
+ } else if (element.getName().equals(ELMNT_MIGRATOR)) {
+ tasklistMigratorElement = element;
+ } else if (element.getName().equals(ELMNT_REPOSITORY_MIGRATOR)) {
+ repositoryMigratorElement = element;
+ }
+ }
+ if (descriptor != null) {
+ descriptor.taskListMigratorElement = tasklistMigratorElement;
+ descriptor.repositoryMigratorElement = repositoryMigratorElement;
+ ConnectorFactory factory = new ConnectorFactory(descriptor, descriptor.getPluginId());
+ descriptors.add(factory);
+ if (descriptor.getId() != null) {
+ add(factoryById, descriptor.getId(), factory);
+ }
+ }
+ }
+ return factoryById;
+ }
+
+ private void checkForConflicts(List<ConnectorFactory> descriptors, MultiStatus result,
+ Map<String, List<ConnectorFactory>> descriptorById) {
+ for (Map.Entry<String, List<ConnectorFactory>> entry : descriptorById.entrySet()) {
+ if (entry.getValue().size() > 1) {
+ MultiStatus status = new MultiStatus(ITasksCoreConstants.ID_PLUGIN, 0, NLS.bind(
+ "Connector ''{0}'' registered by multiple extensions.", entry.getKey()), null); //$NON-NLS-1$
+ for (ConnectorFactory factory : entry.getValue()) {
+ status.add(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, NLS.bind(
+ "All extensions contributed by ''{0}'' have been disabled.", factory.getPluginId()), null)); //$NON-NLS-1$
+ disabledContributors.add(factory.getPluginId());
+ descriptors.remove(factory);
+ }
+ result.add(status);
+ }
+ }
+ }
+
+ private void add(Map<String, List<ConnectorFactory>> descriptorById, String id, ConnectorFactory descriptor) {
+ List<ConnectorFactory> list = descriptorById.get(id);
+ if (list == null) {
+ list = new ArrayList<ConnectorFactory>();
+ descriptorById.put(id, list);
+ }
+ list.add(descriptor);
+ }
+
+ public Set<String> getDisabledContributors() {
+ return new HashSet<String>(disabledContributors);
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryConnectorDescriptor.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryConnectorDescriptor.java
new file mode 100644
index 0000000..f987dac
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryConnectorDescriptor.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.core;
+
+/**
+ * @since 3.10
+ */
+public abstract class RepositoryConnectorDescriptor {
+
+ public abstract AbstractRepositoryConnector createRepositoryConnector();
+
+ public abstract AbstractTaskListMigrator createTaskListMigrator();
+
+ public abstract AbstractRepositoryMigrator createRepositoryMigrator();
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java
index a424ee3..ff0245a 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java
@@ -11,20 +11,14 @@
package org.eclipse.mylyn.internal.tasks.ui.util;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
-import org.eclipse.core.runtime.Assert;
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.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
@@ -35,14 +29,12 @@ import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.internal.tasks.core.activity.DefaultTaskActivityMonitor;
import org.eclipse.mylyn.internal.tasks.core.context.DefaultTaskContextStore;
import org.eclipse.mylyn.internal.tasks.core.externalization.TaskListExternalizer;
+import org.eclipse.mylyn.internal.tasks.core.util.RepositoryConnectorExtensionReader;
import org.eclipse.mylyn.internal.tasks.ui.IDynamicSubMenuContributor;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTaskListPresentation;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
import org.eclipse.mylyn.tasks.core.AbstractDuplicateDetector;
-import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
-import org.eclipse.mylyn.tasks.core.AbstractRepositoryMigrator;
-import org.eclipse.mylyn.tasks.core.AbstractTaskListMigrator;
import org.eclipse.mylyn.tasks.core.RepositoryTemplate;
import org.eclipse.mylyn.tasks.core.activity.AbstractTaskActivityMonitor;
import org.eclipse.mylyn.tasks.core.context.AbstractTaskContextStore;
@@ -57,96 +49,10 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
* @author Mik Kersten
* @author Shawn Minto
* @author Rob Elves
+ * @author Steffen Pingel
*/
public class TasksUiExtensionReader {
- private static class ConnectorDescriptor {
-
- IConfigurationElement element;
-
- IConfigurationElement taskListMigratorElement;
-
- IConfigurationElement repositoryMigratorElement;
-
- AbstractRepositoryConnector repositoryConnector;
-
- AbstractTaskListMigrator taskListMigrator;
-
- AbstractRepositoryMigrator repositoryMigrator;
-
- private final String id;
-
- public ConnectorDescriptor(IConfigurationElement element) {
- this.element = element;
- this.id = element.getAttribute(ATTR_ID);
- }
-
- public String getId() {
- return id;
- }
-
- public String getConnectorKind() {
- return (repositoryConnector != null) ? repositoryConnector.getConnectorKind() : null;
- }
-
- public IStatus createConnector() {
- Assert.isTrue(repositoryConnector == null);
- try {
- Object connectorCore = element.createExecutableExtension(ATTR_CLASS);
- if (connectorCore instanceof AbstractRepositoryConnector) {
- repositoryConnector = (AbstractRepositoryConnector) connectorCore;
- return Status.OK_STATUS;
- } else {
- return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load connector core " //$NON-NLS-1$
- + connectorCore.getClass().getCanonicalName());
- }
- } catch (Throwable e) {
- return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load connector core", e); //$NON-NLS-1$
- }
- }
-
- public IStatus createTaskListMigrator() {
- Assert.isTrue(taskListMigrator == null);
- try {
- Object migratorObject = taskListMigratorElement.createExecutableExtension(ATTR_CLASS);
- if (migratorObject instanceof AbstractTaskListMigrator) {
- taskListMigrator = (AbstractTaskListMigrator) migratorObject;
- return Status.OK_STATUS;
- } else {
- return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Could not load task list migrator: " + migratorObject.getClass().getCanonicalName() //$NON-NLS-1$
- + " must implement " + AbstractTaskListMigrator.class.getCanonicalName()); //$NON-NLS-1$
- }
- } catch (Throwable e) {
- return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Could not load task list migrator extension", e); //$NON-NLS-1$
- }
- }
-
- public IStatus createRepositoryMigrator() {
- Assert.isTrue(repositoryMigrator == null);
- try {
- Object migratorObject = repositoryMigratorElement.createExecutableExtension(ATTR_CLASS);
- if (migratorObject instanceof AbstractRepositoryMigrator) {
- repositoryMigrator = (AbstractRepositoryMigrator) migratorObject;
- return Status.OK_STATUS;
- } else {
- return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Could not load repository migrator: " + migratorObject.getClass().getCanonicalName() //$NON-NLS-1$
- + " must implement " + AbstractRepositoryMigrator.class.getCanonicalName()); //$NON-NLS-1$
- }
- } catch (Throwable e) {
- return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Could not load repository migrator extension", e); //$NON-NLS-1$
- }
- }
-
- public String getPluginId() {
- return element.getContributor().getName();
- }
-
- }
-
public static final String EXTENSION_REPOSITORIES = "org.eclipse.mylyn.tasks.ui.repositories"; //$NON-NLS-1$
public static final String EXTENSION_REPOSITORY_LINKS_PROVIDERS = "org.eclipse.mylyn.tasks.ui.projectLinkProviders"; //$NON-NLS-1$
@@ -177,16 +83,10 @@ public class TasksUiExtensionReader {
public static final String ELMNT_TMPL_ADDAUTO = "addAutomatically"; //$NON-NLS-1$
- public static final String ELMNT_REPOSITORY_CONNECTOR = "connectorCore"; //$NON-NLS-1$
-
public static final String ELMNT_REPOSITORY_LINK_PROVIDER = "linkProvider"; //$NON-NLS-1$
public static final String ELMNT_REPOSITORY_UI = "connectorUi"; //$NON-NLS-1$
- public static final String ELMNT_MIGRATOR = "taskListMigrator"; //$NON-NLS-1$
-
- public static final String ELMNT_REPOSITORY_MIGRATOR = "repositoryMigrator"; //$NON-NLS-1$
-
public static final String ATTR_BRANDING_ICON = "brandingIcon"; //$NON-NLS-1$
public static final String ATTR_OVERLAY_ICON = "overlayIcon"; //$NON-NLS-1$
@@ -242,7 +142,11 @@ public class TasksUiExtensionReader {
IExtensionRegistry registry = Platform.getExtensionRegistry();
// NOTE: has to be read first, consider improving
- initConnectorCores(taskListExternalizer, repositoryManager, registry);
+ IExtensionPoint repositoriesExtensionPoint = registry.getExtensionPoint(EXTENSION_REPOSITORIES);
+ RepositoryConnectorExtensionReader reader = new RepositoryConnectorExtensionReader(taskListExternalizer,
+ repositoryManager);
+ reader.registerConnectors(repositoriesExtensionPoint);
+ disabledContributors.addAll(reader.getDisabledContributors());
IExtensionPoint templatesExtensionPoint = registry.getExtensionPoint(EXTENSION_TEMPLATES);
IExtension[] templateExtensions = templatesExtensionPoint.getExtensions();
@@ -286,121 +190,6 @@ public class TasksUiExtensionReader {
}
}
- private static void initConnectorCores(TaskListExternalizer taskListExternalizer,
- TaskRepositoryManager repositoryManager, IExtensionRegistry registry) {
- List<ConnectorDescriptor> descriptors = new ArrayList<ConnectorDescriptor>();
- MultiStatus result = new MultiStatus(TasksUiPlugin.ID_PLUGIN, 0, "Repository connectors failed to load.", null); //$NON-NLS-1$
-
- // read core and migrator extensions to check for id conflicts
- Map<String, List<ConnectorDescriptor>> descriptorById = new LinkedHashMap<String, List<ConnectorDescriptor>>();
- IExtensionPoint repositoriesExtensionPoint = registry.getExtensionPoint(EXTENSION_REPOSITORIES);
- IExtension[] repositoryExtensions = repositoriesExtensionPoint.getExtensions();
- for (IExtension repositoryExtension : repositoryExtensions) {
- IConfigurationElement[] elements = repositoryExtension.getConfigurationElements();
- ConnectorDescriptor descriptor = null;
- IConfigurationElement tasklistMigratorElement = null;
- IConfigurationElement repositoryMigratorElement = null;
- for (IConfigurationElement element : elements) {
- if (element.getName().equals(ELMNT_REPOSITORY_CONNECTOR)) {
- descriptor = new ConnectorDescriptor(element);
- } else if (element.getName().equals(ELMNT_MIGRATOR)) {
- tasklistMigratorElement = element;
- } else if (element.getName().equals(ELMNT_REPOSITORY_MIGRATOR)) {
- repositoryMigratorElement = element;
- }
- }
- if (descriptor != null) {
- descriptor.taskListMigratorElement = tasklistMigratorElement;
- descriptor.repositoryMigratorElement = repositoryMigratorElement;
- descriptors.add(descriptor);
- if (descriptor.getId() != null) {
- add(descriptorById, descriptor.getId(), descriptor);
- }
- }
- }
-
- checkForConflicts(descriptors, result, descriptorById);
-
- // create instances to check for connector kind conflicts
- Map<String, List<ConnectorDescriptor>> descriptorByConnectorKind = new LinkedHashMap<String, List<ConnectorDescriptor>>();
- for (ConnectorDescriptor descriptor : descriptors) {
- IStatus status = descriptor.createConnector();
- if (status.isOK() && descriptor.repositoryConnector != null) {
- add(descriptorByConnectorKind, descriptor.getConnectorKind(), descriptor);
- } else {
- result.add(status);
- }
- }
-
- checkForConflicts(descriptors, result, descriptorByConnectorKind);
-
- // register connectors
- List<AbstractTaskListMigrator> taskListmigrators = new ArrayList<AbstractTaskListMigrator>();
- List<AbstractRepositoryMigrator> repositoryMigrators = new ArrayList<AbstractRepositoryMigrator>();
- for (ConnectorDescriptor descriptor : descriptors) {
- if (descriptor.repositoryConnector != null) {
- repositoryManager.addRepositoryConnector(descriptor.repositoryConnector);
- if (descriptor.taskListMigratorElement != null) {
- IStatus status = descriptor.createTaskListMigrator();
- if (status.isOK() && descriptor.taskListMigrator != null) {
- taskListmigrators.add(descriptor.taskListMigrator);
- } else {
- result.add(status);
- }
- }
- if (descriptor.repositoryMigratorElement != null) {
- IStatus status = descriptor.createRepositoryMigrator();
- if (status.isOK() && descriptor.repositoryMigrator != null) {
- repositoryMigrators.add(descriptor.repositoryMigrator);
- } else {
- result.add(status);
- }
- }
- }
- }
-
- if (!result.isOK()) {
- StatusHandler.log(result);
- }
-
- repositoryManager.initialize(repositoryMigrators);
- taskListExternalizer.initialize(taskListmigrators);
- }
-
- private static boolean isDisabled(IConfigurationElement element) {
- return disabledContributors.contains(element.getContributor().getName());
- }
-
- private static void checkForConflicts(List<ConnectorDescriptor> descriptors, MultiStatus result,
- Map<String, List<ConnectorDescriptor>> descriptorById) {
- for (Map.Entry<String, List<ConnectorDescriptor>> entry : descriptorById.entrySet()) {
- if (entry.getValue().size() > 1) {
- MultiStatus status = new MultiStatus(TasksUiPlugin.ID_PLUGIN, 0, NLS.bind(
- "Connector ''{0}'' registered by multiple extensions.", entry.getKey()), null); //$NON-NLS-1$
- for (ConnectorDescriptor descriptor : entry.getValue()) {
- status.add(new Status(
- IStatus.ERROR,
- TasksUiPlugin.ID_PLUGIN,
- NLS.bind(
- "All extensions contributed by ''{0}'' have been disabled.", descriptor.getPluginId()), null)); //$NON-NLS-1$
- disabledContributors.add(descriptor.getPluginId());
- descriptors.remove(descriptor);
- }
- result.add(status);
- }
- }
- }
-
- private static void add(Map<String, List<ConnectorDescriptor>> descriptorById, String id,
- ConnectorDescriptor descriptor) {
- List<ConnectorDescriptor> list = descriptorById.get(id);
- if (list == null) {
- list = new ArrayList<ConnectorDescriptor>();
- descriptorById.put(id, list);
- }
- list.add(descriptor);
- }
-
public static void initWorkbenchUiExtensions() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
@@ -705,4 +494,8 @@ public class TasksUiExtensionReader {
return new DefaultTaskContextStore();
}
+ private static boolean isDisabled(IConfigurationElement element) {
+ return disabledContributors.contains(element.getContributor().getName());
+ }
+
}