Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2015-05-13 06:13:06 +0000
committerMarkus Tiede2015-05-13 06:14:58 +0000
commit8f6d366b25d3a358bb1a6e1d28d39ddada221180 (patch)
treee70c25285e1bb9c0743d2edcb926026e91f2a7de /org.eclipse.jubula.mylyn
parent14f63bb2bbd6172f25dde340b403740d1bd5ff53 (diff)
downloadorg.eclipse.jubula.core-8f6d366b25d3a358bb1a6e1d28d39ddada221180.tar.gz
org.eclipse.jubula.core-8f6d366b25d3a358bb1a6e1d28d39ddada221180.tar.xz
org.eclipse.jubula.core-8f6d366b25d3a358bb1a6e1d28d39ddada221180.zip
Sprint task - refactor to provide infrastructure for (shareable; client independent) mylyn integration bundle : part 2 - helper methods relocated.
Diffstat (limited to 'org.eclipse.jubula.mylyn')
-rw-r--r--org.eclipse.jubula.mylyn/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java32
-rw-r--r--org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties11
-rw-r--r--org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java180
4 files changed, 225 insertions, 1 deletions
diff --git a/org.eclipse.jubula.mylyn/META-INF/MANIFEST.MF b/org.eclipse.jubula.mylyn/META-INF/MANIFEST.MF
index 67d21be06..52afe73ed 100644
--- a/org.eclipse.jubula.mylyn/META-INF/MANIFEST.MF
+++ b/org.eclipse.jubula.mylyn/META-INF/MANIFEST.MF
@@ -14,4 +14,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.jubula.mylyn,
- org.eclipse.jubula.mylyn.exceptions
+ org.eclipse.jubula.mylyn.exceptions,
+ org.eclipse.jubula.mylyn.utils
diff --git a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java
new file mode 100644
index 000000000..6855fa9e7
--- /dev/null
+++ b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2015 BREDEX GmbH.
+ * 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:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.mylyn.i18n;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * i18n string internationalization
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.jubula.mylyn.i18n.messages"; //$NON-NLS-1$
+
+ public static String TaskRepositoryNotFound;
+ public static String TaskRepositoryOffline;
+ public static String TaskRepositoryNoCredentialsStored;
+ public static String TaskRepositoryNoConnectorFound;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+ /** Constructor */
+ private Messages() {
+ }
+}
diff --git a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties
new file mode 100644
index 000000000..37341af81
--- /dev/null
+++ b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2013 BREDEX GmbH.
+# 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
+##############################################################################
+TaskRepositoryNotFound=No local task repository configuration "{0}" found.
+TaskRepositoryOffline=The given task repository "{0}" is currently configured as offline.
+TaskRepositoryNoCredentialsStored=There are no authentication credentials stored for "{0}".
+TaskRepositoryNoConnectorFound=There is currently no connector available for the repository "{0}".
diff --git a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java
new file mode 100644
index 000000000..23d0d9f31
--- /dev/null
+++ b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java
@@ -0,0 +1,180 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BREDEX GmbH.
+ * 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:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.mylyn.utils;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jubula.mylyn.Activator;
+import org.eclipse.jubula.mylyn.i18n.Messages;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IRepositoryManager;
+import org.eclipse.mylyn.tasks.core.IRepositoryModel;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+import org.eclipse.osgi.util.NLS;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author BREDEX GmbH
+ */
+public final class MylynAccess {
+ /**
+ * @author BREDEX GmbH
+ */
+ public enum CONNECTOR {
+ /** default handling type */
+ DEFAULT,
+ /** custom handling type */
+ HP_ALM
+ }
+
+ /** the logger */
+ private static final Logger LOG = LoggerFactory
+ .getLogger(MylynAccess.class);
+
+ /** Constructor */
+ private MylynAccess() {
+ // hide
+ }
+
+ /**
+ * @param repoLabel
+ * the label of the repository
+ * @return the task repository or <code>null</code> if not found
+ */
+ public static TaskRepository getRepositoryByLabel(String repoLabel) {
+ List<TaskRepository> allRepositories = getAllRepositories();
+
+ for (TaskRepository repo : allRepositories) {
+ if (repo.getRepositoryLabel().equals(repoLabel)) {
+ return repo;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return a list of all available task repositories
+ */
+ public static List<TaskRepository> getAllRepositories() {
+ IRepositoryManager repositoryManager = TasksUi.getRepositoryManager();
+ return repositoryManager.getAllRepositories();
+ }
+
+ /**
+ * @param repo
+ * the task repository
+ * @param taskId
+ * the taskId
+ * @param monitor
+ * the monitor to use
+ * @return the task or <code>null</code> if not found
+ * @throws CoreException
+ * in case of a problem
+ */
+ public static ITask getTaskByID(TaskRepository repo, String taskId,
+ IProgressMonitor monitor) throws CoreException {
+ ITask task = null;
+ if (validRepository(repo)) {
+ IRepositoryModel repositoryModel = TasksUi.getRepositoryModel();
+ task = repositoryModel.getTask(repo, taskId);
+ if (task == null) {
+ task = repositoryModel.createTask(repo, taskId);
+ }
+ }
+ return task;
+ }
+
+ /**
+ * @param repo
+ * the repository to check
+ * @return if the repository is valid
+ */
+ private static boolean validRepository(TaskRepository repo) {
+ return repo != null && !repo.isOffline();
+ }
+
+ /**
+ * @param repo
+ * the task repository
+ * @param taskId
+ * the taskId
+ * @param monitor
+ * the monitor to use
+ * @return the tasks data or <code>null</code> if not found
+ * @throws CoreException
+ * in case of a problem
+ */
+ public static TaskData getTaskDataByID(TaskRepository repo, String taskId,
+ IProgressMonitor monitor) throws CoreException {
+ TaskData taskData = null;
+ if (validRepository(repo)) {
+ AbstractRepositoryConnector connector = TasksUi
+ .getRepositoryConnector(repo.getConnectorKind());
+ taskData = connector.getTaskData(repo, taskId, monitor);
+ }
+ return taskData;
+ }
+
+ /**
+ * @param repoLabel
+ * the repository to test the connection for
+ * @return a status reflecting the current connection state
+ */
+ public static IStatus testConnection(String repoLabel) {
+ TaskRepository repository = getRepositoryByLabel(repoLabel);
+ if (repository == null) {
+ return new Status(IStatus.ERROR, Activator.ID, NLS.bind(
+ Messages.TaskRepositoryNotFound, repoLabel));
+ }
+ if (repository.isOffline()) {
+ return new Status(IStatus.ERROR, Activator.ID, NLS.bind(
+ Messages.TaskRepositoryOffline, repoLabel));
+ }
+
+ boolean savePassword = repository
+ .getSavePassword(AuthenticationType.REPOSITORY);
+ if (!savePassword) {
+ return new Status(IStatus.ERROR, Activator.ID, NLS.bind(
+ Messages.TaskRepositoryNoCredentialsStored, repoLabel));
+ }
+
+ AbstractRepositoryConnector connector = TasksUi
+ .getRepositoryConnector(repository.getConnectorKind());
+ if (connector == null) {
+ return new Status(IStatus.ERROR, Activator.ID, NLS.bind(
+ Messages.TaskRepositoryNoConnectorFound, repoLabel));
+ }
+
+ try {
+ connector.updateRepositoryConfiguration(repository,
+ new NullProgressMonitor());
+ } catch (CoreException e) {
+ return new Status(IStatus.ERROR, Activator.ID,
+ e.getLocalizedMessage().replace("\n\n", " ")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ IStatus repoStatus = repository.getStatus();
+ if (repoStatus != null) {
+ return repoStatus;
+ }
+ return Status.OK_STATUS;
+ }
+} \ No newline at end of file

Back to the top