From 16c98e34541d6a833ee7cd29ae24eea7f9ed4d2e Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Tue, 29 Mar 2011 11:20:30 +0200 Subject: [PATCH 001/642] HTTP 201 (HTTP Created) is not handled as error GitHUb issues can be created now. Bug: 340900 Change-Id: Ieac3108163f4e7f1b5fa78b369e3140244dee04b Signed-off-by: Christian Trutz --- .../src/org/eclipse/mylyn/github/internal/GitHubService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java index 2c8321005..1cbf791c3 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java @@ -480,6 +480,8 @@ private void executeMethod(HttpMethod method) throws GitHubServiceException { } if (status != HttpStatus.SC_OK) { switch (status) { + case HttpStatus.SC_CREATED: + break; case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_FORBIDDEN: throw new PermissionDeniedException(method.getStatusLine()); From 728bc02d49b7fda5d6b97078d418b69ebab2cb3c Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Tue, 5 Apr 2011 00:25:09 +0200 Subject: [PATCH 002/642] Add comment support to GitHub task editor Adding new comments on existing issues is implemented now. Bug: 340901 Change-Id: I896ace16cc698e4b51ebb61e5a2732a874789dfb Signed-off-by: Christian Trutz --- .../mylyn/github/internal/GitHubIssue.java | 12 +++++++ .../mylyn/github/internal/GitHubService.java | 36 ++++++++++++++++++- .../github/internal/GitHubTaskAttributes.java | 3 +- .../internal/GitHubTaskDataHandler.java | 16 ++++++--- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java index 9a989e00f..0d581a04f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java @@ -26,6 +26,8 @@ public class GitHubIssue { private String body; + private String comment_new; + /** * open, closed */ @@ -53,6 +55,7 @@ public GitHubIssue(final String number, final String user, this.user = user; this.title = title; this.body = body; + this.comment_new = null; } /** @@ -63,6 +66,7 @@ public GitHubIssue() { this.user = ""; this.title = ""; this.body = ""; + this.comment_new = null; } /** @@ -169,4 +173,12 @@ public String getClosed_at() { public void setClosed_at(String closed_at) { this.closed_at = closed_at; } + + public String getComment_new() { + return comment_new; + } + + public void setComment_new(String comment_new) { + this.comment_new = comment_new; + } } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java index 1cbf791c3..dfb25d993 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java @@ -56,6 +56,7 @@ public class GitHubService { private static final String REOPEN = "reopen/"; private final static String CLOSE = "close/"; private final static String EDIT = "edit/"; // Implemented + private final static String COMMENT = "comment/"; // private final static String VIEW = "view/"; private final static String SHOW = "show/"; // :user/:repo/:number private final static String LIST = "list/"; // Implemented @@ -440,7 +441,6 @@ public GitHubIssue editIssue(final String user, final String repo, } } - public GitHubIssue showIssue(final String user, final String repo,final String issueNumber) throws GitHubServiceException { GetMethod method = null; try { @@ -577,4 +577,38 @@ private GitHubIssue changeIssueStatus(final String user, final String repo, } } } + + /** + * Add comment on issues. + * + * @param user + * - The user the repository is owned by + * @param repo + * - The git repository where the issue tracker is hosted + * @param issue + * @param credentials + * @throws GitHubServiceException + */ + public void addComment(final String user, final String repo, + final GitHubIssue issue,final GitHubCredentials credentials) + throws GitHubServiceException { + PostMethod method = null; + try { + method = new PostMethod(gitURLBase + gitIssueRoot + COMMENT + user + + "/" + repo + "/" + issue.getNumber()); + final NameValuePair comment = new NameValuePair("comment", issue + .getComment_new()); + method.setRequestBody(new NameValuePair[] { comment }); + setCredentials(credentials); + executeMethod(method); + }catch (final RuntimeException runTimeException) { + throw runTimeException; + } catch (final Exception e) { + throw new GitHubServiceException(e); + } finally { + if (method != null) { + method.releaseConnection(); + } + } + } } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java index 2c847dcd0..128ea43c4 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java @@ -25,7 +25,8 @@ public enum GitHubTaskAttributes { CLOSED_DATE("Closed:",TaskAttribute.DATE_COMPLETION,TaskAttribute.TYPE_DATETIME,false,true,false), STATUS("Status:",TaskAttribute.STATUS,TaskAttribute.TYPE_SHORT_TEXT,true,false,true), - REPORTER("Reporter:", TaskAttribute.USER_REPORTER, TaskAttribute.TYPE_PERSON, true, true, false) + REPORTER("Reporter:", TaskAttribute.USER_REPORTER, TaskAttribute.TYPE_PERSON, true, true, false), + COMMENT_NEW("Comment:", TaskAttribute.COMMENT_NEW, TaskAttribute.TYPE_LONG_RICH_TEXT, false, false, false) ; private final String id; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java index fd5c2bdd6..2bb8b0076 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java @@ -74,6 +74,7 @@ public TaskData createPartialTaskData(TaskRepository repository, createAttribute(data, GitHubTaskAttributes.MODIFICATION_DATE, toLocalDate(issue.getCreated_at())); createAttribute(data, GitHubTaskAttributes.CLOSED_DATE, toLocalDate(issue.getClosed_at())); createAttribute(data, GitHubTaskAttributes.REPORTER, issue.getUser()); + createAttribute(data, GitHubTaskAttributes.COMMENT_NEW, ""); if (isPartial(data)) { data.setPartial(true); @@ -175,6 +176,7 @@ private GitHubIssue createIssue(TaskData taskData) { issue.setCreated_at(toGitHubDate(taskData,GitHubTaskAttributes.CREATION_DATE)); issue.setCreated_at(toGitHubDate(taskData,GitHubTaskAttributes.MODIFICATION_DATE)); issue.setCreated_at(toGitHubDate(taskData,GitHubTaskAttributes.CLOSED_DATE)); + issue.setComment_new(getAttributeValue(taskData, GitHubTaskAttributes.COMMENT_NEW)); return issue; } @@ -229,11 +231,16 @@ public RepositoryResponse postTaskData(TaskRepository repository, if (taskData.isNew()) { issue = service.openIssue(user , repo, issue, credentials); } else { + + // handle new comment + if(issue.getComment_new() != null) { + if(!"".equals(issue.getComment_new())) { + service.addComment(user, repo, issue, credentials); + } + } + TaskAttribute operationAttribute = taskData.getRoot().getAttribute(TaskAttribute.OPERATION); - GitHubTaskOperation operation = null; - - if (operationAttribute != null) { String opId = operationAttribute.getValue(); operation = GitHubTaskOperation.fromId(opId); @@ -254,12 +261,13 @@ public RepositoryResponse postTaskData(TaskRepository repository, } else { service.editIssue(user , repo, issue, credentials); } + } return new RepositoryResponse(taskData.isNew()?ResponseKind.TASK_CREATED:ResponseKind.TASK_UPDATED,issue.getNumber()); } catch (GitHubServiceException e) { throw new CoreException(GitHub.createErrorStatus(e)); } - + } From 5da76f54865f0f3701d4f3daba361320deaf652b Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Tue, 5 Apr 2011 23:55:47 +0200 Subject: [PATCH 003/642] New launch file Simplify starting Eclipse instance including egit-github plugins Change-Id: I789ecb7684bac1beeef227f9aeee602e3ebfdca8 Signed-off-by: Christian Trutz --- .../.settings/egit-github.launch | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 org.eclipse.mylyn.github.ui/.settings/egit-github.launch diff --git a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch new file mode 100644 index 000000000..7f6dbf0b6 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a193f511f425b8ee1b9b4197dcd7ca14b5154d2a Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Thu, 7 Apr 2011 12:52:07 -0500 Subject: [PATCH 004/642] Add support for creating Gists Supports creating gists on selections with files and on a selected file. Change-Id: Iab9b2a3892aaf6e753d8fcde77917c8d7347e8d0 Signed-off-by: Chris Aniszczyk --- .../META-INF/MANIFEST.MF | 2 +- .../mylyn/github/internal/GitHubService.java | 40 ++++++++ .../.settings/egit-github.launch | 6 +- .../META-INF/MANIFEST.MF | 5 +- .../icons/obj16/github.png | Bin 0 -> 410 bytes org.eclipse.mylyn.github.ui/plugin.xml | 49 +++++++++ .../github/ui/internal/CreateGistHandler.java | 93 ++++++++++++++++++ .../github/ui/internal/CreateGistJob.java | 60 +++++++++++ .../ui/internal/GistNotificationPopup.java | 68 +++++++++++++ .../github/ui/internal/GitHubImages.java | 62 ++++++++++++ .../mylyn/github/ui/internal/GitHubUi.java | 2 +- 11 files changed, 381 insertions(+), 6 deletions(-) create mode 100644 org.eclipse.mylyn.github.ui/icons/obj16/github.png create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistJob.java create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GistNotificationPopup.java create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubImages.java diff --git a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF index f05d1b0dd..bb48a03a7 100644 --- a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: EGit Mylyn GitHub Core Plug-in (Incubation) -Bundle-SymbolicName: org.eclipse.mylyn.github.core +Bundle-SymbolicName: org.eclipse.mylyn.github.core;singleton:=true Bundle-Version: 0.1.0.qualifier Bundle-Vendor: Eclipse EGit Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java index dfb25d993..3d4a1e8d0 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java @@ -32,6 +32,8 @@ /** * Facility to perform API operations on a GitHub issue tracker. + * + * TODO: This class needs to be refactored */ public class GitHubService { @@ -41,6 +43,7 @@ public class GitHubService { * GitHub Issues API Documentation: http://develop.github.com/p/issues.html */ private final String gitURLBase = "https://github.com/api/v2/json/"; + private final String gistPostURL = "https://gist.github.com/gists"; private final String gitIssueRoot = "issues/"; private final String gitUserRoot = "user/"; @@ -378,6 +381,42 @@ public GitHubIssue openIssue(final String user, final String repo, } } + /** + * Create a new gist + * + * @return the url of the gist that was created + * + * @throws GitHubServiceException + * @throws IOException + */ + public String createGist(final String title, final String extension, final String gist, final GitHubCredentials credentials) + throws GitHubServiceException, IOException { + + PostMethod method = null; + try { + // Create the HTTP POST method + setCredentials(credentials); + method = new PostMethod(gistPostURL); + final NameValuePair name = new NameValuePair("file_name[gistfile1]", title); + final NameValuePair ext = new NameValuePair("file_ext[gistfile1]", extension); + final NameValuePair content = new NameValuePair("file_contents[gistfile1]", gist); + method.addParameters(new NameValuePair[] { name, ext, content }); + executeMethod(method); + + return method.getResponseHeader("Location").getValue(); + } catch (GitHubServiceException e) { + throw e; + } catch (final RuntimeException runTimeException) { + throw runTimeException; + } catch (final Exception e) { + throw new GitHubServiceException(e); + } finally { + if (method != null) { + method.releaseConnection(); + } + } + } + /** * Edit an existing issue using the GitHub Issues API. * @@ -481,6 +520,7 @@ private void executeMethod(HttpMethod method) throws GitHubServiceException { if (status != HttpStatus.SC_OK) { switch (status) { case HttpStatus.SC_CREATED: + case HttpStatus.SC_MOVED_TEMPORARILY: break; case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_FORBIDDEN: diff --git a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch index 7f6dbf0b6..81afaf359 100644 --- a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch +++ b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch @@ -12,7 +12,7 @@ - + @@ -49,8 +49,8 @@ - - + + diff --git a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF index 356db6d0f..700432c2a 100644 --- a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF @@ -13,5 +13,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.mylyn.github.core;bundle-version="0.1.0", org.eclipse.jface.text;bundle-version="3.5.0", org.eclipse.mylyn.commons.net;bundle-version="3.2.0", - org.eclipse.mylyn.tasks.core + org.eclipse.mylyn.tasks.core, + org.eclipse.ui.ide;bundle-version="3.5.0", + org.eclipse.mylyn.commons.ui;bundle-version="3.4.0", + org.eclipse.core.resources;bundle-version="3.5.0" Export-Package: org.eclipse.mylyn.github.ui.internal;x-internal:=true diff --git a/org.eclipse.mylyn.github.ui/icons/obj16/github.png b/org.eclipse.mylyn.github.ui/icons/obj16/github.png new file mode 100644 index 0000000000000000000000000000000000000000..8d57b37376835180b9567fa564bc65e3d6e07b3e GIT binary patch literal 410 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgg)7Ir=(!z{0bB|uZ8JY5_^EKV=I zZ0POmD8TZ-e{B$FQ>X(6N7LG=39tD#2rCMBq^4%Sp1)zM5Q}0$wzL3?Bgc)K5^tE4 zmQ3gnnk{(l$0QCtnfE*9&fI%<=k|oEHHoIb8GrqgVBc|EVtwS}IkIPzt`&4D_H77! za;?~mXIYr)1xN8}#gMIAq&v*8XIAFjrc)I$ztaD0e0sxzI Bp(X$T literal 0 HcmV?d00001 diff --git a/org.eclipse.mylyn.github.ui/plugin.xml b/org.eclipse.mylyn.github.ui/plugin.xml index 57da2a548..be433f6e8 100644 --- a/org.eclipse.mylyn.github.ui/plugin.xml +++ b/org.eclipse.mylyn.github.ui/plugin.xml @@ -23,5 +23,54 @@ id="org.eclipse.mylyn.github.ui.internal.GitHubTaskEditorPageFactory"> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java new file mode 100644 index 000000000..0573d99a2 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat 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: + * Chris Aniszczyk - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.ui.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Set; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.mylyn.github.internal.GitHub; +import org.eclipse.mylyn.github.internal.GitHubCredentials; +import org.eclipse.mylyn.github.internal.GitHubService; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.handlers.HandlerUtil; + +public class CreateGistHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + IEditorPart editor = HandlerUtil.getActiveEditor(event); + ISelection selection = HandlerUtil.getCurrentSelection(event); + IStructuredSelection menuSelection = (IStructuredSelection) HandlerUtil + .getActiveMenuSelection(event); + if(selection != null && menuSelection == null) { + if(selection instanceof ITextSelection) { + ITextSelection text = (ITextSelection) selection; + IEditorInput input = editor.getEditorInput(); + if(input instanceof IFileEditorInput) { + // only use the first repository, in the future provide a selection if multiple exist + IFileEditorInput fileInput = (IFileEditorInput) input; + IFile file = fileInput.getFile(); + createGistJob(file.getName(), file.getFileExtension(), text.getText()); + } + } + } + if(menuSelection != null) { + Object obj = menuSelection.getFirstElement(); + if(obj instanceof IFile) { + IFile file = (IFile) obj; + createGistJob(file); + } + } + return null; + } + + private void createGistJob(String name, String extension, String contents) { + Set repositories = TasksUi.getRepositoryManager().getRepositories(GitHub.CONNECTOR_KIND); + TaskRepository repository = repositories.iterator().next(); + GitHubService service = new GitHubService(); + GitHubCredentials credentials = GitHubCredentials.create(repository); + CreateGistJob job = new CreateGistJob("Creating Gist", name, extension, contents, credentials, service); + job.setSystem(true); + job.schedule(); + } + + private void createGistJob(IFile file) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents())); + String line; + StringBuffer result = new StringBuffer(); + while ((line = br.readLine()) != null) { + result.append(line); + result.append('\n'); + } + String contents = result.toString(); + createGistJob(file.getName(), file.getFileExtension(), contents); + } catch (CoreException e) { + GitHubUi.logError(e); + } catch (IOException e) { + GitHubUi.logError(e); + } + } + +} diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistJob.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistJob.java new file mode 100644 index 000000000..ffe6edaf0 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistJob.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat 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: + * Chris Aniszczyk - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.ui.internal; + +import java.io.IOException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.mylyn.github.internal.GitHubCredentials; +import org.eclipse.mylyn.github.internal.GitHubService; +import org.eclipse.mylyn.github.internal.GitHubServiceException; +import org.eclipse.swt.widgets.Display; + +public class CreateGistJob extends Job { + + private String title; + private String extension; + private String content; + private GitHubCredentials credentials; + private GitHubService service; + + public CreateGistJob(String name, String title, String extension, String content, GitHubCredentials credentials, GitHubService service) { + super(name); + this.title = title; + this.extension = extension; + this.content = content; + this.credentials = credentials; + this.service = service; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + final String url = service.createGist(title, extension, content, credentials); + Display.getDefault().asyncExec(new Runnable() { + @SuppressWarnings("restriction") + public void run() { + GistNotificationPopup popup = new GistNotificationPopup(Display.getDefault(), url, title); + popup.create(); + popup.open(); + } + }); + } catch (GitHubServiceException e) { + GitHubUi.logError(e); + } catch (IOException e) { + GitHubUi.logError(e); + } + return Status.OK_STATUS; + } +} \ No newline at end of file diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GistNotificationPopup.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GistNotificationPopup.java new file mode 100644 index 000000000..2d5fac8a9 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GistNotificationPopup.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat 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: + * Chris Aniszczyk - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.ui.internal; + +import org.eclipse.mylyn.internal.provisional.commons.ui.AbstractNotificationPopup; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.program.Program; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; + +@SuppressWarnings("restriction") +public class GistNotificationPopup extends AbstractNotificationPopup { + + private String gistURL; + + private String title; + + public GistNotificationPopup(Display display, String gistURL, String title) { + super(display); + this.gistURL = gistURL; + this.title = title; + } + + @Override + protected void createContentArea(Composite composite) { + composite.setLayout(new GridLayout(1, true)); + Label label = new Label(composite, SWT.NONE); + label.setText("Title: " + title); + Link link = new Link(composite, SWT.WRAP); + String number = gistURL.split("https://gist.github.com/")[1]; + link.setText("Created Gist: " + number + ""); + link.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + link.setBackground(composite.getBackground()); + link.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + Program.launch(gistURL); + } + }); + } + + @Override + protected String getPopupShellTitle() { + return "GitHub Notification"; + } + + @Override + protected Image getPopupShellImage(int maximumHeight) { + return GitHubImages.get(GitHubImages.GITHUB_LOGO_OBJ); + } + +} diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubImages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubImages.java new file mode 100644 index 000000000..ef059ad2a --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubImages.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat 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: + * Chris Aniszczyk - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.ui.internal; + +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.osgi.framework.Bundle; + +public class GitHubImages { + + private static final String NAME_PREFIX = "org.eclipse.mylyn.github.ui"; //$NON-NLS-1$ + private static final String ICONS_PATH = "icons/"; //$NON-NLS-1$ + private static final String PATH_OBJ = ICONS_PATH + "obj16/"; //$NON-NLS-1$ + + private static ImageRegistry manager; + + public static final String GITHUB_LOGO_OBJ = NAME_PREFIX + "OBJ_GITHUB_LOGO"; //$NON-NLS-1$ + + public static final ImageDescriptor DESC_GITHUB_LOGO = create(PATH_OBJ, "github.png"); //$NON-NLS-1$ + + private static ImageDescriptor create(String prefix, String name) { + return ImageDescriptor.createFromURL(makeImageURL(prefix, name)); + } + + public static Image get(String key) { + if (manager == null) + initialize(); + return manager.get(key); + } + + private static final void initialize() { + manager = new ImageRegistry(); + manage(GITHUB_LOGO_OBJ, DESC_GITHUB_LOGO); + } + + private static URL makeImageURL(String prefix, String name) { + String path = "$nl$/" + prefix + name; //$NON-NLS-1$ + Bundle bundle = Platform.getBundle(GitHubUi.BUNDLE_ID); + return FileLocator.find(bundle, new Path(path), null); + } + + private static Image manage(String key, ImageDescriptor desc) { + Image image = desc.createImage(); + manager.put(key, image); + return image; + } + +} diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java index 6b2bdb60c..36ef13514 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java @@ -17,7 +17,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -class GitHubUi { +public class GitHubUi { public static final String BUNDLE_ID = "org.eclipse.mylyn.github.ui"; public static IStatus createStatus(int severity,String message) { From 1eea7cf73f527475e162a51e80a717bbf6208a4d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Apr 2011 13:20:55 -0700 Subject: [PATCH 005/642] Add missing credentials on GitHubService.showIssue This fixes 401 exceptions being thrown when issue in private repository is refreshed in task editor. Change-Id: Ie0fc780a8e439699a203184070de5cf4fd06c56e Signed-off-by: Kevin Sawicki --- .../mylyn/github/internal/GitHubRepositoryConnector.java | 3 ++- .../src/org/eclipse/mylyn/github/internal/GitHubService.java | 5 ++++- .../org/eclipse/mylyn/github/tests/GitHubServiceTest.java | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java index c86ffe06a..681bdb756 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java @@ -154,7 +154,8 @@ public TaskData getTaskData(TaskRepository repository, String taskId, String project = GitHub.computeTaskRepositoryProject(repository.getUrl()); try { - GitHubIssue issue = service.showIssue(user, project, taskId); + GitHubCredentials credentials = GitHubCredentials.create(repository); + GitHubIssue issue = service.showIssue(user, project, taskId, credentials); TaskData taskData = taskDataHandler.createTaskData(repository, monitor, user, project, issue); return taskData; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java index 3d4a1e8d0..17171f601 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java @@ -480,13 +480,16 @@ public GitHubIssue editIssue(final String user, final String repo, } } - public GitHubIssue showIssue(final String user, final String repo,final String issueNumber) throws GitHubServiceException { + public GitHubIssue showIssue(final String user, final String repo, + final String issueNumber, final GitHubCredentials credentials) + throws GitHubServiceException { GetMethod method = null; try { // build HTTP GET method method = new GetMethod(gitURLBase + gitIssueRoot + SHOW + user + "/" + repo + "/" + issueNumber); + setCredentials(credentials); // execute HTTP GET method executeMethod(method); // transform JSON to Java object diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/GitHubServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/GitHubServiceTest.java index 9eabcfd1d..0997c3aa0 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/GitHubServiceTest.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/GitHubServiceTest.java @@ -88,7 +88,8 @@ public void editIssue() throws Exception { service.editIssue(TEST_USER, TEST_PROJECT, issue, new GitHubCredentials(TEST_USER,API_KEY)); - GitHubIssue showIssue = service.showIssue(TEST_USER, TEST_PROJECT, issue.getNumber()); + GitHubIssue showIssue = service.showIssue(TEST_USER, TEST_PROJECT, + issue.getNumber(), new GitHubCredentials(TEST_USER, API_KEY)); assertTrue(showIssue != null); assertEquals(newIssue.getTitle(),showIssue.getTitle()); From 3cf270bcabf7d445685539dee065270b7eef9f15 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Apr 2011 13:53:50 -0700 Subject: [PATCH 006/642] Fix incorrect date format with swapped month and minute Change-Id: Ie6cf75c961eafcf37d31cedf50a0ae2b6586677f Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../eclipse/mylyn/github/internal/GitHubTaskDataHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java index 2bb8b0076..182b92f77 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java @@ -41,7 +41,7 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler { private final GitHubRepositoryConnector connector; private DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(); - private DateFormat githubDateFormat = new SimpleDateFormat("yyyy/mm/dd HH:MM:ss Z"); + private DateFormat githubDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss Z"); public GitHubTaskDataHandler(GitHubRepositoryConnector connector) { this.connector = connector; From 0cc416511934c71fb9c3e0ab7c6312d733ffc16c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Apr 2011 13:28:21 -0700 Subject: [PATCH 007/642] Change summary attribute to type short rich text This improves the appearance in the summary editor part. Change-Id: I11e0e907321d1ec2558f1f568f1b191134a155e9 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java index 128ea43c4..c58277811 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java @@ -17,7 +17,7 @@ public enum GitHubTaskAttributes { KEY("Key",TaskAttribute.TASK_KEY,TaskAttribute.TYPE_SHORT_TEXT,true,true,true), - TITLE("Summary",TaskAttribute.SUMMARY,TaskAttribute.TYPE_SHORT_TEXT,true,false,true), + TITLE("Summary",TaskAttribute.SUMMARY,TaskAttribute.TYPE_SHORT_RICH_TEXT,true,false,true), BODY("Description",TaskAttribute.DESCRIPTION,TaskAttribute.TYPE_LONG_RICH_TEXT,true,false,true), CREATION_DATE("Created:",TaskAttribute.DATE_CREATION,TaskAttribute.TYPE_DATETIME,true,true,false), From b31532a46f79eeaa42fe9b9fe2feaa1b46a27bc3 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Thu, 7 Apr 2011 16:31:22 -0500 Subject: [PATCH 008/642] Use proper GitHub logo Change-Id: If72b62fd5e2389f3bcf9e0db0dc999a9284b0fc3 Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github.ui/build.properties | 3 +-- org.eclipse.mylyn.github.ui/images/git-logo.png | Bin 202 -> 0 bytes org.eclipse.mylyn.github.ui/plugin.xml | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 org.eclipse.mylyn.github.ui/images/git-logo.png diff --git a/org.eclipse.mylyn.github.ui/build.properties b/org.eclipse.mylyn.github.ui/build.properties index 3a0c53af4..8665ac2ff 100644 --- a/org.eclipse.mylyn.github.ui/build.properties +++ b/org.eclipse.mylyn.github.ui/build.properties @@ -3,5 +3,4 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.xml,\ - plugin.properties,\ - images/ + plugin.properties diff --git a/org.eclipse.mylyn.github.ui/images/git-logo.png b/org.eclipse.mylyn.github.ui/images/git-logo.png deleted file mode 100644 index dd98d355a17dfcca350f9faf669bb5a3cc525d21..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFmdKI;Vst013A{*8l(j diff --git a/org.eclipse.mylyn.github.ui/plugin.xml b/org.eclipse.mylyn.github.ui/plugin.xml index be433f6e8..3d7bf9f91 100644 --- a/org.eclipse.mylyn.github.ui/plugin.xml +++ b/org.eclipse.mylyn.github.ui/plugin.xml @@ -9,11 +9,11 @@ name="%org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnector"> + overlayIcon="icons/obj16/github.png"> Date: Thu, 7 Apr 2011 15:45:13 -0700 Subject: [PATCH 009/642] Close reader and use StringBuilder instead of StringBuffer. Change-Id: I33506b4399918c4b4194b73ed6cb1f34a26b286f Signed-off-by: Kevin Sawicki --- .../mylyn/github/ui/internal/CreateGistHandler.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java index 0573d99a2..6392809c0 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java @@ -73,10 +73,11 @@ private void createGistJob(String name, String extension, String contents) { } private void createGistJob(IFile file) { + BufferedReader br = null; try { - BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents())); + br = new BufferedReader(new InputStreamReader(file.getContents())); String line; - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); while ((line = br.readLine()) != null) { result.append(line); result.append('\n'); @@ -87,6 +88,13 @@ private void createGistJob(IFile file) { GitHubUi.logError(e); } catch (IOException e) { GitHubUi.logError(e); + } finally { + if (br != null) + try { + br.close(); + } catch (IOException e) { + GitHubUi.logError(e); + } } } From 7bb025dac9ba6c7275e9bd43c584bfb2ee4933f6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Apr 2011 16:16:41 -0700 Subject: [PATCH 010/642] Add support for converting JSON dates to Java dates. Change-Id: If328b7023e0b8cdc4f19f23fd473b4189b2ffe4e Signed-off-by: Kevin Sawicki --- .../mylyn/github/internal/DateFormatter.java | 92 +++++++++++++++++++ .../mylyn/github/internal/GitHubService.java | 6 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java new file mode 100644 index 000000000..de356f16c --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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.github.internal; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; + +import java.lang.reflect.Type; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.TimeZone; + +/** + * Date formatter for multiple date formats present in the GitHub v2 API. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class DateFormatter implements JsonDeserializer { + + /** + * DATE_FORMAT1 + */ + public static final String DATE_FORMAT1 = "yyyy/MM/dd HH:mm:ss Z"; + + /** + * DATE_FORMAT2 + */ + public static final String DATE_FORMAT2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + + /** + * DATE_FORMAT3 + */ + public static final String DATE_FORMAT3 = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + + /** + * DATE_FORMAT4 + */ + public static final String DATE_FORMAT4 = "yyyy-MM-dd'T'HH:mm:ss"; + + private static final String[] FORMATS = new String[] { DATE_FORMAT1, + DATE_FORMAT2, DATE_FORMAT3, DATE_FORMAT4 }; + + private List formats; + + /** + * Create date formatter + */ + public DateFormatter() { + this.formats = new LinkedList(); + TimeZone timeZone = TimeZone.getTimeZone("Zulu"); + for (String format : FORMATS) { + DateFormat dateFormat = new SimpleDateFormat(format); + dateFormat.setTimeZone(timeZone); + this.formats.add(dateFormat); + } + } + + /** + * @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, + * java.lang.reflect.Type, com.google.gson.JsonDeserializationContext) + */ + public Date deserialize(JsonElement json, Type typeOfT, + JsonDeserializationContext context) throws JsonParseException { + String string = json.getAsString(); + Exception exception = null; + for (DateFormat format : this.formats) { + try { + synchronized (format) { + return format.parse(string); + } + } catch (ParseException e) { + exception = e; + } + } + throw new JsonParseException(exception); + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java index 17171f601..9a5b74386 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java @@ -13,6 +13,7 @@ package org.eclipse.mylyn.github.internal; import java.io.IOException; +import java.util.Date; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; @@ -29,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; /** * Facility to perform API operations on a GitHub issue tracker. @@ -78,7 +80,9 @@ public class GitHubService { */ public GitHubService() { httpClient = new HttpClient(); - gson = new Gson(); + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(Date.class, new DateFormatter()); + gson = builder.create(); } /** From 89204272ead774d6d82b1a380e6f12ace09cb6f6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Apr 2011 15:28:38 -0700 Subject: [PATCH 011/642] Add ability to view comments on an issue. Adds service support for getting a list of comments and maps them as task attributes. Bug: 340901 Change-Id: I0210346e20125e50fc28f5be6aa0a9af5f0562f0 Signed-off-by: Kevin Sawicki --- .../mylyn/github/internal/GitHubIssue.java | 21 +++++ .../github/internal/GitHubIssueComment.java | 83 +++++++++++++++++++ .../github/internal/GitHubIssueComments.java | 33 ++++++++ .../internal/GitHubRepositoryConnector.java | 9 +- .../mylyn/github/internal/GitHubService.java | 35 ++++++++ .../internal/GitHubTaskDataHandler.java | 26 +++++- .../ui/internal/GitHubTaskEditorPage.java | 5 -- 7 files changed, 204 insertions(+), 8 deletions(-) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java index 0d581a04f..f6914b005 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java @@ -28,6 +28,8 @@ public class GitHubIssue { private String comment_new; + private int comments; + /** * open, closed */ @@ -181,4 +183,23 @@ public String getComment_new() { public void setComment_new(String comment_new) { this.comment_new = comment_new; } + + /** + * Get number of comments issue has + * + * @return comments + */ + public int getComments() { + return this.comments; + } + + /** + * Set number of comments that issue has + * + * @param comments + */ + public void setComments(int comments) { + this.comments = comments; + } + } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java new file mode 100644 index 000000000..9a5ddda09 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.Date; + +/** + * GitHub issue comment class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class GitHubIssueComment { + + private String gravatar_id; + private Date created_at; + private String body; + private Date updated_at; + private String id; + private String user; + + /** + * Get gravatar id + * + * @return gravatar id + */ + public String getGravatarId() { + return this.gravatar_id; + } + + /** + * Get created at date + * + * @return created date + */ + public Date getCreatedAt() { + return this.created_at; + } + + /** + * Get body + * + * @return body + */ + public String getBody() { + return this.body; + } + + /** + * Get updated at date + * + * @return date + */ + public Date getUpdatedAt() { + return this.updated_at; + } + + /** + * Get id + * + * @return id + */ + public String getId() { + return this.id; + } + + /** + * Get user + * + * @return user + */ + public String getUser() { + return this.user; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java new file mode 100644 index 000000000..85079e806 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.List; + +/** + * GitHub issue comments wrapper class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class GitHubIssueComments { + + private List comments; + + /** + * Get comments + * + * @return list of comments + */ + public List getComments() { + return this.comments; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java index 681bdb756..8b4b74471 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.github.internal; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -156,7 +157,13 @@ public TaskData getTaskData(TaskRepository repository, String taskId, try { GitHubCredentials credentials = GitHubCredentials.create(repository); GitHubIssue issue = service.showIssue(user, project, taskId, credentials); - TaskData taskData = taskDataHandler.createTaskData(repository, monitor, user, project, issue); + List comments = null; + if (issue.getComments() > 0) { + comments = service.getComments(user, project, issue, + credentials); + } + TaskData taskData = taskDataHandler.createTaskData(repository, + monitor, user, project, issue, comments); return taskData; } catch (GitHubServiceException e) { diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java index 9a5b74386..cf8976920 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java @@ -13,7 +13,9 @@ package org.eclipse.mylyn.github.internal; import java.io.IOException; +import java.io.InputStreamReader; import java.util.Date; +import java.util.List; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; @@ -62,6 +64,7 @@ public class GitHubService { private final static String CLOSE = "close/"; private final static String EDIT = "edit/"; // Implemented private final static String COMMENT = "comment/"; + private final static String COMMENTS = "comments/"; // private final static String VIEW = "view/"; private final static String SHOW = "show/"; // :user/:repo/:number private final static String LIST = "list/"; // Implemented @@ -658,4 +661,36 @@ public void addComment(final String user, final String repo, } } } + + /** + * Get comments associated with issue + * + * @param user + * @param repo + * @param issue + * @param credentials + * @return collection of comments + * @throws GitHubServiceException + */ + public List getComments(final String user, + final String repo, final GitHubIssue issue, + final GitHubCredentials credentials) throws GitHubServiceException { + GetMethod method = null; + try { + method = new GetMethod(gitURLBase + gitIssueRoot + COMMENTS + user + + "/" + repo + "/" + issue.getNumber()); + setCredentials(credentials); + executeMethod(method); + return this.gson.fromJson( + new InputStreamReader(method.getResponseBodyAsStream()), + GitHubIssueComments.class).getComments(); + } catch (IOException e) { + throw new GitHubServiceException(e); + } finally { + if (method != null) { + method.releaseConnection(); + } + } + } + } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java index 182b92f77..3a5474885 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java @@ -16,6 +16,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import java.util.Set; import org.eclipse.core.runtime.CoreException; @@ -28,6 +29,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; +import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskOperation; @@ -158,10 +160,30 @@ private String toGitHubDate(TaskData taskData, public TaskData createTaskData(TaskRepository repository, IProgressMonitor monitor, String user, String project, - GitHubIssue issue) { - TaskData taskData = createPartialTaskData(repository, monitor, user, project, issue); + GitHubIssue issue, List comments) { + TaskData taskData = createPartialTaskData(repository, monitor, user, + project, issue); taskData.setPartial(false); + if (comments != null && !comments.isEmpty()) { + int count = 1; + TaskAttribute root = taskData.getRoot(); + for (GitHubIssueComment comment : comments) { + TaskCommentMapper commentMapper = new TaskCommentMapper(); + commentMapper.setAuthor(repository.createPerson(comment + .getUser())); + commentMapper.setCreationDate(comment.getCreatedAt()); + commentMapper.setText(comment.getBody()); + commentMapper.setCommentId(comment.getId()); + commentMapper.setNumber(count); + + TaskAttribute attribute = root + .createAttribute(TaskAttribute.PREFIX_COMMENT + count); + commentMapper.applyTo(attribute); + count++; + } + } + return taskData; } diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java index a24d8cb15..993012eaf 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java @@ -48,11 +48,6 @@ protected Set createPartDescriptors() { TaskEditorPartDescriptor partDescriptor = descriptorIt.next(); if (partDescriptor.getId().equals(ID_PART_ATTRIBUTES)) { descriptorIt.remove(); - } else if (partDescriptor.getId().equals(ID_PART_COMMENTS)) { - // currently the API doesn't support reading existing comments, - // though it does allow for creating them. Silly really. - // see http://support.github.com/discussions/feature-requests/696-issues-api-improvement - descriptorIt.remove(); } } return partDescriptors; From 03f2f6cdae64043ba54d66a3840544c815ad037e Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Fri, 8 Apr 2011 12:19:25 -0500 Subject: [PATCH 012/642] Add a proper branding icon Signed-off-by: Chris Aniszczyk --- .../icons/obj16/github_8x8.png | Bin 0 -> 246 bytes org.eclipse.mylyn.github.ui/plugin.xml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 org.eclipse.mylyn.github.ui/icons/obj16/github_8x8.png diff --git a/org.eclipse.mylyn.github.ui/icons/obj16/github_8x8.png b/org.eclipse.mylyn.github.ui/icons/obj16/github_8x8.png new file mode 100644 index 0000000000000000000000000000000000000000..8da6ee702d4f6be71d134e088525fbf6a8f7a926 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgg)77jr{?$~d?_W*^;JY5_^BreCE z+0DrmD8PE*a~O+ZN%sa(dk!|WYa1HBp3pwP6{B + overlayIcon="icons/obj16/github_8x8.png"> Date: Sat, 9 Apr 2011 00:23:52 +0200 Subject: [PATCH 013/642] ClassCastException when creating a gist via editor text selection A TextSelection is casted to a IStructuredException in CreateGistHandler. Bug: 342337 Change-Id: I05f5824617b0a6dfc5a03a4c530aeeaebd641876 Signed-off-by: Christian Trutz --- .../.settings/egit-github.launch | 6 +++--- .../github/ui/internal/CreateGistHandler.java | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch index 81afaf359..f26dbc812 100644 --- a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch +++ b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch @@ -12,7 +12,7 @@ - + @@ -49,8 +49,8 @@ - - + + diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java index 6392809c0..5a46a720c 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/CreateGistHandler.java @@ -38,9 +38,7 @@ public class CreateGistHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); ISelection selection = HandlerUtil.getCurrentSelection(event); - IStructuredSelection menuSelection = (IStructuredSelection) HandlerUtil - .getActiveMenuSelection(event); - if(selection != null && menuSelection == null) { + if(selection != null) { if(selection instanceof ITextSelection) { ITextSelection text = (ITextSelection) selection; IEditorInput input = editor.getEditorInput(); @@ -50,13 +48,14 @@ public Object execute(ExecutionEvent event) throws ExecutionException { IFile file = fileInput.getFile(); createGistJob(file.getName(), file.getFileExtension(), text.getText()); } - } - } - if(menuSelection != null) { - Object obj = menuSelection.getFirstElement(); - if(obj instanceof IFile) { - IFile file = (IFile) obj; - createGistJob(file); + } else + if(selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + Object obj = structuredSelection.getFirstElement(); + if(obj instanceof IFile) { + IFile file = (IFile) obj; + createGistJob(file); + } } } return null; From 386e70bf56d43792be79eb5ea3b43117854b6610 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 9 Apr 2011 18:12:16 -0500 Subject: [PATCH 014/642] Update to use Tycho 0.11 Signed-off-by: Chris Aniszczyk --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d97f87718..65589a120 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ - 0.10.0 + 0.11.0 helios http://download.eclipse.org/releases/${platform-version-name} http://download.eclipse.org/tools/orbit/downloads/drops/S20110124210048/repository From dec33a839f902d712036073329f71722a3247e5b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 10 Apr 2011 10:54:15 -0700 Subject: [PATCH 015/642] Add user and request error model support Change-Id: Ic2ddda0eada498ebbabb9aefdd741ce5bd595c34 Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/RequestError.java | 42 ++++++++ .../github/internal/RequestException.java | 47 ++++++++ .../eclipse/mylyn/github/internal/User.java | 101 ++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestError.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestError.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestError.java new file mode 100644 index 000000000..0ba922cae --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestError.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.List; + +/** + * GitHub request error class + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class RequestError { + + private String message; + + private List errors; + + /** + * @return message + */ + public String getMessage() { + return this.message; + } + + /** + * Get errors + * + * @return list of errors + */ + public List getErrors() { + return this.errors; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java new file mode 100644 index 000000000..add415655 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.github.internal; + +import java.io.IOException; + +/** + * Request exception class that wraps an {@link RequestError} object. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class RequestException extends IOException { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = 1197051396535284852L; + + private RequestError error; + + /** + * Create request exception + * + * @param error + */ + public RequestException(RequestError error) { + super(error.getMessage()); + } + + /** + * Get error + * + * @return error + */ + public RequestError getError() { + return this.error; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java new file mode 100644 index 000000000..ae00a90bb --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * 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.github.internal; + +/** + * GitHub user class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class User { + + private String blob; + + private String company; + + private String email; + + private String gravatarUrl; + + private String location; + + private String login; + + private String name; + + private String type; + + private String url; + + /** + * @return blob + */ + public String getBlob() { + return this.blob; + } + + /** + * @return company + */ + public String getCompany() { + return this.company; + } + + /** + * @return email + */ + public String getEmail() { + return this.email; + } + + /** + * @return gravatarUrl + */ + public String getGravatarUrl() { + return this.gravatarUrl; + } + + /** + * @return location + */ + public String getLocation() { + return this.location; + } + + /** + * @return login + */ + public String getLogin() { + return this.login; + } + + /** + * @return name + */ + public String getName() { + return this.name; + } + + /** + * @return type + */ + public String getType() { + return this.type; + } + + /** + * @return url + */ + public String getUrl() { + return this.url; + } + +} From ca6bf1817ac5a15d998395ea28a19aa4fc1f07bd Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 10 Apr 2011 11:04:29 -0700 Subject: [PATCH 016/642] Add comment and milestone model support Change-Id: If336ef2527a58d89d83cd8949370005768e53b89 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/Comment.java | 67 +++++++++++ .../mylyn/github/internal/Milestone.java | 112 ++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java new file mode 100644 index 000000000..1a37ddca6 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.Date; + +/** + * GitHub issue comment class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class Comment { + + private Date createdAt; + + private Date updatedAt; + + private String body; + + private String url; + + private User user; + + /** + * @return createdAt + */ + public Date getCreatedAt() { + return this.createdAt; + } + + /** + * @return updatedAt + */ + public Date getUpdatedAt() { + return this.updatedAt; + } + + /** + * @return body + */ + public String getBody() { + return this.body; + } + + /** + * @return url + */ + public String getUrl() { + return this.url; + } + + /** + * @return user + */ + public User getUser() { + return this.user; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java new file mode 100644 index 000000000..fac305eea --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.Date; + +/** + * GitHub issue milestone class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class Milestone { + + private Date createdAt; + + private Date dueOn; + + private int closedIssues; + + private int number; + + private int openIssues; + + private String description; + + private String state; + + private String title; + + private String url; + + private User creator; + + /** + * @return createdAt + */ + public Date getCreatedAt() { + return this.createdAt; + } + + /** + * @return dueOn + */ + public Date getDueOn() { + return this.dueOn; + } + + /** + * @return closedIssues + */ + public int getClosedIssues() { + return this.closedIssues; + } + + /** + * @return number + */ + public int getNumber() { + return this.number; + } + + /** + * @return openIssues + */ + public int getOpenIssues() { + return this.openIssues; + } + + /** + * @return description + */ + public String getDescription() { + return this.description; + } + + /** + * @return state + */ + public String getState() { + return this.state; + } + + /** + * @return title + */ + public String getTitle() { + return this.title; + } + + /** + * @return url + */ + public String getUrl() { + return this.url; + } + + /** + * @return creator + */ + public User getCreator() { + return this.creator; + } + +} From ccaf4c9baf049ac55745df76c77a82c45cc51cf5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 8 Apr 2011 10:56:08 -0700 Subject: [PATCH 017/642] Add support for displaying an issue's labels Change-Id: I97b56c9fbd4f6c0962a0275c451554786e13e03b Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/GitHubIssue.java | 22 +++++++ .../github/internal/GitHubTaskAttributes.java | 3 +- .../internal/GitHubTaskDataHandler.java | 30 +++++++-- .../ui/internal/GitHubIssueLabelPart.java | 65 +++++++++++++++++++ .../ui/internal/GitHubTaskEditorPage.java | 7 ++ 5 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubIssueLabelPart.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java index f6914b005..05ac5a006 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.mylyn.github.internal; +import java.util.List; + /** * GitHub Issue object to hold all the properties of an individual issue. @@ -30,6 +32,8 @@ public class GitHubIssue { private int comments; + private List labels; + /** * open, closed */ @@ -202,4 +206,22 @@ public void setComments(int comments) { this.comments = comments; } + /** + * Get labels applied to issue + * + * @return labels + */ + public List getLabels() { + return this.labels; + } + + /** + * Set labels applied to issue + * + * @param labels + */ + public void setLabels(List labels) { + this.labels = labels; + } + } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java index c58277811..ca0ead386 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java @@ -26,7 +26,8 @@ public enum GitHubTaskAttributes { STATUS("Status:",TaskAttribute.STATUS,TaskAttribute.TYPE_SHORT_TEXT,true,false,true), REPORTER("Reporter:", TaskAttribute.USER_REPORTER, TaskAttribute.TYPE_PERSON, true, true, false), - COMMENT_NEW("Comment:", TaskAttribute.COMMENT_NEW, TaskAttribute.TYPE_LONG_RICH_TEXT, false, false, false) + COMMENT_NEW("Comment:", TaskAttribute.COMMENT_NEW, TaskAttribute.TYPE_LONG_RICH_TEXT, false, false, false), + LABELS("Labels:", "github.issue.labels", TaskAttribute.TYPE_MULTI_SELECT, true, true, false) ; private final String id; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java index 3a5474885..c762d59d2 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java @@ -15,6 +15,7 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Set; @@ -77,6 +78,7 @@ public TaskData createPartialTaskData(TaskRepository repository, createAttribute(data, GitHubTaskAttributes.CLOSED_DATE, toLocalDate(issue.getClosed_at())); createAttribute(data, GitHubTaskAttributes.REPORTER, issue.getUser()); createAttribute(data, GitHubTaskAttributes.COMMENT_NEW, ""); + createAttribute(data, GitHubTaskAttributes.LABELS, issue.getLabels()); if (isPartial(data)) { data.setPartial(true); @@ -208,20 +210,34 @@ private String getAttributeValue(TaskData taskData, return attribute==null?null:attribute.getValue(); } - private void createAttribute(TaskData data, GitHubTaskAttributes attribute, String value) { + private TaskAttribute createAttribute(TaskData data, + GitHubTaskAttributes attribute) { TaskAttribute attr = data.getRoot().createAttribute(attribute.getId()); TaskAttributeMetaData metaData = attr.getMetaData(); - metaData.defaults() - .setType(attribute.getType()) - .setKind(attribute.getKind()) - .setLabel(attribute.getLabel()) - .setReadOnly(attribute.isReadOnly()); + metaData.defaults().setType(attribute.getType()) + .setKind(attribute.getKind()).setLabel(attribute.getLabel()) + .setReadOnly(attribute.isReadOnly()); + return attr; + } + private void createAttribute(TaskData data, GitHubTaskAttributes attribute, + String value) { + TaskAttribute attr = createAttribute(data, attribute); if (value != null) { attr.addValue(value); } } + private void createAttribute(TaskData data, GitHubTaskAttributes attribute, + Collection values) { + TaskAttribute attr = createAttribute(data, attribute); + if (values != null) { + for (String value : values) { + attr.addValue(value); + } + } + } + @Override public boolean initializeTaskData(TaskRepository repository, TaskData data, ITaskMapping initializationData, IProgressMonitor monitor) @@ -231,7 +247,7 @@ public boolean initializeTaskData(TaskRepository repository, TaskData data, for (GitHubTaskAttributes attr: GitHubTaskAttributes.values()) { if (attr.isInitTask()) { - createAttribute(data, attr,null); + createAttribute(data, attr, (String) null); } } diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubIssueLabelPart.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubIssueLabelPart.java new file mode 100644 index 000000000..81a6f2306 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubIssueLabelPart.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.github.ui.internal; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.mylyn.github.internal.GitHubTaskAttributes; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.IFormColors; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * Editor part for viewing a issue's labels. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class GitHubIssueLabelPart extends AbstractTaskEditorPart { + + /** + * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart#createControl(org.eclipse.swt.widgets.Composite, + * org.eclipse.ui.forms.widgets.FormToolkit) + */ + public void createControl(Composite parent, FormToolkit toolkit) { + Composite displayArea = toolkit.createComposite(parent); + GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5) + .spacing(0, 0).numColumns(2).applyTo(displayArea); + + TaskAttribute labels = getTaskData().getRoot().getAttribute( + GitHubTaskAttributes.LABELS.getId()); + if (labels != null) { + Label labelControl = toolkit.createLabel(displayArea, labels + .getMetaData().getLabel()); + labelControl.setForeground(toolkit.getColors().getColor( + IFormColors.TITLE)); + + StringBuilder labelsValue = new StringBuilder(); + for (String value : labels.getValues()) { + labelsValue.append(' ').append(value).append(','); + } + if (labelsValue.length() > 0) { + labelsValue.deleteCharAt(labelsValue.length() - 1); + } + + Text labelsText = toolkit.createText(displayArea, + labelsValue.toString(), SWT.WRAP | SWT.READ_ONLY); + GridDataFactory.swtDefaults().indent(5, 0).grab(true, false) + .applyTo(labelsText); + } + + setControl(displayArea); + } +} \ No newline at end of file diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java index 993012eaf..7aefa4bfc 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java @@ -19,6 +19,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; +import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor; @@ -50,6 +51,12 @@ protected Set createPartDescriptors() { descriptorIt.remove(); } } + partDescriptors.add(new TaskEditorPartDescriptor("labels") { + + public AbstractTaskEditorPart createPart() { + return new GitHubIssueLabelPart(); + } + }.setPath(PATH_ATTRIBUTES)); return partDescriptors; } From d1db183f3d741b55fa3d66b05ecd9b719a837af3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 10 Apr 2011 11:15:54 -0700 Subject: [PATCH 018/642] Add interface for new API constants Change-Id: I6d6a7c4265921a1cccd5dc5d979824923272c38a Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../github/internal/IGitHubConstants.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java new file mode 100644 index 000000000..290d616e2 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.github.internal; + +/** + * GitHub constants. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public interface IGitHubConstants { + + /** + * REPOS_SEGMENT + */ + String SEGMENT_REPOS = "/repos"; //$NON-NLS-1$ + + /** + * SEGMENT_ISSUES + */ + String SEGMENT_ISSUES = "/issues"; //$NON-NLS-1$ + + /** + * SUFFIX_JSON + */ + String SUFFIX_JSON = ".json"; //$NON-NLS-1$ + + /** + * HOST_API + */ + String HOST_API = "api.github.com"; //$NON-NLS-1$ + + /** + * PROTOCOL_HTTPS + */ + String PROTOCOL_HTTPS = "https"; //$NON-NLS-1$ + +} From 990790463e207419db4b939900fad466b99f4430 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 10 Apr 2011 11:38:08 -0700 Subject: [PATCH 019/642] Add GitHub client class for new API Change-Id: I8f4681353bcfcffc7efbc9bb4f726dc61a45a563 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../META-INF/MANIFEST.MF | 1 + .../mylyn/github/internal/GitHubClient.java | 238 ++++++++++++++++++ .../github/internal/IGitHubConstants.java | 5 + 3 files changed, 244 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java diff --git a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF index bb48a03a7..2494f24a9 100644 --- a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF @@ -10,4 +10,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.mylyn.tasks.core;bundle-version="3.2.0", org.eclipse.mylyn.commons.net;bundle-version="3.2.0" Import-Package: com.google.gson;version="1.6.0", + com.google.gson.reflect;version="1.6.0", org.apache.commons.logging diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java new file mode 100644 index 000000000..765e90bec --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java @@ -0,0 +1,238 @@ +/******************************************************************************* + * 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.github.internal; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HostConfiguration; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.commons.httpclient.auth.BasicScheme; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.protocol.Protocol; + +/** + * Client class for interacting with GitHub HTTP/JSON API. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class GitHubClient { + + private static final AuthScope ANY_SCOPE = new AuthScope( + AuthScope.ANY_HOST, AuthScope.ANY_PORT); + + private HostConfiguration hostConfig; + + private HttpClient client = new HttpClient(); + + private Gson gson = new GsonBuilder() + .setDateFormat(IGitHubConstants.DATE_FORMAT) + .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) + .create(); + + private boolean sendCredentials = false; + + /** + * Create default client + */ + public GitHubClient() { + this.hostConfig = new HostConfiguration(); + this.hostConfig.setHost(IGitHubConstants.HOST_API, -1, + Protocol.getProtocol(IGitHubConstants.PROTOCOL_HTTPS)); + } + + /** + * Create client for configuration + * + * @param configuration + */ + public GitHubClient(HostConfiguration configuration) { + this.hostConfig = configuration; + } + + /** + * Create standard post method + * + * @param uri + * @return post + */ + protected PostMethod createPost(String uri) { + PostMethod method = new PostMethod(uri); + setMethodDefaults(method); + return method; + } + + /** + * Set method defaults + * + * @param method + * @return method + */ + protected HttpMethod setMethodDefaults(HttpMethod method) { + if (this.sendCredentials) { + method.setDoAuthentication(true); + method.getHostAuthState().setPreemptive(); + method.getHostAuthState().setAuthScheme(new BasicScheme()); + } + return method; + } + + /** + * Create get method + * + * @param uri + * @return get method + */ + protected GetMethod createGet(String uri) { + GetMethod method = new GetMethod(uri); + method.setFollowRedirects(true); + setMethodDefaults(method); + return method; + } + + /** + * Set credentials + * + * @param user + * @param password + */ + public void setCredentials(String user, String password) { + this.sendCredentials = user != null && password != null; + Credentials credentials = null; + if (this.sendCredentials) + credentials = new UsernamePasswordCredentials(user, password); + this.client.getState().setCredentials(ANY_SCOPE, credentials); + } + + /** + * Parse json to specified type + * + * @param + * @param method + * @param type + * @return type + * @throws IOException + */ + protected V parseJson(HttpMethodBase method, Type type) + throws IOException { + InputStream stream = method.getResponseBodyAsStream(); + if (stream == null) + throw new JsonParseException("Empty body"); //$NON-NLS-1$ + InputStreamReader reader = new InputStreamReader(stream); + return this.gson.fromJson(reader, type); + } + + /** + * Get name value pairs for data map. + * + * @param data + * @return name value pair array + */ + protected NameValuePair[] getPairs(Map data) { + NameValuePair[] pairs = new NameValuePair[data.size()]; + int i = 0; + for (Entry entry : data.entrySet()) { + pairs[i] = new NameValuePair(entry.getKey(), entry.getValue()); + i++; + } + return pairs; + } + + /** + * Get response from uri and bind to specified type + * + * @param + * @param uri + * @param params + * @param type + * @return V + * @throws IOException + */ + public V get(String uri, Map params, Type type) + throws IOException { + GetMethod method = createGet(uri); + if (params != null && !params.isEmpty()) + method.setQueryString(getPairs(params)); + + try { + int status = this.client.executeMethod(this.hostConfig, method); + switch (status) { + case 200: + return parseJson(method, type); + case 404: + case 500: + RequestError error = parseJson(method, RequestError.class); + throw new RequestException(error); + default: + throw new IOException(method.getStatusText()); + } + } catch (JsonParseException jpe) { + throw new IOException(jpe); + } finally { + method.releaseConnection(); + } + } + + /** + * Post data to uri + * + * @param + * @param uri + * @param params + * @param type + * @return response + * @throws IOException + */ + public V post(String uri, Map params, Type type) + throws IOException { + PostMethod method = createPost(uri); + if (params != null && !params.isEmpty()) + for (Entry entry : params.entrySet()) + method.addParameter(entry.getKey(), entry.getValue()); + + try { + int status = this.client.executeMethod(this.hostConfig, method); + switch (status) { + case 200: + case 201: + if (type != null) + return parseJson(method, type); + break; + case 404: + case 500: + RequestError error = parseJson(method, RequestError.class); + throw new RequestException(error); + default: + throw new IOException(method.getStatusText()); + } + } finally { + method.releaseConnection(); + } + return null; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java index 290d616e2..424e26d2f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java @@ -42,4 +42,9 @@ public interface IGitHubConstants { */ String PROTOCOL_HTTPS = "https"; //$NON-NLS-1$ + /** + * DATE_FORMAT + */ + String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$ + } From 3301f6a91b852f0e181c912601fd05d6fc53e04c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 10 Apr 2011 12:20:14 -0700 Subject: [PATCH 020/642] Add label and issue model classes for new API Change-Id: I035aa1dd7e64354bc2cc07c1da9f36a73016c9f5 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../eclipse/mylyn/github/internal/Issue.java | 149 ++++++++++++++++++ .../eclipse/mylyn/github/internal/Label.java | 47 ++++++ 2 files changed, 196 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Label.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java new file mode 100644 index 000000000..f1947d0ca --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.Date; +import java.util.List; + +/** + * GitHub issue class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class Issue { + + private Date closedAt; + + private Date createdAt; + + private Date updatedAt; + + private int comments; + + private int number; + + private List @@ -72,5 +76,20 @@ commandId="org.eclipse.mylyn.github.ui.command.createGist"> + + + + + + From db4be004d85d0c37f62f5be2bf4401da9666166d Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Thu, 14 Apr 2011 16:05:53 -0500 Subject: [PATCH 085/642] Support gists without a description Signed-off-by: Chris Aniszczyk --- .../mylyn/internal/github/core/gist/GistTaskDataHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index 6f290da36..fa0311bad 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -108,7 +108,8 @@ public TaskData fillTaskData(TaskRepository repository, TaskData data, mapper.setValue(key, gist.getRepo()); TaskAttribute description = GistAttribute.DESCRIPTION.create(data); - mapper.setValue(description, gist.getDescription()); + if(description != null) + mapper.setValue(description, gist.getDescription()); TaskAttribute created = GistAttribute.CREATED.create(data); mapper.setDateValue(created, gist.getCreatedAt()); From c3d1a3ba9603b6702673fdba90e2d5d83942f3aa Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 14:24:49 -0700 Subject: [PATCH 086/642] Only set description task attribute if non-null Change-Id: Idbec391afcdb65009ee58d8b63e814254dd969d8 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../internal/github/core/gist/GistTaskDataHandler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index fa0311bad..da9e3a39c 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -30,8 +30,8 @@ import org.eclipse.mylyn.tasks.core.IRepositoryPerson; import org.eclipse.mylyn.tasks.core.ITaskMapping; import org.eclipse.mylyn.tasks.core.RepositoryResponse; -import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind; +import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler; import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; @@ -108,8 +108,9 @@ public TaskData fillTaskData(TaskRepository repository, TaskData data, mapper.setValue(key, gist.getRepo()); TaskAttribute description = GistAttribute.DESCRIPTION.create(data); - if(description != null) - mapper.setValue(description, gist.getDescription()); + String gistDescription = gist.getDescription(); + if (gistDescription != null) + mapper.setValue(description, gistDescription); TaskAttribute created = GistAttribute.CREATED.create(data); mapper.setDateValue(created, gist.getCreatedAt()); From 1ea5ffc1d7badbab238e6500f30c7f9888039171 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 14:56:52 -0700 Subject: [PATCH 087/642] Add gist history model classes Change-Id: I1b5d05748ebb2897e4a8b79b9fc04e7e38b25d13 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../eclipse/mylyn/github/internal/Gist.java | 10 +++ .../github/internal/GistChangeStatus.java | 45 +++++++++++++ .../mylyn/github/internal/GistRevision.java | 65 +++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistChangeStatus.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java index 99e3450fa..db1804e22 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java @@ -11,6 +11,7 @@ package org.eclipse.mylyn.github.internal; import java.util.Date; +import java.util.List; import java.util.Map; import com.google.gson.annotations.SerializedName; @@ -27,6 +28,8 @@ public class Gist { private int comments; + private List history; + private Map files; private String description; @@ -119,6 +122,13 @@ public String getGitPushUrl() { return this.gitPushUrl; } + /** + * @return history + */ + public List getHistory() { + return this.history; + } + /** * @return id */ diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistChangeStatus.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistChangeStatus.java new file mode 100644 index 000000000..f164bcc42 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistChangeStatus.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.github.internal; + +/** + * Gist change status class. + */ +public class GistChangeStatus { + + private int additions; + + private int deletions; + + private int total; + + /** + * @return additions + */ + public int getAdditions() { + return this.additions; + } + + /** + * @return deletions + */ + public int getDeletions() { + return this.deletions; + } + + /** + * @return total + */ + public int getTotal() { + return this.total; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java new file mode 100644 index 000000000..60bab8603 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.Date; + +/** + * Gist revision class. + */ +public class GistRevision { + + private Date committedAt; + + private GistChangeStatus changeStatus; + + private String url; + + private String version; + + private User user; + + /** + * @return committedAt + */ + public Date getCommittedAt() { + return this.committedAt; + } + + /** + * @return changeStatus + */ + public GistChangeStatus getChangeStatus() { + return this.changeStatus; + } + + /** + * @return url + */ + public String getUrl() { + return this.url; + } + + /** + * @return version + */ + public String getVersion() { + return this.version; + } + + /** + * @return user + */ + public User getUser() { + return this.user; + } + +} From 0dccbf11c3f681f0558c8b8f197462bf5d94101c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 15:28:01 -0700 Subject: [PATCH 088/642] Add generated summary text with file and size summary Change-Id: Iedc49bdb6d8638b6e42e0df2c7f4ff0061deef37 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../github/core/gist/GistTaskDataHandler.java | 40 ++++++++++++++++++- .../internal/github/core/gist/Messages.java | 24 +++++++++++ .../github/core/gist/messages.properties | 8 ++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index da9e3a39c..5ae7ef646 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -11,6 +11,8 @@ package org.eclipse.mylyn.internal.github.core.gist; import java.io.IOException; +import java.text.DecimalFormat; +import java.text.MessageFormat; import java.util.List; import java.util.Map; import java.util.Set; @@ -131,9 +133,13 @@ public TaskData fillTaskData(TaskRepository repository, TaskData data, } Map files = gist.getFiles(); + int fileCount = 0; + long sizeCount = 0; if (files != null && !files.isEmpty()) { int count = 1; for (GistFile file : files.values()) { + fileCount++; + sizeCount += file.getSize(); TaskAttachmentMapper attachmentMapper = new TaskAttachmentMapper(); attachmentMapper.setFileName(file.getFilename()); attachmentMapper.setReplaceExisting(true); @@ -153,9 +159,41 @@ public TaskData fillTaskData(TaskRepository repository, TaskData data, GistAttribute.COMMENT_NEW.create(data); + TaskAttribute summary = GistAttribute.SUMMARY.create(data); + mapper.setValue(summary, generateSummary(fileCount, sizeCount)); + return data; } + private String generateSummary(int files, long size) { + StringBuilder summaryText = new StringBuilder(); + if (files != 1) + summaryText.append(MessageFormat.format( + Messages.GistTaskDataHandler_FilesMultiple, files)); + else + summaryText.append(Messages.GistTaskDataHandler_FilesSingle); + summaryText.append(',').append(' ').append(formatSize(size)); + return summaryText.toString(); + } + + private String formatSize(long size) { + if (size == 1) { + return Messages.GistTaskDataHandler_SizeByte; + } else if (size < 1024) { + return new DecimalFormat(Messages.GistTaskDataHandler_SizeBytes) + .format(size); + } else if (size >= 1024 && size <= 1048575) { + return new DecimalFormat(Messages.GistTaskDataHandler_SizeKilobytes) + .format(size / 1024.0); + } else if (size >= 1048576 && size <= 1073741823) { + return new DecimalFormat(Messages.GistTaskDataHandler_SizeMegabytes) + .format(size / 1048576.0); + } else { + return new DecimalFormat(Messages.GistTaskDataHandler_SizeGigabytes) + .format(size / 1073741824.0); + } + } + /** * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#postTaskData(org.eclipse.mylyn.tasks.core.TaskRepository, * org.eclipse.mylyn.tasks.core.data.TaskData, java.util.Set, @@ -219,7 +257,7 @@ public boolean initializeTaskData(TaskRepository repository, TaskData data, TaskAttributeMapper mapper = data.getAttributeMapper(); TaskAttribute summary = GistAttribute.SUMMARY.create(data); - mapper.setValue(summary, "New Gist"); + mapper.setValue(summary, Messages.GistTaskDataHandler_SummaryNewGist); GistAttribute.DESCRIPTION.create(data); return true; 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 4ba2416cb..30dba4e67 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 @@ -49,6 +49,30 @@ public class Messages extends NLS { /** */ public static String GistConnector_LabelConnector; + /** */ + public static String GistTaskDataHandler_FilesMultiple; + + /** */ + public static String GistTaskDataHandler_FilesSingle; + + /** */ + public static String GistTaskDataHandler_SizeByte; + + /** */ + public static String GistTaskDataHandler_SizeBytes; + + /** */ + public static String GistTaskDataHandler_SizeGigabytes; + + /** */ + public static String GistTaskDataHandler_SizeKilobytes; + + /** */ + public static String GistTaskDataHandler_SizeMegabytes; + + /** */ + public static String GistTaskDataHandler_SummaryNewGist; + 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 3d7885083..53b40d806 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 @@ -8,3 +8,11 @@ GistAttribute_LabelNewComment=New Comment GistAttribute_LabelSummary=Summary GistAttribute_LabelUrl=Url GistConnector_LabelConnector=Github Gists +GistTaskDataHandler_FilesMultiple={0} files +GistTaskDataHandler_FilesSingle=1 file +GistTaskDataHandler_SizeByte=1 byte +GistTaskDataHandler_SizeBytes=0 bytes +GistTaskDataHandler_SizeGigabytes=0.00 GB +GistTaskDataHandler_SizeKilobytes=0.00 KB +GistTaskDataHandler_SizeMegabytes=0.00 MB +GistTaskDataHandler_SummaryNewGist=New Gist From 8ed530d0cf51ce71b120de3ac1c9ec3d2c4769c2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 17:13:21 -0700 Subject: [PATCH 089/642] Use attachment file from attribute instead of source This now correctly uploads the attachment as the filename entered in the task attachment wizard. Change-Id: Ib44706d9a6520ae54d954a8cab38152afacdd9fa Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../internal/github/core/gist/GistAttachmentHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java index 40b111683..03bc94c15 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java @@ -28,6 +28,7 @@ import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler; import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource; +import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; /** @@ -87,11 +88,13 @@ public void postContent(TaskRepository repository, ITask task, AbstractTaskAttachmentSource source, String comment, TaskAttribute attachmentAttribute, IProgressMonitor monitor) throws CoreException { + TaskAttachmentMapper mapper = TaskAttachmentMapper + .createFrom(attachmentAttribute); Gist gist = new Gist().setRepo(task.getTaskId()); gist.setDescription(attachmentAttribute.getParentAttribute() .getAttribute(GistAttribute.DESCRIPTION.getId()).getValue()); GistFile file = new GistFile(); - file.setFilename(source.getName()); + file.setFilename(mapper.getFileName()); gist.setFiles(Collections.singletonMap(file.getFilename(), file)); GitHubClient client = new GitHubClient(); From 23fc43bc827c21cc96b2aca0f242f3de4e1d2a63 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 17:49:53 -0700 Subject: [PATCH 090/642] Set task attachment id to be gist file name File names are unique in gists and attachment ids are required to be able to navigate from the outline view to a specific row in the attachments table. Change-Id: Ie27ed8f7bd5b324b2f59eeee5102ad67e221648f Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../mylyn/internal/github/core/gist/GistTaskDataHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index 5ae7ef646..c77efdc60 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -146,6 +146,7 @@ public TaskData fillTaskData(TaskRepository repository, TaskData data, attachmentMapper.setLength((long) file.getSize()); attachmentMapper.setPatch(false); attachmentMapper.setAuthor(reporterPerson); + attachmentMapper.setAttachmentId(file.getFilename()); TaskAttribute attribute = data.getRoot().createAttribute( TaskAttribute.PREFIX_ATTACHMENT + count); attachmentMapper.applyTo(attribute); From 7e9d5098ab828621d0b9eefb62e930fdbd2ca426 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 18:04:09 -0700 Subject: [PATCH 091/642] Add gist attachment sorter Change-Id: If5b7e84daeb60a95a8099947bbf74983776e7b02 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../github/ui/gist/GistAttachmentSorter.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentSorter.java diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentSorter.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentSorter.java new file mode 100644 index 000000000..cd93321f6 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentSorter.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.ui.gist; + +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.mylyn.internal.provisional.commons.ui.TableSorter; +import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator; +import org.eclipse.mylyn.tasks.core.ITaskAttachment; + +/** + * @author Kevin Sawicki (kevin@github.com) + */ +public class GistAttachmentSorter extends TableSorter { + + private TaskKeyComparator keyComparator = new TaskKeyComparator(); + + /** + * @see org.eclipse.mylyn.internal.provisional.commons.ui.AbstractColumnViewerSorter#compare(org.eclipse.jface.viewers.ColumnViewer, + * java.lang.Object, java.lang.Object, int) + */ + public int compare(TableViewer viewer, Object e1, Object e2, int columnIndex) { + ITaskAttachment attachment1 = (ITaskAttachment) e1; + ITaskAttachment attachment2 = (ITaskAttachment) e2; + switch (columnIndex) { + case 0: + return compare(attachment1.getFileName(), attachment2.getFileName()); + case 1: + return compare(attachment1.getLength(), attachment2.getLength()); + case 2: + return compare(attachment1.getAuthor().toString(), attachment2 + .getAuthor().toString()); + default: + return super.compare(viewer, e1, e2, columnIndex); + } + } + +} From 1ada0edb2ba900156ff4172e460e4f921345bf4f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 18:18:55 -0700 Subject: [PATCH 092/642] Adding stubbed out gist task editor attachment part Change-Id: I988869d57947f1d37869340301c4b3b7a696339c Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../github/ui/gist/GistAttachmentPart.java | 131 ++++++++++++++++++ .../internal/github/ui/gist/Messages.java | 3 + .../github/ui/gist/messages.properties | 1 + 3 files changed, 135 insertions(+) create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java new file mode 100644 index 000000000..11b788209 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * 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.ui.gist; + +import java.io.File; +import java.util.List; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; +import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil; +import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttachmentPart; +import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * Gist editor attachment part. Modeled after {@link TaskEditorAttachmentPart} + * but with less columns. + */ +public class GistAttachmentPart extends AbstractTaskEditorPart { + + private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$ + + private final String[] attachmentsColumns = { + org.eclipse.mylyn.internal.tasks.ui.editors.Messages.TaskEditorAttachmentPart_Name, + org.eclipse.mylyn.internal.tasks.ui.editors.Messages.TaskEditorAttachmentPart_Size, + org.eclipse.mylyn.internal.tasks.ui.editors.Messages.TaskEditorAttachmentPart_Creator }; + + private final int[] attachmentsColumnWidths = { 150, 70, 100 }; + + private List attachments; + + private boolean hasIncoming; + + private MenuManager menuManager; + + private Composite attachmentsComposite; + + private Table attachmentsTable; + + /** + * Create gist editor attachment part + */ + public GistAttachmentPart() { + setPartName(Messages.GistAttachmentPart_PartName); + } + + /** + * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart#createControl(org.eclipse.swt.widgets.Composite, + * org.eclipse.ui.forms.widgets.FormToolkit) + */ + public void createControl(Composite parent, FormToolkit toolkit) { + + } + + /** + * @see org.eclipse.ui.forms.AbstractFormPart#dispose() + */ + public void dispose() { + if (menuManager != null) + menuManager.dispose(); + super.dispose(); + } + + private File getStateFile() { + IPath stateLocation = Platform.getStateLocation(TasksUiPlugin + .getDefault().getBundle()); + return stateLocation.append("GistAttachmentPart.xml").toFile(); //$NON-NLS-1$ + } + + private void createButtons(Composite attachmentsComposite, + FormToolkit toolkit) { + final Composite attachmentControlsComposite = toolkit + .createComposite(attachmentsComposite); + attachmentControlsComposite.setLayout(new GridLayout(2, false)); + attachmentControlsComposite.setLayoutData(new GridData( + GridData.BEGINNING)); + + Button attachFileButton = toolkit + .createButton( + attachmentControlsComposite, + org.eclipse.mylyn.internal.tasks.ui.editors.Messages.TaskEditorAttachmentPart_Attach_, + SWT.PUSH); + attachFileButton.setImage(CommonImages + .getImage(CommonImages.FILE_PLAIN)); + attachFileButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + EditorUtil.openNewAttachmentWizard(getTaskEditorPage(), + Mode.DEFAULT, null); + } + }); + getTaskEditorPage().registerDefaultDropListener(attachFileButton); + } + + /** + * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart#fillToolBar(org.eclipse.jface.action.ToolBarManager) + */ + protected void fillToolBar(ToolBarManager toolBarManager) { + + } + + /** + * @see org.eclipse.ui.forms.AbstractFormPart#setFormInput(java.lang.Object) + */ + public boolean setFormInput(Object input) { + return super.setFormInput(input); + } + +} diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java index 98e6178d4..5f1e200bb 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java @@ -19,6 +19,9 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.github.ui.gist.messages"; //$NON-NLS-1$ + /** */ + public static String GistAttachmentPart_PartName; + /** */ public static String GistConnectorUi_LabelTaskKind; diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties index 6b883af42..08b7f5deb 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties @@ -1,3 +1,4 @@ +GistAttachmentPart_PartName=Files GistConnectorUi_LabelTaskKind=Gist GistRepositoryQueryPage_LabelTitle=Title: GistRepositoryQueryPage_LabelUser=User: From ddaf9f614f4cbc690d6ce17014dd7ac96ac485bc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Apr 2011 18:23:26 -0700 Subject: [PATCH 093/642] Add custom gist task editor attachment part Change-Id: I1497392b9e56a7a7bd35135ddbcdd80ff80d9c85 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../github/ui/gist/GistAttachmentPart.java | 238 +++++++++++++++++- .../github/ui/gist/GistTaskEditorPage.java | 14 +- 2 files changed, 246 insertions(+), 6 deletions(-) diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java index 11b788209..661324ce0 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java @@ -11,28 +11,60 @@ package org.eclipse.mylyn.internal.github.ui.gist; import java.io.File; +import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; +import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.window.ToolTip; +import org.eclipse.mylyn.internal.provisional.commons.ui.CommonFormUtil; import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; +import org.eclipse.mylyn.internal.provisional.commons.ui.TableViewerSupport; +import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler; +import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentTableLabelProvider; import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil; import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttachmentPart; +import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus; import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; +import org.eclipse.mylyn.tasks.core.ITaskAttachment; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; /** * Gist editor attachment part. Modeled after {@link TaskEditorAttachmentPart} @@ -70,8 +102,47 @@ public GistAttachmentPart() { * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart#createControl(org.eclipse.swt.widgets.Composite, * org.eclipse.ui.forms.widgets.FormToolkit) */ - public void createControl(Composite parent, FormToolkit toolkit) { + public void createControl(Composite parent, final FormToolkit toolkit) { + initialize(); + final Section section = createSection(parent, toolkit, hasIncoming); + section.setText(getPartName() + " (" + attachments.size() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ + if (hasIncoming) + expandSection(toolkit, section); + else + section.addExpansionListener(new ExpansionAdapter() { + @Override + public void expansionStateChanged(ExpansionEvent event) { + if (attachmentsComposite == null) { + expandSection(toolkit, section); + getTaskEditorPage().reflow(); + } + } + }); + setSection(toolkit, section); + } + + private void expandSection(FormToolkit toolkit, Section section) { + attachmentsComposite = toolkit.createComposite(section); + attachmentsComposite.setLayout(EditorUtil.createSectionClientLayout()); + attachmentsComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + getTaskEditorPage().registerDefaultDropListener(section); + + if (attachments.size() > 0) + createAttachmentTable(toolkit, attachmentsComposite); + else { + Label label = toolkit + .createLabel( + attachmentsComposite, + org.eclipse.mylyn.internal.tasks.ui.editors.Messages.TaskEditorAttachmentPart_No_attachments); + getTaskEditorPage().registerDefaultDropListener(label); + } + + createButtons(attachmentsComposite, toolkit); + + toolkit.paintBordersFor(attachmentsComposite); + section.setClient(attachmentsComposite); } /** @@ -83,6 +154,89 @@ public void dispose() { super.dispose(); } + private void createAttachmentTable(FormToolkit toolkit, + final Composite attachmentsComposite) { + attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI + | SWT.FULL_SELECTION); + attachmentsTable.setLinesVisible(true); + attachmentsTable.setHeaderVisible(true); + attachmentsTable.setLayout(new GridLayout()); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL) + .grab(true, false).hint(500, SWT.DEFAULT) + .applyTo(attachmentsTable); + attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, + FormToolkit.TREE_BORDER); + + for (int i = 0; i < attachmentsColumns.length; i++) { + TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i); + column.setText(attachmentsColumns[i]); + column.setWidth(attachmentsColumnWidths[i]); + column.setMoveable(true); + if (i == 0) { + attachmentsTable.setSortColumn(column); + attachmentsTable.setSortDirection(SWT.DOWN); + } + } + // size column + attachmentsTable.getColumn(1).setAlignment(SWT.RIGHT); + + TableViewer attachmentsViewer = new TableViewer(attachmentsTable); + attachmentsViewer.setUseHashlookup(true); + attachmentsViewer.setColumnProperties(attachmentsColumns); + ColumnViewerToolTipSupport.enableFor(attachmentsViewer, + ToolTip.NO_RECREATE); + + attachmentsViewer.setSorter(new GistAttachmentSorter()); + + List attachmentList = new ArrayList( + attachments.size()); + for (TaskAttribute attribute : attachments) { + ITaskAttachment taskAttachment = new TaskAttachment(getModel() + .getTaskRepository(), getModel().getTask(), attribute); + getTaskData().getAttributeMapper().updateTaskAttachment( + taskAttachment, attribute); + attachmentList.add(taskAttachment); + } + attachmentsViewer.setContentProvider(new ArrayContentProvider()); + attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider( + getModel(), getTaskEditorPage().getAttributeEditorToolkit()) { + + public String getColumnText(Object element, int columnIndex) { + if (columnIndex > 0) + columnIndex++; + return super.getColumnText(element, columnIndex); + } + + public Image getColumnImage(Object element, int columnIndex) { + if (columnIndex > 0) + columnIndex++; + return super.getColumnImage(element, columnIndex); + } + + }); + attachmentsViewer.addOpenListener(new IOpenListener() { + public void open(OpenEvent event) { + openAttachments(event); + } + }); + attachmentsViewer.addSelectionChangedListener(getTaskEditorPage()); + attachmentsViewer.setInput(attachmentList.toArray()); + + menuManager = new MenuManager(); + menuManager.setRemoveAllWhenShown(true); + menuManager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + TasksUiMenus.fillTaskAttachmentMenu(manager); + } + }); + getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, + menuManager, attachmentsViewer, true); + Menu menu = menuManager.createContextMenu(attachmentsTable); + attachmentsTable.setMenu(menu); + + new TableViewerSupport(attachmentsViewer, getStateFile()); + } + private File getStateFile() { IPath stateLocation = Platform.getStateLocation(TasksUiPlugin .getDefault().getBundle()); @@ -114,18 +268,94 @@ public void widgetSelected(SelectionEvent e) { getTaskEditorPage().registerDefaultDropListener(attachFileButton); } + private void initialize() { + attachments = getTaskData().getAttributeMapper().getAttributesByType( + getTaskData(), TaskAttribute.TYPE_ATTACHMENT); + for (TaskAttribute attachmentAttribute : attachments) + if (getModel().hasIncomingChanges(attachmentAttribute)) { + hasIncoming = true; + break; + } + } + /** * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart#fillToolBar(org.eclipse.jface.action.ToolBarManager) */ protected void fillToolBar(ToolBarManager toolBarManager) { + Action attachFileAction = new Action() { + @Override + public void run() { + EditorUtil.openNewAttachmentWizard(getTaskEditorPage(), + Mode.DEFAULT, null); + } + }; + attachFileAction + .setToolTipText(org.eclipse.mylyn.internal.tasks.ui.editors.Messages.TaskEditorAttachmentPart_Attach_); + attachFileAction.setImageDescriptor(CommonImages.FILE_PLAIN_SMALL); + toolBarManager.add(attachFileAction); + } + protected void openAttachments(OpenEvent event) { + List attachments = new ArrayList(); + + StructuredSelection selection = (StructuredSelection) event + .getSelection(); + + List items = selection.toList(); + for (Object item : items) + if (item instanceof ITaskAttachment) + attachments.add((ITaskAttachment) item); + + if (attachments.isEmpty()) + return; + + IWorkbenchPage page = getTaskEditorPage().getSite() + .getWorkbenchWindow().getActivePage(); + try { + OpenTaskAttachmentHandler.openAttachments(page, attachments); + } catch (OperationCanceledException e) { + // canceled + } } - /** - * @see org.eclipse.ui.forms.AbstractFormPart#setFormInput(java.lang.Object) - */ + @Override public boolean setFormInput(Object input) { + if (input instanceof String) { + if (attachments != null) + for (TaskAttribute attachmentAttribute : attachments) { + if (input.equals(attachmentAttribute.getId())) { + CommonFormUtil.setExpanded( + (ExpandableComposite) getControl(), true); + return selectReveal(attachmentAttribute); + } + } + } return super.setFormInput(input); } + public boolean selectReveal(TaskAttribute attachmentAttribute) { + if (attachmentAttribute == null || attachmentsTable == null) + return false; + + TableItem[] attachments = attachmentsTable.getItems(); + int index = 0; + for (TableItem attachment : attachments) { + Object data = attachment.getData(); + if (data instanceof ITaskAttachment) { + ITaskAttachment attachmentData = ((ITaskAttachment) data); + if (attachmentData.getTaskAttribute().getValue() + .equals(attachmentAttribute.getValue())) { + attachmentsTable.deselectAll(); + attachmentsTable.select(index); + IManagedForm mform = getManagedForm(); + ScrolledForm form = mform.getForm(); + EditorUtil.focusOn(form, attachmentsTable); + return true; + } + } + index++; + } + return false; + } + } diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java index 53a03dc0a..42aef5e35 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java @@ -46,10 +46,11 @@ protected Set createPartDescriptors() { while (descriptorIt.hasNext()) { TaskEditorPartDescriptor partDescriptor = descriptorIt.next(); String id = partDescriptor.getId(); - if (id.equals(ID_PART_ATTRIBUTES) || id.equals(ID_PART_SUMMARY)) + if (id.equals(ID_PART_ATTRIBUTES) || id.equals(ID_PART_SUMMARY) + || id.equals(ID_PART_ATTACHMENTS)) descriptorIt.remove(); } - if (!getModel().getTaskData().isNew()) + if (!getModel().getTaskData().isNew()) { partDescriptors.add(new TaskEditorPartDescriptor(ID_PART_SUMMARY) { public AbstractTaskEditorPart createPart() { @@ -57,6 +58,15 @@ public AbstractTaskEditorPart createPart() { .getId(), null); } }.setPath(PATH_HEADER)); + partDescriptors.add(new TaskEditorPartDescriptor( + ID_PART_ATTACHMENTS) { + + public AbstractTaskEditorPart createPart() { + return new GistAttachmentPart(); + } + }.setPath(PATH_ATTACHMENTS)); + } + return partDescriptors; } } From 06efd7f9b306a4ed3b99057498faae21b12f1893 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Tue, 12 Apr 2011 22:05:09 +0200 Subject: [PATCH 094/642] Newer org.mockito bundle introduced into target platform Change-Id: I85be51e7c97e6f4563af6ff0380af66c5e68cb71 Signed-off-by: Christian Trutz Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github-feature/github.target | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.mylyn.github-feature/github.target b/org.eclipse.mylyn.github-feature/github.target index 9fbaaac70..1bed3bd64 100644 --- a/org.eclipse.mylyn.github-feature/github.target +++ b/org.eclipse.mylyn.github-feature/github.target @@ -1,7 +1,7 @@ - + @@ -12,8 +12,8 @@ - - + + From 2a0c5f8949b0493b77369e4fa9d1244519982333 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Tue, 12 Apr 2011 23:55:10 +0200 Subject: [PATCH 095/642] More unit tests for IssueService Change-Id: Id74b4433756fe103ac7f368b66c2887e15f0d132 Signed-off-by: Christian Trutz Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/IssueService.java | 17 ++-- .../META-INF/MANIFEST.MF | 1 + .../github/internal/IssueServiceTest.java | 81 ++++++++++++++++++- 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java index 6254a5736..5c36136b6 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java @@ -55,22 +55,22 @@ public class IssueService { /** * Issue open state filter value */ - public static final String STATE_OPEN = "open"; + public static final String STATE_OPEN = "open"; //$NON-NLS-1$ /** * Issue closed state filter value */ - public static final String STATE_CLOSED = "closed"; + public static final String STATE_CLOSED = "closed"; //$NON-NLS-1$ /** * Issue body field name */ - public static final String FIELD_BODY = "body"; + public static final String FIELD_BODY = "body"; //$NON-NLS-1$ /** * Issue title field name */ - public static final String FIELD_TITLE = "title"; + public static final String FIELD_TITLE = "title"; //$NON-NLS-1$ private GitHubClient client; @@ -118,6 +118,9 @@ public Issue getIssue(String user, String repository, String id) */ public List getComments(String user, String repository, String id) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(id, "Id cannot be null"); //$NON-NLS-1$ StringBuilder builder = new StringBuilder( IGitHubConstants.SEGMENT_REPOS); builder.append('/').append(user).append('/').append(repository); @@ -141,6 +144,8 @@ public List getComments(String user, String repository, String id) */ public List getIssues(String user, String repository, Map filterData) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ StringBuilder builder = new StringBuilder( IGitHubConstants.SEGMENT_REPOS); builder.append('/').append(user).append('/').append(repository); @@ -188,12 +193,14 @@ protected Map createIssueMap(Issue issue) { */ public Issue createIssue(String user, String repository, Issue issue) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS); uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES).append( IGitHubConstants.SUFFIX_JSON); - Map params = createIssueMap(issue); + Map params = issue != null ? createIssueMap(issue) : null; return this.client.post(uri.toString(), params, Issue.class); } diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index b30a22649..edc0d0524 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -14,5 +14,6 @@ Require-Bundle: org.junit4;bundle-version="4.5.0", org.eclipse.core.runtime;bundle-version="3.5.0" Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", + com.google.gson.reflect;version="1.6.0", org.mockito;version="1.8.4", org.mockito.runners;version="1.8.4" diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java index 2e76bd4ec..3d765ee21 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.mylyn.github.internal; +import static org.mockito.Mockito.verify; + import java.io.IOException; +import java.util.List; import org.eclipse.core.runtime.AssertionFailedException; import org.junit.Before; @@ -19,6 +22,8 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import com.google.gson.reflect.TypeToken; + /** * Unit tests for {@link IssueService} */ @@ -42,18 +47,88 @@ public void constructor_NullArgument() { } @Test(expected = AssertionFailedException.class) - public void getIssue_NullUser() throws IOException{ + public void getIssue_NullUser() throws IOException { issueService.getIssue(null, "not null", "not null"); } @Test(expected = AssertionFailedException.class) - public void getIssue_NullRepository() throws IOException{ + public void getIssue_NullRepository() throws IOException { issueService.getIssue("not null", null, "not null"); } @Test(expected = AssertionFailedException.class) - public void getIssue_NullId() throws IOException{ + public void getIssue_NullId() throws IOException { issueService.getIssue("not null", "not null", null); } + @Test + public void getIssue_OK() throws IOException { + issueService.getIssue("test_user", "test_repository", "test_id"); + verify(gitHubClient).get( + "/repos/test_user/test_repository/issues/test_id.json", + Issue.class); + } + + @Test(expected = AssertionFailedException.class) + public void getComments_NullUser() throws IOException { + issueService.getComments(null, "not null", "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void getComments_NullRepository() throws IOException { + issueService.getComments("not null", null, "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void getComments_NullId() throws IOException { + issueService.getComments("not null", "not null", null); + } + + @Test + public void getComments_OK() throws IOException { + issueService.getComments("test_user", "test_repository", "test_id"); + TypeToken> commentToken = new TypeToken>() { + }; + verify(gitHubClient) + .get("/repos/test_user/test_repository/issues/test_id/comments.json", + commentToken.getType()); + } + + @Test(expected = AssertionFailedException.class) + public void getIssues_NullUser() throws IOException { + issueService.getIssues(null, "not null", null); + } + + @Test(expected = AssertionFailedException.class) + public void getIssues_NullRepository() throws IOException { + issueService.getIssues("not null", null, null); + } + + @Test + public void getIssues_OK() throws IOException { + issueService.getIssues("test_user", "test_repository", null); + TypeToken> issuesToken = new TypeToken>() { + }; + verify(gitHubClient).get( + "/repos/test_user/test_repository/issues.json", null, + issuesToken.getType()); + } + + @Test(expected = AssertionFailedException.class) + public void createIssue_NullUser() throws IOException { + issueService.createIssue(null, "not null", null); + } + + @Test(expected = AssertionFailedException.class) + public void createIssue_NullRepository() throws IOException { + issueService.createIssue("not null", null, null); + } + + @Test + public void createIssue_NullIssue() throws IOException { + issueService.createIssue("test_user", "test_repository", null); + verify(gitHubClient).post( + "/repos/test_user/test_repository/issues.json", null, + Issue.class); + } } From 9a64661d2a7bd33c9150d8e3d1be35c459580435 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Fri, 15 Apr 2011 10:48:45 -0500 Subject: [PATCH 096/642] Add org.eclipse.mylyn.github.tests to the build Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github.core/pom.xml | 3 +- .../META-INF/MANIFEST.MF | 3 +- org.eclipse.mylyn.github.tests/pom.xml | 46 +++++++++++++++++++ pom.xml | 7 +-- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 org.eclipse.mylyn.github.tests/pom.xml diff --git a/org.eclipse.mylyn.github.core/pom.xml b/org.eclipse.mylyn.github.core/pom.xml index 12b22700b..9ae42d0a2 100644 --- a/org.eclipse.mylyn.github.core/pom.xml +++ b/org.eclipse.mylyn.github.core/pom.xml @@ -19,7 +19,8 @@ 4.0.0 - core + org.eclipse.mylyn.github.core eclipse-plugin Eclipse EGit Mylyn GitHub Core (Incubation) + 0.1.0-SNAPSHOT diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index edc0d0524..ad8e4248f 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.junit4;bundle-version="4.5.0", org.eclipse.mylyn.tasks.ui;bundle-version="3.2.0", org.eclipse.equinox.security;bundle-version="1.0.100", org.eclipse.mylyn.tasks.core, - org.eclipse.core.runtime;bundle-version="3.5.0" + org.eclipse.core.runtime;bundle-version="3.5.0", + org.hamcrest;bundle-version="1.1.0" Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", com.google.gson.reflect;version="1.6.0", diff --git a/org.eclipse.mylyn.github.tests/pom.xml b/org.eclipse.mylyn.github.tests/pom.xml new file mode 100644 index 000000000..5ce2941f6 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/pom.xml @@ -0,0 +1,46 @@ + + + + + 4.0.0 + + + org.eclipse.mylyn.github + github-parent + 0.1.0-SNAPSHOT + + + org.eclipse.mylyn.github.tests + eclipse-test-plugin + + Mylyn GitHub Test Plug-in (Incubation) + + + + + org.sonatype.tycho + maven-osgi-test-plugin + ${tycho-version} + + + + **/Test*.class + + false + false + org.eclipse.mylyn.github.tests + org.eclipse.mylyn.github.tests.AllHeadlessTests + + + + + diff --git a/pom.xml b/pom.xml index 65589a120..4be3bda02 100644 --- a/pom.xml +++ b/pom.xml @@ -40,21 +40,22 @@ 0.11.0 - helios + indigo http://download.eclipse.org/releases/${platform-version-name} - http://download.eclipse.org/tools/orbit/downloads/drops/S20110124210048/repository + http://download.eclipse.org/tools/orbit/downloads/drops/S20110304120314/repository org.eclipse.mylyn.github.core org.eclipse.mylyn.github.ui org.eclipse.mylyn.github-feature + org.eclipse.mylyn.github.tests org.eclipse.mylyn.github-site - helios + indigo p2 ${eclipse-site} From e3d366782907da89f931224481251c7ffb6d9b33 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Fri, 15 Apr 2011 21:45:04 +0200 Subject: [PATCH 097/642] Target platform upgraded to Mylyn 3.5 Change-Id: If6e0155559f58e262e9b0da1b170749889485d1e Signed-off-by: Christian Trutz --- org.eclipse.mylyn.github-feature/github.target | 17 ++++++++++------- .../META-INF/MANIFEST.MF | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/org.eclipse.mylyn.github-feature/github.target b/org.eclipse.mylyn.github-feature/github.target index 1bed3bd64..88231ac24 100644 --- a/org.eclipse.mylyn.github-feature/github.target +++ b/org.eclipse.mylyn.github-feature/github.target @@ -1,19 +1,22 @@ - + - - + + + + + - - + + - - + + diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index ad8e4248f..3b4f7f3d0 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Require-Bundle: org.junit4;bundle-version="4.5.0", org.eclipse.equinox.security;bundle-version="1.0.100", org.eclipse.mylyn.tasks.core, org.eclipse.core.runtime;bundle-version="3.5.0", - org.hamcrest;bundle-version="1.1.0" + org.hamcrest;bundle-version="1.1.0", + org.objenesis;bundle-version="1.0.0" Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", com.google.gson.reflect;version="1.6.0", From 74087e9a09cec9f91d2f50bc7031456a0225a37c Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Fri, 15 Apr 2011 22:46:46 +0200 Subject: [PATCH 098/642] Unit tests for IssueService#editIssue Change-Id: I080a8c4ad3cf70512bc0431e6e83a0dd04aa169a Signed-off-by: Christian Trutz --- .../mylyn/github/internal/IssueService.java | 43 +++++++++++-------- .../github/internal/IssueServiceTest.java | 37 +++++++++++++++- .../.settings/egit-github.launch | 4 +- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java index 5c36136b6..8ef124720 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java @@ -22,7 +22,7 @@ /** * Issue service class for listing, searching, and fetching {@link Issue} * objects using a {@link GitHubClient}. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class IssueService { @@ -76,7 +76,7 @@ public class IssueService { /** * Create issue service - * + * * @param client * cannot be null */ @@ -87,7 +87,7 @@ public IssueService(GitHubClient client) { /** * Get issue - * + * * @param user * @param repository * @param id @@ -109,7 +109,7 @@ public Issue getIssue(String user, String repository, String id) /** * Get an issue's comments - * + * * @param user * @param repository * @param id @@ -135,7 +135,7 @@ public List getComments(String user, String repository, String id) /** * Get a list of {@link Issue} objects that match the specified filter data - * + * * @param user * @param repository * @param filterData @@ -165,26 +165,28 @@ public List getIssues(String user, String repository, */ protected Map createIssueMap(Issue issue) { Map params = new HashMap(); - params.put(FIELD_BODY, issue.getBody()); - params.put(FIELD_TITLE, issue.getTitle()); - User assignee = issue.getAssignee(); - if (assignee != null) - params.put(FILTER_ASSIGNEE, assignee.getName()); + if (issue != null) { + params.put(FIELD_BODY, issue.getBody()); + params.put(FIELD_TITLE, issue.getTitle()); + User assignee = issue.getAssignee(); + if (assignee != null) + params.put(FILTER_ASSIGNEE, assignee.getName()); - Milestone milestone = issue.getMilestone(); - if (milestone != null) { - int number = milestone.getNumber(); - if (number > 0) - params.put(FILTER_MILESTONE, Integer.toString(number)); - else - params.put(FILTER_MILESTONE, ""); //$NON-NLS-1$ + Milestone milestone = issue.getMilestone(); + if (milestone != null) { + int number = milestone.getNumber(); + if (number > 0) + params.put(FILTER_MILESTONE, Integer.toString(number)); + else + params.put(FILTER_MILESTONE, ""); //$NON-NLS-1$ + } } return params; } /** * Create issue - * + * * @param user * @param repository * @param issue @@ -200,7 +202,7 @@ public Issue createIssue(String user, String repository, Issue issue) uri.append(IGitHubConstants.SEGMENT_ISSUES).append( IGitHubConstants.SUFFIX_JSON); - Map params = issue != null ? createIssueMap(issue) : null; + Map params = createIssueMap(issue); return this.client.post(uri.toString(), params, Issue.class); } @@ -215,6 +217,9 @@ public Issue createIssue(String user, String repository, Issue issue) */ public Issue editIssue(String user, String repository, Issue issue) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(issue, "Issue cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS); uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES); diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java index 3d765ee21..a61032166 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java @@ -13,7 +13,9 @@ import static org.mockito.Mockito.verify; import java.io.IOException; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.core.runtime.AssertionFailedException; import org.junit.Before; @@ -128,7 +130,40 @@ public void createIssue_NullRepository() throws IOException { public void createIssue_NullIssue() throws IOException { issueService.createIssue("test_user", "test_repository", null); verify(gitHubClient).post( - "/repos/test_user/test_repository/issues.json", null, + "/repos/test_user/test_repository/issues.json", + new HashMap(), Issue.class); + } + + @Test(expected = AssertionFailedException.class) + public void editIssue_NullUser() throws IOException { + issueService.editIssue(null, "not null", null); + } + + @Test(expected = AssertionFailedException.class) + public void editIssue_NullRepository() throws IOException { + issueService.editIssue("not null", null, null); + } + + @Test(expected = AssertionFailedException.class) + public void editIssue_NullIssue() throws IOException { + issueService.editIssue("not null", "not null", null); + } + + @Test + public void editIssue_OK() throws IOException { + Issue issue = new Issue(); + issue.setNumber(1); + issue.setTitle("test_title"); + issue.setBody("test_body"); + issue.setState("test_state"); + issueService.editIssue("test_user", "test_repository", issue); + + Map params = new HashMap(); + params.put(IssueService.FIELD_TITLE, "test_title"); + params.put(IssueService.FIELD_BODY, "test_body"); + params.put(IssueService.FILTER_STATE, "test_state"); + verify(gitHubClient).put( + "/repos/test_user/test_repository/issues/1.json", params, Issue.class); } } diff --git a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch index f26dbc812..e94fee4fb 100644 --- a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch +++ b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch @@ -12,7 +12,7 @@ - + @@ -49,7 +49,7 @@ - + From 5a1c8564877a0abf9480371f3b6fd9edbaac5e24 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Fri, 15 Apr 2011 23:03:44 +0200 Subject: [PATCH 099/642] Unit tests for IssueService#createComment Change-Id: If029714fe7d89e713228ab3516b8ec54e2e45cf9 Signed-off-by: Christian Trutz --- .../mylyn/github/internal/IssueService.java | 3 +++ .../github/internal/IssueServiceTest.java | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java index 8ef124720..c623c9fdb 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java @@ -246,6 +246,9 @@ public Issue editIssue(String user, String repository, Issue issue) */ public Comment createComment(String user, String repository, String issueId, String comment) throws IOException { + Assert.isNotNull(user, "User cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ + Assert.isNotNull(issueId, "Issue id cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS); uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES); diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java index a61032166..6afeed1f5 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueServiceTest.java @@ -166,4 +166,31 @@ public void editIssue_OK() throws IOException { "/repos/test_user/test_repository/issues/1.json", params, Issue.class); } + + @Test(expected = AssertionFailedException.class) + public void createComment_NullUser() throws IOException { + issueService.createComment(null, "not null", "not null", "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void createComment_NullRepository() throws IOException { + issueService.createComment("not null", null, "not null", "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void createComment_NullIssueId() throws IOException { + issueService.createComment("not null", "not null", null, "not null"); + } + + @Test + public void createComment_OK() throws IOException { + issueService.createComment("test_user", "test_repository", "1", + "test_comment"); + + Map params = new HashMap(); + params.put(IssueService.FIELD_BODY, "test_comment"); + verify(gitHubClient).post( + "/repos/test_user/test_repository/issues/1/comments.json", + params, Comment.class); + } } From 5c0caecc19c6d4ac8763d6115180a236555e7cec Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 15 Apr 2011 23:57:31 +0200 Subject: [PATCH 100/642] Add static checks to maven build In order to enable findbugs and CPD static checks enable the profile "static-checks": mvn -P static-checks clean install Change-Id: I06241207c4fc8f4ad7dd87c36de17fd896c77a6f Signed-off-by: Matthias Sohn --- pom.xml | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4be3bda02..e82ad4acd 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,7 @@ + codehaus.snapshots + http://snapshots.repository.codehaus.org/ + + + @@ -110,12 +121,47 @@ consider + + org.codehaus.mojo + findbugs-maven-plugin + 2.3.2-SNAPSHOT + + true + false + + + + + check + + + + + + org.apache.maven.plugins + maven-pmd-plugin + 2.5 + + utf-8 + 100 + 1.5 + xml + false + + + + + cpd-check + + + + src/ - + platform-helios @@ -142,5 +188,20 @@ [3.7,3.8) + + static-checks + + + + org.codehaus.mojo + findbugs-maven-plugin + + + org.apache.maven.plugins + maven-pmd-plugin + + + + From 71d3ea86a0e34b3da7ee3e0672d4bbc21b16f742 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 19 Apr 2011 14:17:04 -0700 Subject: [PATCH 101/642] Add response status value to request exception Change-Id: Ida4cb329426e51a2961123386de0d3faea31edfc Signed-off-by: Kevin Sawicki --- .../mylyn/github/internal/GitHubClient.java | 30 +++++++++---------- .../github/internal/RequestException.java | 21 ++++++++++--- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java index ffbe25b14..594f3739c 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java @@ -69,7 +69,7 @@ public GitHubClient() { /** * Create client for configuration - * + * * @param configuration */ public GitHubClient(HostConfiguration configuration) { @@ -78,7 +78,7 @@ public GitHubClient(HostConfiguration configuration) { /** * Create standard post method - * + * * @param uri * @return post */ @@ -102,7 +102,7 @@ protected PutMethod createPut(String uri) { /** * Set method defaults - * + * * @param method * @return method */ @@ -117,7 +117,7 @@ protected HttpMethod setMethodDefaults(HttpMethod method) { /** * Create get method - * + * * @param uri * @return get method */ @@ -130,7 +130,7 @@ protected GetMethod createGet(String uri) { /** * Set credentials - * + * * @param user * @param password */ @@ -144,7 +144,7 @@ public void setCredentials(String user, String password) { /** * Parse json to specified type - * + * * @param * @param method * @param type @@ -162,7 +162,7 @@ protected V parseJson(HttpMethodBase method, Type type) /** * Get name value pairs for data map. - * + * * @param data * @return name value pair array */ @@ -178,7 +178,7 @@ protected NameValuePair[] getPairs(Map data) { /** * Get response from uri and bind to specified type - * + * * @param * @param uri * @param type @@ -213,7 +213,7 @@ public InputStream getStream(String uri, Map params) case 404: case 500: RequestError error = parseJson(method, RequestError.class); - throw new RequestException(error); + throw new RequestException(error, status); default: throw new IOException(method.getStatusText()); } @@ -224,7 +224,7 @@ public InputStream getStream(String uri, Map params) /** * Get response from uri and bind to specified type - * + * * @param * @param uri * @param params @@ -247,7 +247,7 @@ public V get(String uri, Map params, Type type) case 404: case 500: RequestError error = parseJson(method, RequestError.class); - throw new RequestException(error); + throw new RequestException(error, status); default: throw new IOException(method.getStatusText()); } @@ -268,8 +268,8 @@ public V get(String uri, Map params, Type type) * @return resource * @throws IOException */ - protected V sendJson(EntityEnclosingMethod method, - Object params, Type type) throws IOException { + protected V sendJson(EntityEnclosingMethod method, Object params, + Type type) throws IOException { if (params != null) { StringBuilder payload = new StringBuilder(); this.gson.toJson(params, payload); @@ -291,7 +291,7 @@ protected V sendJson(EntityEnclosingMethod method, case 404: case 500: RequestError error = parseJson(method, RequestError.class); - throw new RequestException(error); + throw new RequestException(error, status); default: throw new IOException(method.getStatusText()); } @@ -303,7 +303,7 @@ protected V sendJson(EntityEnclosingMethod method, /** * Post data to uri - * + * * @param * @param uri * @param params diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java index add415655..e36122e3f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RequestException.java @@ -14,7 +14,7 @@ /** * Request exception class that wraps an {@link RequestError} object. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class RequestException extends IOException { @@ -25,23 +25,36 @@ public class RequestException extends IOException { private static final long serialVersionUID = 1197051396535284852L; private RequestError error; + private int status; /** * Create request exception - * + * * @param error + * @param status */ - public RequestException(RequestError error) { + public RequestException(RequestError error, int status) { super(error.getMessage()); + this.error = error; + this.status = status; } /** * Get error - * + * * @return error */ public RequestError getError() { return this.error; } + /** + * Get status + * + * @return status + */ + public int getStatus() { + return this.status; + } + } From 1a19ef58647087ce594a5040c78caf72458e204e Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Tue, 19 Apr 2011 23:42:42 +0200 Subject: [PATCH 102/642] Unit tests for LabelService Change-Id: I512313960dfbd4bdf6c8480c16d41ff5e8b5c511 Signed-off-by: Christian Trutz --- .../mylyn/github/internal/LabelService.java | 8 ++ .../github/internal/IssueServiceTest.java | 2 +- .../github/internal/LabelServiceTest.java | 132 ++++++++++++++++++ .../mylyn/github/tests/AllHeadlessTests.java | 6 +- 4 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/LabelServiceTest.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java index 9ce5d471a..6b243713d 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java @@ -45,6 +45,8 @@ public LabelService(GitHubClient client) { */ public List From c1f48ed5b7824fded23ade1431fd5bd9399e450e Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Thu, 28 Apr 2011 20:38:28 +0200 Subject: [PATCH 142/642] book.css added Change-Id: I12915acc7f0642e4158a76b8f4b0961da49dab76 Signed-off-by: Christian Trutz --- org.eclipse.mylyn.github.doc/help/book.css | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 org.eclipse.mylyn.github.doc/help/book.css diff --git a/org.eclipse.mylyn.github.doc/help/book.css b/org.eclipse.mylyn.github.doc/help/book.css new file mode 100755 index 000000000..c6b3f94ac --- /dev/null +++ b/org.eclipse.mylyn.github.doc/help/book.css @@ -0,0 +1,110 @@ +P.Code { + display: block; + text-align: left; + text-indent: 0.00pt; + margin-top: 0.000000pt; + margin-bottom: 0.000000pt; + margin-right: 0.000000pt; + margin-left: 15pt; + font-weight: normal; + font-style: normal; + color: #4444CC; + text-decoration: none; + vertical-align: baseline; + text-transform: none; + font-family: "Courier New", Courier, monospace; +} +H6.CaptionFigColumn { + display: block; + text-align: left; + text-indent: 0.000000pt; + margin-top: 3.000000pt; + margin-bottom: 11.000000pt; + margin-right: 0.000000pt; + margin-left: 0.000000pt; + font-size: 75%; + font-weight: bold; + font-style: Italic; + color: #000000; + text-decoration: none; + vertical-align: baseline; + text-transform: none; +} +P.Note { + display: block; + text-align: left; + text-indent: 0pt; + margin-top: 19.500000pt; + margin-bottom: 19.500000pt; + margin-right: 0.000000pt; + margin-left: 30pt; + font-size: 110%; + font-weight: normal; + font-style: Italic; + color: #000000; + text-decoration: none; + vertical-align: baseline; + text-transform: none; +} +EM.UILabel { + font-weight: Bold; + font-style: normal; + text-decoration: none; + vertical-align: baseline; + text-transform: none; +} +EM.CodeName { + font-weight: Bold; + font-style: normal; + text-decoration: none; + vertical-align: baseline; + text-transform: none; + font-family: "Courier New", Courier, monospace; +} +UL.NavList { + margin-left: 1.5em; + padding-left: 0px; + list-style-type: none; +} + +body, html { border: 0px } + + +/* following font face declarations need to be removed for DBCS */ + +body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt {font-family: Arial, Helvetica, sans-serif; color: #000000} +pre, code { font-family: "Courier New", Courier, monospace;} + +/* end font face declarations */ + +@media print { + html { font-size: 12pt } +} + +body { font-size: 83%; background: #FFFFFF; margin-bottom: 1em } +h1 { font-size: 180%; margin-top: 5px; margin-bottom: 1px } +h2 { font-size: 140%; margin-top: 25px; margin-bottom: 3px } +h3 { font-size: 110%; margin-top: 20px; margin-bottom: 3px } +h4 { font-size: 100%; margin-top: 20px; margin-bottom: 3px; font-style: italic } +p { margin-top: 10px; margin-bottom: 10px } +pre { font-size: 93%; margin-left: 6; color: #4444CC } +code { font-size: 93%; } +table { font-size: 100% } /* needed for quirks mode */ +a:link { color: #0000FF } +a:hover { color: #000080 } +a:visited { text-decoration: underline } +ul { margin-top: 10px; margin-bottom: 10px; } +li { margin-top: 5px; margin-bottom: 5px; } +li p { margin-top: 5px; margin-bottom: 5px; } +ol { margin-top: 10px; margin-bottom: 10px; } +dl { margin-top: 10px; margin-bottom: 10px; } +dt { margin-top: 5px; margin-bottom: 5px; font-weight: bold; } +dd { margin-top: 5px; margin-bottom: 5px; } +strong { font-weight: bold} +em { font-style: italic} +var { font-style: italic} +div.revision { + border-left-style: solid; border-left-width: thin; + border-left-color: #7B68EE; padding-left:5 +} +th { font-weight: bold } From 0643f069a0a91db136a01b3e1c2826c3edfd5a2d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 29 Apr 2011 10:19:31 -0700 Subject: [PATCH 143/642] Add support for Gist updated at field. This date field is now present in the JSON API response and can be used in the GistConnector to compute if a Gist has changed. Change-Id: Iae28cd8cb315a481f9ae845500e3bb766aec119e Signed-off-by: Kevin Sawicki --- .../org/eclipse/mylyn/github/internal/Gist.java | 9 +++++++++ .../github/core/gist/GistAttribute.java | 7 +++++++ .../github/core/gist/GistConnector.java | 17 ++++++++++++++++- .../github/core/gist/GistTaskDataHandler.java | 3 +++ .../internal/github/core/gist/Messages.java | 3 +++ .../github/core/gist/messages.properties | 1 + 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java index e84e7a49b..2707be5a1 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java @@ -25,6 +25,8 @@ public class Gist { private boolean isPublic; private Date createdAt; + + private Date updatedAt; private int comments; @@ -152,6 +154,13 @@ public Gist setId(String id) { return this; } + /** + * @return updatedAt + */ + public Date getUpdatedAt() { + return this.updatedAt; + } + /** * @return url */ diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttribute.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttribute.java index ef8608d9e..75c7d5c9a 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttribute.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttribute.java @@ -44,6 +44,13 @@ public enum GistAttribute { CREATED(TaskAttribute.DATE_CREATION, Messages.GistAttribute_LabelCreated, TaskAttribute.TYPE_DATETIME, true), + /** + * Gist updated date + */ + UPDATED(TaskAttribute.DATE_MODIFICATION, + Messages.GistAttribute_LabelModified, TaskAttribute.TYPE_DATETIME, + true), + /** * Comment being added to gist */ 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 index 93e10fdd0..fa7b74a89 100644 --- 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 @@ -11,6 +11,7 @@ package org.eclipse.mylyn.internal.github.core.gist; import java.io.IOException; +import java.util.Date; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -28,6 +29,7 @@ import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler; import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; @@ -163,7 +165,20 @@ public String getTaskUrl(String repositoryUrl, String taskId) { */ public boolean hasTaskChanged(TaskRepository taskRepository, ITask task, TaskData taskData) { - return false; + TaskAttribute modAttribute = taskData.getRoot().getAttribute( + TaskAttribute.DATE_MODIFICATION); + if (modAttribute == null) + return false; + + boolean changed = true; + Date modDate = task.getModificationDate(); + if (modDate != null) { + Date updateDate = taskData.getAttributeMapper().getDateValue( + modAttribute); + if (updateDate != null) + changed = updateDate.after(modDate); + } + return changed; } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index 420e7d946..b1d7cd19d 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -117,6 +117,9 @@ public TaskData fillTaskData(TaskRepository repository, TaskData data, TaskAttribute created = GistAttribute.CREATED.create(data); mapper.setDateValue(created, gist.getCreatedAt()); + TaskAttribute updated = GistAttribute.UPDATED.create(data); + mapper.setDateValue(updated, gist.getUpdatedAt()); + TaskAttribute url = GistAttribute.URL.create(data); url.setValue(gist.getHtmlUrl()); 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 ce3fc9b0e..50c4e3db9 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 @@ -40,6 +40,9 @@ public class Messages extends NLS { /** */ public static String GistAttribute_LabelKey; + /** */ + public static String GistAttribute_LabelModified; + /** */ public static String GistAttribute_LabelNewComment; 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 8410c1cf9..aa9f10a5e 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 @@ -5,6 +5,7 @@ GistAttribute_LabelCreated=Created: GistAttribute_LabelDescription=Description: GistAttribute_LabelFileUrl=File url GistAttribute_LabelKey=Key +GistAttribute_LabelModified=Modified: GistAttribute_LabelNewComment=New Comment GistAttribute_LabelSummary=Summary GistAttribute_LabelUrl=Url From 6689d9bb91121b00bfdb35032d65d66e5a24a554 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 25 Apr 2011 17:01:13 -0700 Subject: [PATCH 144/642] Set per_page query param to 100 for all requests The default number of results is currently 30 if unspecified. Change-Id: I244ea4d3a784da70d578195033dd2686a3f7593a Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/GitHubClient.java | 24 ++++++++++++------- .../github/internal/IGitHubConstants.java | 5 ++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java index 32d3cbb21..57ccf4961 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java @@ -44,6 +44,9 @@ */ public class GitHubClient { + private static final NameValuePair PER_PAGE_PARAM = new NameValuePair( + IGitHubConstants.PARAM_PER_PAGE, Integer.toString(100)); + private static final AuthScope ANY_SCOPE = new AuthScope( AuthScope.ANY_HOST, AuthScope.ANY_PORT); @@ -167,12 +170,17 @@ protected V parseJson(HttpMethodBase method, Type type) * @return name value pair array */ protected NameValuePair[] getPairs(Map data) { - NameValuePair[] pairs = new NameValuePair[data.size()]; + if (data == null || data.isEmpty()) + return new NameValuePair[] { PER_PAGE_PARAM }; + + int size = data.containsKey(IGitHubConstants.PARAM_PER_PAGE) ? data + .size() : data.size() + 1; + NameValuePair[] pairs = new NameValuePair[size]; int i = 0; - for (Entry entry : data.entrySet()) { - pairs[i] = new NameValuePair(entry.getKey(), entry.getValue()); - i++; - } + for (Entry entry : data.entrySet()) + pairs[i++] = new NameValuePair(entry.getKey(), entry.getValue()); + if (i < size) + pairs[i] = PER_PAGE_PARAM; return pairs; } @@ -201,8 +209,7 @@ public V get(String uri, Type type) throws IOException { public InputStream getStream(String uri, Map params) throws IOException { GetMethod method = createGet(uri); - if (params != null && !params.isEmpty()) - method.setQueryString(getPairs(params)); + method.setQueryString(getPairs(params)); try { int status = this.client.executeMethod(this.hostConfig, method); @@ -237,8 +244,7 @@ public InputStream getStream(String uri, Map params) public V get(String uri, Map params, Type type) throws IOException { GetMethod method = createGet(uri); - if (params != null && !params.isEmpty()) - method.setQueryString(getPairs(params)); + method.setQueryString(getPairs(params)); try { int status = this.client.executeMethod(this.hostConfig, method); diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java index e61961b64..62a1a7a1f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java @@ -120,4 +120,9 @@ public interface IGitHubConstants { */ String CHARSET_UTF8 = "UTF-8"; //$NON-NLS-1$ + /** + * PARAM_PER_PAGE + */ + String PARAM_PER_PAGE = "per_page"; //$NON-NLS-1$ + } From 6180fab51874473a6dc4f423f1d278d528dd5978 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 2 May 2011 16:32:28 -0700 Subject: [PATCH 145/642] Add request class and interfaces for pagination support These classes will be used to support task queries that span multiple pages. Change-Id: I8c5421d6983d0c732f9e218cb7f8769525acd60d Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/GitHubRequest.java | 101 ++++++++++++++++++ .../github/internal/IGitHubConstants.java | 45 ++++++++ .../github/internal/IResourceCollector.java | 31 ++++++ .../internal/ListResourceCollector.java | 53 +++++++++ 4 files changed, 230 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRequest.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceCollector.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/ListResourceCollector.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRequest.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRequest.java new file mode 100644 index 000000000..bd62411c6 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRequest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * 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.github.internal; + +import java.lang.reflect.Type; +import java.util.Map; + +/** + * GitHub API request class. + */ +public class GitHubRequest { + + private String uri; + + private Map params; + + private Type type; + + private int page = 1; + + /** + * @return uri + */ + public String getUri() { + return this.uri; + } + + /** + * @param uri + * @return this request + */ + public GitHubRequest setUri(StringBuilder uri) { + return setUri(uri != null ? uri.toString() : null); + } + + /** + * @param uri + * @return this request + */ + public GitHubRequest setUri(String uri) { + this.uri = uri; + return this; + } + + /** + * @return params + */ + public Map getParams() { + return this.params; + } + + /** + * @param params + * @return this request + */ + public GitHubRequest setParams(Map params) { + this.params = params; + return this; + } + + /** + * @return type + */ + public Type getType() { + return this.type; + } + + /** + * @param type + * @return this request + */ + public GitHubRequest setType(Type type) { + this.type = type; + return this; + } + + /** + * @return page + */ + public int getPage() { + return this.page; + } + + /** + * @param page + * @return this request + */ + public GitHubRequest setPage(int page) { + this.page = page; + return this; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java index 62a1a7a1f..99cc89ecb 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java @@ -125,4 +125,49 @@ public interface IGitHubConstants { */ String PARAM_PER_PAGE = "per_page"; //$NON-NLS-1$ + /** + * PARAM_PAGE + */ + String PARAM_PAGE = "page"; //$NON-NLS-1$ + + /** + * HEADER_LINK + */ + String HEADER_LINK = "Link"; //$NON-NLS-1$ + + /** + * HEADER_NEXT + */ + String HEADER_NEXT = "X-Next"; //$NON-NLS-1$ + + /** + * HEADER_LAST + */ + String HEADER_LAST = "X-Last"; //$NON-NLS-1$ + + /** + * META_REL + */ + String META_REL = "rel"; //$NON-NLS-1$ + + /** + * META_LAST + */ + String META_LAST = "last"; //$NON-NLS-1$ + + /** + * META_NEXT + */ + String META_NEXT = "next"; //$NON-NLS-1$ + + /** + * META_FIRST + */ + String META_FIRST = "first"; //$NON-NLS-1$ + + /** + * META_PREV + */ + String META_PREV = "prev"; //$NON-NLS-1$ + } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceCollector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceCollector.java new file mode 100644 index 000000000..57028d59b --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceCollector.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.Collection; + +/** + * Interface for accepting collections of resources page by page. + * + * @param + */ +public interface IResourceCollector { + + /** + * Accept page response. + * + * @param page + * @param response + * @return true to continue collecting, false to abort + */ + boolean accept(int page, Collection response); + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/ListResourceCollector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/ListResourceCollector.java new file mode 100644 index 000000000..1772f95ba --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/ListResourceCollector.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +/** + * {@link LinkedList} based resource collector + * + * @param + */ +public class ListResourceCollector implements IResourceCollector { + + private List resources = new LinkedList(); + + /** + * Clear resources from collector + * + * @return this collector + */ + public ListResourceCollector clear() { + this.resources.clear(); + return this; + } + + /** + * Get resources + * + * @return collection of resources + */ + public List getResources() { + return this.resources; + } + + /** + * @see org.eclipse.mylyn.github.internal.IResourceCollector#accept(int, + * java.util.Collection) + */ + public boolean accept(int page, Collection resources) { + return this.resources.addAll(resources); + } + +} From f6a43aac89499faa78a2c30fb2d0415dc37b800a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 2 May 2011 16:40:50 -0700 Subject: [PATCH 146/642] Add response class and link header support Responses that contain paginated results contain a Link header to request uris relative to the current response. Change-Id: I372bb065b6fa2937c0039491851a03547f7a0b90 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/GitHubResponse.java | 80 +++++++++++++ .../mylyn/github/internal/PageLinks.java | 112 ++++++++++++++++++ .../mylyn/github/internal/PagedRequest.java | 42 +++++++ 3 files changed, 234 insertions(+) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubResponse.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PageLinks.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PagedRequest.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubResponse.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubResponse.java new file mode 100644 index 000000000..e10d39aff --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubResponse.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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.github.internal; + +import org.apache.commons.httpclient.HttpMethod; + +/** + * GitHub API response class. + */ +public class GitHubResponse { + + private PageLinks links; + + private Object body; + + /** + * Create response + * + * @param method + * @param body + */ + public GitHubResponse(HttpMethod method, Object body) { + links = new PageLinks(method); + this.body = body; + } + + /** + * Get link uri to first page + * + * @return possibly null uri + */ + public String getFirst() { + return this.links.getFirst(); + } + + /** + * Get link uri to previous page + * + * @return possibly null uri + */ + public String getPrevious() { + return this.links.getPrev(); + } + + /** + * Get link uri to next page + * + * @return possibly null uri + */ + public String getNext() { + return this.links.getNext(); + } + + /** + * Get link uri to last page + * + * @return possibly null uri + */ + public String getLast() { + return this.links.getLast(); + } + + /** + * Parsed response body + * + * @return body + */ + public Object getBody() { + return this.body; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PageLinks.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PageLinks.java new file mode 100644 index 000000000..0d5a030aa --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PageLinks.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * 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.github.internal; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpMethod; + +/** + * Page link class to be used to determine the links to other pages of request + * responses encoded in the current response. These will be present if the + * result set size exceeds the per page limit. + */ +public class PageLinks { + + private static final String DELIM_LINKS = ","; //$NON-NLS-1$ + + private static final String DELIM_LINK_PARAM = ";"; //$NON-NLS-1;$ + + private String first; + private String last; + private String next; + private String prev; + + /** + * Parse links from executed method + * + * @param method + */ + public PageLinks(HttpMethod method) { + Header[] linkHeaders = method + .getResponseHeaders(IGitHubConstants.HEADER_LINK); + if (linkHeaders.length > 0) { + String[] links = linkHeaders[0].getValue().split(DELIM_LINKS); + for (String link : links) { + String[] segments = link.split(DELIM_LINK_PARAM); + if (segments.length < 2) + continue; + + String linkPart = segments[0].trim(); + if (!linkPart.startsWith("<") || !linkPart.endsWith(">")) //$NON-NLS-1$ //$NON-NLS-2$ + continue; + linkPart = linkPart.substring(1, linkPart.length() - 1); + + for (int i = 1; i < segments.length; i++) { + String[] rel = segments[i].trim().split("="); //$NON-NLS-1$ + if (rel.length < 2 + || !IGitHubConstants.META_REL.equals(rel[0])) + continue; + + String relValue = rel[1]; + if (relValue.startsWith("\"") && relValue.endsWith("\"")) //$NON-NLS-1$ //$NON-NLS-2$ + relValue = relValue.substring(1, relValue.length() - 1); + + if (IGitHubConstants.META_FIRST.equals(relValue)) + first = linkPart; + else if (IGitHubConstants.META_LAST.equals(relValue)) + last = linkPart; + else if (IGitHubConstants.META_NEXT.equals(relValue)) + next = linkPart; + else if (IGitHubConstants.META_PREV.equals(relValue)) + prev = linkPart; + } + } + } else { + Header[] nextHeaders = method + .getResponseHeaders(IGitHubConstants.HEADER_NEXT); + if (nextHeaders.length > 0) + next = nextHeaders[0].getValue(); + + Header[] lastHeaders = method + .getResponseHeaders(IGitHubConstants.HEADER_LAST); + if (lastHeaders.length > 0) + last = lastHeaders[0].getValue(); + } + } + + /** + * @return first + */ + public String getFirst() { + return this.first; + } + + /** + * @return last + */ + public String getLast() { + return this.last; + } + + /** + * @return next + */ + public String getNext() { + return this.next; + } + + /** + * @return prev + */ + public String getPrev() { + return this.prev; + } +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PagedRequest.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PagedRequest.java new file mode 100644 index 000000000..b61f0e076 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PagedRequest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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.github.internal; + +import org.eclipse.core.runtime.Assert; + +/** + * Pages request class that contains a collector for accept resources page by + * page. + * + * @param + */ +public class PagedRequest extends GitHubRequest { + + private IResourceCollector collector; + + /** + * Create paged request with non-null collector + * + * @param collector + */ + public PagedRequest(IResourceCollector collector) { + Assert.isNotNull(collector, "Collecto cannot be null"); //$NON-NLS-1$ + this.collector = collector; + } + + /** + * @return collector + */ + public IResourceCollector getCollector() { + return this.collector; + } + +} From e1551203823beb3e8cc7e2ef135a518dcf8bda03 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 2 May 2011 17:02:15 -0700 Subject: [PATCH 147/642] Add resource provider interface for v2 api calls Change-Id: I21983d7cf05d263a705b1c7e1538ea72e7bb3289 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../github/internal/IResourceProvider.java | 30 +++++++++++++++++++ .../github/internal/RepositoryContainer.java | 8 ++--- .../github/internal/RepositoryService.java | 4 +-- 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceProvider.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceProvider.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceProvider.java new file mode 100644 index 000000000..37d15b37e --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceProvider.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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.github.internal; + +import java.util.List; + +/** + * Interface for container classes that can provide a collection of resources of + * the same type. + * + * @param + */ +public interface IResourceProvider { + + /** + * Get collection of resources + * + * @return non-null but possibly empty collection + */ + List getResources(); + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryContainer.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryContainer.java index aa0b1e997..df3b0750a 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryContainer.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryContainer.java @@ -17,16 +17,14 @@ * * @author Kevin Sawicki (kevin@github.com) */ -public class RepositoryContainer { +public class RepositoryContainer implements IResourceProvider { private List repositories; /** - * Get repositories - * - * @return list of repositories + * @see org.eclipse.mylyn.github.internal.IResourceProvider#getResources() */ - public List getRepositories() { + public List getResources() { return this.repositories; } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java index be8a5a306..4d24de166 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java @@ -49,7 +49,7 @@ public List getOrganizationRepositories() throws IOException { RepositoryContainer container = client.get(uri.toString(), RepositoryContainer.class); - return container.getRepositories(); + return container.getResources(); } /** @@ -66,6 +66,6 @@ public List getRepositories(String user) throws IOException { RepositoryContainer container = client.get(uri.toString(), RepositoryContainer.class); - return container.getRepositories(); + return container.getResources(); } } From fbc0628fe40135927c0c5c397918654211614cda Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 3 May 2011 09:05:53 -0700 Subject: [PATCH 148/642] Update dependencies to feature xml and manifest. Change-Id: Ia661fc24fbe2d8147f4784c6502e12a38b0b13f2 Signed-off-by: Kevin Sawicki --- org.eclipse.mylyn.github-feature/feature.xml | 6 +++++- org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/org.eclipse.mylyn.github-feature/feature.xml b/org.eclipse.mylyn.github-feature/feature.xml index 37331401b..091b29406 100644 --- a/org.eclipse.mylyn.github-feature/feature.xml +++ b/org.eclipse.mylyn.github-feature/feature.xml @@ -19,10 +19,14 @@ + - + + + + Date: Fri, 29 Apr 2011 20:06:40 +0200 Subject: [PATCH 149/642] Unit tests for PullRequestService Change-Id: Idca802fadabb7489e13250361c48a57dfb8003d6 Signed-off-by: Christian Trutz Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/GitHubClient.java | 12 ++-- .../github/internal/PullRequestService.java | 4 +- .../META-INF/MANIFEST.MF | 4 +- .../github/internal/GitHubClientTest.java | 27 +++++++ .../internal/PullRequestServiceTest.java | 70 +++++++++++++++++++ .../mylyn/github/tests/AllHeadlessTests.java | 8 ++- 6 files changed, 115 insertions(+), 10 deletions(-) create mode 100755 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GitHubClientTest.java create mode 100755 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java index 57ccf4961..8507280df 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java @@ -10,11 +10,6 @@ *******************************************************************************/ package org.eclipse.mylyn.github.internal; -import com.google.gson.FieldNamingPolicy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; - import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -38,6 +33,12 @@ import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.protocol.Protocol; +import org.eclipse.core.runtime.Assert; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; /** * Client class for interacting with GitHub HTTP/JSON API. @@ -76,6 +77,7 @@ public GitHubClient() { * @param configuration */ public GitHubClient(HostConfiguration configuration) { + Assert.isNotNull(configuration, "Configuration cannot be null"); //$NON-NLS-1$ this.hostConfig = configuration; } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java index c22219f38..37622ada9 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java @@ -71,9 +71,11 @@ public PullRequest getPullRequest(Repository repository, String id) throws IOException { Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ Assert.isNotNull(id, "Id cannot be null"); //$NON-NLS-1$ + String repositoryId = repository.getId(); + Assert.isNotNull(repositoryId, "Repository id cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_V2_API); uri.append(IGitHubConstants.SEGMENT_PULLS); - uri.append('/').append(repository.getId()); + uri.append('/').append(repositoryId); uri.append('/').append(id); PullRequestWrapper wrapper = this.client.get(uri.toString(), PullRequestWrapper.class); diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index 5f1f7e71e..16d752dc3 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -17,5 +17,7 @@ Require-Bundle: org.eclipse.mylyn.github.core;bundle-version="0.1.0", Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", com.google.gson.reflect;version="1.6.0", + org.apache.commons.httpclient;version="3.1.0", org.mockito;version="1.8.4", - org.mockito.runners;version="1.8.4" + org.mockito.runners;version="1.8.4", + org.mockito.stubbing;version="1.8.4" diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GitHubClientTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GitHubClientTest.java new file mode 100755 index 000000000..088adb9f2 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GitHubClientTest.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import org.eclipse.core.runtime.AssertionFailedException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class GitHubClientTest { + + @Test(expected = AssertionFailedException.class) + public void constructor_NullArgument() { + new GitHubClient(null); + } + +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java new file mode 100755 index 000000000..2b0b78c37 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import static org.mockito.Mockito.when; + +import java.io.IOException; + +import org.eclipse.core.runtime.AssertionFailedException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +/** + * Tests for {@link PullRequestServiceTest} + */ +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class PullRequestServiceTest { + + @Mock + private GitHubClient gitHubClient; + + @Mock + private Repository repository; + + private PullRequestService pullRequestService; + + @Before + public void before() { + pullRequestService = new PullRequestService(gitHubClient); + } + + @Test(expected = AssertionFailedException.class) + public void constructor_NullArgument() { + new PullRequestService(null); + } + + @Test(expected = AssertionFailedException.class) + public void getPullRequest_NullRepository() throws IOException { + pullRequestService.getPullRequest(null, "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void getPullRequest_NullId() throws IOException { + pullRequestService.getPullRequest(repository, null); + } + + @Test(expected = AssertionFailedException.class) + public void getPullRequest_NullRepositoryId() throws IOException { + when(repository.getId()).thenReturn(null); + pullRequestService.getPullRequest(repository, "test_id"); + } + + @Test + public void getPullRequest_OK() throws IOException { + // the OK unit test is not possible with Mockito, but with JMOckit + } + +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java index c20c5eac9..cf4c4e936 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java @@ -13,17 +13,19 @@ package org.eclipse.mylyn.github.tests; import org.eclipse.mylyn.github.internal.GistServiceTest; +import org.eclipse.mylyn.github.internal.GitHubClientTest; import org.eclipse.mylyn.github.internal.IssueServiceTest; import org.eclipse.mylyn.github.internal.LabelServiceTest; import org.eclipse.mylyn.github.internal.MilestoneServiceTest; +import org.eclipse.mylyn.github.internal.PullRequestServiceTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ // -IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class, - GistServiceTest.class }) +@SuiteClasses({ GitHubClientTest.class, IssueServiceTest.class, + LabelServiceTest.class, MilestoneServiceTest.class, + GistServiceTest.class, PullRequestServiceTest.class }) public class AllHeadlessTests { } From 039ce32da4ca76c9138ec879f52c9649507a6d4e Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Thu, 5 May 2011 22:54:05 +0200 Subject: [PATCH 150/642] PullRequestService unit tests completed. Change-Id: I2668a1d4249b7e31af38647a51d9860576dbe928 Signed-off-by: Christian Trutz --- .../github/internal/PullRequestService.java | 4 ++- .../internal/PullRequestServiceTest.java | 25 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java index 37622ada9..496a21f66 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java @@ -94,9 +94,11 @@ public List getPullRequests(Repository repository, String state) throws IOException { Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ Assert.isNotNull(state, "State cannot be null"); //$NON-NLS-1$ + String repositoryId = repository.getId(); + Assert.isNotNull(repositoryId, "Repository id cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_V2_API); uri.append(IGitHubConstants.SEGMENT_PULLS); - uri.append('/').append(repository.getId()); + uri.append('/').append(repositoryId); uri.append('/').append(state); PullRequestsWrapper wrapper = this.client.get(uri.toString(), PullRequestsWrapper.class); diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java index 2b0b78c37..512c0804f 100755 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/PullRequestServiceTest.java @@ -16,6 +16,7 @@ import org.eclipse.core.runtime.AssertionFailedException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -63,8 +64,30 @@ public void getPullRequest_NullRepositoryId() throws IOException { } @Test + @Ignore public void getPullRequest_OK() throws IOException { - // the OK unit test is not possible with Mockito, but with JMOckit + // the OK unit test is not possible with Mockito, but with JMockit } + @Test(expected = AssertionFailedException.class) + public void getPullRequests_NullRepository() throws IOException { + pullRequestService.getPullRequests(null, "not null"); + } + + @Test(expected = AssertionFailedException.class) + public void getPullRequests_NullState() throws IOException { + pullRequestService.getPullRequests(repository, null); + } + + @Test(expected = AssertionFailedException.class) + public void getPullRequests_NullRepositoryId() throws IOException { + when(repository.getId()).thenReturn(null); + pullRequestService.getPullRequests(repository, "test_state"); + } + + @Test + @Ignore + public void getPullRequests_OK() throws IOException { + // the OK unit test is not possible with Mockito, but with JMockit + } } From e27e1f65f4145d0340815294907af3bfd45a0e3a Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Thu, 5 May 2011 14:40:11 -0500 Subject: [PATCH 151/642] Use egit repository as a dependency Change-Id: I7d977e191606d213efd572cc1689393eacf1a9f6 Signed-off-by: Chris Aniszczyk --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index a5cbc0c83..ae830639d 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,7 @@ 0.11.0 + file:/${basedir}/../../egit/org.eclipse.egit-updatesite/target/site indigo http://download.eclipse.org/tools/mylyn/update/weekly http://download.eclipse.org/releases/${platform-version-name} @@ -57,6 +58,11 @@ + + egit + p2 + ${egit-site} + indigo p2 From 513669caf8449908e845159eb8623177da0aec4f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Apr 2011 15:27:29 -0700 Subject: [PATCH 152/642] Add clone gist handler messages and dependencies Change-Id: I3249fe3bc7ba4d3e6f26fe7ea2454ec2f4475e4f Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../META-INF/MANIFEST.MF | 6 +++++- .../internal/github/ui/gist/Messages.java | 21 +++++++++++++++++++ .../github/ui/gist/messages.properties | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF index 446427b16..c69b4a55a 100644 --- a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF @@ -17,6 +17,10 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.mylyn.tasks.core, org.eclipse.ui.ide;bundle-version="3.5.0", org.eclipse.mylyn.commons.ui;bundle-version="3.4.0", - org.eclipse.core.resources;bundle-version="3.5.0" + org.eclipse.core.resources;bundle-version="3.5.0", + org.eclipse.egit.core;bundle-version="0.12.0", + org.eclipse.jgit;bundle-version="0.12.0", + org.eclipse.egit.ui;bundle-version="0.12.0", + org.eclipse.core.expressions;bundle-version="3.4.0" Export-Package: org.eclipse.mylyn.github.ui.internal;x-internal:=true Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java index 50e71924f..f7cb88aa3 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java @@ -19,6 +19,27 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.github.ui.gist.messages"; //$NON-NLS-1$ + /** */ + public static String CloneGistHandler_ErrorMessage; + + /** */ + public static String CloneGistHandler_ErrorRepoExists; + + /** */ + public static String CloneGistHandler_ErrorTitle; + + /** */ + public static String CloneGistHandler_TaskCloning; + + /** */ + public static String CloneGistHandler_TaskConnectingProject; + + /** */ + public static String CloneGistHandler_TaskCreatingProject; + + /** */ + public static String CloneGistHandler_TaskRegisteringRepository; + /** */ public static String GistAttachmentPage_Description; diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties index 543399f85..339bb8a23 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties @@ -1,3 +1,10 @@ +CloneGistHandler_ErrorMessage=Cloning Gist failed. +CloneGistHandler_ErrorRepoExists=Repository {0} already exists +CloneGistHandler_ErrorTitle=Clone Gist Error +CloneGistHandler_TaskCloning=Cloning gist +CloneGistHandler_TaskConnectingProject=Associating project with Git repository +CloneGistHandler_TaskCreatingProject=Creating project +CloneGistHandler_TaskRegisteringRepository=Registering Git repository GistAttachmentPage_Description=Enter file name GistAttachmentPage_LabelBinaryWarning=Note: Binary content in Gist attachments is not supported GistAttachmentPage_LabelFile=File: From 99dd356b60813ad490441e416e448f8e74694a91 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Apr 2011 15:30:17 -0700 Subject: [PATCH 153/642] Add clone gist handler This handler clones a gist locally, adds it as a registered gist repository and creates a project with the files in the gist. Change-Id: I8b2a81a40258bf443593470940d8e672de7907f8 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github.ui/plugin.xml | 9 + .../github/ui/gist/CloneGistHandler.java | 232 ++++++++++++++++++ 2 files changed, 241 insertions(+) create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java diff --git a/org.eclipse.mylyn.github.ui/plugin.xml b/org.eclipse.mylyn.github.ui/plugin.xml index f381c0bd7..33c137674 100644 --- a/org.eclipse.mylyn.github.ui/plugin.xml +++ b/org.eclipse.mylyn.github.ui/plugin.xml @@ -34,6 +34,11 @@ id="org.eclipse.mylyn.github.ui.command.createGist" name="Create Gist"> + + @@ -76,6 +81,10 @@ class="org.eclipse.mylyn.github.ui.internal.CreateGistHandler" commandId="org.eclipse.mylyn.github.ui.command.createGist"> + + diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java new file mode 100644 index 000000000..e1e508e02 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * 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.ui.gist; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.text.MessageFormat; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.egit.core.RepositoryUtil; +import org.eclipse.egit.core.op.CloneOperation; +import org.eclipse.egit.core.op.CloneOperation.PostCloneTask; +import org.eclipse.egit.core.op.ConnectProviderOperation; +import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.UIPreferences; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; +import org.eclipse.mylyn.commons.net.AuthenticationCredentials; +import org.eclipse.mylyn.commons.net.AuthenticationType; +import org.eclipse.mylyn.internal.github.core.gist.GistAttribute; +import org.eclipse.mylyn.internal.github.core.gist.GistConnector; +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.ui.IWorkbenchSite; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.progress.IWorkbenchSiteProgressService; + +/** + * Clone Gist handler class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class CloneGistHandler extends AbstractHandler { + + /** + * ID + */ + public static final String ID = "org.eclipse.mylyn.github.ui.command.cloneGist"; //$NON-NLS-1$ + + private File getParentDirectory() { + String destinationDir = Activator.getDefault().getPreferenceStore() + .getString(UIPreferences.DEFAULT_REPO_DIR); + File parentDir = new File(destinationDir); + if (!parentDir.exists() || !parentDir.isDirectory()) + parentDir = ResourcesPlugin.getWorkspace().getRoot() + .getRawLocation().toFile(); + return parentDir; + } + + private void createProject(final File workDir, final String name, + final Repository repository, IProgressMonitor monitor) + throws CoreException { + IProjectDescription description = null; + String projectName = null; + File projectFile = new File(workDir, ".project"); //$NON-NLS-1$ + if (projectFile.exists()) { + description = ResourcesPlugin.getWorkspace() + .loadProjectDescription( + Path.fromOSString(projectFile.getAbsolutePath())); + projectName = description.getName(); + } else { + description = ResourcesPlugin.getWorkspace().newProjectDescription( + name); + description + .setLocation(Path.fromOSString(workDir.getAbsolutePath())); + projectName = name; + } + + monitor.setTaskName(Messages.CloneGistHandler_TaskCreatingProject); + IProject project = ResourcesPlugin.getWorkspace().getRoot() + .getProject(projectName); + project.create(description, monitor); + project.open(IResource.BACKGROUND_REFRESH, monitor); + + monitor.setTaskName(Messages.CloneGistHandler_TaskConnectingProject); + ConnectProviderOperation cpo = new ConnectProviderOperation(project, + repository.getDirectory()); + cpo.execute(monitor); + } + + private CloneOperation createCloneOperation(TaskData data, String name) + throws IOException, URISyntaxException { + String pullUrl = data.getRoot() + .getAttribute(GistAttribute.CLONE_URL.getId()).getValue(); + URIish uri = new URIish(pullUrl); + int timeout = Activator.getDefault().getPreferenceStore() + .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); + final File workDir = new File(getParentDirectory(), name); + + if (getRepoUtil().getConfiguredRepositories().contains( + new File(workDir, Constants.DOT_GIT).getAbsolutePath())) + throw new IOException(MessageFormat.format( + Messages.CloneGistHandler_ErrorRepoExists, name)); + + return new CloneOperation(uri, true, null, workDir, Constants.R_HEADS + + Constants.MASTER, Constants.DEFAULT_REMOTE_NAME, timeout); + } + + private void updateCredentials(TaskData data, CloneOperation operation) { + TaskRepository repository = TasksUi.getRepositoryManager() + .getRepository(GistConnector.KIND, data.getRepositoryUrl()); + AuthenticationCredentials credentials = repository + .getCredentials(AuthenticationType.REPOSITORY); + if (credentials != null) { + UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider( + credentials.getUserName(), credentials.getPassword() + .toCharArray()); + operation.setCredentialsProvider(provider); + } + } + + private RepositoryUtil getRepoUtil() { + return org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil(); + } + + private Job createCloneJob(final ExecutionEvent event, final TaskData data) { + Job job = new Job(Messages.CloneGistHandler_TaskCloning) { + + protected IStatus run(IProgressMonitor monitor) { + try { + final String name = "gist-" + data.getTaskId(); //$NON-NLS-1$ + + CloneOperation operation = createCloneOperation(data, name); + updateCredentials(data, operation); + + operation.addPostCloneTask(new PostCloneTask() { + + public void execute(Repository repository, + IProgressMonitor monitor) throws CoreException { + if (monitor.isCanceled()) + return; + monitor.setTaskName(Messages.CloneGistHandler_TaskRegisteringRepository); + getRepoUtil().addConfiguredRepository( + repository.getDirectory()); + } + }); + + operation.addPostCloneTask(new PostCloneTask() { + + public void execute(final Repository repository, + IProgressMonitor monitor) throws CoreException { + IWorkspaceRunnable runnable = new IWorkspaceRunnable() { + + public void run(IProgressMonitor monitor) + throws CoreException { + if (monitor.isCanceled()) + return; + createProject(repository.getDirectory() + .getParentFile(), name, repository, + monitor); + } + }; + ResourcesPlugin.getWorkspace().run(runnable, + monitor); + } + }); + + operation.run(monitor); + } catch (Exception e) { + displayError(event, e); + Activator.logError("Error cloning gist", e); //$NON-NLS-1$ + } + return Status.OK_STATUS; + } + }; + return job; + } + + private void displayError(final ExecutionEvent event, Exception exception) { + final Throwable cause = exception.getCause() != null ? exception + .getCause() : exception; + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + + public void run() { + ErrorDialog.openError(HandlerUtil.getActiveShell(event), + Messages.CloneGistHandler_ErrorTitle, + Messages.CloneGistHandler_ErrorMessage, Activator + .createErrorStatus(cause.getLocalizedMessage(), + cause)); + } + }); + } + + /** + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event); + IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) activeSite + .getService(IWorkbenchSiteProgressService.class); + + ISelection selection = HandlerUtil.getCurrentSelection(event); + if (selection == null || selection.isEmpty()) + selection = HandlerUtil.getActiveMenuSelection(event); + + if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + Object first = ((IStructuredSelection) selection).getFirstElement(); + if (first instanceof TaskData) + service.schedule(createCloneJob(event, (TaskData) first)); + } + return null; + } +} From 8e3aae9d211ce852c364ee4823a14ad3893c591b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Apr 2011 15:39:59 -0700 Subject: [PATCH 154/642] Add clone action to gist task editor page Change-Id: I104553771e5324b1cd51d4bee57e570fd83115bb Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../github/ui/gist/GistTaskEditorPage.java | 58 +++++++++++++++++++ .../internal/github/ui/gist/Messages.java | 3 + .../github/ui/gist/messages.properties | 1 + 3 files changed, 62 insertions(+) diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java index 3d88a4d98..80ab3ede4 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java @@ -13,6 +13,18 @@ import java.util.Iterator; import java.util.Set; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.NotEnabledException; +import org.eclipse.core.commands.NotHandledException; +import org.eclipse.core.commands.common.NotDefinedException; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.egit.ui.UIIcons; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.mylyn.github.ui.internal.IssueSummaryPart; import org.eclipse.mylyn.internal.github.core.gist.GistAttribute; import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorActionPart; @@ -21,7 +33,10 @@ import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor; import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISources; +import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.handlers.IHandlerService; /** * Gist task editor page class @@ -38,6 +53,49 @@ public GistTaskEditorPage(TaskEditor editor, String connectorKind) { setNeedsSubmitButton(true); } + /** + * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage#fillToolBar(org.eclipse.jface.action.IToolBarManager) + */ + public void fillToolBar(IToolBarManager toolBarManager) { + super.fillToolBar(toolBarManager); + + Action cloneGist = new Action( + Messages.GistTaskEditorPage_LabelCloneGistAction, + UIIcons.CLONEGIT) { + + public void run() { + ICommandService srv = (ICommandService) getSite().getService( + ICommandService.class); + IHandlerService hsrv = (IHandlerService) getSite().getService( + IHandlerService.class); + Command command = srv.getCommand(CloneGistHandler.ID); + + ExecutionEvent event = hsrv.createExecutionEvent(command, null); + if (event.getApplicationContext() instanceof IEvaluationContext) { + IEvaluationContext context = (IEvaluationContext) event + .getApplicationContext(); + IStructuredSelection selection = new StructuredSelection( + getModel().getTaskData()); + context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, + selection); + try { + command.executeWithChecks(event); + } catch (ExecutionException ignored) { + // Ignored + } catch (NotDefinedException ignored) { + // Ignored + } catch (NotEnabledException ignored) { + // Ignored + } catch (NotHandledException ignored) { + // Ignored + } + } + } + + }; + toolBarManager.prependToGroup("open", cloneGist); //$NON-NLS-1$ + } + /** * @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage#createPartDescriptors() */ diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java index f7cb88aa3..ea7aaa9b5 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java @@ -88,6 +88,9 @@ public class Messages extends NLS { /** */ public static String GistRepositorySettingsPage_Title; + /** */ + public static String GistTaskEditorPage_LabelCloneGistAction; + /** */ public static String GistTaskEditorPageFactory_PageText; diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties index 339bb8a23..2368cd40c 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties @@ -21,4 +21,5 @@ GistRepositorySettingsPage_StatusSuccess=Success\! GistRepositorySettingsPage_TaskContacting=Contacting server GistRepositorySettingsPage_TaskValidating=Validating Settings... GistRepositorySettingsPage_Title=Gist repository settings +GistTaskEditorPage_LabelCloneGistAction=Clone Gist GistTaskEditorPageFactory_PageText=Gist From 3fb03e8738f17fad7be37c4d8c894849feeb37dc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 25 Apr 2011 15:27:49 -0700 Subject: [PATCH 155/642] Add repository selection wizard page This will be used in the import repositories wizard. Change-Id: I5df9733e299b8fcfcb0b8283f42e219b9be2843b Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../META-INF/MANIFEST.MF | 1 + .../RepositorySelectionWizardPage.java | 247 ++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java diff --git a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF index c69b4a55a..8e5b9e8d9 100644 --- a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF @@ -24,3 +24,4 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.core.expressions;bundle-version="3.4.0" Export-Package: org.eclipse.mylyn.github.ui.internal;x-internal:=true Bundle-ActivationPolicy: lazy +Import-Package: org.eclipse.egit.ui.internal;version="0.12.0" diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java new file mode 100644 index 000000000..af9da75ae --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java @@ -0,0 +1,247 @@ +/******************************************************************************* + * 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.github.ui.internal; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.httpclient.HostConfiguration; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.egit.ui.internal.FilteredCheckboxTree; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.mylyn.github.internal.GitHub; +import org.eclipse.mylyn.github.internal.GitHubClient; +import org.eclipse.mylyn.github.internal.IGitHubConstants; +import org.eclipse.mylyn.github.internal.Repository; +import org.eclipse.mylyn.github.internal.RepositoryService; +import org.eclipse.mylyn.internal.github.core.gist.GistConnector; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PatternFilter; +import org.eclipse.ui.model.WorkbenchAdapter; +import org.eclipse.ui.model.WorkbenchContentProvider; + +/** + * Repository selection wizard page. + */ +public class RepositorySelectionWizardPage extends WizardPage { + + private Button addGistRepoButton; + private Label selectedLabel; + private FilteredCheckboxTree tree; + private int repoCount = 0; + private String user; + private String password; + + /** + * Create repository selection wizard page + */ + public RepositorySelectionWizardPage() { + super( + "repositoriesPage", Messages.RepositorySelectionWizardPage_Title, null); //$NON-NLS-1$ + setDescription(Messages.RepositorySelectionWizardPage_Description); + } + + /** @param user */ + public void setUser(String user) { + this.user = user; + } + + /** @param password */ + public void setPassword(String password) { + this.password = password; + } + + /** @return true to create giste repository, false otherwise */ + public boolean createGistRepository() { + return this.addGistRepoButton.getSelection() + && this.addGistRepoButton.isVisible(); + } + + /** @return array of selected repositories */ + public Object[] getRepositories() { + return this.tree.getCheckboxTreeViewer().getCheckedLeafElements(); + } + + /** @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) */ + public void createControl(Composite parent) { + Composite displayArea = new Composite(parent, SWT.NONE); + GridLayoutFactory.swtDefaults().numColumns(2).applyTo(displayArea); + + Label repoLabel = new Label(displayArea, SWT.NONE); + repoLabel.setText(Messages.RepositorySelectionWizardPage_LabelRepos); + GridDataFactory.fillDefaults().grab(true, false).span(2, 1) + .applyTo(repoLabel); + + tree = new FilteredCheckboxTree(displayArea, null, SWT.V_SCROLL + | SWT.H_SCROLL | SWT.BORDER, new PatternFilter()); + CheckboxTreeViewer viewer = tree.getCheckboxTreeViewer(); + viewer.setContentProvider(new WorkbenchContentProvider()); + viewer.setLabelProvider(new LabelProvider()); + viewer.setSorter(new ViewerSorter()); + viewer.addCheckStateListener(new ICheckStateListener() { + + public void checkStateChanged(CheckStateChangedEvent event) { + updateSelectionLabel(); + } + }); + GridDataFactory.fillDefaults().grab(true, true).applyTo(tree); + + ToolBar toolbar = new ToolBar(displayArea, SWT.FLAT | SWT.VERTICAL); + GridDataFactory.fillDefaults().grab(false, true).applyTo(toolbar); + ToolItem checkItem = new ToolItem(toolbar, SWT.PUSH); + checkItem.setImage(GitHubImages.get(GitHubImages.GITHUB_CHECKALL_OBJ)); + checkItem + .setToolTipText(Messages.RepositorySelectionWizardPage_TooltipCheckAll); + checkItem.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + tree.getCheckboxTreeViewer().setAllChecked(true); + updateSelectionLabel(); + } + }); + ToolItem uncheckItem = new ToolItem(toolbar, SWT.PUSH); + uncheckItem.setImage(GitHubImages + .get(GitHubImages.GITHUB_UNCHECKALL_OBJ)); + uncheckItem + .setToolTipText(Messages.RepositorySelectionWizardPage_TooltipUncheckAll); + uncheckItem.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + tree.getCheckboxTreeViewer().setAllChecked(false); + updateSelectionLabel(); + } + }); + + selectedLabel = new Label(displayArea, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).span(2, 1) + .applyTo(selectedLabel); + + addGistRepoButton = new Button(displayArea, SWT.CHECK); + addGistRepoButton + .setText(Messages.RepositorySelectionWizardPage_LabelAddGist); + addGistRepoButton.setSelection(true); + GridDataFactory.swtDefaults().span(2, 1).applyTo(addGistRepoButton); + addGistRepoButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + validatePage(); + } + + }); + + setControl(displayArea); + setPageComplete(false); + } + + private void updateSelectionLabel() { + selectedLabel.setText(MessageFormat.format( + Messages.RepositorySelectionWizardPage_LabelSelectionCount, + tree.getCheckboxTreeViewer().getCheckedLeafCount(), repoCount)); + selectedLabel.getParent().layout(true, true); + validatePage(); + } + + private void validatePage() { + setPageComplete(getRepositories().length > 0 || createGistRepository()); + } + + private void updateInput(final List repos) { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + + public void run() { + if (getControl().isDisposed()) + return; + tree.getCheckboxTreeViewer().setCheckedElements(new Object[0]); + tree.getViewer().setInput(new WorkbenchAdapter() { + + public Object[] getChildren(Object object) { + return repos.toArray(); + } + + }); + updateSelectionLabel(); + } + }); + } + + /** @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) */ + public void setVisible(boolean visible) { + super.setVisible(visible); + if (!visible) + return; + addGistRepoButton.setVisible(TasksUi.getRepositoryManager() + .getRepositories(GistConnector.KIND).isEmpty()); + try { + getContainer().run(true, true, new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + HostConfiguration config = new HostConfiguration(); + config.setHost(IGitHubConstants.HOST_API_V2, -1, + IGitHubConstants.PROTOCOL_HTTPS); + GitHubClient client = new GitHubClient(config); + client.setCredentials(user, password); + RepositoryService service = new RepositoryService(client); + repoCount = 0; + List repos = new ArrayList(); + try { + monitor.beginTask("", 2); //$NON-NLS-1$ + monitor.setTaskName(Messages.RepositorySelectionWizardPage_TaskFetchingRepositories); + repos.addAll(service.getRepositories(user)); + monitor.worked(1); + monitor.setTaskName(Messages.RepositorySelectionWizardPage_TaskFetchingOrganizationRepositories); + repos.addAll(service.getOrganizationRepositories()); + monitor.worked(1); + for (TaskRepository repo : TasksUi + .getRepositoryManager().getRepositories( + GitHub.CONNECTOR_KIND)) { + repos.remove(GitHub.getRepository(repo + .getRepositoryUrl())); + } + repoCount = repos.size(); + updateInput(repos); + } catch (IOException e) { + throw new InvocationTargetException(e); + } + } + }); + } catch (InvocationTargetException e) { + updateInput(Collections. emptyList()); + setErrorMessage(MessageFormat.format( + Messages.RepositorySelectionWizardPage_ErrorLoading, e + .getTargetException().getLocalizedMessage())); + } catch (InterruptedException ignored) { + // Ignored + } + } +} From 59bfd0df475f9036c408a4dc310862c33499eeb8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 25 Apr 2011 15:31:01 -0700 Subject: [PATCH 156/642] Add import wizard for bulk adding GitHub task repositories Change-Id: Idca217ba34757e6a1eb63b6bf9717680f37c2712 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github.ui/plugin.properties | 3 +- org.eclipse.mylyn.github.ui/plugin.xml | 10 ++ .../ui/internal/ImportRepositoriesWizard.java | 117 ++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/ImportRepositoriesWizard.java diff --git a/org.eclipse.mylyn.github.ui/plugin.properties b/org.eclipse.mylyn.github.ui/plugin.properties index e20b049d4..8751f28ff 100644 --- a/org.eclipse.mylyn.github.ui/plugin.properties +++ b/org.eclipse.mylyn.github.ui/plugin.properties @@ -3,4 +3,5 @@ org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnectorUI=GitHub reposito gistCoreConnectorName=GitHub Gist repository connector gistUiConnectorName=GitHub Gist repository connector UI pluginName=Mylyn GitHub Connector UI (Incubation) -providerName=Eclipse EGit \ No newline at end of file +providerName=Eclipse EGit +importRepositoriesWizardName=GitHub Task Repositories \ No newline at end of file diff --git a/org.eclipse.mylyn.github.ui/plugin.xml b/org.eclipse.mylyn.github.ui/plugin.xml index 33c137674..da73b429f 100644 --- a/org.eclipse.mylyn.github.ui/plugin.xml +++ b/org.eclipse.mylyn.github.ui/plugin.xml @@ -101,5 +101,15 @@ overlayIcon="icons/obj16/github_8x8.png"> + + + + diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/ImportRepositoriesWizard.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/ImportRepositoriesWizard.java new file mode 100644 index 000000000..bae092b50 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/ImportRepositoriesWizard.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * 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.github.ui.internal; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.mylyn.commons.net.AuthenticationCredentials; +import org.eclipse.mylyn.commons.net.AuthenticationType; +import org.eclipse.mylyn.github.internal.GitHub; +import org.eclipse.mylyn.github.internal.Repository; +import org.eclipse.mylyn.internal.github.core.gist.GistConnector; +import org.eclipse.mylyn.internal.github.ui.gist.GistRepositorySettingsPage; +import org.eclipse.mylyn.internal.github.ui.gist.Messages; +import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.internal.IWorkbenchGraphicConstants; +import org.eclipse.ui.internal.WorkbenchImages; + +/** + * Import repositories wizard class. + * + * @author Kevin Sawicki (kevin@github.com) + */ +public class ImportRepositoriesWizard extends Wizard implements IImportWizard { + + private CredentialsWizardPage credentialsPage; + + private RepositorySelectionWizardPage reposPage; + + /** + * Create import repositories wizard + */ + public ImportRepositoriesWizard() { + setNeedsProgressMonitor(true); + setDefaultPageImageDescriptor(WorkbenchImages + .getImageDescriptor(IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_WIZ)); + } + + /** + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + public void addPages() { + this.credentialsPage = new CredentialsWizardPage(); + addPage(this.credentialsPage); + this.reposPage = new RepositorySelectionWizardPage(); + addPage(this.reposPage); + } + + /** + * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage) + */ + public IWizardPage getNextPage(IWizardPage page) { + IWizardPage next = super.getNextPage(page); + if (next == reposPage) { + reposPage.setUser(credentialsPage.getUserName()); + reposPage.setPassword(credentialsPage.getPassword()); + } + return next; + } + + /** + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, + * org.eclipse.jface.viewers.IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + + } + + /** + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + public boolean performFinish() { + String user = credentialsPage.getUserName(); + String password = credentialsPage.getPassword(); + for (Object selected : reposPage.getRepositories()) { + Repository repo = (Repository) selected; + AuthenticationCredentials credentials = new AuthenticationCredentials( + user, password); + TaskRepository repository = new TaskRepository( + GitHub.CONNECTOR_KIND, GitHub.createGitHubUrl( + repo.getOwner(), repo.getName())); + repository.setProperty(IRepositoryConstants.PROPERTY_LABEL, + repo.getId()); + repository.setCredentials(AuthenticationType.REPOSITORY, + credentials, true); + repository.setProperty(IRepositoryConstants.PROPERTY_CATEGORY, + IRepositoryConstants.CATEGORY_BUGS); + TasksUi.getRepositoryManager().addRepository(repository); + } + if (reposPage.createGistRepository()) { + AuthenticationCredentials credentials = new AuthenticationCredentials( + user, password); + TaskRepository repository = new TaskRepository(GistConnector.KIND, + GistRepositorySettingsPage.URL); + repository.setProperty(IRepositoryConstants.PROPERTY_LABEL, + Messages.GistRepositorySettingsPage_RepositoryLabelDefault); + repository.setCredentials(AuthenticationType.REPOSITORY, + credentials, true); + repository.setProperty(IRepositoryConstants.PROPERTY_CATEGORY, + IRepositoryConstants.CATEGORY_REVIEW); + TasksUi.getRepositoryManager().addRepository(repository); + } + return true; + } +} From a50b21285bb3f65956b5edf756f3f65d1a16e394 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 26 Apr 2011 09:28:18 -0700 Subject: [PATCH 157/642] Add update milestones and labels button to query page Change-Id: Ic8de4156566229d4cb9764d0b401d980f8e8130f Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../internal/GitHubRepositoryQueryPage.java | 196 +++++++++++------- .../mylyn/github/ui/internal/Messages.java | 3 + .../github/ui/internal/messages.properties | 1 + 3 files changed, 121 insertions(+), 79 deletions(-) diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java index 090423d30..1a2d9410b 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java @@ -12,9 +12,9 @@ *******************************************************************************/ package org.eclipse.mylyn.github.ui.internal; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; @@ -24,7 +24,7 @@ import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -36,10 +36,15 @@ import org.eclipse.mylyn.github.internal.LabelComparator; import org.eclipse.mylyn.github.internal.Milestone; import org.eclipse.mylyn.github.internal.QueryUtils; +import org.eclipse.mylyn.internal.provisional.commons.ui.CommonUiUtil; +import org.eclipse.mylyn.internal.provisional.commons.ui.ICoreRunnable; import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.TasksUiImages; import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; @@ -52,6 +57,8 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; import org.eclipse.ui.PlatformUI; /** @@ -124,39 +131,13 @@ public void selectionChanged(SelectionChangedEvent event) { }); } - /** - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ - public void createControl(Composite parent) { - Composite displayArea = new Composite(parent, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false) - .applyTo(displayArea); - GridDataFactory.fillDefaults().grab(true, true).applyTo(displayArea); - - if (!inSearchContainer()) { - Composite titleArea = new Composite(displayArea, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).applyTo(titleArea); - GridDataFactory.fillDefaults().grab(true, false).span(2, 1) - .applyTo(titleArea); - - new Label(titleArea, SWT.NONE) - .setText(Messages.GitHubRepositoryQueryPage_TitleLabel); - titleText = new Text(titleArea, SWT.SINGLE | SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(titleText); - titleText.addModifyListener(new ModifyListener() { - - public void modifyText(ModifyEvent e) { - setPageComplete(isPageComplete()); - } - }); - } - - Composite leftArea = new Composite(displayArea, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).applyTo(leftArea); - GridDataFactory.fillDefaults().grab(true, true).applyTo(leftArea); + private void createOptionsArea(Composite parent) { + Composite optionsArea = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(optionsArea); + GridDataFactory.fillDefaults().grab(true, true).applyTo(optionsArea); - Composite statusArea = new Composite(leftArea, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false) + Composite statusArea = new Composite(optionsArea, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(4).equalWidth(false) .applyTo(statusArea); GridDataFactory.fillDefaults().grab(true, false).span(2, 1) .applyTo(statusArea); @@ -174,26 +155,80 @@ public void modifyText(ModifyEvent e) { closedButton.setText(Messages.GitHubRepositoryQueryPage_StatusClosed); closedButton.addSelectionListener(this.completeListener); - Label milestonesLabel = new Label(leftArea, SWT.NONE); + ToolBar toolbar = new ToolBar(statusArea, SWT.FLAT); + ToolItem updateItem = new ToolItem(toolbar, SWT.PUSH); + final Image updateImage = TasksUiImages.REPOSITORY_UPDATE_CONFIGURATION + .createImage(); + toolbar.addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + updateImage.dispose(); + } + }); + updateItem.setImage(updateImage); + updateItem + .setToolTipText(Messages.GitHubRepositoryQueryPage_TooltipUpdateRepository); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL) + .grab(true, false).applyTo(toolbar); + updateItem.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + refreshRepository(); + } + + }); + + Label milestonesLabel = new Label(optionsArea, SWT.NONE); milestonesLabel .setText(Messages.GitHubRepositoryQueryPage_MilestoneLabel); - milestoneCombo = new Combo(leftArea, SWT.DROP_DOWN | SWT.READ_ONLY); + milestoneCombo = new Combo(optionsArea, SWT.DROP_DOWN | SWT.READ_ONLY); GridDataFactory.fillDefaults().grab(true, false) .applyTo(milestoneCombo); - Label assigneeLabel = new Label(leftArea, SWT.NONE); + Label assigneeLabel = new Label(optionsArea, SWT.NONE); assigneeLabel.setText(Messages.GitHubRepositoryQueryPage_AssigneeLabel); - assigneeText = new Text(leftArea, SWT.BORDER | SWT.SINGLE); + assigneeText = new Text(optionsArea, SWT.BORDER | SWT.SINGLE); GridDataFactory.fillDefaults().grab(true, false).applyTo(assigneeText); - Label mentionLabel = new Label(leftArea, SWT.NONE); + Label mentionLabel = new Label(optionsArea, SWT.NONE); mentionLabel.setText(Messages.GitHubRepositoryQueryPage_MentionsLabel); - mentionText = new Text(leftArea, SWT.BORDER | SWT.SINGLE); + mentionText = new Text(optionsArea, SWT.BORDER | SWT.SINGLE); GridDataFactory.fillDefaults().grab(true, false).applyTo(mentionText); + } + + /** + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + Composite displayArea = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true) + .applyTo(displayArea); + GridDataFactory.fillDefaults().grab(true, true).applyTo(displayArea); + + if (!inSearchContainer()) { + Composite titleArea = new Composite(displayArea, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(titleArea); + GridDataFactory.fillDefaults().grab(true, false).span(2, 1) + .applyTo(titleArea); + + new Label(titleArea, SWT.NONE) + .setText(Messages.GitHubRepositoryQueryPage_TitleLabel); + titleText = new Text(titleArea, SWT.SINGLE | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(titleText); + titleText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + setPageComplete(isPageComplete()); + } + }); + } + + createOptionsArea(displayArea); + createLabelsArea(displayArea); loadRepository(); @@ -271,6 +306,12 @@ private boolean updateMilestones() { this.milestoneCombo.removeAll(); this.milestoneCombo .add(Messages.GitHubRepositoryQueryPage_MilestoneNone); + Collections.sort(this.milestones, new Comparator() { + + public int compare(Milestone m1, Milestone m2) { + return m1.getTitle().compareToIgnoreCase(m2.getTitle()); + } + }); for (Milestone milestone : milestones) this.milestoneCombo.add(milestone.getTitle()); @@ -281,49 +322,46 @@ private boolean updateMilestones() { private void refreshRepository() { try { - getContainer().run(true, true, new IRunnableWithProgress() { + ICoreRunnable runnable = new ICoreRunnable() { - public void run(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { + public void run(IProgressMonitor monitor) throws CoreException { Policy.monitorFor(monitor); monitor.beginTask("", 2); //$NON-NLS-1$ - try { - GitHubRepositoryConnector connector = GitHubRepositoryConnectorUI - .getCoreConnector(); - TaskRepository repository = getTaskRepository(); - - monitor.setTaskName(Messages.GitHubRepositoryQueryPage_TaskLoadingLabels); - connector.refreshLabels(repository); - monitor.worked(1); - - monitor.setTaskName(Messages.GitHubRepositoryQueryPage_TaskLoadingMilestones); - connector.refreshMilestones(repository); - monitor.done(); - - PlatformUI.getWorkbench().getDisplay() - .asyncExec(new Runnable() { - - public void run() { - updateLabels(); - updateMilestones(); - initialize(); - } - }); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } + GitHubRepositoryConnector connector = GitHubRepositoryConnectorUI + .getCoreConnector(); + TaskRepository repository = getTaskRepository(); + + monitor.setTaskName(Messages.GitHubRepositoryQueryPage_TaskLoadingLabels); + connector.refreshLabels(repository); + monitor.worked(1); + + monitor.setTaskName(Messages.GitHubRepositoryQueryPage_TaskLoadingMilestones); + connector.refreshMilestones(repository); + monitor.done(); + + PlatformUI.getWorkbench().getDisplay() + .asyncExec(new Runnable() { + + public void run() { + updateLabels(); + updateMilestones(); + initialize(); + } + }); } - }); - } catch (InvocationTargetException e) { - Throwable target = e.getTargetException(); - if (target instanceof CoreException) { - IStatus status = ((CoreException) target).getStatus(); - ErrorDialog.openError(getShell(), - Messages.GitHubRepositoryQueryPage_ErrorLoading, - target.getLocalizedMessage(), status); - } - } catch (InterruptedException ignore) { - // Ignore + }; + IRunnableContext context = getContainer(); + if (context == null) + if (inSearchContainer()) + context = getSearchContainer().getRunnableContext(); + else + context = PlatformUI.getWorkbench().getProgressService(); + CommonUiUtil.run(context, runnable); + } catch (CoreException e) { + IStatus status = e.getStatus(); + ErrorDialog.openError(getShell(), + Messages.GitHubRepositoryQueryPage_ErrorLoading, + e.getLocalizedMessage(), status); } } diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/Messages.java index 36251ce46..9c1cc2dd6 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/Messages.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/Messages.java @@ -79,6 +79,9 @@ public class Messages extends NLS { /** */ public static String GitHubRepositoryQueryPage_TitleLabel; + /** */ + public static String GitHubRepositoryQueryPage_TooltipUpdateRepository; + /** */ public static String GitHubRepositorySettingsPage_Description; diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/messages.properties index dd5369966..0cb0e3aad 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/messages.properties +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/messages.properties @@ -18,6 +18,7 @@ GitHubRepositoryQueryPage_StatusOpen=Open GitHubRepositoryQueryPage_TaskLoadingLabels=Loading labels GitHubRepositoryQueryPage_TaskLoadingMilestones=Loading milestones GitHubRepositoryQueryPage_TitleLabel=Title: +GitHubRepositoryQueryPage_TooltipUpdateRepository=Update milestones and labels GitHubRepositorySettingsPage_Description=Enter repository location and credentials GitHubRepositorySettingsPage_StatusError=Error validating settings: {0} GitHubRepositorySettingsPage_ErrorMalformedUrl=Server URL must be in the form http://github.com/user/project From 84c7ade8ea08be53cc97e396f8ab326002916586 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Fri, 29 Apr 2011 15:51:28 +0200 Subject: [PATCH 158/642] Unit tests (headless) cleanup. Change-Id: Ief5253b945fb41800603e1526deb2361d02e26fb Signed-off-by: Christian Trutz Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github.tests/pom.xml | 2 +- .../mylyn/github/tests/resources/issues.json | 1 - .../ui/GitHubRepositoryConnectorUITest.java | 41 ------------- ...tHubRepositoryConnectorUIHeadlessTest.java | 58 +++++++++++++++++++ 4 files changed, 59 insertions(+), 43 deletions(-) delete mode 100644 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/resources/issues.json delete mode 100644 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/ui/GitHubRepositoryConnectorUITest.java create mode 100644 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUIHeadlessTest.java diff --git a/org.eclipse.mylyn.github.tests/pom.xml b/org.eclipse.mylyn.github.tests/pom.xml index 5ce2941f6..8cddc4043 100644 --- a/org.eclipse.mylyn.github.tests/pom.xml +++ b/org.eclipse.mylyn.github.tests/pom.xml @@ -22,7 +22,7 @@ org.eclipse.mylyn.github.tests eclipse-test-plugin - Mylyn GitHub Test Plug-in (Incubation) + Eclipse EGit Mylyn GitHub Test Plug-in (Incubation) diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/resources/issues.json b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/resources/issues.json deleted file mode 100644 index d99eb9f31..000000000 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/resources/issues.json +++ /dev/null @@ -1 +0,0 @@ -{"issues":[{"number":1,"votes":0,"created_at":"2010/02/02 22:58:39 -0800","body":"","title":"Test objective-c marshaling code","updated_at":"2010/02/02 22:58:39 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":2,"votes":0,"created_at":"2010/02/02 22:59:02 -0800","body":"","title":"Provide instructions for use","updated_at":"2010/02/02 22:59:02 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":3,"votes":0,"created_at":"2010/02/02 22:59:26 -0800","body":"","title":"add support for JSON marshalling","updated_at":"2010/02/04 17:56:02 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":4,"votes":0,"created_at":"2010/02/02 22:59:45 -0800","body":"","title":"provide working sample project","updated_at":"2010/02/02 22:59:45 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":5,"votes":0,"created_at":"2010/02/02 23:00:19 -0800","body":"","title":"support object inheritance","updated_at":"2010/02/02 23:00:19 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":6,"votes":0,"created_at":"2010/02/02 23:00:37 -0800","body":"","title":"provide support for nested types","updated_at":"2010/02/02 23:00:37 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":7,"votes":0,"created_at":"2010/02/02 23:00:49 -0800","body":"","title":"client enum support","updated_at":"2010/02/02 23:00:49 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":8,"votes":0,"created_at":"2010/02/02 23:01:09 -0800","body":"","title":"refactor templates to use field iterator","updated_at":"2010/02/02 23:01:09 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":9,"votes":0,"created_at":"2010/02/02 23:01:35 -0800","body":"","title":"wiki should explain target architecture","updated_at":"2010/02/02 23:01:35 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":10,"votes":0,"created_at":"2010/02/04 21:03:54 -0800","body":"test description 2 ","title":"test issue for testing mylyn github connector2","updated_at":"2010/02/04 21:09:37 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"}]} \ No newline at end of file diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/ui/GitHubRepositoryConnectorUITest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/ui/GitHubRepositoryConnectorUITest.java deleted file mode 100644 index fe58f09e5..000000000 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/ui/GitHubRepositoryConnectorUITest.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.eclipse.mylyn.github.tests.ui; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import junit.framework.Assert; - -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.mylyn.github.internal.GitHub; -import org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnectorUI; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TaskHyperlink; -import org.junit.Before; -import org.junit.Test; - -public class GitHubRepositoryConnectorUITest { - - private GitHubRepositoryConnectorUI connectorUI; - private TaskRepository repository; - - @Before - public void before() { - connectorUI = new GitHubRepositoryConnectorUI(); - repository = new TaskRepository(GitHub.CONNECTOR_KIND, GitHub.createGitHubUrl("foo", "bar")); - } - - @Test - public void testFindHyperlinksTaskRepositoryStringIntInt() { - IHyperlink[] hyperlinks = connectorUI.findHyperlinks(repository, "one #2 three", -1, 0); - assertNotNull(hyperlinks); - assertEquals(1,hyperlinks.length); - assertEquals(new Region(4,2),hyperlinks[0].getHyperlinkRegion()); - - hyperlinks = connectorUI.findHyperlinks(repository, "one #2 three", -1, 4); - assertNotNull(hyperlinks); - assertEquals(1,hyperlinks.length); - assertEquals(new Region(8,2),hyperlinks[0].getHyperlinkRegion()); - } - -} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUIHeadlessTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUIHeadlessTest.java new file mode 100644 index 000000000..a42a5ce3d --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUIHeadlessTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz 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: + * David Green - initial contribution + * Christian Trutz - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.ui.internal; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.hyperlink.IHyperlink; +import org.eclipse.mylyn.github.internal.GitHub; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.junit.Before; +import org.junit.Test; + +/** + * Headless test for {@link GitHubRepositoryConnectorUI} + * + * @author Christian Trutz + */ +@SuppressWarnings("restriction") +public class GitHubRepositoryConnectorUIHeadlessTest { + + private GitHubRepositoryConnectorUI connectorUI; + + private TaskRepository repository; + + @Before + public void before() { + connectorUI = new GitHubRepositoryConnectorUI(); + repository = new TaskRepository(GitHub.CONNECTOR_KIND, + GitHub.createGitHubUrl("foo", "bar")); + } + + @Test + public void testFindHyperlinksTaskRepositoryStringIntInt() { + IHyperlink[] hyperlinks = connectorUI.findHyperlinks(repository, + "one #2 three", -1, 0); + assertNotNull(hyperlinks); + assertEquals(1, hyperlinks.length); + assertEquals(new Region(4, 2), hyperlinks[0].getHyperlinkRegion()); + + hyperlinks = connectorUI.findHyperlinks(repository, "one #2 three", -1, + 4); + assertNotNull(hyperlinks); + assertEquals(1, hyperlinks.length); + assertEquals(new Region(8, 2), hyperlinks[0].getHyperlinkRegion()); + } + +} From ae81bd433ef66f15ccc9993ba27aae37f537427c Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Fri, 6 May 2011 14:33:28 +0200 Subject: [PATCH 159/642] Add CommentTest Change-Id: I4162c7b5e9b81d3dad11ae5e6fc8cdef878a2ee7 Signed-off-by: Christian Trutz Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/Comment.java | 10 ++-- .../META-INF/MANIFEST.MF | 1 + .../mylyn/github/internal/CommentTest.java | 47 +++++++++++++++++++ .../mylyn/github/tests/AllHeadlessTests.java | 8 ++-- 4 files changed, 60 insertions(+), 6 deletions(-) create mode 100755 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/CommentTest.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java index 1a37ddca6..cabb24d28 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Comment.java @@ -14,7 +14,7 @@ /** * GitHub issue comment class. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class Comment { @@ -33,14 +33,18 @@ public class Comment { * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.createdAt.getTime()); } /** * @return updatedAt */ public Date getUpdatedAt() { - return this.updatedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.updatedAt.getTime()); } /** diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF index 16d752dc3..8d67c5944 100644 --- a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -18,6 +18,7 @@ Bundle-Vendor: Eclipse EGit Import-Package: com.google.gson;version="1.6.0", com.google.gson.reflect;version="1.6.0", org.apache.commons.httpclient;version="3.1.0", + org.apache.commons.logging;version="1.0.4", org.mockito;version="1.8.4", org.mockito.runners;version="1.8.4", org.mockito.stubbing;version="1.8.4" diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/CommentTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/CommentTest.java new file mode 100755 index 000000000..f22dc0293 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/CommentTest.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Unit tests for {@link Comment} + */ +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class CommentTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + Comment comment = gson.fromJson("{createdAt : '2003-10-10'}", + Comment.class); + comment.getCreatedAt().setTime(0); + assertTrue(comment.getCreatedAt().getTime() != 0); + } + + @Test + public void getUpdatedAt_ReferenceMutableObject() { + Comment comment = gson.fromJson("{updatedAt : '2003-10-10'}", + Comment.class); + comment.getUpdatedAt().setTime(0); + assertTrue(comment.getUpdatedAt().getTime() != 0); + } +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java index cf4c4e936..4fadbb4c7 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.github.tests; +import org.eclipse.mylyn.github.internal.CommentTest; import org.eclipse.mylyn.github.internal.GistServiceTest; import org.eclipse.mylyn.github.internal.GitHubClientTest; import org.eclipse.mylyn.github.internal.IssueServiceTest; @@ -23,9 +24,10 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ GitHubClientTest.class, IssueServiceTest.class, - LabelServiceTest.class, MilestoneServiceTest.class, - GistServiceTest.class, PullRequestServiceTest.class }) +@SuiteClasses({ CommentTest.class, GitHubClientTest.class, + IssueServiceTest.class, LabelServiceTest.class, + MilestoneServiceTest.class, GistServiceTest.class, + PullRequestServiceTest.class }) public class AllHeadlessTests { } From 5304013c52035e09910f19db44372f1add48ae4d Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Fri, 6 May 2011 22:56:18 +0200 Subject: [PATCH 160/642] Unit tests for Gist, Issue, Milestone, GistRevision. See also FindBugs warnings in Hudson. Change-Id: Ice5cd46fc56612ce2a76ac85fd7f0d8bf07edac3 Signed-off-by: Christian Trutz --- .../eclipse/mylyn/github/internal/Gist.java | 10 ++-- .../mylyn/github/internal/GistRevision.java | 4 +- .../eclipse/mylyn/github/internal/Issue.java | 14 +++-- .../mylyn/github/internal/Milestone.java | 10 ++-- .../github/internal/GistRevisionTest.java | 39 ++++++++++++++ .../mylyn/github/internal/GistTest.java | 46 ++++++++++++++++ .../mylyn/github/internal/IssueTest.java | 53 +++++++++++++++++++ .../mylyn/github/internal/MilestoneTest.java | 48 +++++++++++++++++ .../mylyn/github/tests/AllHeadlessTests.java | 7 ++- 9 files changed, 219 insertions(+), 12 deletions(-) create mode 100755 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistRevisionTest.java create mode 100755 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistTest.java create mode 100755 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueTest.java create mode 100755 org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneTest.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java index 2707be5a1..7743443a3 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java @@ -25,7 +25,7 @@ public class Gist { private boolean isPublic; private Date createdAt; - + private Date updatedAt; private int comments; @@ -68,7 +68,9 @@ public Gist setPublic(boolean isPublic) { * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.createdAt.getTime()); } /** @@ -158,7 +160,9 @@ public Gist setId(String id) { * @return updatedAt */ public Date getUpdatedAt() { - return this.updatedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.updatedAt.getTime()); } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java index 60bab8603..1d9e2b870 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java @@ -31,7 +31,9 @@ public class GistRevision { * @return committedAt */ public Date getCommittedAt() { - return this.committedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.committedAt.getTime()); } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java index e669393c8..80640f269 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java @@ -15,7 +15,7 @@ /** * GitHub issue class. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class Issue { @@ -52,21 +52,27 @@ public class Issue { * @return closedAt */ public Date getClosedAt() { - return this.closedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.closedAt.getTime()); } /** * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.createdAt.getTime()); } /** * @return updatedAt */ public Date getUpdatedAt() { - return this.updatedAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.updatedAt.getTime()); } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java index 31ff4c9d1..5024f4e97 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java @@ -14,7 +14,7 @@ /** * GitHub issue milestone class. - * + * * @author Kevin Sawicki (kevin@github.com) */ public class Milestone { @@ -43,14 +43,18 @@ public class Milestone { * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.createdAt.getTime()); } /** * @return dueOn */ public Date getDueOn() { - return this.dueOn; + // see EI_EXPOSE_REP at + // http://findbugs.sourceforge.net/bugDescriptions.html + return new Date(this.dueOn.getTime()); } /** diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistRevisionTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistRevisionTest.java new file mode 100755 index 000000000..e12b261d3 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistRevisionTest.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Unit tests for {@link GistRevision} + */ +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class GistRevisionTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + GistRevision gistRevision = gson.fromJson( + "{committedAt : '2003-10-10'}", GistRevision.class); + gistRevision.getCommittedAt().setTime(0); + assertTrue(gistRevision.getCommittedAt().getTime() != 0); + } +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistTest.java new file mode 100755 index 000000000..29d2a15ff --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/GistTest.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Unit tests for {@link Gist} + */ +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class GistTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + Gist gist = gson.fromJson("{createdAt : '2003-10-10'}", Gist.class); + gist.getCreatedAt().setTime(0); + assertTrue(gist.getCreatedAt().getTime() != 0); + } + + @Test + public void getUpdatedAt_ReferenceMutableObject() { + Gist gist = gson.fromJson("{updatedAt : '2003-10-10'}", Gist.class); + gist.getUpdatedAt().setTime(0); + assertTrue(gist.getUpdatedAt().getTime() != 0); + } + +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueTest.java new file mode 100755 index 000000000..f52e88878 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/IssueTest.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Unit tests for {@link Issue} + */ +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class IssueTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + Issue issue = gson.fromJson("{createdAt : '2003-10-10'}", Issue.class); + issue.getCreatedAt().setTime(0); + assertTrue(issue.getCreatedAt().getTime() != 0); + } + + @Test + public void getUpdatedAt_ReferenceMutableObject() { + Issue issue = gson.fromJson("{updatedAt : '2003-10-10'}", Issue.class); + issue.getUpdatedAt().setTime(0); + assertTrue(issue.getUpdatedAt().getTime() != 0); + } + + @Test + public void getClosedAt_ReferenceMutableObject() { + Issue issue = gson.fromJson("{closedAt : '2003-10-10'}", Issue.class); + issue.getClosedAt().setTime(0); + assertTrue(issue.getClosedAt().getTime() != 0); + } + +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneTest.java new file mode 100755 index 000000000..957b4c5c6 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/internal/MilestoneTest.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Unit tests for {@link Milestone} + */ +@SuppressWarnings("restriction") +@RunWith(MockitoJUnitRunner.class) +public class MilestoneTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + Milestone milestone = gson.fromJson("{createdAt : '2003-10-10'}", + Milestone.class); + milestone.getCreatedAt().setTime(0); + assertTrue(milestone.getCreatedAt().getTime() != 0); + } + + @Test + public void getDueOn_ReferenceMutableObject() { + Milestone milestone = gson.fromJson("{dueOn : '2003-10-10'}", + Milestone.class); + milestone.getDueOn().setTime(0); + assertTrue(milestone.getDueOn().getTime() != 0); + } + +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java index 4fadbb4c7..40065a5de 100644 --- a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java @@ -13,18 +13,23 @@ package org.eclipse.mylyn.github.tests; import org.eclipse.mylyn.github.internal.CommentTest; +import org.eclipse.mylyn.github.internal.GistRevisionTest; import org.eclipse.mylyn.github.internal.GistServiceTest; +import org.eclipse.mylyn.github.internal.GistTest; import org.eclipse.mylyn.github.internal.GitHubClientTest; import org.eclipse.mylyn.github.internal.IssueServiceTest; +import org.eclipse.mylyn.github.internal.IssueTest; import org.eclipse.mylyn.github.internal.LabelServiceTest; import org.eclipse.mylyn.github.internal.MilestoneServiceTest; +import org.eclipse.mylyn.github.internal.MilestoneTest; import org.eclipse.mylyn.github.internal.PullRequestServiceTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ CommentTest.class, GitHubClientTest.class, +@SuiteClasses({ CommentTest.class, GistTest.class, GistRevisionTest.class, + IssueTest.class, MilestoneTest.class, GitHubClientTest.class, IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class, GistServiceTest.class, PullRequestServiceTest.class }) From e33c18496108f47a746e38fc15080d87160e6d2a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 8 May 2011 17:29:12 -0700 Subject: [PATCH 161/642] Prevent null pointer exceptions on date getter methods. Change-Id: I6d3843531c0b7fef6c52a5a484c07440ae224c93 Signed-off-by: Kevin Sawicki --- .../org/eclipse/mylyn/github/internal/Gist.java | 10 ++++------ .../mylyn/github/internal/GistRevision.java | 5 ++--- .../org/eclipse/mylyn/github/internal/Issue.java | 14 +++++--------- .../eclipse/mylyn/github/internal/Milestone.java | 9 +++------ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java index 7743443a3..a1c1bfe51 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java @@ -68,9 +68,8 @@ public Gist setPublic(boolean isPublic) { * @return createdAt */ public Date getCreatedAt() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.createdAt.getTime()); + return this.createdAt != null ? new Date(this.createdAt.getTime()) + : null; } /** @@ -160,9 +159,8 @@ public Gist setId(String id) { * @return updatedAt */ public Date getUpdatedAt() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.updatedAt.getTime()); + return this.updatedAt != null ? new Date(this.updatedAt.getTime()) + : null; } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java index 1d9e2b870..41e81fec9 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistRevision.java @@ -31,9 +31,8 @@ public class GistRevision { * @return committedAt */ public Date getCommittedAt() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.committedAt.getTime()); + return this.committedAt != null ? new Date(this.committedAt.getTime()) + : null; } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java index 80640f269..0c92c9a2f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java @@ -52,27 +52,23 @@ public class Issue { * @return closedAt */ public Date getClosedAt() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.closedAt.getTime()); + return this.closedAt != null ? new Date(this.closedAt.getTime()) : null; } /** * @return createdAt */ public Date getCreatedAt() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.createdAt.getTime()); + return this.createdAt != null ? new Date(this.createdAt.getTime()) + : null; } /** * @return updatedAt */ public Date getUpdatedAt() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.updatedAt.getTime()); + return this.updatedAt != null ? new Date(this.updatedAt.getTime()) + : null; } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java index 5024f4e97..adedd2d4a 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java @@ -43,18 +43,15 @@ public class Milestone { * @return createdAt */ public Date getCreatedAt() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.createdAt.getTime()); + return this.createdAt != null ? new Date(this.createdAt.getTime()) + : null; } /** * @return dueOn */ public Date getDueOn() { - // see EI_EXPOSE_REP at - // http://findbugs.sourceforge.net/bugDescriptions.html - return new Date(this.dueOn.getTime()); + return this.dueOn != null ? new Date(this.dueOn.getTime()) : null; } /** From ac188dc96601e23790e43b66578f46a56c755716 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 9 May 2011 16:06:28 +0200 Subject: [PATCH 162/642] Remove java nature from doc plugin The doc plugin has no sources so we can remove the java nature. Also include /images to binary build. Change-Id: I0a2ca2a27ec8f65876bbac29aef139e9e52a52ce Signed-off-by: Matthias Sohn --- org.eclipse.mylyn.github.doc/.classpath | 12 +++++------- org.eclipse.mylyn.github.doc/.project | 6 ------ org.eclipse.mylyn.github.doc/META-INF/MANIFEST.MF | 1 - org.eclipse.mylyn.github.doc/build.properties | 5 ++--- .../.settings/org.eclipse.jdt.core.prefs | 12 ------------ 5 files changed, 7 insertions(+), 29 deletions(-) delete mode 100644 org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs diff --git a/org.eclipse.mylyn.github.doc/.classpath b/org.eclipse.mylyn.github.doc/.classpath index 2d1a4302f..710b27a72 100755 --- a/org.eclipse.mylyn.github.doc/.classpath +++ b/org.eclipse.mylyn.github.doc/.classpath @@ -1,7 +1,5 @@ - - - - - - - + + + + + diff --git a/org.eclipse.mylyn.github.doc/.project b/org.eclipse.mylyn.github.doc/.project index 3790a796f..efd1c2f66 100755 --- a/org.eclipse.mylyn.github.doc/.project +++ b/org.eclipse.mylyn.github.doc/.project @@ -5,11 +5,6 @@ - - org.eclipse.jdt.core.javabuilder - - - org.eclipse.pde.ManifestBuilder @@ -23,6 +18,5 @@ org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature diff --git a/org.eclipse.mylyn.github.doc/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.doc/META-INF/MANIFEST.MF index 1e241ee33..78fd3eb71 100755 --- a/org.eclipse.mylyn.github.doc/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.doc/META-INF/MANIFEST.MF @@ -4,7 +4,6 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.mylyn.github.doc;singleton:=true Bundle-Version: 0.1.0.qualifier -Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Vendor: %providerName Require-Bundle: org.eclipse.mylyn.wikitext.core;bundle-version="[1.3.0,2.0.0)";resolution:=optional, org.eclipse.mylyn.wikitext.mediawiki.core;bundle-version="[1.3.0,2.0.0)";resolution:=optional diff --git a/org.eclipse.mylyn.github.doc/build.properties b/org.eclipse.mylyn.github.doc/build.properties index 83b4ef650..b9714b19a 100755 --- a/org.eclipse.mylyn.github.doc/build.properties +++ b/org.eclipse.mylyn.github.doc/build.properties @@ -1,7 +1,6 @@ -source.. = src/ -output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.properties,\ plugin.xml,\ - help/ + help/,\ + images/ diff --git a/org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 094b34722..000000000 --- a/org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Sun Aug 23 18:34:16 EDT 2009 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 From dce76310f81ca8f097a0260957a0fa7177775945 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 9 May 2011 17:26:46 +0200 Subject: [PATCH 163/642] Fix line endings Change-Id: I4e635bea33f18eb31846f6aa2a2ad72c90ec2171 Signed-off-by: Matthias Sohn --- .../build.properties | 6 +- .../github.target | 48 +- org.eclipse.mylyn.github.core/.project | 56 +- .../org.eclipse.core.resources.prefs | 6 +- .../.settings/org.eclipse.core.runtime.prefs | 6 +- .../.settings/org.eclipse.jdt.core.prefs | 24 +- .../build.properties | 10 +- .../internal/GitHubRepositoryConnector.java | 794 +++++++++--------- org.eclipse.mylyn.github.doc/.project | 44 +- .../.settings/org.eclipse.jdt.core.prefs | 16 +- org.eclipse.mylyn.github.doc/build.properties | 12 +- org.eclipse.mylyn.github.doc/help/book.css | 220 ++--- org.eclipse.mylyn.github.doc/pom.xml | 116 +-- .../mylyn/github/internal/CommentTest.java | 94 +-- .../github/internal/GistRevisionTest.java | 78 +- .../mylyn/github/internal/GistTest.java | 92 +- .../github/internal/GitHubClientTest.java | 54 +- .../mylyn/github/internal/IssueTest.java | 106 +-- .../mylyn/github/internal/MilestoneTest.java | 96 +-- .../internal/PullRequestServiceTest.java | 186 ++-- org.eclipse.mylyn.github.ui/.project | 56 +- .../.settings/egit-github.launch | 122 +-- .../org.eclipse.core.resources.prefs | 6 +- .../.settings/org.eclipse.core.runtime.prefs | 6 +- org.eclipse.mylyn.github.ui/build.properties | 14 +- org.eclipse.mylyn.github.ui/plugin.xml | 230 ++--- .../internal/GitHubRepositoryConnectorUI.java | 346 ++++---- 27 files changed, 1422 insertions(+), 1422 deletions(-) diff --git a/org.eclipse.mylyn.github-feature/build.properties b/org.eclipse.mylyn.github-feature/build.properties index 5f3966167..2cbd85420 100644 --- a/org.eclipse.mylyn.github-feature/build.properties +++ b/org.eclipse.mylyn.github-feature/build.properties @@ -1,3 +1,3 @@ -bin.includes = feature.xml,\ - feature.properties,\ - license.html +bin.includes = feature.xml,\ + feature.properties,\ + license.html diff --git a/org.eclipse.mylyn.github-feature/github.target b/org.eclipse.mylyn.github-feature/github.target index 185f5ae23..b654883b0 100644 --- a/org.eclipse.mylyn.github-feature/github.target +++ b/org.eclipse.mylyn.github-feature/github.target @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.mylyn.github.core/.project b/org.eclipse.mylyn.github.core/.project index 3ae827bb2..e143958d9 100644 --- a/org.eclipse.mylyn.github.core/.project +++ b/org.eclipse.mylyn.github.core/.project @@ -1,28 +1,28 @@ - - - org.eclipse.mylyn.github.core - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - + + + org.eclipse.mylyn.github.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.resources.prefs b/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.resources.prefs index 315bf27cd..82ce64e7d 100644 --- a/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.resources.prefs +++ b/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,3 @@ -#Tue Jun 09 20:22:30 CEST 2009 -eclipse.preferences.version=1 -encoding/=UTF-8 +#Tue Jun 09 20:22:30 CEST 2009 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.runtime.prefs index 5b9dcff1e..94514501b 100644 --- a/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.runtime.prefs +++ b/org.eclipse.mylyn.github.core/.settings/org.eclipse.core.runtime.prefs @@ -1,3 +1,3 @@ -#Tue Jun 09 20:22:30 CEST 2009 -eclipse.preferences.version=1 -line.separator=\n +#Tue Jun 09 20:22:30 CEST 2009 +eclipse.preferences.version=1 +line.separator=\n diff --git a/org.eclipse.mylyn.github.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.github.core/.settings/org.eclipse.jdt.core.prefs index 1d6b3c182..8b0622bf7 100644 --- a/org.eclipse.mylyn.github.core/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.mylyn.github.core/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,12 @@ -#Fri Jul 30 10:22:35 CEST 2010 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 +#Fri Jul 30 10:22:35 CEST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/org.eclipse.mylyn.github.core/build.properties b/org.eclipse.mylyn.github.core/build.properties index f4ae97015..aa1a00826 100644 --- a/org.eclipse.mylyn.github.core/build.properties +++ b/org.eclipse.mylyn.github.core/build.properties @@ -1,5 +1,5 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.properties +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java index 5a7a6f293..2757f1a00 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java @@ -1,397 +1,397 @@ -/******************************************************************************* - * Copyright (c) 2011 Red Hat 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: - * David Green - initial contribution - * Christian Trutz - initial contribution - * Chris Aniszczyk - initial contribution - *******************************************************************************/ -package org.eclipse.mylyn.github.internal; - -import java.io.IOException; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.eclipse.core.runtime.Assert; -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.commons.net.Policy; -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.TaskAttribute; -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; - -/** - * GitHub connector. - */ -public class GitHubRepositoryConnector extends AbstractRepositoryConnector { - - /** - * GitHub kind. - */ - public static final String KIND = GitHub.CONNECTOR_KIND; - - /** - * Create client for repository - * - * @param repository - * @return client - */ - public static 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; - } - - /** - * GitHub specific {@link AbstractTaskDataHandler}. - */ - private final GitHubTaskDataHandler taskDataHandler; - - private final Map> repositoryLabels = Collections - .synchronizedMap(new HashMap>()); - - private final Map> repositoryMilestones = Collections - .synchronizedMap(new HashMap>()); - - /** - * Create GitHub issue repository connector - */ - public GitHubRepositoryConnector() { - taskDataHandler = new GitHubTaskDataHandler(this); - } - - /** - * Refresh labels for repository - * - * @param repository - * @return labels - * @throws CoreException - */ - public List - org.sonatype.tycho + org.eclipse.tycho tycho-maven-plugin ${tycho-version} true - org.sonatype.tycho + org.eclipse.tycho target-platform-configuration ${tycho-version} @@ -110,7 +114,7 @@ - org.sonatype.tycho + org.eclipse.tycho maven-osgi-compiler-plugin ${tycho-version} @@ -126,7 +130,7 @@ - org.sonatype.tycho + org.eclipse.tycho target-platform-configuration ${tycho-version} From e58c0ccc5cf5da2628fc9921a239cc29d3cac1c1 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Tue, 10 May 2011 16:27:16 -0500 Subject: [PATCH 169/642] Reverts work for using Tycho 0.12 Tycho has issues running UI tests. Change-Id: Iac92759109a326fffe794de9d4b5652b1d610dff Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github.tests/pom.xml | 2 +- pom.xml | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/org.eclipse.mylyn.github.tests/pom.xml b/org.eclipse.mylyn.github.tests/pom.xml index f63f6c20e..8cddc4043 100644 --- a/org.eclipse.mylyn.github.tests/pom.xml +++ b/org.eclipse.mylyn.github.tests/pom.xml @@ -27,7 +27,7 @@ - org.eclipse.tycho + org.sonatype.tycho maven-osgi-test-plugin ${tycho-version} diff --git a/pom.xml b/pom.xml index b486168ef..ae830639d 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ - 0.12.0 + 0.11.0 file:/${basedir}/../../egit/org.eclipse.egit-updatesite/target/site indigo http://download.eclipse.org/tools/mylyn/update/weekly @@ -88,22 +88,18 @@ codehaus.snapshots http://snapshots.repository.codehaus.org/ - - tycho-snapshot - https://repository.sonatype.org/content/repositories/tycho-014/ - - org.eclipse.tycho + org.sonatype.tycho tycho-maven-plugin ${tycho-version} true - org.eclipse.tycho + org.sonatype.tycho target-platform-configuration ${tycho-version} @@ -114,7 +110,7 @@ - org.eclipse.tycho + org.sonatype.tycho maven-osgi-compiler-plugin ${tycho-version} @@ -130,7 +126,7 @@ - org.eclipse.tycho + org.sonatype.tycho target-platform-configuration ${tycho-version} From 87e52a84cf770fe3ea0354e7a0b8b6218fa4a601 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Tue, 10 May 2011 17:53:24 -0500 Subject: [PATCH 170/642] Use findbugs-maven-plugin 2.3.2 Change-Id: Ibab1308e2f37e46db763f77db9ea9306c1547fb0 Signed-off-by: Chris Aniszczyk --- pom.xml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index ae830639d..608f92970 100644 --- a/pom.xml +++ b/pom.xml @@ -80,16 +80,6 @@ - - - - codehaus.snapshots - http://snapshots.repository.codehaus.org/ - - - @@ -137,7 +127,7 @@ org.codehaus.mojo findbugs-maven-plugin - 2.3.2-SNAPSHOT + 2.3.2 true false From 579592646e39afaf1872259a4b81bd1c17730291 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 10 May 2011 16:03:40 -0700 Subject: [PATCH 171/642] Use proper type when loading repositories Bug: 345346 Change-Id: I682bd0e682b7673966a038b524864fdafcc633c5 Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../org/eclipse/mylyn/github/internal/RepositoryService.java | 2 ++ .../mylyn/github/ui/internal/RepositorySelectionWizardPage.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java index 6c3c9871b..29df41e1a 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java @@ -46,6 +46,7 @@ public List getOrganizationRepositories() throws IOException { PagedRequest request = new PagedRequest( collector); request.setUri(uri); + request.setType(RepositoryContainer.class); getAll(request); return collector.getResources(); } @@ -66,6 +67,7 @@ public List getRepositories(String user) throws IOException { PagedRequest request = new PagedRequest( collector); request.setUri(uri); + request.setType(RepositoryContainer.class); getAll(request); return collector.getResources(); } diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java index af9da75ae..b67870f72 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java @@ -173,6 +173,8 @@ private void updateSelectionLabel() { private void validatePage() { setPageComplete(getRepositories().length > 0 || createGistRepository()); + if (isPageComplete()) + setErrorMessage(null); } private void updateInput(final List repos) { From 31e119034516c7674964a6c7c87fedefd57376b8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 10 May 2011 16:08:42 -0700 Subject: [PATCH 172/642] Support new field error objects and null field requirements Bug: 345341 Change-Id: Ie4cc6c20a33fbf91fbeab1c92c4196ac8e99fb2e Signed-off-by: Kevin Sawicki Signed-off-by: Chris Aniszczyk --- .../mylyn/github/internal/FieldError.java | 97 +++++++++++++++++++ .../mylyn/github/internal/GistService.java | 18 ++-- .../mylyn/github/internal/GitHubClient.java | 19 ++-- .../internal/GitHubTaskDataHandler.java | 2 + .../github/internal/IGitHubConstants.java | 5 - .../mylyn/github/internal/IssueService.java | 34 +++---- .../mylyn/github/internal/LabelService.java | 15 ++- .../mylyn/github/internal/Messages.java | 12 +++ .../github/internal/MilestoneService.java | 3 +- .../mylyn/github/internal/RequestError.java | 8 +- .../github/internal/RequestException.java | 16 ++- .../mylyn/github/internal/messages.properties | 4 + .../github/internal/GistServiceTest.java | 10 +- .../github/internal/IssueServiceTest.java | 12 +-- .../github/internal/LabelServiceTest.java | 8 +- 15 files changed, 189 insertions(+), 74 deletions(-) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/FieldError.java diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/FieldError.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/FieldError.java new file mode 100644 index 000000000..6e38c7758 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/FieldError.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * 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.github.internal; + +import java.text.MessageFormat; + +/** + * Field error + */ +public class FieldError { + + /** + * CODE_INVALID + */ + public static final String CODE_INVALID = "invalid"; //$NON-NLS-1$ + + /** + * CODE_MISSING + */ + public static final String CODE_MISSING = "missing"; //$NON-NLS-1$ + + /** + * CODE_MISSING_FIELD + */ + public static final String CODE_MISSING_FIELD = "missing_field"; //$NON-NLS-1$ + + /** + * CODE_ALREADY_EXISTS + */ + public static final String CODE_ALREADY_EXISTS = "already_exists"; //$NON-NLS-1$ + + private String code; + + private String field; + + private String resource; + + private String value; + + /** + * @return code + */ + public String getCode() { + return this.code; + } + + /** + * @return field + */ + public String getField() { + return this.field; + } + + /** + * @return resource + */ + public String getResource() { + return this.resource; + } + + /** + * @return value + */ + public String getValue() { + return this.value; + } + + /** + * Format into human-readable error message + * + * @return error + */ + public String format() { + if (CODE_INVALID.equals(code)) + if (value != null) + return MessageFormat + .format(Messages.FieldError_InvalidFieldWithValue, + value, field); + else + return MessageFormat.format(Messages.FieldError_InvalidField, + field, value); + else if (CODE_MISSING_FIELD.equals(code)) + return MessageFormat + .format(Messages.FieldError_MissingField, field); + else + return MessageFormat.format(Messages.FieldError_ResourceError, + field, resource); + } +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java index 7ed5925c4..31ade3366 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java @@ -43,7 +43,7 @@ public GistService(GitHubClient client) { public Gist getGist(String id) throws IOException { Assert.isNotNull(id, "Gist id cannot be null"); StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS); - uri.append('/').append(id).append(IGitHubConstants.SUFFIX_JSON); + uri.append('/').append(id); GitHubRequest request = new GitHubRequest(); request.setUri(uri); request.setType(Gist.class); @@ -61,8 +61,7 @@ public List getGists(String user) throws IOException { Assert.isNotNull(user, "User cannot be null"); StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_USERS); uri.append('/').append(user); - uri.append(IGitHubConstants.SEGMENT_GISTS).append( - IGitHubConstants.SUFFIX_JSON); + uri.append(IGitHubConstants.SEGMENT_GISTS); ListResourceCollector collector = new ListResourceCollector(); PagedRequest request = new PagedRequest(collector); request.setUri(uri).setType(new TypeToken>() { @@ -88,8 +87,7 @@ public Gist createGist(Gist gist) throws IOException { uri.append(IGitHubConstants.SEGMENT_USERS); uri.append('/').append(login); } - uri.append(IGitHubConstants.SEGMENT_GISTS).append( - IGitHubConstants.SUFFIX_JSON); + uri.append(IGitHubConstants.SEGMENT_GISTS); return this.client.post(uri.toString(), gist, Gist.class); } @@ -105,8 +103,8 @@ public Gist updateGist(Gist gist) throws IOException { String id = gist.getId(); Assert.isNotNull(id, "Gist id cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS); - uri.append('/').append(id).append(IGitHubConstants.SUFFIX_JSON); - return this.client.put(uri.toString(), gist, Gist.class); + uri.append('/').append(id); + return this.client.post(uri.toString(), gist, Gist.class); } /** @@ -123,8 +121,7 @@ public Comment createComment(String gistId, String comment) Assert.isNotNull(comment, "Gist comment cannot be null"); StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS); uri.append('/').append(gistId); - uri.append(IGitHubConstants.SEGMENT_COMMENTS).append( - IGitHubConstants.SUFFIX_JSON); + uri.append(IGitHubConstants.SEGMENT_COMMENTS); Map params = new HashMap(1, 1); params.put(IssueService.FIELD_BODY, comment); @@ -142,8 +139,7 @@ public List getComments(String gistId) throws IOException { Assert.isNotNull(gistId, "Gist id cannot be null"); StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS); uri.append('/').append(gistId); - uri.append(IGitHubConstants.SEGMENT_COMMENTS).append( - IGitHubConstants.SUFFIX_JSON); + uri.append(IGitHubConstants.SEGMENT_COMMENTS); ListResourceCollector collector = new ListResourceCollector(); PagedRequest request = new PagedRequest(collector); request.setUri(uri).setType(new TypeToken>() { diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java index ad5cd005e..cc35e9834 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java @@ -10,6 +10,11 @@ *******************************************************************************/ package org.eclipse.mylyn.github.internal; +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -35,11 +40,6 @@ import org.apache.commons.httpclient.protocol.Protocol; import org.eclipse.core.runtime.Assert; -import com.google.gson.FieldNamingPolicy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; - /** * Client class for interacting with GitHub HTTP/JSON API. */ @@ -58,7 +58,7 @@ public class GitHubClient { private Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new DateFormatter()) .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) - .create(); + .serializeNulls().create(); private boolean sendCredentials = false; @@ -162,7 +162,12 @@ protected V parseJson(HttpMethodBase method, Type type) if (stream == null) throw new JsonParseException("Empty body"); //$NON-NLS-1$ InputStreamReader reader = new InputStreamReader(stream); - return this.gson.fromJson(reader, type); + try { + return this.gson.fromJson(reader, type); + } catch (JsonParseException jpe) { + jpe.printStackTrace(); + throw new IOException(jpe); + } } /** diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java index fb7d64926..4cd1d26af 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java @@ -229,6 +229,8 @@ private Issue createIssue(TaskData taskData) { String assigneeValue = getAttributeValue(taskData, GitHubTaskAttributes.ASSIGNEE); if (assigneeValue != null) { + if (assigneeValue.trim().length() == 0) + assigneeValue = null; User assignee = new User().setName(assigneeValue); issue.setAssignee(assignee); } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java index 99cc89ecb..a084d2c7d 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java @@ -75,11 +75,6 @@ public interface IGitHubConstants { */ String SEGMENT_V2_API = "/api/v2/json"; //$NON-NLS-1$ - /** - * SUFFIX_JSON - */ - String SUFFIX_JSON = ".json"; //$NON-NLS-1$ - /** * HOST_API */ diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java index b3ceb1e99..e203eeb79 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java @@ -100,7 +100,7 @@ public Issue getIssue(String user, String repository, String id) IGitHubConstants.SEGMENT_REPOS); builder.append('/').append(user).append('/').append(repository); builder.append(IGitHubConstants.SEGMENT_ISSUES); - builder.append('/').append(id).append(IGitHubConstants.SUFFIX_JSON); + builder.append('/').append(id); GitHubRequest request = new GitHubRequest(); request.setUri(builder.toString()); request.setType(Issue.class); @@ -126,8 +126,7 @@ public List getComments(String user, String repository, String id) builder.append('/').append(user).append('/').append(repository); builder.append(IGitHubConstants.SEGMENT_ISSUES); builder.append('/').append(id); - builder.append(IGitHubConstants.SEGMENT_COMMENTS).append( - IGitHubConstants.SUFFIX_JSON); + builder.append(IGitHubConstants.SEGMENT_COMMENTS); ListResourceCollector collector = new ListResourceCollector(); PagedRequest request = new PagedRequest(collector); request.setUri(builder.toString()).setType( @@ -153,8 +152,7 @@ public List getIssues(String user, String repository, StringBuilder builder = new StringBuilder( IGitHubConstants.SEGMENT_REPOS); builder.append('/').append(user).append('/').append(repository); - builder.append(IGitHubConstants.SEGMENT_ISSUES).append( - IGitHubConstants.SUFFIX_JSON); + builder.append(IGitHubConstants.SEGMENT_ISSUES); ListResourceCollector collector = new ListResourceCollector(); PagedRequest request = new PagedRequest(collector); request.setParams(filterData).setUri(builder.toString()); @@ -168,15 +166,16 @@ public List getIssues(String user, String repository, * Create issue map for issue * * @param issue + * @param newIssue * @return map */ - protected Map createIssueMap(Issue issue) { + protected Map createIssueMap(Issue issue, boolean newIssue) { Map params = new HashMap(); if (issue != null) { params.put(FIELD_BODY, issue.getBody()); params.put(FIELD_TITLE, issue.getTitle()); User assignee = issue.getAssignee(); - if (assignee != null) + if (assignee != null && !newIssue) params.put(FILTER_ASSIGNEE, assignee.getName()); Milestone milestone = issue.getMilestone(); @@ -184,8 +183,10 @@ protected Map createIssueMap(Issue issue) { int number = milestone.getNumber(); if (number > 0) params.put(FILTER_MILESTONE, Integer.toString(number)); - else - params.put(FILTER_MILESTONE, ""); //$NON-NLS-1$ + else { + if (!newIssue) + params.put(FILTER_MILESTONE, null); + } } } return params; @@ -206,10 +207,9 @@ public Issue createIssue(String user, String repository, Issue issue) Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS); uri.append('/').append(user).append('/').append(repository); - uri.append(IGitHubConstants.SEGMENT_ISSUES).append( - IGitHubConstants.SUFFIX_JSON); + uri.append(IGitHubConstants.SEGMENT_ISSUES); - Map params = createIssueMap(issue); + Map params = createIssueMap(issue, true); return this.client.post(uri.toString(), params, Issue.class); } @@ -230,15 +230,14 @@ public Issue editIssue(String user, String repository, Issue issue) StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS); uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES); - uri.append('/').append(issue.getNumber()) - .append(IGitHubConstants.SUFFIX_JSON); + uri.append('/').append(issue.getNumber()); - Map params = createIssueMap(issue); + Map params = createIssueMap(issue, false); String state = issue.getState(); if (state != null) { params.put(FILTER_STATE, state); } - return this.client.put(uri.toString(), params, Issue.class); + return this.client.post(uri.toString(), params, Issue.class); } /** @@ -260,8 +259,7 @@ public Comment createComment(String user, String repository, uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES); uri.append('/').append(issueId); - uri.append(IGitHubConstants.SEGMENT_COMMENTS).append( - IGitHubConstants.SUFFIX_JSON); + uri.append(IGitHubConstants.SEGMENT_COMMENTS); Map params = new HashMap(1, 1); params.put(FIELD_BODY, comment); diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java index f1e5ceed8..876afd333 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java @@ -46,8 +46,7 @@ public List + org.eclipse.egit.github.core org.eclipse.mylyn.github.core org.eclipse.mylyn.github.ui org.eclipse.mylyn.github-feature - org.eclipse.mylyn.github.tests + org.eclipse.egit.github.core.tests + org.eclipse.mylyn.github-site org.eclipse.mylyn.github.doc From 8d67bad3b63edd9b4ac99c1af7f69041715b7c59 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Thu, 12 May 2011 16:15:16 +0200 Subject: [PATCH 174/642] Unit tests cleanup. Change-Id: I7b2b0b29824a1cc2354eda9a23d67228810833da Signed-off-by: Christian Trutz --- .../org/eclipse/egit/github/core/tests/CommentTest.java | 1 - .../eclipse/egit/github/core/tests/GistRevisionTest.java | 1 - .../eclipse/egit/github/core/tests/GistServiceTest.java | 7 ------- .../src/org/eclipse/egit/github/core/tests/GistTest.java | 1 - .../eclipse/egit/github/core/tests/GitHubClientTest.java | 1 - .../eclipse/egit/github/core/tests/IssueServiceTest.java | 1 - .../org/eclipse/egit/github/core/tests/IssueTest.java | 1 - .../eclipse/egit/github/core/tests/LabelServiceTest.java | 3 --- .../egit/github/core/tests/MilestoneServiceTest.java | 9 --------- .../eclipse/egit/github/core/tests/MilestoneTest.java | 1 - .../egit/github/core/tests/PullRequestServiceTest.java | 1 - 11 files changed, 27 deletions(-) mode change 100755 => 100644 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java mode change 100755 => 100644 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java mode change 100755 => 100644 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java mode change 100755 => 100644 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java mode change 100755 => 100644 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java mode change 100755 => 100644 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneTest.java mode change 100755 => 100644 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java old mode 100755 new mode 100644 index eddc8d967..3b6c6a3e0 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java @@ -23,7 +23,6 @@ /** * Unit tests for {@link Comment} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class CommentTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java old mode 100755 new mode 100644 index facc6e42d..ec129b0cb --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java @@ -23,7 +23,6 @@ /** * Unit tests for {@link GistRevision} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class GistRevisionTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java index d3b158bb3..830130227 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java @@ -14,11 +14,8 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -import com.google.gson.reflect.TypeToken; - import java.io.IOException; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.egit.github.core.Comment; @@ -38,7 +35,6 @@ /** * Unit tests for {@link GistService} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class GistServiceTest { @@ -162,9 +158,6 @@ public void getComments_NullGistId() throws IOException { @Test public void getComments_OK() throws IOException { gistService.getComments("1"); - - TypeToken> commentsToken = new TypeToken>() { - }; verify(gitHubClient).get(any(GitHubRequest.class)); } } diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java old mode 100755 new mode 100644 index ef12103da..957ac959e --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java @@ -23,7 +23,6 @@ /** * Unit tests for {@link Gist} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class GistTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java old mode 100755 new mode 100644 index 2354b1e59..296a95b76 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java @@ -15,7 +15,6 @@ import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class GitHubClientTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java index 1fb1dce26..a35c219f8 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java @@ -33,7 +33,6 @@ /** * Unit tests for {@link IssueService} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class IssueServiceTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java old mode 100755 new mode 100644 index 9b27e7013..53e2114be --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java @@ -23,7 +23,6 @@ /** * Unit tests for {@link Issue} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class IssueTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java index e18393477..9851f4fd7 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java @@ -34,7 +34,6 @@ /** * Unit tests for {@link LabelService}. */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class LabelServiceTest { @@ -70,8 +69,6 @@ public void getLabels_NullRepository() throws IOException { @Test public void getLabels_OK() throws IOException { labelService.getLabels("test_user", "test_repository"); - TypeToken> labelsToken = new TypeToken>() { - }; verify(gitHubClient).get(any(GitHubRequest.class)); } diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneServiceTest.java index 473293252..0b2de43e7 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneServiceTest.java @@ -14,12 +14,8 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -import com.google.gson.reflect.TypeToken; - import java.io.IOException; -import java.util.List; -import org.eclipse.egit.github.core.Milestone; import org.eclipse.egit.github.core.client.GitHubClient; import org.eclipse.egit.github.core.client.GitHubRequest; import org.eclipse.egit.github.core.client.GitHubResponse; @@ -33,7 +29,6 @@ /** * Unit tests for {@link MilestoneService} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class MilestoneServiceTest { @@ -69,8 +64,6 @@ public void getMilestones_NullRepository() throws IOException { @Test public void getMilestones_NullState() throws IOException { milestoneService.getMilestones("test_user", "test_repository", null); - TypeToken> milestonesToken = new TypeToken>() { - }; verify(gitHubClient).get(any(GitHubRequest.class)); } @@ -78,8 +71,6 @@ public void getMilestones_NullState() throws IOException { public void getMilestones_OK() throws IOException { milestoneService.getMilestones("test_user", "test_repository", "test_state"); - TypeToken> milestonesToken = new TypeToken>() { - }; verify(gitHubClient).get(any(GitHubRequest.class)); } diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneTest.java old mode 100755 new mode 100644 index 372e570e2..4a8f64473 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/MilestoneTest.java @@ -23,7 +23,6 @@ /** * Unit tests for {@link Milestone} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class MilestoneTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java old mode 100755 new mode 100644 index 088778f2f..3d65b0826 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java @@ -27,7 +27,6 @@ /** * Tests for {@link PullRequestServiceTest} */ -@SuppressWarnings("restriction") @RunWith(MockitoJUnitRunner.class) public class PullRequestServiceTest { From 675f6e47212164c49f9d81bf8d00702ea4d3b38a Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Thu, 12 May 2011 22:25:08 +0200 Subject: [PATCH 175/642] Unit tests for PullRequest. Change-Id: Iee8529a027a9fea91de5dda8ee5a1dc71098289a Signed-off-by: Christian Trutz --- .../core/tests/PullRequestServiceTest.java | 2 +- .../github/core/tests/PullRequestTest.java | 77 +++++++++++++++++++ .../eclipse/egit/github/core/PullRequest.java | 16 ++-- 3 files changed, 88 insertions(+), 7 deletions(-) create mode 100755 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java index 3d65b0826..5434871b7 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestServiceTest.java @@ -25,7 +25,7 @@ import org.mockito.runners.MockitoJUnitRunner; /** - * Tests for {@link PullRequestServiceTest} + * Tests for {@link PullRequestService} */ @RunWith(MockitoJUnitRunner.class) public class PullRequestServiceTest { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java new file mode 100755 index 000000000..0cf7000a5 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestTest.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertTrue; + +import org.eclipse.egit.github.core.PullRequest; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Tests for {@link PullRequest} + */ +public class PullRequestTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + PullRequest pullRequest = gson.fromJson("{createdAt : '2003-10-10'}", + PullRequest.class); + pullRequest.getCreatedAt().setTime(0); + assertTrue(pullRequest.getCreatedAt().getTime() != 0); + } + + @Test + public void getIssueCreatedAt_ReferenceMutableObject() { + PullRequest pullRequest = gson.fromJson( + "{issueCreatedAt : '2003-10-10'}", PullRequest.class); + pullRequest.getIssueCreatedAt().setTime(0); + assertTrue(pullRequest.getIssueCreatedAt().getTime() != 0); + } + + @Test + public void getIssueUpdatedAt_ReferenceMutableObject() { + PullRequest pullRequest = gson.fromJson( + "{issueUpdatedAt : '2003-10-10'}", PullRequest.class); + pullRequest.getIssueUpdatedAt().setTime(0); + assertTrue(pullRequest.getIssueUpdatedAt().getTime() != 0); + } + + @Test + public void getMergedAt_ReferenceMutableObject() { + PullRequest pullRequest = gson.fromJson("{mergedAt : '2003-10-10'}", + PullRequest.class); + pullRequest.getMergedAt().setTime(0); + assertTrue(pullRequest.getMergedAt().getTime() != 0); + } + + @Test + public void getUpdatedAt_ReferenceMutableObject() { + PullRequest pullRequest = gson.fromJson("{updatedAt : '2003-10-10'}", + PullRequest.class); + pullRequest.getUpdatedAt().setTime(0); + assertTrue(pullRequest.getUpdatedAt().getTime() != 0); + } + + @Test + public void getClosedAt_ReferenceMutableObject() { + PullRequest pullRequest = gson.fromJson("{closedAt : '2003-10-10'}", + PullRequest.class); + pullRequest.getClosedAt().setTime(0); + assertTrue(pullRequest.getClosedAt().getTime() != 0); + } + +} diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java index 3fa651859..a42fbe3b1 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequest.java @@ -51,42 +51,46 @@ public class PullRequest { * @return closedAt */ public Date getClosedAt() { - return this.closedAt; + return this.closedAt != null ? new Date(this.closedAt.getTime()) : null; } /** * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + return this.createdAt != null ? new Date(this.createdAt.getTime()) + : null; } /** * @return issueCreatedAt */ public Date getIssueCreatedAt() { - return this.issueCreatedAt; + return this.issueCreatedAt != null ? new Date( + this.issueCreatedAt.getTime()) : null; } /** * @return issueUpdatedAt */ public Date getIssueUpdatedAt() { - return this.issueUpdatedAt; + return this.issueUpdatedAt != null ? new Date( + this.issueUpdatedAt.getTime()) : null; } /** * @return mergedAt */ public Date getMergedAt() { - return this.mergedAt; + return this.mergedAt != null ? new Date(this.mergedAt.getTime()) : null; } /** * @return updatedAt */ public Date getUpdatedAt() { - return this.updatedAt; + return this.updatedAt != null ? new Date(this.updatedAt.getTime()) + : null; } /** From ed34e491f53478844b88f61f4313168db586d78f Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Thu, 12 May 2011 22:52:18 +0200 Subject: [PATCH 176/642] Unit tests for Repository. Change-Id: I770a575c60f9a51d94210d02eb6e3816fb04c051 Signed-off-by: Christian Trutz --- .../github/core/tests/RepositoryTest.java | 45 +++++++++++++++++++ .../eclipse/egit/github/core/Repository.java | 9 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java new file mode 100755 index 000000000..e0feb281b --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertTrue; + +import org.eclipse.egit.github.core.Repository; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Tests for {@link Repository}. + */ +public class RepositoryTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + Repository repository = gson.fromJson("{createdAt : '2003-10-10'}", + Repository.class); + repository.getCreatedAt().setTime(0); + assertTrue(repository.getCreatedAt().getTime() != 0); + } + + @Test + public void getPushedAt_ReferenceMutableObject() { + Repository repository = gson.fromJson("{pushedAt : '2003-10-10'}", + Repository.class); + repository.getPushedAt().setTime(0); + assertTrue(repository.getPushedAt().getTime() != 0); + } + +} diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java index badf17603..7ea72d5db 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java @@ -10,12 +10,12 @@ *******************************************************************************/ package org.eclipse.egit.github.core; -import com.google.gson.annotations.SerializedName; - import java.net.MalformedURLException; import java.net.URL; import java.util.Date; +import com.google.gson.annotations.SerializedName; + /** * GitHub Repository class. */ @@ -207,14 +207,15 @@ public boolean isPrivate() { * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + return this.createdAt != null ? new Date(this.createdAt.getTime()) + : null; } /** * @return pushedAt */ public Date getPushedAt() { - return this.pushedAt; + return this.pushedAt != null ? new Date(this.pushedAt.getTime()) : null; } /** From 27eee5bce42e0bc35a19ca8892fd0e7454262ddc Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Thu, 12 May 2011 23:08:27 +0200 Subject: [PATCH 177/642] Unit tests for PullRequestDiscussion. Change-Id: I44b76785b2cb7ccdaac94ca5459e8ee072ec8fa8 Signed-off-by: Christian Trutz --- .../github/core/tests/AllHeadlessTests.java | 7 ++- .../core/tests/PullRequestDiscussionTest.java | 61 +++++++++++++++++++ .../github/core/PullRequestDiscussion.java | 12 ++-- 3 files changed, 73 insertions(+), 7 deletions(-) create mode 100755 org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestDiscussionTest.java diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java index 54aaaaf47..2410d63c9 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java @@ -28,9 +28,10 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ CommentTest.class, GistTest.class, GistRevisionTest.class, - IssueTest.class, MilestoneTest.class, GitHubClientTest.class, - IssueServiceTest.class, LabelServiceTest.class, +@SuiteClasses({ PullRequestDiscussionTest.class, RepositoryTest.class, + PullRequestTest.class, CommentTest.class, GistTest.class, + GistRevisionTest.class, IssueTest.class, MilestoneTest.class, + GitHubClientTest.class, IssueServiceTest.class, LabelServiceTest.class, MilestoneServiceTest.class, GistServiceTest.class, PullRequestServiceTest.class }) public class AllHeadlessTests { diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestDiscussionTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestDiscussionTest.java new file mode 100755 index 000000000..34ba40c17 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/PullRequestDiscussionTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * 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: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertTrue; + +import org.eclipse.egit.github.core.PullRequestDiscussion; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Tests for {@link PullRequestDiscussion} + */ +public class PullRequestDiscussionTest { + + private static final Gson gson = new GsonBuilder().setDateFormat( + "yyyy-MM-dd").create(); + + @Test + public void getCreatedAt_ReferenceMutableObject() { + PullRequestDiscussion pullRequestDiscussion = gson.fromJson( + "{createdAt : '2003-10-10'}", PullRequestDiscussion.class); + pullRequestDiscussion.getCreatedAt().setTime(0); + assertTrue(pullRequestDiscussion.getCreatedAt().getTime() != 0); + } + + @Test + public void getUpdatedAt_ReferenceMutableObject() { + PullRequestDiscussion pullRequestDiscussion = gson.fromJson( + "{updatedAt : '2003-10-10'}", PullRequestDiscussion.class); + pullRequestDiscussion.getUpdatedAt().setTime(0); + assertTrue(pullRequestDiscussion.getUpdatedAt().getTime() != 0); + } + + @Test + public void getCommitedDate_ReferenceMutableObject() { + PullRequestDiscussion pullRequestDiscussion = gson.fromJson( + "{commitedDate : '2003-10-10'}", PullRequestDiscussion.class); + pullRequestDiscussion.getCommitedDate().setTime(0); + assertTrue(pullRequestDiscussion.getCommitedDate().getTime() != 0); + } + + @Test + public void getAuthoredDate_ReferenceMutableObject() { + PullRequestDiscussion pullRequestDiscussion = gson.fromJson( + "{authoredDate : '2003-10-10'}", PullRequestDiscussion.class); + pullRequestDiscussion.getAuthoredDate().setTime(0); + assertTrue(pullRequestDiscussion.getAuthoredDate().getTime() != 0); + } + +} diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequestDiscussion.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequestDiscussion.java index 6581c4250..eee46cd56 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequestDiscussion.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/PullRequestDiscussion.java @@ -56,28 +56,32 @@ public class PullRequestDiscussion { * @return authoredDate */ public Date getAuthoredDate() { - return this.authoredDate; + return this.authoredDate != null ? new Date(this.authoredDate.getTime()) + : null; } /** * @return commitedDate */ public Date getCommitedDate() { - return this.commitedDate; + return this.commitedDate != null ? new Date(this.commitedDate.getTime()) + : null; } /** * @return createdAt */ public Date getCreatedAt() { - return this.createdAt; + return this.createdAt != null ? new Date(this.createdAt.getTime()) + : null; } /** * @return updatedAt */ public Date getUpdatedAt() { - return this.updatedAt; + return this.updatedAt != null ? new Date(this.updatedAt.getTime()) + : null; } /** From eefbffdc758cd694c8e4c6c6c49ce62550e00b88 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Tue, 10 May 2011 22:01:35 +0200 Subject: [PATCH 178/642] Using HttpComponents 4.1 CQ: 5162 Change-Id: I8c251fc40b97edc414bf9e210320341ea74bf281 Signed-off-by: Christian Trutz Signed-off-by: Matthias Sohn --- .../github.target | 6 + .../META-INF/MANIFEST.MF | 3 +- .../.settings/egit-github.launch | 122 +++++++++--------- 3 files changed, 69 insertions(+), 62 deletions(-) diff --git a/org.eclipse.mylyn.github-feature/github.target b/org.eclipse.mylyn.github-feature/github.target index b654883b0..cbe58687b 100644 --- a/org.eclipse.mylyn.github-feature/github.target +++ b/org.eclipse.mylyn.github-feature/github.target @@ -9,6 +9,7 @@ + @@ -19,6 +20,11 @@ + + + + + diff --git a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF index 1721cbc71..f01e6266c 100644 --- a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF @@ -8,7 +8,8 @@ Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: org.eclipse.mylyn.github.internal;x-friends:="org.eclipse.mylyn.github.ui", org.eclipse.mylyn.internal.github.core.gist;x-friends:="org.eclipse.mylyn.github.ui" -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", +Require-Bundle: org.apache.httpcomponents.httpclient;bundle-version="4.1.0", + org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.mylyn.tasks.core;bundle-version="3.2.0", org.eclipse.mylyn.commons.net;bundle-version="3.2.0", org.eclipse.egit.github.core;bundle-version="0.1.0" diff --git a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch index f4771c0d7..3b9f3c217 100644 --- a/org.eclipse.mylyn.github.ui/.settings/egit-github.launch +++ b/org.eclipse.mylyn.github.ui/.settings/egit-github.launch @@ -1,61 +1,61 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 455d98c75c285abe3c4c020de75816f248f4c6da Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 May 2011 18:43:28 -0700 Subject: [PATCH 179/642] Remove httpcomponents dependency from mylyn core plug-in. All HTTP dependencies are now in the github core plug-in Change-Id: Ifb4b58ea0048a593eba3fdebd11143b22ea4bac3 Signed-off-by: Kevin Sawicki --- org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF index f01e6266c..1721cbc71 100644 --- a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF @@ -8,8 +8,7 @@ Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: org.eclipse.mylyn.github.internal;x-friends:="org.eclipse.mylyn.github.ui", org.eclipse.mylyn.internal.github.core.gist;x-friends:="org.eclipse.mylyn.github.ui" -Require-Bundle: org.apache.httpcomponents.httpclient;bundle-version="4.1.0", - org.eclipse.core.runtime;bundle-version="3.5.0", +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.mylyn.tasks.core;bundle-version="3.2.0", org.eclipse.mylyn.commons.net;bundle-version="3.2.0", org.eclipse.egit.github.core;bundle-version="0.1.0" From 6cb1424c1b03c4519e3ae7b59b58e64bd4ad04d8 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 14 May 2011 17:56:39 -0500 Subject: [PATCH 180/642] Add build-server profile to enable signing Signed-off-by: Chris Aniszczyk --- pom.xml | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/pom.xml b/pom.xml index 7ad3f689b..3d370d185 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,13 @@ + + + maven.eclipse.org + http://maven.eclipse.org/nexus/content/repositories/nightly-indigo + + + @@ -208,5 +215,81 @@ + + build-server + + + + org.eclipse.dash.m4e + eclipse-signing-maven-plugin + 1.0-SNAPSHOT + + + pack + package + + pack + + + + sign + + /home/data/httpd/download-staging.priv/egit-github + + package + + sign + + + + repack + + ${project.build.directory}/signed/site_assembly.zip + + package + + pack + + + + fixCheckSums + package + + fixCheckSums + + + + + + maven-antrun-plugin + + + deploy + install + + run + + + + + + + + + + + + + + + + + + + + + From b3032391abce23473703e83446f5edd27d89812c Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 14 May 2011 18:04:12 -0500 Subject: [PATCH 181/642] Fix build-server profile entry Signed-off-by: Chris Aniszczyk --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3d370d185..85d15baab 100644 --- a/pom.xml +++ b/pom.xml @@ -220,9 +220,9 @@ - org.eclipse.dash.m4e - eclipse-signing-maven-plugin - 1.0-SNAPSHOT + org.eclipse.dash.maven + eclipse-maven-signing-plugin + 1.0.0.0-SNAPSHOT pack From ff1ef4f75e17cedf7677375380eb7bc05a16d860 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 14 May 2011 18:16:20 -0500 Subject: [PATCH 182/642] Fix build-server profile entry, again. Signed-off-by: Chris Aniszczyk --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 85d15baab..1c8c798c4 100644 --- a/pom.xml +++ b/pom.xml @@ -244,7 +244,7 @@ repack - ${project.build.directory}/signed/site_assembly.zip + ${project.build.directory}/org.eclipse.mylyn.github-site/target/github-updatesite.zip package From 97d7c0dee3844e0826c049c3ef40f6ea12a94ee8 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 14 May 2011 18:20:52 -0500 Subject: [PATCH 183/642] Try again to fix build-server profile Signed-off-by: Chris Aniszczyk --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index 1c8c798c4..66d64e9fa 100644 --- a/pom.xml +++ b/pom.xml @@ -229,6 +229,9 @@ package pack + + ${project.build.directory}/org.eclipse.mylyn.github-site/target/github-updatesite.zip + From a06d254a9dd6f1ba11622011216f870298ddb719 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 14 May 2011 18:23:03 -0500 Subject: [PATCH 184/642] Try again to fix build-server profile Signed-off-by: Chris Aniszczyk --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 66d64e9fa..34f12d09f 100644 --- a/pom.xml +++ b/pom.xml @@ -226,12 +226,12 @@ pack - package - - pack ${project.build.directory}/org.eclipse.mylyn.github-site/target/github-updatesite.zip + package + + pack From b86c21b21276916f3e3e7d0bc2da1d6219e85d59 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 14 May 2011 18:27:23 -0500 Subject: [PATCH 185/642] Add proper path for build-server profile Signed-off-by: Chris Aniszczyk --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 34f12d09f..5c308caa5 100644 --- a/pom.xml +++ b/pom.xml @@ -227,7 +227,7 @@ pack - ${project.build.directory}/org.eclipse.mylyn.github-site/target/github-updatesite.zip + ${project.build.directory}/../org.eclipse.mylyn.github-site/target/github-updatesite.zip package @@ -247,7 +247,7 @@ repack - ${project.build.directory}/org.eclipse.mylyn.github-site/target/github-updatesite.zip + ${project.build.directory}/../org.eclipse.mylyn.github-site/target/github-updatesite.zip package From 4a1dff2af46ad965398453b46f6ea3b2c6be4336 Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sat, 14 May 2011 19:42:05 -0500 Subject: [PATCH 186/642] Clean up build-server profile for signing Change-Id: I6f1b1b2122b99570af180ed2cf46112a953ac066 Signed-off-by: Chris Aniszczyk --- org.eclipse.mylyn.github-site/pom.xml | 85 +++++++++++++++++++++++++++ pom.xml | 79 ------------------------- 2 files changed, 85 insertions(+), 79 deletions(-) diff --git a/org.eclipse.mylyn.github-site/pom.xml b/org.eclipse.mylyn.github-site/pom.xml index 369e3cc56..3053c57c2 100644 --- a/org.eclipse.mylyn.github-site/pom.xml +++ b/org.eclipse.mylyn.github-site/pom.xml @@ -35,5 +35,90 @@ + + + build-server + + + + org.eclipse.dash.maven + eclipse-maven-signing-plugin + 1.0.0.0-SNAPSHOT + + + pack + + ${project.build.directory}/github-updatesite.zip + + package + + pack + + + + sign + + ${project.build.directory}/github-updatesite.zip + /home/data/httpd/download-staging.priv/egit-github + + package + + sign + + + + repack + + ${project.build.directory}/github-updatesite.zip + + package + + pack + + + + fixCheckSums + + ${project.build.directory}/github-updatesite.zip + + package + + fixCheckSums + + + + + + maven-antrun-plugin + + + deploy + install + + run + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 5c308caa5..7118a2d25 100644 --- a/pom.xml +++ b/pom.xml @@ -215,84 +215,5 @@ - - build-server - - - - org.eclipse.dash.maven - eclipse-maven-signing-plugin - 1.0.0.0-SNAPSHOT - - - pack - - ${project.build.directory}/../org.eclipse.mylyn.github-site/target/github-updatesite.zip - - package - - pack - - - - sign - - /home/data/httpd/download-staging.priv/egit-github - - package - - sign - - - - repack - - ${project.build.directory}/../org.eclipse.mylyn.github-site/target/github-updatesite.zip - - package - - pack - - - - fixCheckSums - package - - fixCheckSums - - - - - - maven-antrun-plugin - - - deploy - install - - run - - - - - - - - - - - - - - - - - - - - - From 5296efdc3cd88f2869de93b0dcf93c1dfcf481c5 Mon Sep 17 00:00:00 2001 From: Christian Trutz Date: Mon, 16 May 2011 10:46:59 -0700 Subject: [PATCH 187/642] GitHubClient refactored to use HttpClient 4.1 Change-Id: I87ac2e8e097e6436a4765126af2b044013e5592f Signed-off-by: Christian Trutz Signed-off-by: Kevin Sawicki --- .../META-INF/MANIFEST.MF | 2 +- .../egit/github/core/tests/live/LiveTest.java | 7 +- .../META-INF/MANIFEST.MF | 16 +- .../egit/github/core/client/GitHubClient.java | 270 +++++++++--------- .../github/core/client/GitHubResponse.java | 6 +- .../egit/github/core/client/PageLinks.java | 20 +- .../META-INF/MANIFEST.MF | 3 +- .../RepositorySelectionWizardPage.java | 7 +- 8 files changed, 173 insertions(+), 158 deletions(-) diff --git a/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF b/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF index bc4e2aea0..5d2c02361 100644 --- a/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF @@ -7,7 +7,7 @@ Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: com.google.gson;version="1.6.0", com.google.gson.reflect;version="1.6.0", - org.apache.commons.httpclient;version="3.1.0", + org.apache.http;version="4.1.0", org.mockito;version="1.8.4", org.mockito.runners;version="1.8.4", org.mockito.stubbing;version="1.8.4" diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTest.java index 93e2493dc..fd7cc6660 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/LiveTest.java @@ -15,7 +15,7 @@ import junit.framework.TestCase; -import org.apache.commons.httpclient.HostConfiguration; +import org.apache.http.HttpHost; import org.eclipse.egit.github.core.client.GitHubClient; /** @@ -51,11 +51,10 @@ protected GitHubClient configure(GitHubClient client) { protected GitHubClient createClient(String url) throws IOException { GitHubClient client = null; if (url != null) { - HostConfiguration config = new HostConfiguration(); URL parsed = new URL(url); - config.setHost(parsed.getHost(), parsed.getPort(), + HttpHost httpHost = new HttpHost(parsed.getHost(), parsed.getPort(), parsed.getProtocol()); - client = new GitHubClient(config); + client = new GitHubClient(httpHost); } else client = new GitHubClient(); return configure(client); diff --git a/org.eclipse.egit.github.core/META-INF/MANIFEST.MF b/org.eclipse.egit.github.core/META-INF/MANIFEST.MF index fda2872b6..b35dd3ba8 100644 --- a/org.eclipse.egit.github.core/META-INF/MANIFEST.MF +++ b/org.eclipse.egit.github.core/META-INF/MANIFEST.MF @@ -9,10 +9,18 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: com.google.gson;version="1.6.0", com.google.gson.annotations;version="1.6.0", com.google.gson.reflect;version="1.6.0", - org.apache.commons.httpclient;version="3.1.0", - org.apache.commons.httpclient.auth;version="3.1.0", - org.apache.commons.httpclient.methods;version="3.1.0", - org.apache.commons.httpclient.protocol;version="3.1.0" + org.apache.http;version="4.1.0", + org.apache.http.auth;version="4.1.0", + org.apache.http.client;version="4.1.0", + org.apache.http.client.entity;version="4.1.0", + org.apache.http.client.methods;version="4.1.0", + org.apache.http.client.protocol;version="4.1.0", + org.apache.http.client.utils;version="4.1.0", + org.apache.http.entity;version="4.1.0", + org.apache.http.impl.auth;version="4.1.0", + org.apache.http.impl.client;version="4.1.0", + org.apache.http.message;version="4.1.0", + org.apache.http.protocol;version="4.1.0" Export-Package: org.eclipse.egit.github.core, org.eclipse.egit.github.core.client, org.eclipse.egit.github.core.service, diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java index 6ceaed08a..38f09b95f 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java @@ -7,6 +7,7 @@ * * Contributors: * Kevin Sawicki (GitHub Inc.) - initial API and implementation + * Christian Trutz - HttpClient 4.1 *******************************************************************************/ package org.eclipse.egit.github.core.client; @@ -20,24 +21,31 @@ import java.io.InputStreamReader; import java.lang.reflect.Type; import java.util.Date; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.HostConfiguration; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.HttpMethodBase; -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.auth.BasicScheme; -import org.apache.commons.httpclient.methods.EntityEnclosingMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.PutMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.StatusLine; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.AuthCache; +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.protocol.ClientContext; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.BasicAuthCache; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; import org.eclipse.egit.github.core.Assert; import org.eclipse.egit.github.core.RequestError; @@ -46,40 +54,42 @@ */ public class GitHubClient { - private static final NameValuePair PER_PAGE_PARAM = new NameValuePair( + private static final NameValuePair PER_PAGE_PARAM = new BasicNameValuePair( IGitHubConstants.PARAM_PER_PAGE, Integer.toString(100)); - private static final AuthScope ANY_SCOPE = new AuthScope( - AuthScope.ANY_HOST, AuthScope.ANY_PORT); + private final HttpHost httpHost; - private HostConfiguration hostConfig; + private final HttpContext httpContext; - private HttpClient client = new HttpClient(); + private final DefaultHttpClient client = new DefaultHttpClient(); - private Gson gson = new GsonBuilder() + private final Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new DateFormatter()) .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .serializeNulls().create(); - private boolean sendCredentials = false; - /** * Create default client */ public GitHubClient() { - this.hostConfig = new HostConfiguration(); - this.hostConfig.setHost(IGitHubConstants.HOST_API, -1, - Protocol.getProtocol(IGitHubConstants.PROTOCOL_HTTPS)); + this(new HttpHost(IGitHubConstants.HOST_API, -1, + IGitHubConstants.PROTOCOL_HTTPS)); } /** - * Create client for configuration + * Create client for host configuration * - * @param configuration + * @param httpHost */ - public GitHubClient(HostConfiguration configuration) { - Assert.notNull("Configuration cannot be null", configuration); //$NON-NLS-1$ - this.hostConfig = configuration; + public GitHubClient(HttpHost httpHost) { + Assert.notNull("Http host cannot be null", httpHost); //$NON-NLS-1$ + this.httpHost = httpHost; + + // Preemptive authentication + httpContext = new BasicHttpContext(); + AuthCache authCache = new BasicAuthCache(); + authCache.put(this.httpHost, new BasicScheme()); + httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache); } /** @@ -88,10 +98,8 @@ public GitHubClient(HostConfiguration configuration) { * @param uri * @return post */ - protected PostMethod createPost(String uri) { - PostMethod method = new PostMethod(uri); - setMethodDefaults(method); - return method; + protected HttpPost createPost(String uri) { + return new HttpPost(uri); } /** @@ -100,25 +108,8 @@ protected PostMethod createPost(String uri) { * @param uri * @return post */ - protected PutMethod createPut(String uri) { - PutMethod method = new PutMethod(uri); - setMethodDefaults(method); - return method; - } - - /** - * Set method defaults - * - * @param method - * @return method - */ - protected HttpMethod setMethodDefaults(HttpMethod method) { - if (this.sendCredentials) { - method.setDoAuthentication(true); - method.getHostAuthState().setPreemptive(); - method.getHostAuthState().setAuthScheme(new BasicScheme()); - } - return method; + protected HttpPut createPut(String uri) { + return new HttpPut(uri); } /** @@ -127,11 +118,8 @@ protected HttpMethod setMethodDefaults(HttpMethod method) { * @param uri * @return get method */ - protected GetMethod createGet(String uri) { - GetMethod method = new GetMethod(uri); - method.setFollowRedirects(true); - setMethodDefaults(method); - return method; + protected HttpGet createGet(String uri) { + return new HttpGet(uri); } /** @@ -141,33 +129,33 @@ protected GetMethod createGet(String uri) { * @param password */ public void setCredentials(String user, String password) { - this.sendCredentials = user != null && password != null; - Credentials credentials = null; - if (this.sendCredentials) - credentials = new UsernamePasswordCredentials(user, password); - this.client.getState().setCredentials(ANY_SCOPE, credentials); + if (user != null && password != null) + this.client.getCredentialsProvider().setCredentials( + new AuthScope(httpHost.getHostName(), httpHost.getPort()), + new UsernamePasswordCredentials(user, password)); + else + this.client.getCredentialsProvider().clear(); } /** * Parse json to specified type * * @param - * @param method + * @param response * @param type * @return type * @throws IOException */ - protected V parseJson(HttpMethodBase method, Type type) + protected V parseJson(HttpResponse response, Type type) throws IOException { - InputStream stream = method.getResponseBodyAsStream(); + InputStream stream = response.getEntity().getContent(); if (stream == null) throw new JsonParseException("Empty body"); //$NON-NLS-1$ InputStreamReader reader = new InputStreamReader(stream); try { return this.gson.fromJson(reader, type); } catch (JsonParseException jpe) { - jpe.printStackTrace(); - throw new IOException(jpe); + throw new IOException(jpe.getMessage()); } } @@ -178,23 +166,35 @@ protected V parseJson(HttpMethodBase method, Type type) * @param page * @return name value pair array */ - protected NameValuePair[] getPairs(Map data, int page) { - if (data == null || data.isEmpty()) - return new NameValuePair[] { - new NameValuePair(IGitHubConstants.PARAM_PAGE, - Integer.toString(page)), PER_PAGE_PARAM }; - - int size = data.containsKey(IGitHubConstants.PARAM_PER_PAGE) ? data - .size() : data.size() + 1; - NameValuePair[] pairs = new NameValuePair[size]; - int i = 0; - for (Entry entry : data.entrySet()) - pairs[i++] = new NameValuePair(entry.getKey(), entry.getValue()); - if (i < size) - pairs[i] = PER_PAGE_PARAM; + protected List getPairs(Map data, int page) { + List pairs = new LinkedList(); + if (data == null || data.isEmpty()) { + pairs.add(new BasicNameValuePair(IGitHubConstants.PARAM_PAGE, + Integer.toString(page))); + pairs.add(PER_PAGE_PARAM); + } else { + for (Entry entry : data.entrySet()) + pairs.add(new BasicNameValuePair(entry.getKey(), entry + .getValue())); + if (!data.containsKey(IGitHubConstants.PARAM_PER_PAGE)) + pairs.add(PER_PAGE_PARAM); + } return pairs; } + /** + * Get uri for request + * + * @param request + * @return uri + */ + protected String getUri(GitHubRequest request) { + return request.getUri() + + (request.getUri().indexOf('?') == -1 ? '?' : '&') + + URLEncodedUtils.format( + getPairs(request.getParams(), request.getPage()), null); + } + /** * Get response stream from uri. It is the responsibility of the calling * method to close the returned stream. @@ -204,25 +204,29 @@ protected NameValuePair[] getPairs(Map data, int page) { * @throws IOException */ public InputStream getStream(GitHubRequest request) throws IOException { - GetMethod method = createGet(request.getUri()); - if (method.getQueryString() == null) - method.setQueryString(getPairs(request.getParams(), - request.getPage())); + HttpGet method = createGet(getUri(request)); try { - int status = this.client.executeMethod(this.hostConfig, method); + HttpResponse response = this.client.execute(this.httpHost, method, + this.httpContext); + StatusLine statusLine = response.getStatusLine(); + if (statusLine == null) { + throw new IllegalStateException( + "HTTP response status line should not be null."); //$NON-NLS-1$ + } + int status = statusLine.getStatusCode(); switch (status) { case 200: - return method.getResponseBodyAsStream(); + return response.getEntity().getContent(); case 400: case 401: case 403: case 404: case 422: case 500: - RequestError error = parseJson(method, RequestError.class); + RequestError error = parseJson(response, RequestError.class); throw new RequestException(error, status); default: - throw new IOException(method.getStatusText()); + throw new IOException(statusLine.getReasonPhrase()); } } catch (JsonParseException jpe) { throw new IOException(jpe.getMessage()); @@ -237,15 +241,19 @@ public InputStream getStream(GitHubRequest request) throws IOException { * @throws IOException */ public GitHubResponse get(GitHubRequest request) throws IOException { - GetMethod method = createGet(request.getUri()); - if (method.getQueryString() == null) - method.setQueryString(getPairs(request.getParams(), - request.getPage())); + HttpGet method = createGet(getUri(request)); try { - int status = this.client.executeMethod(this.hostConfig, method); + HttpResponse response = this.client.execute(this.httpHost, method, + this.httpContext); + StatusLine statusLine = response.getStatusLine(); + if (statusLine == null) { + throw new IllegalStateException( + "HTTP response status line should not be null."); //$NON-NLS-1$ + } + int status = statusLine.getStatusCode(); switch (status) { case 200: - return new GitHubResponse(method, parseJson(method, + return new GitHubResponse(response, parseJson(response, request.getType())); case 400: case 401: @@ -253,15 +261,13 @@ public GitHubResponse get(GitHubRequest request) throws IOException { case 404: case 422: case 500: - RequestError error = parseJson(method, RequestError.class); + RequestError error = parseJson(response, RequestError.class); throw new RequestException(error, status); default: - throw new IOException(method.getStatusText()); + throw new IOException(statusLine.getReasonPhrase()); } } catch (JsonParseException jpe) { throw new IOException(jpe.getMessage()); - } finally { - method.releaseConnection(); } } @@ -275,38 +281,40 @@ public GitHubResponse get(GitHubRequest request) throws IOException { * @return resource * @throws IOException */ - protected V sendJson(EntityEnclosingMethod method, Object params, - Type type) throws IOException { + protected V sendJson(HttpEntityEnclosingRequestBase method, + Object params, Type type) throws IOException { if (params != null) { StringBuilder payload = new StringBuilder(); this.gson.toJson(params, payload); - method.setRequestEntity(new StringRequestEntity(payload.toString(), + method.setEntity(new StringEntity(payload.toString(), IGitHubConstants.CONTENT_TYPE_JSON, IGitHubConstants.CHARSET_UTF8)); } - - try { - int status = this.client.executeMethod(this.hostConfig, method); - switch (status) { - case 200: - case 201: - if (type != null) - return parseJson(method, type); - case 204: - break; - case 400: - case 401: - case 403: - case 404: - case 422: - case 500: - RequestError error = parseJson(method, RequestError.class); - throw new RequestException(error, status); - default: - throw new IOException(method.getStatusText()); - } - } finally { - method.releaseConnection(); + HttpResponse response = this.client.execute(this.httpHost, method, + this.httpContext); + StatusLine statusLine = response.getStatusLine(); + if (statusLine == null) { + throw new IllegalStateException( + "HTTP response status line should not be null."); //$NON-NLS-1$ + } + int status = statusLine.getStatusCode(); + switch (status) { + case 200: + case 201: + if (type != null) + return parseJson(response, type); + case 204: + break; + case 400: + case 401: + case 403: + case 404: + case 422: + case 500: + RequestError error = parseJson(response, RequestError.class); + throw new RequestException(error, status); + default: + throw new IOException(statusLine.getReasonPhrase()); } return null; } @@ -322,8 +330,8 @@ protected V sendJson(EntityEnclosingMethod method, Object params, * @throws IOException */ public V post(String uri, Object params, Type type) throws IOException { - PostMethod method = createPost(uri); - return sendJson(method, params, type); + HttpPost message = createPost(uri); + return sendJson(message, params, type); } /** @@ -337,8 +345,8 @@ public V post(String uri, Object params, Type type) throws IOException { * @throws IOException */ public V put(String uri, Object params, Type type) throws IOException { - PutMethod method = createPut(uri); - return sendJson(method, params, type); + HttpPut message = createPut(uri); + return sendJson(message, params, type); } } diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubResponse.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubResponse.java index 43c2a3d23..8bd379281 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubResponse.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubResponse.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.egit.github.core.client; -import org.apache.commons.httpclient.HttpMethod; +import org.apache.http.HttpResponse; /** * GitHub API response class. @@ -27,8 +27,8 @@ public class GitHubResponse { * @param method * @param body */ - public GitHubResponse(HttpMethod method, Object body) { - links = new PageLinks(method); + public GitHubResponse(HttpResponse response, Object body) { + links = new PageLinks(response); this.body = body; } diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/PageLinks.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/PageLinks.java index d08cef8da..e48301e61 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/PageLinks.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/PageLinks.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.egit.github.core.client; -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpMethod; +import org.apache.http.Header; +import org.apache.http.HttpResponse; /** * Page link class to be used to determine the links to other pages of request @@ -32,11 +32,11 @@ public class PageLinks { /** * Parse links from executed method * - * @param method + * @param response */ - public PageLinks(HttpMethod method) { - Header[] linkHeaders = method - .getResponseHeaders(IGitHubConstants.HEADER_LINK); + public PageLinks(HttpResponse response) { + Header[] linkHeaders = response + .getHeaders(IGitHubConstants.HEADER_LINK); if (linkHeaders.length > 0) { String[] links = linkHeaders[0].getValue().split(DELIM_LINKS); for (String link : links) { @@ -70,13 +70,13 @@ else if (IGitHubConstants.META_PREV.equals(relValue)) } } } else { - Header[] nextHeaders = method - .getResponseHeaders(IGitHubConstants.HEADER_NEXT); + Header[] nextHeaders = response + .getHeaders(IGitHubConstants.HEADER_NEXT); if (nextHeaders.length > 0) next = nextHeaders[0].getValue(); - Header[] lastHeaders = method - .getResponseHeaders(IGitHubConstants.HEADER_LAST); + Header[] lastHeaders = response + .getHeaders(IGitHubConstants.HEADER_LAST); if (lastHeaders.length > 0) last = lastHeaders[0].getValue(); } diff --git a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF index f6433a998..0b56028f1 100644 --- a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF @@ -25,4 +25,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.egit.github.core;bundle-version="0.1.0" Export-Package: org.eclipse.mylyn.github.ui.internal;x-internal:=true Bundle-ActivationPolicy: lazy -Import-Package: org.eclipse.egit.ui.internal;version="0.12.0" +Import-Package: org.apache.http;version="4.1.0", + org.eclipse.egit.ui.internal;version="0.12.0" diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java index 2c8293b88..c26e13cf2 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/RepositorySelectionWizardPage.java @@ -17,7 +17,7 @@ import java.util.Collections; import java.util.List; -import org.apache.commons.httpclient.HostConfiguration; +import org.apache.http.HttpHost; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.egit.github.core.Repository; import org.eclipse.egit.github.core.client.GitHubClient; @@ -208,10 +208,9 @@ public void setVisible(boolean visible) { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - HostConfiguration config = new HostConfiguration(); - config.setHost(IGitHubConstants.HOST_API_V2, -1, + HttpHost httpHost = new HttpHost(IGitHubConstants.HOST_API_V2, -1, IGitHubConstants.PROTOCOL_HTTPS); - GitHubClient client = new GitHubClient(config); + GitHubClient client = new GitHubClient(httpHost); client.setCredentials(user, password); RepositoryService service = new RepositoryService(client); repoCount = 0; From 48fe56ce3a3bb048d1103afb4c5ceb168f79a961 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 16 May 2011 11:13:34 -0700 Subject: [PATCH 188/642] Add unit test for limiting result set size. Change-Id: I4ea96d2d60af9a825377cb1529acac74ea5a640a Signed-off-by: Kevin Sawicki --- .../github/core/tests/live/IssueTest.java | 42 +++++++++++++++++++ .../github/core/service/GitHubService.java | 22 ++++++++++ .../github/core/service/IssueService.java | 9 ++-- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/IssueTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/IssueTest.java index 9061fcec6..e7313defc 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/IssueTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/IssueTest.java @@ -11,10 +11,16 @@ package org.eclipse.egit.github.core.tests.live; import java.io.IOException; +import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.eclipse.egit.github.core.IResourceCollector; import org.eclipse.egit.github.core.Issue; +import org.eclipse.egit.github.core.client.IGitHubConstants; +import org.eclipse.egit.github.core.client.PagedRequest; import org.eclipse.egit.github.core.service.IssueService; /** @@ -56,4 +62,40 @@ public void testFetchAll() throws IOException { assertNotNull(issue); } + /** + * Test limiting result size + * + * @throws IOException + */ + public void testLimit() throws IOException { + IssueService service = new IssueService(client) { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected PagedRequest createPagedRequest( + final IResourceCollector collector) { + return super.createPagedRequest(new IResourceCollector() { + + public boolean accept(int page, Collection response) { + collector.accept(page, response); + return false; + } + }); + } + + }; + Map params = new HashMap(); + params.put(IssueService.FILTER_STATE, IssueService.STATE_CLOSED); + List issues = service.getIssues("schacon", "showoff", params); + assertNotNull(issues); + assertTrue(issues.size() > 2); + params.put(IGitHubConstants.PARAM_PER_PAGE, "1"); + issues = service.getIssues("schacon", "showoff", params); + assertNotNull(issues); + assertEquals(1, issues.size()); + params.put(IGitHubConstants.PARAM_PER_PAGE, "2"); + issues = service.getIssues("schacon", "showoff", params); + assertNotNull(issues); + assertEquals(2, issues.size()); + } + } diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java index 39cab3319..33affcccb 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java @@ -18,6 +18,7 @@ import org.eclipse.egit.github.core.IResourceCollector; import org.eclipse.egit.github.core.IResourceProvider; import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; import org.eclipse.egit.github.core.client.GitHubResponse; import org.eclipse.egit.github.core.client.PagedRequest; @@ -41,6 +42,27 @@ public GitHubService(GitHubClient client) { this.client = client; } + /** + * Unified request creation method that all sub-classes should use so + * overriding classes can extend and configure the default request. + * + * @return request + */ + protected GitHubRequest createRequest() { + return new GitHubRequest(); + } + + /** + * Unified paged request creation method that all sub-classes should use so + * overriding classes can extend and configure the default request. + * + * @param collector + * @return request + */ + protected PagedRequest createPagedRequest(IResourceCollector collector) { + return new PagedRequest(collector); + } + /** * Get paged request by performing multiple requests until no more pages are * available of the request collector no longer accepts resource results. diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java index 2844029b6..2d38a052b 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java @@ -109,9 +109,8 @@ public Issue getIssue(String user, String repository, String id) uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES); uri.append('/').append(id); - GitHubRequest request = new GitHubRequest(); - request.setUri(uri); - request.setType(Issue.class); + GitHubRequest request = createRequest().setUri(uri) + .setType(Issue.class); return (Issue) client.get(request).getBody(); } @@ -136,7 +135,7 @@ public List getComments(String user, String repository, String id) builder.append('/').append(id); builder.append(IGitHubConstants.SEGMENT_COMMENTS); ListResourceCollector collector = new ListResourceCollector(); - PagedRequest request = new PagedRequest(collector); + PagedRequest request = createPagedRequest(collector); request.setUri(builder.toString()).setType( new TypeToken>() { }.getType()); @@ -161,7 +160,7 @@ public List getIssues(String user, String repository, uri.append('/').append(user).append('/').append(repository); uri.append(IGitHubConstants.SEGMENT_ISSUES); ListResourceCollector collector = new ListResourceCollector(); - PagedRequest request = new PagedRequest(collector); + PagedRequest request = createPagedRequest(collector); request.setParams(filterData).setUri(uri); request.setType(new TypeToken>() { }.getType()); From f196bf7bc2f5e6f61f86a0f41a4ee9ce061b8b31 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 16 May 2011 12:44:31 -0700 Subject: [PATCH 189/642] Refactor package and class names for issue connector. Change-Id: Icfaf402936f0ebd2527ac9ba2fbbeb135a58e5c4 Signed-off-by: Kevin Sawicki --- .../META-INF/MANIFEST.MF | 5 +- .../mylyn/github/internal/Messages.java | 98 --------------- .../mylyn/github/internal/messages.properties | 23 ---- .../github/core}/GitHub.java | 2 +- .../github/core}/GitHubException.java | 2 +- .../mylyn/internal/github/core/Messages.java | 41 +++++++ .../github/core}/QueryUtils.java | 2 +- .../core/gist/GistAttachmentHandler.java | 2 +- .../github/core/gist/GistConnector.java | 2 +- .../github/core/gist/GistTaskDataHandler.java | 6 +- .../github/core/issue/IssueAttribute.java} | 36 +++--- .../core/issue/IssueAttributeMapper.java} | 6 +- .../github/core/issue/IssueConnector.java} | 21 ++-- .../github/core/issue/IssueOperation.java} | 10 +- .../core/issue/IssueTaskDataHandler.java} | 90 +++++++------- .../internal/github/core/issue/Messages.java | 86 +++++++++++++ .../github/core/issue/messages.properties | 19 +++ .../internal/github/core/messages.properties | 4 + ...tHubRepositoryConnectorUIHeadlessTest.java | 9 +- .../META-INF/MANIFEST.MF | 4 +- org.eclipse.mylyn.github.ui/plugin.xml | 8 +- .../ui/internal/ImportRepositoriesWizard.java | 2 +- .../mylyn/github/ui/internal/Messages.java | 87 -------------- .../RepositorySelectionWizardPage.java | 2 +- .../github/ui/internal/messages.properties | 29 ----- .../github/ui/gist}/CreateGistHandler.java | 3 +- .../github/ui/gist}/CreateGistJob.java | 3 +- .../ui/gist}/GistNotificationPopup.java | 3 +- .../github/ui/gist/GistTaskEditorPage.java | 2 +- .../github/ui/issue}/IssueAttributePart.java | 12 +- .../github/ui/issue/IssueConnectorUi.java} | 18 +-- .../ui/issue}/IssueLabelAttributeEditor.java | 3 +- .../ui/issue/IssueRepositoryQueryPage.java} | 51 ++++---- .../issue/IssueRepositorySettingsPage.java} | 22 ++-- .../github/ui/issue}/IssueSummaryPart.java | 12 +- .../github/ui/issue/IssueTaskEditorPage.java} | 14 +-- .../ui/issue/IssueTaskEditorPageFactory.java} | 11 +- .../internal/github/ui/issue/Messages.java | 113 ++++++++++++++++++ .../github/ui/issue/messages.properties | 28 +++++ 39 files changed, 480 insertions(+), 411 deletions(-) delete mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java delete mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal => internal/github/core}/GitHub.java (98%) rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal => internal/github/core}/GitHubException.java (97%) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/Messages.java rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal => internal/github/core}/QueryUtils.java (97%) rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal/GitHubTaskAttributes.java => internal/github/core/issue/IssueAttribute.java} (75%) rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal/GitHubTaskAttributeMapper.java => internal/github/core/issue/IssueAttributeMapper.java} (91%) rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal/GitHubRepositoryConnector.java => internal/github/core/issue/IssueConnector.java} (94%) rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal/GitHubTaskOperation.java => internal/github/core/issue/IssueOperation.java} (85%) rename org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/{github/internal/GitHubTaskDataHandler.java => internal/github/core/issue/IssueTaskDataHandler.java} (83%) create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/Messages.java create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/messages.properties create mode 100644 org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/messages.properties rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal => internal/github/ui/gist}/CreateGistHandler.java (97%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal => internal/github/ui/gist}/CreateGistJob.java (95%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal => internal/github/ui/gist}/GistNotificationPopup.java (95%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal => internal/github/ui/issue}/IssueAttributePart.java (95%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal/GitHubRepositoryConnectorUI.java => internal/github/ui/issue/IssueConnectorUi.java} (91%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal => internal/github/ui/issue}/IssueLabelAttributeEditor.java (98%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal/GitHubRepositoryQueryPage.java => internal/github/ui/issue/IssueRepositoryQueryPage.java} (89%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal/GitHubRepositorySettingsPage.java => internal/github/ui/issue/IssueRepositorySettingsPage.java} (89%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal => internal/github/ui/issue}/IssueSummaryPart.java (94%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal/GitHubTaskEditorPage.java => internal/github/ui/issue/IssueTaskEditorPage.java} (84%) rename org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/{github/ui/internal/GitHubTaskEditorPageFactory.java => internal/github/ui/issue/IssueTaskEditorPageFactory.java} (83%) create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/Messages.java create mode 100644 org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/messages.properties diff --git a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF index 1721cbc71..f03adb370 100644 --- a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF @@ -6,8 +6,9 @@ Bundle-SymbolicName: org.eclipse.mylyn.github.core;singleton:=true Bundle-Version: 0.1.0.qualifier Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.eclipse.mylyn.github.internal;x-friends:="org.eclipse.mylyn.github.ui", - org.eclipse.mylyn.internal.github.core.gist;x-friends:="org.eclipse.mylyn.github.ui" +Export-Package: org.eclipse.mylyn.internal.github.core;x-friends:="org.eclipse.mylyn.github.ui", + org.eclipse.mylyn.internal.github.core.gist;x-friends:="org.eclipse.mylyn.github.ui", + org.eclipse.mylyn.internal.github.core.issue;x-friends:="org.eclipse.mylyn.github.ui" Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.mylyn.tasks.core;bundle-version="3.2.0", org.eclipse.mylyn.commons.net;bundle-version="3.2.0", diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java deleted file mode 100644 index 596178615..000000000 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * 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.github.internal; - -import org.eclipse.osgi.util.NLS; - -/** - * NLS for Mylyn GitHub Core - */ -public class Messages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.mylyn.github.internal.messages"; //$NON-NLS-1$ - - /** */ - public static String FieldError_InvalidField; - - /** */ - public static String FieldError_InvalidFieldWithValue; - - /** */ - public static String FieldError_MissingField; - - /** */ - public static String FieldError_ResourceError; - - /** */ - public static String GitHubRepositoryConnector_LabelConnector; - - /** */ - public static String GitHubRepositoryConnector_TaskQuerying; - - /** */ - public static String GitHubRepositoryConnector_TaskUpdatingLabels; - - /** */ - public static String GitHubRepositoryConnector_TaskUpdatingMilestones; - - /** */ - public static String GitHubTaskAttributes_LabekSummary; - - /** */ - public static String GitHubTaskAttributes_LabelAssignee; - - /** */ - public static String GitHubTaskAttributes_LabelAssigneeGravatar; - - /** */ - public static String GitHubTaskAttributes_LabelClosed; - - /** */ - public static String GitHubTaskAttributes_LabelComment; - - /** */ - public static String GitHubTaskAttributes_LabelCreated; - - /** */ - public static String GitHubTaskAttributes_LabelDescription; - - /** */ - public static String GitHubTaskAttributes_LabelKey; - - /** */ - public static String GitHubTaskAttributes_LabelLabels; - - /** */ - public static String GitHubTaskAttributes_LabelMilestone; - - /** */ - public static String GitHubTaskAttributes_LabelModified; - - /** */ - public static String GitHubTaskAttributes_LabelReporter; - - /** */ - public static String GitHubTaskAttributes_LabelReporterGravatar; - - /** */ - public static String GitHubTaskAttributes_LabelStatus; - - /** */ - public static String GitHubTaskDataHandler_MilestoneNone; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties deleted file mode 100644 index 77706e84a..000000000 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties +++ /dev/null @@ -1,23 +0,0 @@ -FieldError_InvalidField=Invalid value for field {1} -FieldError_InvalidFieldWithValue=Invalid value of {0} for field {1} -FieldError_MissingField=Missing required field {0} -FieldError_ResourceError=Error with field {0} in {1} resource -GitHubRepositoryConnector_LabelConnector=GitHub Issues -GitHubRepositoryConnector_TaskQuerying=Querying repository... -GitHubRepositoryConnector_TaskUpdatingLabels=Updating labels -GitHubRepositoryConnector_TaskUpdatingMilestones=Updating milestones -GitHubTaskAttributes_LabekSummary=Summary -GitHubTaskAttributes_LabelAssignee=Assignee: -GitHubTaskAttributes_LabelAssigneeGravatar=Assignee -GitHubTaskAttributes_LabelClosed=Closed: -GitHubTaskAttributes_LabelComment=Comment: -GitHubTaskAttributes_LabelCreated=Created: -GitHubTaskAttributes_LabelDescription=Description -GitHubTaskAttributes_LabelKey=Key -GitHubTaskAttributes_LabelLabels=Labels: -GitHubTaskAttributes_LabelMilestone=Milestone: -GitHubTaskAttributes_LabelModified=Modified: -GitHubTaskAttributes_LabelReporter=Reporter: -GitHubTaskAttributes_LabelReporterGravatar=Reporter -GitHubTaskAttributes_LabelStatus=Status: -GitHubTaskDataHandler_MilestoneNone=None diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHub.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java similarity index 98% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHub.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java index cf2e1330f..6206ad0fd 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHub.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java @@ -10,7 +10,7 @@ * Christian Trutz - initial contribution * Chris Aniszczyk - initial contribution *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core; import java.util.regex.Pattern; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubException.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java similarity index 97% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubException.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java index 6ff1a9088..a0a58cf78 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubException.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java @@ -8,7 +8,7 @@ * Contributors: * Kevin Sawicki (GitHub Inc.) - initial API and implementation *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core; import java.io.IOException; import java.text.MessageFormat; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/Messages.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/Messages.java new file mode 100644 index 000000000..0c8858bfd --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/Messages.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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; + +import org.eclipse.osgi.util.NLS; + +/** + * NLS for Mylyn GitHub Core + */ +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.github.core.messages"; //$NON-NLS-1$ + + /** */ + public static String FieldError_InvalidField; + + /** */ + public static String FieldError_InvalidFieldWithValue; + + /** */ + public static String FieldError_MissingField; + + /** */ + public static String FieldError_ResourceError; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/QueryUtils.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/QueryUtils.java similarity index 97% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/QueryUtils.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/QueryUtils.java index c2496f3d1..85728004c 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/QueryUtils.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/QueryUtils.java @@ -8,7 +8,7 @@ * Contributors: * Kevin Sawicki (GitHub Inc.) - initial API and implementation *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core; import java.util.Collection; import java.util.Collections; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java index 172c93324..09609f7e6 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java @@ -24,7 +24,7 @@ import org.eclipse.egit.github.core.service.GistService; import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.github.internal.GitHub; +import org.eclipse.mylyn.internal.github.core.GitHub; import org.eclipse.mylyn.tasks.core.ITask; import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler; 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 index fe3760bca..f92c6d1a6 100644 --- 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 @@ -22,7 +22,7 @@ import org.eclipse.egit.github.core.service.GistService; import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.github.internal.GitHub; +import org.eclipse.mylyn.internal.github.core.GitHub; import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.ITask; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index a09539e94..e68a29003 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -27,8 +27,8 @@ import org.eclipse.egit.github.core.service.GistService; import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.github.internal.GitHub; -import org.eclipse.mylyn.github.internal.GitHubTaskAttributeMapper; +import org.eclipse.mylyn.internal.github.core.GitHub; +import org.eclipse.mylyn.internal.github.core.issue.IssueAttributeMapper; import org.eclipse.mylyn.tasks.core.IRepositoryPerson; import org.eclipse.mylyn.tasks.core.ITaskMapping; import org.eclipse.mylyn.tasks.core.RepositoryResponse; @@ -274,7 +274,7 @@ public boolean initializeTaskData(TaskRepository repository, TaskData data, * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper(org.eclipse.mylyn.tasks.core.TaskRepository) */ public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) { - return new GitHubTaskAttributeMapper(taskRepository); + return new IssueAttributeMapper(taskRepository); } } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueAttribute.java similarity index 75% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueAttribute.java index 1b6cd3b97..8c97c965b 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributes.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueAttribute.java @@ -10,104 +10,104 @@ * Christian Trutz - initial contribution * Chris Aniszczyk - initial contribution *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core.issue; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; /** * GitHub issue task attributes */ -public enum GitHubTaskAttributes { +public enum IssueAttribute { /** * Issue key */ - KEY(Messages.GitHubTaskAttributes_LabelKey, TaskAttribute.TASK_KEY, + KEY(Messages.IssueAttribute_LabelKey, TaskAttribute.TASK_KEY, TaskAttribute.TYPE_SHORT_TEXT, true, true), /** * Issue title */ - TITLE(Messages.GitHubTaskAttributes_LabekSummary, TaskAttribute.SUMMARY, + TITLE(Messages.IssueAttribute_LabekSummary, TaskAttribute.SUMMARY, TaskAttribute.TYPE_SHORT_RICH_TEXT, false, true), /** * Issue description */ - BODY(Messages.GitHubTaskAttributes_LabelDescription, + BODY(Messages.IssueAttribute_LabelDescription, TaskAttribute.DESCRIPTION, TaskAttribute.TYPE_LONG_RICH_TEXT, false, true), /** * Issue creation date */ - CREATION_DATE(Messages.GitHubTaskAttributes_LabelCreated, + CREATION_DATE(Messages.IssueAttribute_LabelCreated, TaskAttribute.DATE_CREATION, TaskAttribute.TYPE_DATETIME, true, false), /** * Issue modification date */ - MODIFICATION_DATE(Messages.GitHubTaskAttributes_LabelModified, + MODIFICATION_DATE(Messages.IssueAttribute_LabelModified, TaskAttribute.DATE_MODIFICATION, TaskAttribute.TYPE_DATETIME, true, false), /** * Issue closed date */ - CLOSED_DATE(Messages.GitHubTaskAttributes_LabelClosed, + CLOSED_DATE(Messages.IssueAttribute_LabelClosed, TaskAttribute.DATE_COMPLETION, TaskAttribute.TYPE_DATETIME, true, false), /** * Issue status */ - STATUS(Messages.GitHubTaskAttributes_LabelStatus, TaskAttribute.STATUS, + STATUS(Messages.IssueAttribute_LabelStatus, TaskAttribute.STATUS, TaskAttribute.TYPE_SHORT_TEXT, false, true), /** * Issue reporter */ - REPORTER(Messages.GitHubTaskAttributes_LabelReporter, + REPORTER(Messages.IssueAttribute_LabelReporter, TaskAttribute.USER_REPORTER, TaskAttribute.TYPE_PERSON, true, false), /** * Comment being added to issue */ - COMMENT_NEW(Messages.GitHubTaskAttributes_LabelComment, + COMMENT_NEW(Messages.IssueAttribute_LabelComment, TaskAttribute.COMMENT_NEW, TaskAttribute.TYPE_LONG_RICH_TEXT, false, false), /** * Labels applied to issue */ - LABELS(Messages.GitHubTaskAttributes_LabelLabels, "github.issue.labels", //$NON-NLS-1$ + LABELS(Messages.IssueAttribute_LabelLabels, "github.issue.labels", //$NON-NLS-1$ TaskAttribute.TYPE_MULTI_SELECT, true, false), /** * Issue assignee */ - ASSIGNEE(Messages.GitHubTaskAttributes_LabelAssignee, + ASSIGNEE(Messages.IssueAttribute_LabelAssignee, TaskAttribute.USER_ASSIGNED, TaskAttribute.TYPE_PERSON, false, true), /** * Issue milestone */ - MILESTONE(Messages.GitHubTaskAttributes_LabelMilestone, + MILESTONE(Messages.IssueAttribute_LabelMilestone, "github.issue.milestone", TaskAttribute.TYPE_SINGLE_SELECT, //$NON-NLS-1$ false, true), /** * Issue assignee gravatar */ - ASSIGNEE_GRAVATAR(Messages.GitHubTaskAttributes_LabelAssigneeGravatar, + ASSIGNEE_GRAVATAR(Messages.IssueAttribute_LabelAssigneeGravatar, "github.issue.assignee.gravatar", TaskAttribute.TYPE_URL, null, //$NON-NLS-1$ true, false), /** * Issue reporter gravatar */ - REPORTER_GRAVATAR(Messages.GitHubTaskAttributes_LabelReporterGravatar, + REPORTER_GRAVATAR(Messages.IssueAttribute_LabelReporterGravatar, "github.issue.reporter.gravatar", TaskAttribute.TYPE_URL, null, //$NON-NLS-1$ true, false); @@ -118,12 +118,12 @@ public enum GitHubTaskAttributes { private final boolean initTask; private final String type; - private GitHubTaskAttributes(String label, String id, String type, + private IssueAttribute(String label, String id, String type, boolean readOnly, boolean initTask) { this(label, id, type, TaskAttribute.KIND_DEFAULT, readOnly, initTask); } - private GitHubTaskAttributes(String label, String id, String type, + private IssueAttribute(String label, String id, String type, String kind, boolean readOnly, boolean initTask) { this.label = label; this.id = id; diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributeMapper.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueAttributeMapper.java similarity index 91% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributeMapper.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueAttributeMapper.java index 776ffc054..e4038af7f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskAttributeMapper.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueAttributeMapper.java @@ -10,7 +10,7 @@ * Christian Trutz - initial contribution * Chris Aniszczyk - initial contribution *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core.issue; import java.text.DateFormat; import java.util.Collections; @@ -24,7 +24,7 @@ /** * GitHub task attribute mapper class. */ -public class GitHubTaskAttributeMapper extends TaskAttributeMapper { +public class IssueAttributeMapper extends TaskAttributeMapper { private DateFormat format = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.SHORT); @@ -32,7 +32,7 @@ public class GitHubTaskAttributeMapper extends TaskAttributeMapper { /** * @param taskRepository */ - public GitHubTaskAttributeMapper(TaskRepository taskRepository) { + public IssueAttributeMapper(TaskRepository taskRepository) { super(taskRepository); } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java similarity index 94% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java index 24f688b54..274c4bcc8 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java @@ -10,7 +10,7 @@ * Christian Trutz - initial contribution * Chris Aniszczyk - initial contribution *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core.issue; import java.io.IOException; import java.util.Collections; @@ -41,6 +41,9 @@ import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; import org.eclipse.mylyn.commons.net.Policy; +import org.eclipse.mylyn.internal.github.core.GitHub; +import org.eclipse.mylyn.internal.github.core.GitHubException; +import org.eclipse.mylyn.internal.github.core.QueryUtils; import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.ITask; @@ -55,7 +58,7 @@ /** * GitHub connector. */ -public class GitHubRepositoryConnector extends AbstractRepositoryConnector { +public class IssueConnector extends AbstractRepositoryConnector { /** * GitHub kind. @@ -81,7 +84,7 @@ public static GitHubClient createClient(TaskRepository repository) { /** * GitHub specific {@link AbstractTaskDataHandler}. */ - private final GitHubTaskDataHandler taskDataHandler; + private final IssueTaskDataHandler taskDataHandler; private final Map> repositoryLabels = Collections .synchronizedMap(new HashMap>()); @@ -92,8 +95,8 @@ public static GitHubClient createClient(TaskRepository repository) { /** * Create GitHub issue repository connector */ - public GitHubRepositoryConnector() { - taskDataHandler = new GitHubTaskDataHandler(this); + public IssueConnector() { + taskDataHandler = new IssueTaskDataHandler(this); } /** @@ -233,7 +236,7 @@ public String getConnectorKind() { */ @Override public String getLabel() { - return Messages.GitHubRepositoryConnector_LabelConnector; + return Messages.IssueConnector_LabelConnector; } /** @@ -252,7 +255,7 @@ public IStatus performQuery(TaskRepository repository, List statuses = QueryUtils.getAttributes( IssueService.FILTER_STATE, query); - monitor.beginTask(Messages.GitHubRepositoryConnector_TaskQuerying, + monitor.beginTask(Messages.IssueConector_TaskQuerying, statuses.size()); try { Repository repo = GitHub.getRepository(repository @@ -370,10 +373,10 @@ public void updateRepositoryConfiguration(TaskRepository taskRepository, IProgressMonitor monitor) throws CoreException { monitor = Policy.monitorFor(monitor); monitor.beginTask("", 2); //$NON-NLS-1$ - monitor.setTaskName(Messages.GitHubRepositoryConnector_TaskUpdatingLabels); + monitor.setTaskName(Messages.IssueConnector_TaskUpdatingLabels); refreshLabels(taskRepository); monitor.worked(1); - monitor.setTaskName(Messages.GitHubRepositoryConnector_TaskUpdatingMilestones); + monitor.setTaskName(Messages.IssueConnector_TaskUpdatingMilestones); refreshMilestones(taskRepository); monitor.done(); } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskOperation.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueOperation.java similarity index 85% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskOperation.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueOperation.java index 58c5b6ea1..d851919db 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskOperation.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueOperation.java @@ -10,12 +10,12 @@ * Christian Trutz - initial contribution * Chris Aniszczyk - initial contribution *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core.issue; /** * Enumeration of task operations */ -public enum GitHubTaskOperation { +public enum IssueOperation { /** * LEAD @@ -34,7 +34,7 @@ public enum GitHubTaskOperation { private final String label; - private GitHubTaskOperation(String label) { + private IssueOperation(String label) { this.label = label; } @@ -64,8 +64,8 @@ public String getId() { * @return the operation, or null if the id was null or did not match any * operation */ - public static GitHubTaskOperation fromId(String opId) { - for (GitHubTaskOperation op : values()) { + public static IssueOperation fromId(String opId) { + for (IssueOperation op : values()) { if (op.getId().equals(opId)) { return op; } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueTaskDataHandler.java similarity index 83% rename from org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java rename to org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueTaskDataHandler.java index f65b92398..3cb43c810 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueTaskDataHandler.java @@ -10,7 +10,7 @@ * Christian Trutz - initial contribution * Chris Aniszczyk - initial contribution *******************************************************************************/ -package org.eclipse.mylyn.github.internal; +package org.eclipse.mylyn.internal.github.core.issue; import java.io.IOException; import java.util.Date; @@ -30,6 +30,8 @@ import org.eclipse.egit.github.core.client.RequestException; import org.eclipse.egit.github.core.service.IssueService; import org.eclipse.egit.github.core.service.LabelService; +import org.eclipse.mylyn.internal.github.core.GitHub; +import org.eclipse.mylyn.internal.github.core.GitHubException; import org.eclipse.mylyn.tasks.core.IRepositoryPerson; import org.eclipse.mylyn.tasks.core.ITaskMapping; import org.eclipse.mylyn.tasks.core.RepositoryResponse; @@ -46,26 +48,26 @@ /** * GitHub issue task data handler */ -public class GitHubTaskDataHandler extends AbstractTaskDataHandler { +public class IssueTaskDataHandler extends AbstractTaskDataHandler { private static final String DATA_VERSION = "1"; //$NON-NLS-1$ private static final String MILESTONE_NONE_KEY = "0"; //$NON-NLS-1$ - private GitHubTaskAttributeMapper taskAttributeMapper = null; - private final GitHubRepositoryConnector connector; + private IssueAttributeMapper taskAttributeMapper = null; + private final IssueConnector connector; /** * Create GitHub issue task data handler for connector * * @param connector */ - public GitHubTaskDataHandler(GitHubRepositoryConnector connector) { + public IssueTaskDataHandler(IssueConnector connector) { this.connector = connector; } @Override public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) { if (this.taskAttributeMapper == null) - this.taskAttributeMapper = new GitHubTaskAttributeMapper( + this.taskAttributeMapper = new IssueAttributeMapper( taskRepository); return this.taskAttributeMapper; } @@ -75,40 +77,40 @@ public TaskData createTaskData(TaskRepository repository, String key = Integer.toString(issue.getNumber()); TaskData data = new TaskData(getAttributeMapper(repository), - GitHubRepositoryConnector.KIND, repository.getRepositoryUrl(), + IssueConnector.KIND, repository.getRepositoryUrl(), key); data.setVersion(DATA_VERSION); createOperations(data, issue); - createAttribute(data, GitHubTaskAttributes.KEY, key); - createAttribute(data, GitHubTaskAttributes.TITLE, issue.getTitle()); - createAttribute(data, GitHubTaskAttributes.BODY, issue.getBody()); - createAttribute(data, GitHubTaskAttributes.STATUS, issue.getState()); - createAttribute(data, GitHubTaskAttributes.CREATION_DATE, + createAttribute(data, IssueAttribute.KEY, key); + createAttribute(data, IssueAttribute.TITLE, issue.getTitle()); + createAttribute(data, IssueAttribute.BODY, issue.getBody()); + createAttribute(data, IssueAttribute.STATUS, issue.getState()); + createAttribute(data, IssueAttribute.CREATION_DATE, issue.getCreatedAt()); - createAttribute(data, GitHubTaskAttributes.MODIFICATION_DATE, + createAttribute(data, IssueAttribute.MODIFICATION_DATE, issue.getUpdatedAt()); - createAttribute(data, GitHubTaskAttributes.CLOSED_DATE, + createAttribute(data, IssueAttribute.CLOSED_DATE, issue.getClosedAt()); User reporter = issue.getUser(); - createAttribute(data, GitHubTaskAttributes.REPORTER, reporter, + createAttribute(data, IssueAttribute.REPORTER, reporter, repository); String reporterGravatar = reporter != null ? reporter.getGravatarUrl() : null; - createAttribute(data, GitHubTaskAttributes.REPORTER_GRAVATAR, + createAttribute(data, IssueAttribute.REPORTER_GRAVATAR, reporterGravatar); User assignee = issue.getAssignee(); - createAttribute(data, GitHubTaskAttributes.ASSIGNEE, assignee, + createAttribute(data, IssueAttribute.ASSIGNEE, assignee, repository); String assigneeGravatar = assignee != null ? assignee.getGravatarUrl() : null; - createAttribute(data, GitHubTaskAttributes.ASSIGNEE_GRAVATAR, + createAttribute(data, IssueAttribute.ASSIGNEE_GRAVATAR, assigneeGravatar); - createAttribute(data, GitHubTaskAttributes.COMMENT_NEW); + createAttribute(data, IssueAttribute.COMMENT_NEW); createLabels(repository, data, issue); @@ -123,7 +125,7 @@ private void createMilestone(TaskRepository repository, TaskData data, String number = current != null ? Integer.toString(current.getNumber()) : MILESTONE_NONE_KEY; TaskAttribute milestoneAttribute = createAttribute(data, - GitHubTaskAttributes.MILESTONE, number); + IssueAttribute.MILESTONE, number); if (!this.connector.hasCachedMilestones(repository)) try { @@ -135,7 +137,7 @@ private void createMilestone(TaskRepository repository, TaskData data, List cachedMilestones = this.connector .getMilestones(repository); milestoneAttribute.putOption(MILESTONE_NONE_KEY, - Messages.GitHubTaskDataHandler_MilestoneNone); + Messages.IssueAttribute_MilestoneNone); for (Milestone milestone : cachedMilestones) milestoneAttribute.putOption( Integer.toString(milestone.getNumber()), @@ -145,7 +147,7 @@ private void createMilestone(TaskRepository repository, TaskData data, private void createLabels(TaskRepository repository, TaskData data, Issue issue) { TaskAttribute labels = createAttribute(data, - GitHubTaskAttributes.LABELS, issue.getLabels()); + IssueAttribute.LABELS, issue.getLabels()); if (!this.connector.hasCachedLabels(repository)) try { @@ -167,17 +169,17 @@ private void createOperations(TaskData data, Issue issue) { if (!data.isNew()) { String state = issue.getState(); if (state != null) { - addOperation(data, issue, GitHubTaskOperation.LEAVE, true); + addOperation(data, issue, IssueOperation.LEAVE, true); if (state.equals(IssueService.STATE_OPEN)) - addOperation(data, issue, GitHubTaskOperation.CLOSE, false); + addOperation(data, issue, IssueOperation.CLOSE, false); else if (state.equals(IssueService.STATE_CLOSED)) - addOperation(data, issue, GitHubTaskOperation.REOPEN, false); + addOperation(data, issue, IssueOperation.REOPEN, false); } } } private void addOperation(TaskData data, Issue issue, - GitHubTaskOperation operation, boolean asDefault) { + IssueOperation operation, boolean asDefault) { TaskAttribute attribute = data.getRoot().createAttribute( TaskAttribute.PREFIX_OPERATION + operation.getId()); String label = createOperationLabel(issue, operation); @@ -191,8 +193,8 @@ private void addOperation(TaskData data, Issue issue, } private String createOperationLabel(Issue issue, - GitHubTaskOperation operation) { - return operation == GitHubTaskOperation.LEAVE ? operation.getLabel() + IssueOperation operation) { + return operation == IssueOperation.LEAVE ? operation.getLabel() + issue.getState() : operation.getLabel(); } @@ -233,11 +235,11 @@ private Issue createIssue(TaskData taskData) { if (!taskData.isNew()) { issue.setNumber(Integer.parseInt(taskData.getTaskId())); } - issue.setBody(getAttributeValue(taskData, GitHubTaskAttributes.BODY)); - issue.setTitle(getAttributeValue(taskData, GitHubTaskAttributes.TITLE)); + issue.setBody(getAttributeValue(taskData, IssueAttribute.BODY)); + issue.setTitle(getAttributeValue(taskData, IssueAttribute.TITLE)); String assigneeValue = getAttributeValue(taskData, - GitHubTaskAttributes.ASSIGNEE); + IssueAttribute.ASSIGNEE); if (assigneeValue != null) { if (assigneeValue.trim().length() == 0) assigneeValue = null; @@ -246,7 +248,7 @@ private Issue createIssue(TaskData taskData) { } String milestoneValue = getAttributeValue(taskData, - GitHubTaskAttributes.MILESTONE); + IssueAttribute.MILESTONE); if (milestoneValue != null) { Milestone milestone = new Milestone(); if (milestoneValue.length() > 0) @@ -257,13 +259,13 @@ private Issue createIssue(TaskData taskData) { } private String getAttributeValue(TaskData taskData, - GitHubTaskAttributes attr) { + IssueAttribute attr) { TaskAttribute attribute = taskData.getRoot().getAttribute(attr.getId()); return attribute == null ? null : attribute.getValue(); } private TaskAttribute createAttribute(TaskData data, - GitHubTaskAttributes attribute) { + IssueAttribute attribute) { TaskAttribute attr = data.getRoot().createAttribute(attribute.getId()); TaskAttributeMetaData metaData = attr.getMetaData(); metaData.defaults().setType(attribute.getType()) @@ -273,7 +275,7 @@ private TaskAttribute createAttribute(TaskData data, } private TaskAttribute createAttribute(TaskData data, - GitHubTaskAttributes attribute, String value) { + IssueAttribute attribute, String value) { TaskAttribute attr = createAttribute(data, attribute); if (value != null) { data.getAttributeMapper().setValue(attr, value); @@ -282,7 +284,7 @@ private TaskAttribute createAttribute(TaskData data, } private TaskAttribute createAttribute(TaskData data, - GitHubTaskAttributes attribute, Date value) { + IssueAttribute attribute, Date value) { TaskAttribute attr = createAttribute(data, attribute); if (value != null) { data.getAttributeMapper().setDateValue(attr, value); @@ -290,7 +292,7 @@ private TaskAttribute createAttribute(TaskData data, return attr; } - private void createAttribute(TaskData data, GitHubTaskAttributes attribute, + private void createAttribute(TaskData data, IssueAttribute attribute, User value, TaskRepository repository) { TaskAttribute attr = createAttribute(data, attribute); if (value != null) { @@ -302,7 +304,7 @@ private void createAttribute(TaskData data, GitHubTaskAttributes attribute, } private TaskAttribute createAttribute(TaskData data, - GitHubTaskAttributes attribute, List