Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2006-07-06 15:09:23 +0000
committermkersten2006-07-06 15:09:23 +0000
commitebd5c8eb0dba12d645ad90047c98fa63745713ca (patch)
treefafd7d51ade875fecf5343e3687156631682acbd /org.eclipse.mylyn.trac.ui
parentfc4fbb4b481b91eb60fb0a629bbf40fd329136b3 (diff)
downloadorg.eclipse.mylyn.tasks-ebd5c8eb0dba12d645ad90047c98fa63745713ca.tar.gz
org.eclipse.mylyn.tasks-ebd5c8eb0dba12d645ad90047c98fa63745713ca.tar.xz
org.eclipse.mylyn.tasks-ebd5c8eb0dba12d645ad90047c98fa63745713ca.zip
Progress on: 149385: Trac connector: implement externalizer and adding of existing tickets
https://bugs.eclipse.org/bugs/show_bug.cgi?id=149385
Diffstat (limited to 'org.eclipse.mylyn.trac.ui')
-rw-r--r--org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.mylyn.trac.ui/build.properties3
-rw-r--r--org.eclipse.mylyn.trac.ui/plugin.xml18
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracRepositoryConnector.java84
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTask.java142
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTaskExternalizer.java76
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java2
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java42
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/AddExistingTracTaskWizard.java25
9 files changed, 386 insertions, 8 deletions
diff --git a/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF
index 295953a09..3410a853f 100644
--- a/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mylar Trac Plug-in
-Bundle-SymbolicName: org.eclipse.mylar.trac
+Bundle-SymbolicName: org.eclipse.mylar.trac;singleton:=true
Bundle-Version: 0.5.3
Bundle-Activator: org.eclipse.mylar.internal.trac.MylarTracPlugin
Bundle-Vendor: Eclipse.org
diff --git a/org.eclipse.mylyn.trac.ui/build.properties b/org.eclipse.mylyn.trac.ui/build.properties
index 34d2e4d2d..e9863e281 100644
--- a/org.eclipse.mylyn.trac.ui/build.properties
+++ b/org.eclipse.mylyn.trac.ui/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ plugin.xml
diff --git a/org.eclipse.mylyn.trac.ui/plugin.xml b/org.eclipse.mylyn.trac.ui/plugin.xml
new file mode 100644
index 000000000..7337a6262
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/plugin.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ id="org.eclipse.mylar.trac.repository"
+ name="Trac Repository"
+ point="org.eclipse.mylar.tasklist.repositories">
+ <repositoryType
+ class="org.eclipse.mylar.internal.trac.TracRepositoryConnector"
+ id="org.eclipse.mylar.trac.tasklist.repositories"
+ name="Trac Repository Client"
+ type="trac"/>
+ <externalizer
+ class="org.eclipse.mylar.internal.trac.TracTaskExternalizer"
+ id="org.eclipse.mylar.trac.tasklist.externalizer"/>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracRepositoryConnector.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracRepositoryConnector.java
index cc63e9e28..67a87c195 100644
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracRepositoryConnector.java
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracRepositoryConnector.java
@@ -19,9 +19,15 @@ import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage;
import org.eclipse.mylar.internal.trac.core.ITracClient;
+import org.eclipse.mylar.internal.trac.core.TracClientManager;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
+import org.eclipse.mylar.internal.trac.model.TracTicket;
+import org.eclipse.mylar.internal.trac.model.TracTicket.Key;
+import org.eclipse.mylar.internal.trac.ui.wizard.AddExistingTracTaskWizard;
import org.eclipse.mylar.internal.trac.ui.wizard.TracRepositorySettingsPage;
import org.eclipse.mylar.provisional.tasklist.AbstractQueryHit;
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
@@ -30,6 +36,7 @@ import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
import org.eclipse.mylar.provisional.tasklist.IAttachmentHandler;
import org.eclipse.mylar.provisional.tasklist.IOfflineTaskHandler;
import org.eclipse.mylar.provisional.tasklist.ITask;
+import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
/**
@@ -41,6 +48,8 @@ public class TracRepositoryConnector extends AbstractRepositoryConnector {
private List<String> supportedVersions;
+ private TracClientManager clientManager;
+
@Override
public boolean canCreateNewTask() {
return false;
@@ -48,7 +57,7 @@ public class TracRepositoryConnector extends AbstractRepositoryConnector {
@Override
public boolean canCreateTaskFromKey() {
- return false;
+ return true;
}
@Override
@@ -115,9 +124,8 @@ public class TracRepositoryConnector extends AbstractRepositoryConnector {
}
@Override
- public IWizard getAddExistingTaskWizard(TaskRepository repository) {
- // TODO Auto-generated method stub
- return null;
+ public Wizard getAddExistingTaskWizard(TaskRepository repository) {
+ return new AddExistingTracTaskWizard(repository);
}
@Override
@@ -141,8 +149,74 @@ public class TracRepositoryConnector extends AbstractRepositoryConnector {
@Override
public ITask createTaskFromExistingKey(TaskRepository repository, String id) {
- // TODO Auto-generated method stub
+ try {
+ // TODO do this in a non-blocking way like
+ // BugzillaRepositoryConnector once IOfflineTaskHandler has been
+ // implemented
+
+ ITracClient connection = getClientManager().getRepository(repository);
+ TracTicket ticket = connection.getTicket(Integer.parseInt(id));
+
+ String handleIdentifier = AbstractRepositoryTask.getHandle(repository.getUrl(), ticket.getId());
+ TracTask task = createTask(ticket, handleIdentifier);
+ updateTaskDetails(repository.getUrl(), task, ticket);
+
+ return task;
+ } catch (Exception e) {
+ MylarStatusHandler.log(e, "Error creating task from key " + id);
+ }
return null;
}
+ public synchronized TracClientManager getClientManager() {
+ if (clientManager == null) {
+ clientManager = new TracClientManager();
+ }
+ return clientManager;
+ }
+
+ public static TracTask createTask(TracTicket ticket, String handleIdentifier) {
+ TracTask task;
+ ITask existingTask = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(handleIdentifier);
+ if (existingTask instanceof TracTask) {
+ task = (TracTask) existingTask;
+ } else {
+ task = new TracTask(handleIdentifier, ticket.getValue(Key.SUMMARY), true);
+ MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(task);
+ }
+ return task;
+ }
+
+ /**
+ * Updates fields of <code>task</code> from <code>ticket</code>.
+ */
+ public static void updateTaskDetails(String repositoryUrl, TracTask task, TracTicket ticket) {
+ if (ticket.isValid()) {
+ String url = repositoryUrl + ITracClient.TICKET_URL + ticket.getId();
+ task.setUrl(url);
+ if (ticket.getValue(Key.SUMMARY) != null) {
+ task.setDescription("#" + ticket.getId() + ": " + ticket.getValue(Key.SUMMARY));
+ }
+ }
+ if (ticket.getValue(Key.STATUS) != null) {
+ TracTask.Status status = TracTask.Status.fromStatus(ticket.getValue(Key.STATUS));
+ task.setCompleted(status != null && status == TracTask.Status.CLOSED);
+ } else {
+ task.setCompleted(false);
+ }
+ if (ticket.getValue(Key.PRIORITY) != null) {
+ String translatedPriority = TracTask.PriorityLevel.fromPriority(ticket.getValue(Key.PRIORITY)).toString();
+ task.setPriority(translatedPriority);
+ }
+ if (ticket.getValue(Key.TYPE) != null) {
+ String translatedKind = TracTask.Kind.fromType(ticket.getValue(Key.TYPE)).toString();
+ task.setKind(translatedKind);
+ }
+ if (ticket.getCreated() != null) {
+ task.setCreationDate(ticket.getCreated());
+ }
+
+ MylarTaskListPlugin.getTaskListManager().getTaskList().notifyLocalInfoChanged(task);
+ }
+
}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTask.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTask.java
new file mode 100644
index 000000000..60669e6c1
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTask.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac;
+
+import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracTask extends AbstractRepositoryTask {
+
+ public enum PriorityLevel {
+ BLOCKER, CRITICAL, MAJOR, MINOR, TRIVIAL;
+
+ @Override
+ public String toString() {
+ switch (this) {
+ case BLOCKER:
+ return "P1";
+ case CRITICAL:
+ return "P2";
+ case MAJOR:
+ return "P3";
+ case MINOR:
+ return "P4";
+ case TRIVIAL:
+ return "P5";
+ default:
+ return "P5";
+ }
+ }
+
+ public static PriorityLevel fromPriority(String priority) {
+ if (priority == null)
+ return null;
+ if (priority.equals("blocker"))
+ return BLOCKER;
+ if (priority.equals("critical"))
+ return CRITICAL;
+ if (priority.equals("major"))
+ return MAJOR;
+ if (priority.equals("minor"))
+ return MINOR;
+ if (priority.equals("trivial"))
+ return TRIVIAL;
+ return null;
+ }
+ }
+
+ public enum Kind {
+ DEFECT, ENHANCEMENT, TASK;
+
+ @Override
+ public String toString() {
+ switch (this) {
+ case DEFECT:
+ return "Defect";
+ case ENHANCEMENT:
+ return "Enhancement";
+ case TASK:
+ return "Task";
+ default:
+ return "";
+ }
+ }
+
+ public static Kind fromType(String type) {
+ if (type == null)
+ return null;
+ if (type.equals("defect"))
+ return DEFECT;
+ if (type.equals("enhancement"))
+ return ENHANCEMENT;
+ if (type.equals("task"))
+ return TASK;
+ return null;
+ }
+
+ }
+
+ public enum Status {
+ NEW, ASSIGNED, CLOSED;
+
+ @Override
+ public String toString() {
+ switch (this) {
+ case NEW:
+ return "New";
+ case ASSIGNED:
+ return "Assigned";
+ case CLOSED:
+ return "Closed";
+ default:
+ return "";
+ }
+ }
+
+ public static Status fromStatus(String status) {
+ if (status == null)
+ return null;
+ if (status.equals("new"))
+ return NEW;
+ if (status.equals("assigned"))
+ return ASSIGNED;
+ if (status.equals("closed"))
+ return CLOSED;
+ return null;
+ }
+
+ }
+
+ public TracTask(String handle, String label, boolean newTask) {
+ super(handle, label, newTask);
+ }
+
+ @Override
+ public String getRepositoryKind() {
+ return MylarTracPlugin.REPOSITORY_KIND;
+ }
+
+ @Override
+ public boolean isDownloaded() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isPersistentInWorkspace() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTaskExternalizer.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTaskExternalizer.java
new file mode 100644
index 000000000..beff051a7
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracTaskExternalizer.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac;
+
+import org.eclipse.mylar.internal.tasklist.TaskExternalizationException;
+import org.eclipse.mylar.provisional.tasklist.AbstractTaskContainer;
+import org.eclipse.mylar.provisional.tasklist.DelegatingTaskExternalizer;
+import org.eclipse.mylar.provisional.tasklist.ITask;
+import org.eclipse.mylar.provisional.tasklist.TaskList;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracTaskExternalizer extends DelegatingTaskExternalizer {
+
+ private static final String KEY_TRAC = "Trac";
+
+ private static final String KEY_TRAC_CATEGORY = KEY_TRAC + KEY_CATEGORY;
+
+ private static final String KEY_TRAC_TASK = KEY_TRAC + KEY_TASK;
+
+ @Override
+ public boolean canCreateElementFor(ITask task) {
+ return task instanceof TracTask;
+ }
+
+ @Override
+ public boolean canReadCategory(Node node) {
+ return node.getNodeName().equals(KEY_TRAC_CATEGORY);
+ }
+
+ @Override
+ public String getCategoryTagName() {
+ return KEY_TRAC_CATEGORY;
+ }
+
+ @Override
+ public String getTaskTagName() {
+ return KEY_TRAC_TASK;
+ }
+
+ @Override
+ public ITask readTask(Node node, TaskList taskList, AbstractTaskContainer category, ITask parent)
+ throws TaskExternalizationException {
+
+ Element element = (Element) node;
+ String handle;
+ String label;
+ if (element.hasAttribute(KEY_HANDLE)) {
+ handle = element.getAttribute(KEY_HANDLE);
+ } else {
+ throw new TaskExternalizationException("Handle not stored for task");
+ }
+ if (element.hasAttribute(KEY_LABEL)) {
+ label = element.getAttribute(KEY_LABEL);
+ } else {
+ throw new TaskExternalizationException("Description not stored for task");
+ }
+
+ TracTask task = new TracTask(handle, label, false);
+ readTaskInfo(task, taskList, element, parent, category);
+ return task;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java
index d0cb0ca84..78c25f26a 100644
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java
@@ -41,7 +41,7 @@ public interface ITracClient {
case TRAC_0_9:
return "Trac 0.9 and higher";
case XML_RPC:
- return "XML-RPC Plugin (Rev. 826)";
+ return "XML-RPC Plugin (Rev. 848)";
default:
return null;
}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
new file mode 100644
index 000000000..085e2b039
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core;
+
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
+import org.eclipse.mylar.provisional.tasklist.TaskRepository;
+
+/**
+ * Caches {@link ITracClient} objects.
+ *
+ * @author Steffen Pingel
+ */
+public class TracClientManager {
+
+ Map<String, ITracClient> clientByUrl = new HashMap<String, ITracClient>();
+
+ public TracClientManager() {
+ }
+
+ public ITracClient getRepository(TaskRepository taskRepository) throws MalformedURLException {
+ ITracClient repository = clientByUrl.get(taskRepository.getUrl());
+ if (repository == null) {
+ repository = TracClientFactory.createClient(taskRepository.getUrl(), Version.fromVersion(taskRepository
+ .getVersion()), taskRepository.getUserName(), taskRepository.getPassword());
+ clientByUrl.put(taskRepository.getUrl(), repository);
+ }
+ return repository;
+ }
+}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/AddExistingTracTaskWizard.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/AddExistingTracTaskWizard.java
new file mode 100644
index 000000000..dcb9eacda
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/AddExistingTracTaskWizard.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylar.internal.trac.ui.wizard;
+
+import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractAddExistingTaskWizard;
+import org.eclipse.mylar.provisional.tasklist.TaskRepository;
+
+/**
+ * @author Steffen Pingel
+ */
+public class AddExistingTracTaskWizard extends AbstractAddExistingTaskWizard {
+
+ public AddExistingTracTaskWizard(TaskRepository repository) {
+ super(repository);
+ }
+
+}

Back to the top