diff options
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src')
4 files changed, 229 insertions, 17 deletions
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(); + } + +} |