summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-13 19:44:47 (EDT)
committerChris Aniszczyk2011-04-14 11:09:30 (EDT)
commitbccdc244f930a9fb6df14263a992540e8e33519c (patch)
tree725a0c3bbce4ea1af07141614fc5860d4cf57b87
parent8d1fdd24dd440ddb91a5d578ceba6fee745b00bc (diff)
downloadegit-github-bccdc244f930a9fb6df14263a992540e8e33519c.zip
egit-github-bccdc244f930a9fb6df14263a992540e8e33519c.tar.gz
egit-github-bccdc244f930a9fb6df14263a992540e8e33519c.tar.bz2
Add initial gist repository connectorrefs/changes/04/3104/2
Change-Id: Ia4ccd306f1d71b2e92b79b6803e3accb57403f0c Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java207
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java3
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties1
3 files changed, 211 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
new file mode 100644
index 0000000..4b2a2b5
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.github.core.gist;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.github.internal.Gist;
+import org.eclipse.mylyn.github.internal.GistService;
+import org.eclipse.mylyn.github.internal.GitHub;
+import org.eclipse.mylyn.github.internal.GitHubClient;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
+import org.eclipse.mylyn.tasks.core.data.TaskMapper;
+import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
+
+/**
+ * Gist repository connector class.
+ */
+public class GistConnector extends AbstractRepositoryConnector {
+
+ /**
+ * KIND
+ */
+ public static final String KIND = "githubGists"; //$NON-NLS-1$
+
+ private GistTaskDataHandler dataHandler = new GistTaskDataHandler();
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#getTaskDataHandler()
+ */
+ public AbstractTaskDataHandler getTaskDataHandler() {
+ return this.dataHandler;
+ }
+
+ /**
+ * Create client for repository
+ *
+ * @param repository
+ * @return client
+ */
+ protected GitHubClient createClient(TaskRepository repository) {
+ GitHubClient client = new GitHubClient();
+ AuthenticationCredentials credentials = repository
+ .getCredentials(AuthenticationType.REPOSITORY);
+ if (credentials != null)
+ client.setCredentials(credentials.getUserName(),
+ credentials.getPassword());
+ return client;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#canCreateNewTask(org.eclipse.mylyn.tasks.core.TaskRepository)
+ */
+ public boolean canCreateNewTask(TaskRepository repository) {
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#canCreateTaskFromKey(org.eclipse.mylyn.tasks.core.TaskRepository)
+ */
+ public boolean canCreateTaskFromKey(TaskRepository repository) {
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#getConnectorKind()
+ */
+ public String getConnectorKind() {
+ return KIND;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#getLabel()
+ */
+ public String getLabel() {
+ return Messages.GistConnector_LabelConnector;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#getRepositoryUrlFromTaskUrl(java.lang.String)
+ */
+ public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
+ int lastSlash = taskFullUrl.lastIndexOf('/');
+ return lastSlash >= 0 ? taskFullUrl.substring(0, lastSlash) : null;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#getTaskData(org.eclipse.mylyn.tasks.core.TaskRepository,
+ * java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public TaskData getTaskData(TaskRepository repository, String taskId,
+ IProgressMonitor monitor) throws CoreException {
+ GistService service = new GistService(createClient(repository));
+ try {
+ TaskAttributeMapper mapper = this.dataHandler
+ .getAttributeMapper(repository);
+ Gist gist = service.getGist(taskId);
+ TaskData data = new TaskData(mapper, getConnectorKind(),
+ repository.getUrl(), gist.getRepo());
+ data.setPartial(false);
+ this.dataHandler.fillTaskData(data, gist);
+ if (gist.getComments() > 0)
+ this.dataHandler.fillComments(repository, data,
+ service.getComments(gist.getRepo()));
+
+ return data;
+ } catch (IOException e) {
+ throw new CoreException(GitHub.createErrorStatus(e));
+ }
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#getTaskIdFromTaskUrl(java.lang.String)
+ */
+ public String getTaskIdFromTaskUrl(String taskFullUrl) {
+ int lastSlash = taskFullUrl.lastIndexOf('/') + 1;
+ return lastSlash > 0 && lastSlash < taskFullUrl.length() ? taskFullUrl
+ .substring(lastSlash) : null;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#getTaskUrl(java.lang.String,
+ * java.lang.String)
+ */
+ public String getTaskUrl(String repositoryUrl, String taskId) {
+ return repositoryUrl + '/' + taskId;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#hasTaskChanged(org.eclipse.mylyn.tasks.core.TaskRepository,
+ * org.eclipse.mylyn.tasks.core.ITask,
+ * org.eclipse.mylyn.tasks.core.data.TaskData)
+ */
+ public boolean hasTaskChanged(TaskRepository taskRepository, ITask task,
+ TaskData taskData) {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#performQuery(org.eclipse.mylyn.tasks.core.TaskRepository,
+ * org.eclipse.mylyn.tasks.core.IRepositoryQuery,
+ * org.eclipse.mylyn.tasks.core.data.TaskDataCollector,
+ * org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus performQuery(TaskRepository repository,
+ IRepositoryQuery query, TaskDataCollector collector,
+ ISynchronizationSession session, IProgressMonitor monitor) {
+ IStatus status = Status.OK_STATUS;
+ GistService service = new GistService(createClient(repository));
+ String user = query.getAttribute("user"); //$NON-NLS-1$
+ try {
+ TaskAttributeMapper mapper = this.dataHandler
+ .getAttributeMapper(repository);
+ for (Gist gist : service.getGists(user)) {
+ TaskData data = new TaskData(mapper, getConnectorKind(),
+ repository.getUrl(), gist.getRepo());
+ data.setPartial(true);
+ this.dataHandler.fillTaskData(data, gist);
+ collector.accept(data);
+ }
+ } catch (IOException e) {
+ status = GitHub.createErrorStatus(e);
+ }
+ return status;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#updateRepositoryConfiguration(org.eclipse.mylyn.tasks.core.TaskRepository,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void updateRepositoryConfiguration(TaskRepository taskRepository,
+ IProgressMonitor monitor) throws CoreException {
+
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#updateTaskFromTaskData(org.eclipse.mylyn.tasks.core.TaskRepository,
+ * org.eclipse.mylyn.tasks.core.ITask,
+ * org.eclipse.mylyn.tasks.core.data.TaskData)
+ */
+ public void updateTaskFromTaskData(TaskRepository taskRepository,
+ ITask task, TaskData taskData) {
+ new TaskMapper(taskData).applyTo(task);
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java
index b7127ff..292e59c 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java
@@ -37,6 +37,9 @@ public class Messages extends NLS {
/** */
public static String GistAttribute_LabelUrl;
+ /** */
+ public static String GistConnector_LabelConnector;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties
index 04cf280..e20438c 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties
@@ -4,3 +4,4 @@ GistAttribute_LabelDescription=Description:
GistAttribute_LabelKey=Key
GistAttribute_LabelNewComment=New Comment
GistAttribute_LabelUrl=Url
+GistConnector_LabelConnector=Github Gists