diff options
author | Steffen Pingel | 2012-10-06 02:56:23 +0000 |
---|---|---|
committer | Steffen Pingel | 2013-09-26 19:45:58 +0000 |
commit | b25ac21444f9250945fa89c2a9bb20cb8c8d67b6 (patch) | |
tree | 83ddfbc36c084485080e714b5f22838aa25edbbd /org.eclipse.mylyn.tasks.core | |
parent | d4245c3b3223e8fbae7927a5acc0cc8401690448 (diff) | |
download | org.eclipse.mylyn.tasks-b25ac21444f9250945fa89c2a9bb20cb8c8d67b6.tar.gz org.eclipse.mylyn.tasks-b25ac21444f9250945fa89c2a9bb20cb8c8d67b6.tar.xz org.eclipse.mylyn.tasks-b25ac21444f9250945fa89c2a9bb20cb8c8d67b6.zip |
386117: [api] declare repository connector extensions in tasks.core
Change-Id: I9eafa88b5731e9aaf1d46bd0f91e1b3c51f4f129
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=386117
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
6 files changed, 390 insertions, 17 deletions
diff --git a/org.eclipse.mylyn.tasks.core/plugin.xml b/org.eclipse.mylyn.tasks.core/plugin.xml index cb398f106..5661bb737 100644 --- a/org.eclipse.mylyn.tasks.core/plugin.xml +++ b/org.eclipse.mylyn.tasks.core/plugin.xml @@ -18,4 +18,5 @@ <extension-point id="activityMonitor" name="Task Activity Monitor" schema="schema/activityMonitor.exsd"/> <extension-point id="contextStore" name="Task Context Store" schema="schema/contextStore.exsd"/> <extension-point id="repositoryConnectorContributor" name="Repository Connector Contributor" schema="schema/repositoryConnectorContributor.exsd"/> + <extension-point id="repositories" name="Task Repositories" schema="schema/repositories.exsd"/> </plugin> diff --git a/org.eclipse.mylyn.tasks.core/schema/repositories.exsd b/org.eclipse.mylyn.tasks.core/schema/repositories.exsd new file mode 100644 index 000000000..68d567078 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/schema/repositories.exsd @@ -0,0 +1,160 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.mylyn.tasks.core" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.mylyn.tasks.core" id="repositories" name="Repositories"/> + </appInfo> + <documentation> + Connectors provide integrations with task repositories. For more information please see: http://wiki.eclipse.org/index.php/Mylyn_Integrator_Reference. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + <documentation> + (no description available) + </documentation> + </annotation> + <complexType> + <sequence> + <element ref="connectorCore" minOccurs="1" maxOccurs="1"/> + <element ref="taskListMigrator" minOccurs="0" maxOccurs="1"/> + <element ref="repositoryMigrator" minOccurs="0" maxOccurs="1"/> + </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="taskListMigrator"> + <annotation> + <appInfo> + <meta.element labelAttribute="name"/> + </appInfo> + <documentation> + (no description available) + </documentation> + </annotation> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn="org.eclipse.mylyn.tasks.core.AbstractTaskListMigrator:"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="connectorCore"> + <annotation> + <documentation> + (no description available) + </documentation> + </annotation> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn="org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector"/> + </appInfo> + </annotation> + </attribute> + <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> + </complexType> + </element> + + <element name="repositoryMigrator"> + <annotation> + <documentation> + (no description available) + </documentation> + </annotation> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn="org.eclipse.mylyn.tasks.core.AbstractRepositoryMigrator:"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + 2.0 + </documentation> + </annotation> + + + + + <annotation> + <appInfo> + <meta.section type="copyright"/> + </appInfo> + <documentation> + 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 + </documentation> + </annotation> + +</schema> diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/ContributorBlackList.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/ContributorBlackList.java new file mode 100644 index 000000000..599d47149 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/ContributorBlackList.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.IConfigurationElement; + +/** + * Manages a list of plug-in IDs that have been black listed for contributions. + */ +public class ContributorBlackList { + + /** + * Plug-in ids of connector extensions that are black listed. + */ + private final Set<String> disabledContributors = new HashSet<String>(); + + public boolean isDisabled(IConfigurationElement element) { + return disabledContributors.contains(element.getContributor().getName()); + } + + public Set<String> getDisabledContributors() { + return Collections.unmodifiableSet(new HashSet<String>(disabledContributors)); + } + + public void disableContributor(String pluginId) { + disabledContributors.add(pluginId); + } + + public void merge(ContributorBlackList blackList) { + disabledContributors.addAll(blackList.getDisabledContributors()); + } + +} 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 index 3523a502a..8f6c78c79 100644 --- 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 @@ -13,11 +13,9 @@ package org.eclipse.mylyn.internal.tasks.core.util; import java.util.ArrayList; import java.util.Collection; -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; @@ -56,6 +54,8 @@ public class RepositoryConnectorExtensionReader { private static final String EXTENSION_CONTRIBUTORS = ITasksCoreConstants.ID_PLUGIN + ".repositoryConnectorContributor"; //$NON-NLS-1$ + private static final String EXTENSION_REPOSITORIES = ITasksCoreConstants.ID_PLUGIN + ".repositories"; //$NON-NLS-1$ + private static class ConnectorFactory { private AbstractRepositoryConnector connector; @@ -197,10 +197,7 @@ public class RepositoryConnectorExtensionReader { } - /** - * Plug-in ids of connector extensions that failed to load. - */ - private final Set<String> disabledContributors = new HashSet<String>(); + private final ContributorBlackList blackList = new ContributorBlackList(); private final TaskListExternalizer taskListExternalizer; @@ -210,26 +207,29 @@ public class RepositoryConnectorExtensionReader { private final List<RepositoryConnectorDescriptor> descriptors = new ArrayList<RepositoryConnectorDescriptor>(); - private MultiStatus result; + private final MultiStatus result; public RepositoryConnectorExtensionReader(TaskListExternalizer taskListExternalizer, TaskRepositoryManager repositoryManager) { this.taskListExternalizer = taskListExternalizer; this.repositoryManager = repositoryManager; + this.result = new MultiStatus(ITasksCoreConstants.ID_PLUGIN, 0, "Repository connectors failed to load.", null); //$NON-NLS-1$ } - public void registerConnectors(IExtensionPoint repositoriesExtensionPoint) { - if (result != null) { - throw new IllegalStateException("registerConnectors may only be invoked once"); //$NON-NLS-1$ - } - - result = new MultiStatus(ITasksCoreConstants.ID_PLUGIN, 0, "Repository connectors failed to load.", null); //$NON-NLS-1$ - + public void loadConnectors(IExtensionPoint repositoriesExtensionPoint) { Map<String, List<ConnectorFactory>> factoryById = readFromRepositoriesExtensionPoint(repositoriesExtensionPoint); checkForConflicts(factoryById); + } + + public void loadConnectorsFromRepositoriesExtension() { + loadConnectors(Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_REPOSITORIES)); + } + public void loadConnectorsFromContributors() { readFromContributorsExtensionPoint(); + } + public void registerConnectors() { Map<String, List<ConnectorFactory>> factoryByConnectorKind = createConnectorInstances(); checkForConflicts(factoryByConnectorKind); @@ -366,7 +366,7 @@ public class RepositoryConnectorExtensionReader { 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()); + blackList.disableContributor(factory.getPluginId()); factories.remove(factory); } result.add(status); @@ -387,8 +387,8 @@ public class RepositoryConnectorExtensionReader { return new ArrayList<RepositoryConnectorDescriptor>(descriptors); } - public Set<String> getDisabledContributors() { - return new HashSet<String>(disabledContributors); + public ContributorBlackList getBlackList() { + return blackList; } public IStatus getResult() { diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryTemplateExtensionReader.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryTemplateExtensionReader.java new file mode 100644 index 000000000..b1ee232b7 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryTemplateExtensionReader.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * 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: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.tasks.core.util; + +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.mylyn.commons.core.StatusHandler; +import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; +import org.eclipse.mylyn.internal.tasks.core.RepositoryTemplateManager; +import org.eclipse.mylyn.tasks.core.IRepositoryManager; +import org.eclipse.mylyn.tasks.core.RepositoryTemplate; +import org.eclipse.osgi.util.NLS; + +/** + * @author Mik Kersten + * @author Shawn Minto + * @author Rob Elves + */ +public class RepositoryTemplateExtensionReader { + + public static final String EXTENSION_TEMPLATES = "org.eclipse.mylyn.tasks.core.templates"; //$NON-NLS-1$ + + public static final String EXTENSION_TMPL_REPOSITORY = "repository"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_LABEL = "label"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_URLREPOSITORY = "urlRepository"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_REPOSITORYKIND = "repositoryKind"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_CHARACTERENCODING = "characterEncoding"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_ANONYMOUS = "anonymous"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_VERSION = "version"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_URLNEWTASK = "urlNewTask"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_URLTASK = "urlTask"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_URLTASKQUERY = "urlTaskQuery"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_NEWACCOUNTURL = "urlNewAccount"; //$NON-NLS-1$ + + public static final String ELMNT_TMPL_ADDAUTO = "addAutomatically"; //$NON-NLS-1$ + + private final IRepositoryManager repositoryManager; + + private final RepositoryTemplateManager templateManager; + + public RepositoryTemplateExtensionReader(IRepositoryManager repositoryManager, + RepositoryTemplateManager templateManager) { + this.repositoryManager = repositoryManager; + this.templateManager = templateManager; + + } + + public void loadExtensions(ContributorBlackList blackList) { + MultiStatus result = new MultiStatus(ITasksCoreConstants.ID_PLUGIN, 0, + "Unexpected error while loading repository template extensions", null); //$NON-NLS-1$ + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint templatesExtensionPoint = registry.getExtensionPoint(EXTENSION_TEMPLATES); + IExtension[] templateExtensions = templatesExtensionPoint.getExtensions(); + for (IExtension templateExtension : templateExtensions) { + IConfigurationElement[] elements = templateExtension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + if (!blackList.isDisabled(element)) { + if (element.getName().equals(EXTENSION_TMPL_REPOSITORY)) { + IStatus status = readRepositoryTemplate(element); + if (!status.isOK()) { + result.add(status); + } + } + } + } + } + + if (!result.isOK()) { + StatusHandler.log(result); + } + } + + private IStatus readRepositoryTemplate(IConfigurationElement element) { + String label = element.getAttribute(ELMNT_TMPL_LABEL); + String serverUrl = element.getAttribute(ELMNT_TMPL_URLREPOSITORY); + String repKind = element.getAttribute(ELMNT_TMPL_REPOSITORYKIND); + String version = element.getAttribute(ELMNT_TMPL_VERSION); + String newTaskUrl = element.getAttribute(ELMNT_TMPL_URLNEWTASK); + String taskPrefix = element.getAttribute(ELMNT_TMPL_URLTASK); + String taskQueryUrl = element.getAttribute(ELMNT_TMPL_URLTASKQUERY); + String newAccountUrl = element.getAttribute(ELMNT_TMPL_NEWACCOUNTURL); + String encoding = element.getAttribute(ELMNT_TMPL_CHARACTERENCODING); + boolean addAuto = Boolean.parseBoolean(element.getAttribute(ELMNT_TMPL_ADDAUTO)); + boolean anonymous = Boolean.parseBoolean(element.getAttribute(ELMNT_TMPL_ANONYMOUS)); + + if (serverUrl != null && label != null && repKind != null + && repositoryManager.getRepositoryConnector(repKind) != null) { + RepositoryTemplate template = new RepositoryTemplate(label, serverUrl, encoding, version, newTaskUrl, + taskPrefix, taskQueryUrl, newAccountUrl, anonymous, addAuto); + for (IConfigurationElement configElement : element.getChildren()) { + String name = configElement.getAttribute("name"); //$NON-NLS-1$ + String value = configElement.getAttribute("value"); //$NON-NLS-1$ + if (name != null && name.length() > 0 && value != null) { + template.addAttribute(name, value); + } + } + templateManager.addTemplate(repKind, template); + return Status.OK_STATUS; + } else { + return new Status( + IStatus.ERROR, + ITasksCoreConstants.ID_PLUGIN, + NLS.bind( + "Could not load repository template extension contributed by ''{0}'' with connectorKind ''{1}''", element.getNamespaceIdentifier(), repKind)); //$NON-NLS-1$ + } + } + +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TasksCoreExtensionReader.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TasksCoreExtensionReader.java new file mode 100644 index 000000000..164109059 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TasksCoreExtensionReader.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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 org.eclipse.mylyn.commons.core.ExtensionPointReader; +import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; +import org.eclipse.mylyn.internal.tasks.core.context.DefaultTaskContextStore; +import org.eclipse.mylyn.tasks.core.context.AbstractTaskContextStore; + +public class TasksCoreExtensionReader { + + public static AbstractTaskContextStore loadTaskContextStore() { + ExtensionPointReader<AbstractTaskContextStore> reader = new ExtensionPointReader<AbstractTaskContextStore>( + ITasksCoreConstants.ID_PLUGIN, "contextStore", "contextStore", AbstractTaskContextStore.class); //$NON-NLS-1$ //$NON-NLS-2$ + reader.read(); + AbstractTaskContextStore contextStore = reader.getItem(); + if (contextStore != null) { + return contextStore; + } + return new DefaultTaskContextStore(); + } + +} |