Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Inline asserts and use static imports for constants

Change-Id: I498121563675d2e9c2c8180919d9c16d4b2d2566
Signed-off-by: Kevin Sawicki <kevin@github.com>
  • Loading branch information...
commit 35fd2b0a504d5d5fac8010bd116b6dd877d58df0 1 parent b1f12be
@kevinsawicki kevinsawicki authored
Showing with 992 additions and 768 deletions.
  1. +1 −1  org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/IssueTest.java
  2. +55 −0 org.eclipse.egit.github.core/.settings/org.eclipse.jdt.ui.prefs
  3. +0 −69 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Assert.java
  4. +13 −9 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryId.java
  5. +15 −11 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/SearchRepository.java
  6. +32 −31 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
  7. +2 −2 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/OAuth2Scheme.java
  8. +16 −13 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/CollaboratorService.java
  9. +67 −56 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/CommitService.java
  10. +78 −59 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DataService.java
  11. +20 −18 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DeployKeyService.java
  12. +37 −27 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DownloadService.java
  13. +47 −33 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GistService.java
  14. +24 −18 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
  15. +94 −65 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java
  16. +63 −41 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/LabelService.java
  17. +45 −29 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/MilestoneService.java
  18. +87 −55 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/OrganizationService.java
  19. +43 −33 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/PullRequestService.java
  20. +69 −53 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java
  21. +46 −30 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/TeamService.java
  22. +87 −71 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/UserService.java
  23. +51 −44 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/WatcherService.java
View
2  org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/live/IssueTest.java
@@ -28,7 +28,7 @@
import org.junit.Test;
/**
- *
+ * Unit tests of {@link IssueService}
*/
public class IssueTest extends LiveTest {
View
55 org.eclipse.egit.github.core/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,55 @@
+#Tue Aug 16 14:24:16 PDT 2011
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=false
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=false
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=false
+sp_cleanup.format_source_code=false
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.make_local_variable_final=false
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=false
+sp_cleanup.remove_unnecessary_nls_tags=false
+sp_cleanup.remove_unused_imports=false
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_this_for_non_static_field_access=false
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=false
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
View
69 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Assert.java
@@ -1,69 +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.egit.github.core;
-
-/**
- *
- */
-public abstract class Assert {
-
- /**
- * Throw an {@link IllegalArgumentException} if the specified object is
- * null.
- *
- * @param message
- * @param object
- * @throws IllegalArgumentException
- */
- public static void notNull(String message, Object object)
- throws IllegalArgumentException {
- if (object == null)
- throw new IllegalArgumentException(message);
- }
-
- /**
- * Throw an {@link IllegalArgumentException} if the specified object is
- * null.
- *
- * @param object
- * @throws IllegalArgumentException
- */
- public static void notNull(Object object) throws IllegalArgumentException {
- notNull("Illegal null argument", object); //$NON-NLS-1$
- }
-
- /**
- * Throw an {@link IllegalArgumentException} if the specified string is
- * empty. This method does not check if the string is null.
- * {@link #notNull(Object)} should be used to first assert the string is
- * non-null if that is a requirement of the argument.
- *
- * @param message
- * @param string
- * @throws IllegalArgumentException
- */
- public static void notEmpty(String message, String string)
- throws IllegalArgumentException {
- if (string.length() == 0)
- throw new IllegalArgumentException(message);
- }
-
- /**
- * Throw an {@link IllegalArgumentException} if the specified string is null
- * or empty.
- *
- * @param string
- * @throws IllegalArgumentException
- */
- public static void notEmpty(String string) throws IllegalArgumentException {
- notEmpty("Illegal empty string argument", string); //$NON-NLS-1$
- }
-}
View
22 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryId.java
@@ -20,7 +20,7 @@
/**
* Create repository from url.
- *
+ *
* @see #createFromId(String)
* @param url
* @return repository or null if parsing fails
@@ -33,7 +33,7 @@ public static RepositoryId createFromUrl(URL url) {
* Create repository from id. The id is split on the '/' character and the
* first two non-empty segments are interpreted to be the repository owner
* and name.
- *
+ *
* @param id
* @return repository
*/
@@ -57,7 +57,7 @@ else if (name == null)
/**
* Create from string url
- *
+ *
* @see #createFromUrl(URL)
* @param url
* @return repository or null if it could not be parsed from url path
@@ -74,16 +74,20 @@ public static RepositoryId createFromUrl(String url) {
* Create repository id from given owner and name. This method validates the
* parameters and throws an {@link IllegalArgumentException} if either is
* null or empty.
- *
+ *
* @param owner
* @param name
* @return repository id
*/
public static RepositoryId create(String owner, String name) {
- Assert.notNull("Owner cannot be null", owner);
- Assert.notEmpty("Owner cannot be empty", owner);
- Assert.notNull("Name cannot be null", name);
- Assert.notEmpty("Name cannot be empty", name);
+ if (owner == null)
+ throw new IllegalArgumentException("Owner cannot be null");
+ if (owner.length() == 0)
+ throw new IllegalArgumentException("Owner cannot be empty");
+ if (name == null)
+ throw new IllegalArgumentException("Name cannot be null");
+ if (name.length() == 0)
+ throw new IllegalArgumentException("Name cannot be empty");
return new RepositoryId(owner, name);
}
@@ -93,7 +97,7 @@ public static RepositoryId create(String owner, String name) {
/**
* Create repository id with given owner and name
- *
+ *
* @param owner
* must be non-null and non-empty
* @param name
View
26 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/SearchRepository.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.
*/
@@ -23,7 +23,7 @@
/**
* Create repository from url.
- *
+ *
* @see SearchRepository#createFromId(String)
* @param url
* @return repository or null if parsing fails
@@ -36,7 +36,7 @@ public static SearchRepository createFromUrl(URL url) {
* Create repository from id. The id is split on the '/' character and the
* last two non-empty segments are interpreted to be the repository owner
* and name.
- *
+ *
* @param id
* @return repository
*/
@@ -61,7 +61,7 @@ else if (owner == null)
/**
* Create from string url
- *
+ *
* @see SearchRepository#createFromUrl(URL)
* @param url
* @return repository or null if it could not be parsed from url path
@@ -98,15 +98,19 @@ public static SearchRepository createFromUrl(String url) {
/**
* Create repository with owner and name
- *
+ *
* @param owner
* @param name
*/
public SearchRepository(String owner, String name) {
- Assert.notNull("Owner cannot be null", owner); //$NON-NLS-1$
- Assert.notEmpty("Owner cannot be empty", owner); //$NON-NLS-1$
- Assert.notNull("Name cannot be null", name); //$NON-NLS-1$
- Assert.notEmpty("Name cannot be empty", name); //$NON-NLS-1$
+ if (owner == null)
+ throw new IllegalArgumentException("Owner cannot be null");
+ if (owner.length() == 0)
+ throw new IllegalArgumentException("Owner cannot be empty");
+ if (name == null)
+ throw new IllegalArgumentException("Name cannot be null");
+ if (name.length() == 0)
+ throw new IllegalArgumentException("Name cannot be empty");
this.owner = owner;
this.name = name;
@@ -147,7 +151,7 @@ public String toString() {
/**
* Get unique identifier for repository
- *
+ *
* @return id
*/
public String getId() {
View
63 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
@@ -47,7 +47,6 @@
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
-import org.eclipse.egit.github.core.Assert;
import org.eclipse.egit.github.core.RequestError;
/**
@@ -57,10 +56,10 @@
/**
* Create API client from URL.
- *
+ *
* This creates an HTTPS-based client with a host that contains the host
* value of the given URL prefixed with 'api'.
- *
+ *
* @param url
* @return client
*/
@@ -96,7 +95,7 @@ public GitHubClient() {
/**
* Create client for host configuration
- *
+ *
* @param hostname
* @param port
* @param scheme
@@ -107,11 +106,13 @@ public GitHubClient(String hostname, int port, String scheme) {
/**
* Create client for host configuration
- *
+ *
* @param httpHost
*/
public GitHubClient(HttpHost httpHost) {
- Assert.notNull("Http host cannot be null", httpHost); //$NON-NLS-1$
+ if (httpHost == null)
+ throw new IllegalArgumentException("Http host cannot be null"); //$NON-NLS-1$
+
this.httpHost = httpHost;
// Support JVM configured proxy servers
@@ -130,7 +131,7 @@ public GitHubClient(HttpHost httpHost) {
* Set the value to set as the user agent header on every request created.
* Specifying a null or empty agent parameter will reset this client to use
* the default user agent header value.
- *
+ *
* @param agent
* @return this client
*/
@@ -144,7 +145,7 @@ public GitHubClient setUserAgent(String agent) {
/**
* Configure request with standard headers
- *
+ *
* @param request
* @return configured request
*/
@@ -155,7 +156,7 @@ public GitHubClient setUserAgent(String agent) {
/**
* Create standard post method
- *
+ *
* @param uri
* @return post
*/
@@ -165,7 +166,7 @@ protected HttpPost createPost(String uri) {
/**
* Create standard post method
- *
+ *
* @param uri
* @return post
*/
@@ -175,7 +176,7 @@ protected HttpPut createPut(String uri) {
/**
* Create get method
- *
+ *
* @param uri
* @return get method
*/
@@ -185,7 +186,7 @@ protected HttpGet createGet(String uri) {
/**
* Create delete method
- *
+ *
* @param uri
* @return get method
*/
@@ -195,7 +196,7 @@ protected HttpDelete createDelete(String uri) {
/**
* Update credential on http client credentials provider
- *
+ *
* @param user
* @param password
* @return this client
@@ -212,7 +213,7 @@ protected GitHubClient updateCredentials(String user, String password) {
/**
* Set credentials
- *
+ *
* @param user
* @param password
* @return this client
@@ -227,7 +228,7 @@ public GitHubClient setCredentials(String user, String password) {
/**
* Set OAuth2 token
- *
+ *
* @param token
* @return this client
*/
@@ -241,7 +242,7 @@ public GitHubClient setOAuth2Token(String token) {
/**
* Get the user that this client is currently authenticating as
- *
+ *
* @return user or null if not authentication
*/
public String getUser() {
@@ -255,7 +256,7 @@ public String getUser() {
/**
* Parse json to specified type
- *
+ *
* @param <V>
* @param response
* @param type
@@ -280,7 +281,7 @@ public String getUser() {
/**
* Convert object to a JSON string
- *
+ *
* @param object
* @return JSON string
* @throws IOException
@@ -295,7 +296,7 @@ private String toJson(Object object) throws IOException {
/**
* Get {@link HttpEntity} from response
- *
+ *
* @param response
* @return non-null entity
* @throws IOException
@@ -309,7 +310,7 @@ protected HttpEntity getEntity(HttpResponse response) throws IOException {
/**
* Get {@link InputStream} from response
- *
+ *
* @param response
* @return non-null input stream
* @throws IOException
@@ -323,7 +324,7 @@ protected InputStream getStream(HttpResponse response) throws IOException {
/**
* Parse error from response
- *
+ *
* @param response
* @return request error
* @throws IOException
@@ -334,7 +335,7 @@ protected RequestError parseError(HttpResponse response) throws IOException {
/**
* Create error exception from response and throw it
- *
+ *
* @param response
* @param status
* @return non-null newly created {@link IOException}
@@ -363,7 +364,7 @@ protected IOException createException(HttpResponse response,
/**
* Is the response successful?
- *
+ *
* @param response
* @param status
* @return true if okay, false otherwise
@@ -380,7 +381,7 @@ protected boolean isOk(HttpResponse response, StatusLine status) {
/**
* Is the response empty?
- *
+ *
* @param response
* @param status
* @return true if empty, false otherwise
@@ -391,7 +392,7 @@ protected boolean isEmpty(HttpResponse response, StatusLine status) {
/**
* Get status line from response
- *
+ *
* @param response
* @return Non-null status line
* @throws IOException
@@ -406,7 +407,7 @@ protected StatusLine getStatus(HttpResponse response) throws IOException {
/**
* Get response stream from uri. It is the responsibility of the calling
* method to close the returned stream.
- *
+ *
* @param request
* @return stream
* @throws IOException
@@ -422,7 +423,7 @@ public InputStream getStream(GitHubRequest request) throws IOException {
/**
* Get response from URI and bind to specified type
- *
+ *
* @param request
* @return response
* @throws IOException
@@ -445,7 +446,7 @@ public GitHubResponse get(GitHubRequest request) throws IOException {
/**
* Send json using specified method
- *
+ *
* @param <V>
* @param method
* @param params
@@ -473,7 +474,7 @@ public GitHubResponse get(GitHubRequest request) throws IOException {
/**
* Post data to uri
- *
+ *
* @param <V>
* @param uri
* @param params
@@ -487,7 +488,7 @@ public GitHubResponse get(GitHubRequest request) throws IOException {
/**
* Put data to uri
- *
+ *
* @param <V>
* @param uri
* @param params
@@ -502,7 +503,7 @@ public GitHubResponse get(GitHubRequest request) throws IOException {
/**
* Delete resource at URI. This method will throw an {@link IOException}
* when the response status is not a 204 (No Content).
- *
+ *
* @param uri
* @throws IOException
*/
View
4 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/OAuth2Scheme.java
@@ -18,7 +18,6 @@
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.impl.auth.RFC2617Scheme;
import org.apache.http.message.BasicHeader;
-import org.eclipse.egit.github.core.Assert;
/**
* OAuth2 authorization scheme. Sets an authorization header with a value of the
@@ -48,7 +47,8 @@ public boolean isComplete() {
public Header authenticate(Credentials credentials, HttpRequest request)
throws AuthenticationException {
- Assert.notNull(credentials);
+ if (credentials == null)
+ throw new IllegalArgumentException("Credentials cannot be null"); //$NON-NLS-1$
return new BasicHeader(HttpHeaders.AUTHORIZATION, credentials
.getUserPrincipal().getName() + ' ' + credentials.getPassword());
}
View
29 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/CollaboratorService.java
@@ -10,6 +10,9 @@
*****************************************************************************/
package org.eclipse.egit.github.core.service;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_COLLABORATORS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
+
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
@@ -18,12 +21,11 @@
import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.client.GitHubClient;
-import org.eclipse.egit.github.core.client.IGitHubConstants;
import org.eclipse.egit.github.core.client.PagedRequest;
/**
* Service for interacting with the collaborators on a GitHub repository
- *
+ *
* @see <a href="http://developer.github.com/v3/repos/collaborators/">GitHub
* collaborator API documentation</a>
*/
@@ -38,7 +40,7 @@ public CollaboratorService(GitHubClient client) {
/**
* Get collaborators for given repository
- *
+ *
* @param repository
* @return non-null list of collaborators
* @throws IOException
@@ -46,9 +48,9 @@ public CollaboratorService(GitHubClient client) {
public List<User> getCollaborators(IRepositoryIdProvider repository)
throws IOException {
String id = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COLLABORATORS);
+ uri.append(SEGMENT_COLLABORATORS);
PagedRequest<User> request = createPagedRequest();
request.setUri(uri);
request.setType(new TypeToken<List<User>>() {
@@ -58,7 +60,7 @@ public CollaboratorService(GitHubClient client) {
/**
* Create URI for updating collaborators
- *
+ *
* @param repository
* @param user
* @return URI
@@ -67,19 +69,20 @@ protected String createUpdateUri(IRepositoryIdProvider repository,
String user) {
String id = getId(repository);
if (user == null)
- throw new IllegalArgumentException("User cannot be null");
+ throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
if (user.length() == 0)
- throw new IllegalArgumentException("User cannot be empty");
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COLLABORATORS);
+ uri.append(SEGMENT_COLLABORATORS);
uri.append('/').append(user);
return uri.toString();
}
/**
* Is given user a collaborator on the given repository
- *
+ *
* @param repository
* @param user
* @return true if collaborator, false otherwise
@@ -92,7 +95,7 @@ public boolean isCollaborator(IRepositoryIdProvider repository, String user)
/**
* Add given user as a collaborator on the given repository
- *
+ *
* @param repository
* @param user
* @throws IOException
@@ -104,7 +107,7 @@ public void addCollaborator(IRepositoryIdProvider repository, String user)
/**
* Remove given user as a collaborator on the given repository
- *
+ *
* @param repository
* @param user
* @throws IOException
View
123 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/CommitService.java
@@ -10,6 +10,12 @@
*****************************************************************************/
package org.eclipse.egit.github.core.service;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_COMMENTS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_COMMITS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
+
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
@@ -23,13 +29,12 @@
import org.eclipse.egit.github.core.RepositoryCommit;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
-import org.eclipse.egit.github.core.client.IGitHubConstants;
import org.eclipse.egit.github.core.client.PageIterator;
import org.eclipse.egit.github.core.client.PagedRequest;
/**
* Service for interacting with repository commits
- *
+ *
* @see <a href="http://developer.github.com/v3/repos/commits">GitHub commit API
* documentation</a>
*/
@@ -44,7 +49,7 @@ public CommitService(GitHubClient client) {
/**
* Get all commits in given repository
- *
+ *
* @param repository
* @return non-null but possibly empty list of repository commits
* @throws IOException
@@ -56,7 +61,7 @@ public CommitService(GitHubClient client) {
/**
* Get all commits in given repository
- *
+ *
* @param repository
* @param sha
* @param path
@@ -70,7 +75,7 @@ public CommitService(GitHubClient client) {
/**
* Page commits in given repository
- *
+ *
* @param repository
* @return page iterator
*/
@@ -81,7 +86,7 @@ public CommitService(GitHubClient client) {
/**
* Page commits in given repository
- *
+ *
* @param repository
* @param size
* @return page iterator
@@ -93,7 +98,7 @@ public CommitService(GitHubClient client) {
/**
* Page commits in given repository
- *
+ *
* @param repository
* @param sha
* @param path
@@ -101,12 +106,12 @@ public CommitService(GitHubClient client) {
*/
public PageIterator<RepositoryCommit> pageCommits(
IRepositoryIdProvider repository, String sha, String path) {
- return pageCommits(repository, sha, path, PagedRequest.PAGE_SIZE);
+ return pageCommits(repository, sha, path, PAGE_SIZE);
}
/**
* Page commits in given repository
- *
+ *
* @param repository
* @param sha
* @param path
@@ -116,11 +121,11 @@ public CommitService(GitHubClient client) {
public PageIterator<RepositoryCommit> pageCommits(
IRepositoryIdProvider repository, String sha, String path, int size) {
String id = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COMMITS);
- PagedRequest<RepositoryCommit> request = createPagedRequest(
- PagedRequest.PAGE_FIRST, size);
+ uri.append(SEGMENT_COMMITS);
+ PagedRequest<RepositoryCommit> request = createPagedRequest(PAGE_FIRST,
+ size);
request.setUri(uri);
request.setType(new TypeToken<List<RepositoryCommit>>() {
}.getType());
@@ -128,9 +133,9 @@ public CommitService(GitHubClient client) {
if (sha != null || path != null) {
Map<String, String> params = new HashMap<String, String>();
if (sha != null)
- params.put("sha", sha);
+ params.put("sha", sha); //$NON-NLS-1$
if (path != null)
- params.put("path", path);
+ params.put("path", path); //$NON-NLS-1$
request.setParams(params);
}
@@ -139,7 +144,7 @@ public CommitService(GitHubClient client) {
/**
* Get commit with given SHA-1 from given repository
- *
+ *
* @param repository
* @param sha
* @return repository commit
@@ -149,12 +154,13 @@ public RepositoryCommit getCommit(IRepositoryIdProvider repository,
String sha) throws IOException {
String id = getId(repository);
if (sha == null)
- throw new IllegalArgumentException("Sha cannot be null");
+ throw new IllegalArgumentException("Sha cannot be null"); //$NON-NLS-1$
if (sha.length() == 0)
- throw new IllegalArgumentException("Sha cannot be empty");
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ throw new IllegalArgumentException("Sha cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COMMITS);
+ uri.append(SEGMENT_COMMITS);
uri.append('/').append(sha);
GitHubRequest request = createRequest();
request.setUri(uri);
@@ -164,7 +170,7 @@ public RepositoryCommit getCommit(IRepositoryIdProvider repository,
/**
* Get all comments on commit with given SHA-1
- *
+ *
* @param repository
* @param sha
* @return non-null but possibly empty list of commits
@@ -177,19 +183,19 @@ public RepositoryCommit getCommit(IRepositoryIdProvider repository,
/**
* Page comments on commit with given SHA-1
- *
+ *
* @param repository
* @param sha
* @return page iterator over comments
*/
public PageIterator<CommitComment> pageComments(
IRepositoryIdProvider repository, String sha) {
- return pageComments(repository, sha, PagedRequest.PAGE_SIZE);
+ return pageComments(repository, sha, PAGE_SIZE);
}
/**
* Page comments on commit with given SHA-1
- *
+ *
* @param repository
* @param sha
* @param size
@@ -197,12 +203,12 @@ public RepositoryCommit getCommit(IRepositoryIdProvider repository,
*/
public PageIterator<CommitComment> pageComments(
IRepositoryIdProvider repository, String sha, int size) {
- return pageComments(repository, sha, PagedRequest.PAGE_FIRST, size);
+ return pageComments(repository, sha, PAGE_FIRST, size);
}
/**
* Page comments on commit with given SHA-1
- *
+ *
* @param repository
* @param sha
* @param start
@@ -213,14 +219,15 @@ public RepositoryCommit getCommit(IRepositoryIdProvider repository,
IRepositoryIdProvider repository, String sha, int start, int size) {
String id = getId(repository);
if (sha == null)
- throw new IllegalArgumentException("Sha cannot be null");
+ throw new IllegalArgumentException("Sha cannot be null"); //$NON-NLS-1$
if (sha.length() == 0)
- throw new IllegalArgumentException("Sha cannot be empty");
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ throw new IllegalArgumentException("Sha cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COMMITS);
+ uri.append(SEGMENT_COMMITS);
uri.append('/').append(sha);
- uri.append(IGitHubConstants.SEGMENT_COMMENTS);
+ uri.append(SEGMENT_COMMENTS);
PagedRequest<CommitComment> request = createPagedRequest(start, size);
request.setUri(uri);
request.setType(new TypeToken<List<CommitComment>>() {
@@ -230,7 +237,7 @@ public RepositoryCommit getCommit(IRepositoryIdProvider repository,
/**
* Get commit comment with given id
- *
+ *
* @param repository
* @param id
* @return commit comment
@@ -240,12 +247,13 @@ public CommitComment getComment(IRepositoryIdProvider repository, String id)
throws IOException {
String repoId = getId(repository);
if (id == null)
- throw new IllegalArgumentException("Id cannot be null");
+ throw new IllegalArgumentException("Id cannot be null"); //$NON-NLS-1$
if (id.length() == 0)
- throw new IllegalArgumentException("Id cannot be empty");
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ throw new IllegalArgumentException("Id cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_COMMENTS);
+ uri.append(SEGMENT_COMMENTS);
uri.append('/').append(id);
GitHubRequest request = createRequest();
request.setUri(uri);
@@ -255,7 +263,7 @@ public CommitComment getComment(IRepositoryIdProvider repository, String id)
/**
* Add comment to given commit
- *
+ *
* @param repository
* @param sha
* @param comment
@@ -266,20 +274,21 @@ public CommitComment addComment(IRepositoryIdProvider repository,
String sha, CommitComment comment) throws IOException {
String id = getId(repository);
if (sha == null)
- throw new IllegalArgumentException("Sha cannot be null");
+ throw new IllegalArgumentException("Sha cannot be null"); //$NON-NLS-1$
if (sha.length() == 0)
- throw new IllegalArgumentException("Sha cannot be empty");
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ throw new IllegalArgumentException("Sha cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COMMITS);
+ uri.append(SEGMENT_COMMITS);
uri.append('/').append(sha);
- uri.append(IGitHubConstants.SEGMENT_COMMENTS);
+ uri.append(SEGMENT_COMMENTS);
return client.post(uri.toString(), comment, CommitComment.class);
}
/**
* Edit given comment
- *
+ *
* @param repository
* @param comment
* @return edited comment
@@ -289,24 +298,25 @@ public CommitComment editComment(IRepositoryIdProvider repository,
CommitComment comment) throws IOException {
String id = getId(repository);
if (comment == null)
- throw new IllegalArgumentException("Comment cannot be null");
+ throw new IllegalArgumentException("Comment cannot be null"); //$NON-NLS-1$
String commentId = comment.getId();
if (commentId == null)
- throw new IllegalArgumentException("Comment id cannot be null");
+ throw new IllegalArgumentException("Comment id cannot be null"); //$NON-NLS-1$
if (commentId.length() == 0)
- throw new IllegalArgumentException("Comment id cannot be empty");
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ throw new IllegalArgumentException("Comment id cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COMMENTS);
+ uri.append(SEGMENT_COMMENTS);
uri.append('/').append(commentId);
- return client.post(uri.toString(),
- Collections.singletonMap("body", comment.getBody()),
- CommitComment.class);
+ Map<String, String> params = Collections.singletonMap(
+ "body", comment.getBody()); //$NON-NLS-1$
+ return client.post(uri.toString(), params, CommitComment.class);
}
/**
* Delete commit comment with given id from given repository
- *
+ *
* @param repository
* @param commentId
* @throws IOException
@@ -315,12 +325,13 @@ public void deleteComment(IRepositoryIdProvider repository, String commentId)
throws IOException {
String id = getId(repository);
if (commentId == null)
- throw new IllegalArgumentException("Comment Id cannot be null");
+ throw new IllegalArgumentException("Comment Id cannot be null"); //$NON-NLS-1$
if (commentId.length() == 0)
- throw new IllegalArgumentException("Comment Id cannot be empty");
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ throw new IllegalArgumentException("Comment Id cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_COMMENTS);
+ uri.append(SEGMENT_COMMENTS);
uri.append('/').append(commentId);
client.delete(uri.toString());
}
View
137 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DataService.java
@@ -10,6 +10,14 @@
*****************************************************************************/
package org.eclipse.egit.github.core.service;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_BLOBS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_COMMITS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_GIT;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REFS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_TAGS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_TREES;
+
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
@@ -48,7 +56,7 @@ public DataService(GitHubClient client) {
/**
* Get blob for given SHA-1
- *
+ *
* @param repository
* @param sha
* @return blob
@@ -59,11 +67,12 @@ public Blob getBlob(IRepositoryIdProvider repository, String sha)
final String id = getId(repository);
if (sha == null)
throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_BLOBS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_BLOBS);
uri.append('/').append(sha);
GitHubRequest request = createRequest();
request.setType(Blob.class);
@@ -73,7 +82,7 @@ public Blob getBlob(IRepositoryIdProvider repository, String sha)
/**
* Create blob with given content
- *
+ *
* @param repository
* @param blob
* @return SHA-1 of created blob
@@ -84,11 +93,12 @@ public String createBlob(IRepositoryIdProvider repository, Blob blob)
final String id = getId(repository);
if (blob == null)
throw new IllegalArgumentException("Blob cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_BLOBS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_BLOBS);
ShaResource created = client.post(uri.toString(), blob,
ShaResource.class);
return created.getSha();
@@ -96,7 +106,7 @@ public String createBlob(IRepositoryIdProvider repository, Blob blob)
/**
* Get tree with given SHA-1
- *
+ *
* @param repository
* @param sha
* @return tree
@@ -109,7 +119,7 @@ public Tree getTree(IRepositoryIdProvider repository, String sha)
/**
* Get tree with given SHA-1
- *
+ *
* @param repository
* @param sha
* @param recursive
@@ -121,23 +131,24 @@ public Tree getTree(IRepositoryIdProvider repository, String sha,
final String id = getId(repository);
if (sha == null)
throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_TREES);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_TREES);
uri.append('/').append(sha);
GitHubRequest request = createRequest();
request.setType(Tree.class);
request.setUri(uri);
if (recursive)
- request.setParams(Collections.singletonMap("recursive", "1"));
+ request.setParams(Collections.singletonMap("recursive", "1")); //$NON-NLS-1$ //$NON-NLS-2$
return (Tree) client.get(request).getBody();
}
/**
* Create tree
- *
+ *
* @param repository
* @param entries
* @return created tree
@@ -150,7 +161,7 @@ public Tree createTree(IRepositoryIdProvider repository,
/**
* Create tree
- *
+ *
* @param repository
* @param entries
* @param baseTree
@@ -162,24 +173,25 @@ public Tree createTree(IRepositoryIdProvider repository,
final String id = getId(repository);
if (entries == null)
throw new IllegalArgumentException("Tree cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_TREES);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_TREES);
GitHubRequest request = createRequest();
request.setType(Tree.class);
request.setUri(uri);
Map<String, Object> params = new HashMap<String, Object>();
- params.put("tree", entries.toArray());
+ params.put("tree", entries.toArray()); //$NON-NLS-1$
if (baseTree != null)
- params.put("base_tree", baseTree);
+ params.put("base_tree", baseTree); //$NON-NLS-1$
return client.post(uri.toString(), params, Tree.class);
}
/**
* Get reference with given name
- *
+ *
* @param repository
* @param name
* @return reference
@@ -192,10 +204,11 @@ public Reference getReference(IRepositoryIdProvider repository, String name)
throw new IllegalArgumentException("Name cannot be null"); //$NON-NLS-1$
if (name.length() == 0)
throw new IllegalArgumentException("Name cannot be empty"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
+ uri.append(SEGMENT_GIT);
if (!name.startsWith("refs/")) //$NON-NLS-1$
uri.append(IGitHubConstants.SEGMENT_REFS);
uri.append('/').append(name);
@@ -207,7 +220,7 @@ public Reference getReference(IRepositoryIdProvider repository, String name)
/**
* Get references for given repository
- *
+ *
* @param repository
* @return non-null but possibly empty list of references
* @throws IOException
@@ -216,10 +229,10 @@ public Reference getReference(IRepositoryIdProvider repository, String name)
throws IOException {
final String id = getId(repository);
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_REFS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_REFS);
PagedRequest<Reference> request = createPagedRequest();
request.setType(new TypeToken<List<Reference>>() {
}.getType());
@@ -229,7 +242,7 @@ public Reference getReference(IRepositoryIdProvider repository, String name)
/**
* Create reference
- *
+ *
* @param repository
* @param reference
* @throws IOException
@@ -248,11 +261,12 @@ public void createReference(IRepositoryIdProvider repository,
String ref = reference.getRef();
if (ref == null)
throw new IllegalArgumentException("Ref cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_REFS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_REFS);
Map<String, String> params = new HashMap<String, String>();
params.put("ref", ref); //$NON-NLS-1$
params.put("sha", sha); //$NON-NLS-1$
@@ -261,7 +275,7 @@ public void createReference(IRepositoryIdProvider repository,
/**
* Edit reference
- *
+ *
* @param repository
* @param reference
* @return updated reference
@@ -274,7 +288,7 @@ public Reference editReference(IRepositoryIdProvider repository,
/**
* Edit reference
- *
+ *
* @param repository
* @param reference
* @param force
@@ -292,12 +306,13 @@ public Reference editReference(IRepositoryIdProvider repository,
String ref = reference.getRef();
if (ref == null)
throw new IllegalArgumentException("Ref cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
+ uri.append(SEGMENT_GIT);
if (!ref.startsWith("refs/")) //$NON-NLS-1$
- uri.append(IGitHubConstants.SEGMENT_REFS);
+ uri.append(SEGMENT_REFS);
uri.append('/').append(ref);
Map<String, Object> params = new HashMap<String, Object>();
params.put("sha", object.getSha()); //$NON-NLS-1$
@@ -308,7 +323,7 @@ public Reference editReference(IRepositoryIdProvider repository,
/**
* Get commit for given SHA-1
- *
+ *
* @param repository
* @param sha
* @return commit
@@ -321,11 +336,12 @@ public Commit getCommit(IRepositoryIdProvider repository, String sha)
throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$
if (sha.length() == 0)
throw new IllegalArgumentException("SHA-1 cannot be empty"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_COMMITS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_COMMITS);
uri.append('/').append(sha);
GitHubRequest request = createRequest();
request.setType(Commit.class);
@@ -335,7 +351,7 @@ public Commit getCommit(IRepositoryIdProvider repository, String sha)
/**
* Create commit in given repository
- *
+ *
* @param repository
* @param commit
* @return created commit
@@ -346,11 +362,12 @@ public Commit createCommit(IRepositoryIdProvider repository, Commit commit)
final String id = getId(repository);
if (commit == null)
throw new IllegalArgumentException("Commit cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_COMMITS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_COMMITS);
Map<String, Object> params = new HashMap<String, Object>();
params.put("author", commit.getAuthor()); //$NON-NLS-1$
params.put("committer", commit.getCommitter()); //$NON-NLS-1$
@@ -370,7 +387,7 @@ public Commit createCommit(IRepositoryIdProvider repository, Commit commit)
/**
* Get tag for given SHA-1
- *
+ *
* @param repository
* @param sha
* @return tag
@@ -383,11 +400,12 @@ public Tag getTag(IRepositoryIdProvider repository, String sha)
throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$
if (sha.length() == 0)
throw new IllegalArgumentException("SHA-1 cannot be empty"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_TAGS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_TAGS);
uri.append('/').append(sha);
GitHubRequest request = createRequest();
request.setType(Tag.class);
@@ -397,7 +415,7 @@ public Tag getTag(IRepositoryIdProvider repository, String sha)
/**
* Create tag object in given repository
- *
+ *
* @param repository
* @param tag
* @return created tag
@@ -407,21 +425,22 @@ public Tag createTag(IRepositoryIdProvider repository, Tag tag)
throws IOException {
final String id = getId(repository);
if (tag == null)
- throw new IllegalArgumentException("Tag cannot be null");
+ throw new IllegalArgumentException("Tag cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder();
- uri.append(IGitHubConstants.SEGMENT_REPOS);
+ uri.append(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_GIT);
- uri.append(IGitHubConstants.SEGMENT_TAGS);
+ uri.append(SEGMENT_GIT);
+ uri.append(SEGMENT_TAGS);
Map<String, Object> params = new HashMap<String, Object>();
- params.put("tag", tag.getTag());
- params.put("message", tag.getMessage());
+ params.put("tag", tag.getTag()); //$NON-NLS-1$
+ params.put("message", tag.getMessage()); //$NON-NLS-1$
TypedResource object = tag.getObject();
if (object != null) {
- params.put("object", object.getSha());
- params.put("type", object.getType());
+ params.put("object", object.getSha()); //$NON-NLS-1$
+ params.put("type", object.getType()); //$NON-NLS-1$
}
- params.put("tagger", tag.getTagger());
+ params.put("tagger", tag.getTagger()); //$NON-NLS-1$
return client.post(uri.toString(), params, Tag.class);
}
}
View
38 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DeployKeyService.java
@@ -10,6 +10,9 @@
*****************************************************************************/
package org.eclipse.egit.github.core.service;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_KEYS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
+
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
@@ -19,12 +22,11 @@
import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
-import org.eclipse.egit.github.core.client.IGitHubConstants;
import org.eclipse.egit.github.core.client.PagedRequest;
/**
* Service for interacting with a repository's deploy keys
- *
+ *
* @see <a href="http://developer.github.com/v3/repos/keys">GitHub Deploy Key
* API documentation</a>
*/
@@ -39,7 +41,7 @@ public DeployKeyService(GitHubClient client) {
/**
* Get all deploys keys associated with the given repository
- *
+ *
* @param repository
* @return non-null but possibly empty list of deploy keys
* @throws IOException
@@ -47,9 +49,9 @@ public DeployKeyService(GitHubClient client) {
public List<DeployKey> getKeys(IRepositoryIdProvider repository)
throws IOException {
String id = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_KEYS);
+ uri.append(SEGMENT_KEYS);
PagedRequest<DeployKey> request = createPagedRequest();
request.setUri(uri);
request.setType(new TypeToken<List<DeployKey>>() {
@@ -59,7 +61,7 @@ public DeployKeyService(GitHubClient client) {
/**
* Get deploy key with given id from given repository
- *
+ *
* @param repository
* @param id
* @return deploy key
@@ -68,9 +70,9 @@ public DeployKeyService(GitHubClient client) {
public DeployKey getKey(IRepositoryIdProvider repository, int id)
throws IOException {
String repoId = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_KEYS);
+ uri.append(SEGMENT_KEYS);
uri.append('/').append(id);
GitHubRequest request = createRequest();
request.setUri(uri);
@@ -80,7 +82,7 @@ public DeployKey getKey(IRepositoryIdProvider repository, int id)
/**
* Create deploy key to be associated with given repository
- *
+ *
* @param repository
* @param key
* @return created deploy key
@@ -89,15 +91,15 @@ public DeployKey getKey(IRepositoryIdProvider repository, int id)
public DeployKey createKey(IRepositoryIdProvider repository, DeployKey key)
throws IOException {
String id = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(id);
- uri.append(IGitHubConstants.SEGMENT_KEYS);
+ uri.append(SEGMENT_KEYS);
return client.post(uri.toString(), key, DeployKey.class);
}
/**
* Edit given deploy key
- *
+ *
* @param repository
* @param key
* @return edited deploy key
@@ -106,18 +108,18 @@ public DeployKey createKey(IRepositoryIdProvider repository, DeployKey key)
public DeployKey editKey(IRepositoryIdProvider repository, DeployKey key)
throws IOException {
if (key == null)
- throw new IllegalArgumentException("Key cannot be null");
+ throw new IllegalArgumentException("Key cannot be null"); //$NON-NLS-1$
String repoId = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_KEYS);
+ uri.append(SEGMENT_KEYS);
uri.append('/').append(key.getId());
return client.post(uri.toString(), key, DeployKey.class);
}
/**
* Deploy deploy key with given id from given repository
- *
+ *
* @param repository
* @param id
* @throws IOException
@@ -125,9 +127,9 @@ public DeployKey editKey(IRepositoryIdProvider repository, DeployKey key)
public void deleteKey(IRepositoryIdProvider repository, int id)
throws IOException {
String repoId = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_KEYS);
+ uri.append(SEGMENT_KEYS);
uri.append('/').append(id);
client.delete(uri.toString());
}
View
64 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DownloadService.java
@@ -10,6 +10,11 @@
*****************************************************************************/
package org.eclipse.egit.github.core.service;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_DOWNLOADS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
+
import com.google.gson.reflect.TypeToken;
import java.io.File;
@@ -28,13 +33,11 @@
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
-import org.eclipse.egit.github.core.Assert;
import org.eclipse.egit.github.core.Download;
import org.eclipse.egit.github.core.DownloadResource;
import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
-import org.eclipse.egit.github.core.client.IGitHubConstants;
import org.eclipse.egit.github.core.client.PageIterator;
import org.eclipse.egit.github.core.client.PagedRequest;
@@ -110,7 +113,7 @@ public DownloadService(GitHubClient client) {
/**
* Get download metadata for given repository and id
- *
+ *
* @param repository
* @param id
* @return download
@@ -119,9 +122,9 @@ public DownloadService(GitHubClient client) {
public Download getDownload(IRepositoryIdProvider repository, int id)
throws IOException {
final String repoId = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_DOWNLOADS);
+ uri.append(SEGMENT_DOWNLOADS);
uri.append('/').append(id);
GitHubRequest request = createRequest();
request.setUri(uri);
@@ -131,7 +134,7 @@ public Download getDownload(IRepositoryIdProvider repository, int id)
/**
* Create paged downloads request
- *
+ *
* @param repository
* @param start
* @param size
@@ -140,9 +143,9 @@ public Download getDownload(IRepositoryIdProvider repository, int id)
protected PagedRequest<Download> createDownloadsRequest(
IRepositoryIdProvider repository, int start, int size) {
final String repoId = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_DOWNLOADS);
+ uri.append(SEGMENT_DOWNLOADS);
PagedRequest<Download> request = createPagedRequest(start, size);
request.setType(new TypeToken<List<Download>>() {
}.getType());
@@ -152,7 +155,7 @@ public Download getDownload(IRepositoryIdProvider repository, int id)
/**
* Get metadata for all downloads for given repository
- *
+ *
* @param repository
* @return non-null but possibly empty list of download metadata
* @throws IOException
@@ -160,35 +163,35 @@ public Download getDownload(IRepositoryIdProvider repository, int id)
public List<Download> getDownloads(IRepositoryIdProvider repository)
throws IOException {
PagedRequest<Download> request = createDownloadsRequest(repository,
- PagedRequest.PAGE_FIRST, PagedRequest.PAGE_SIZE);
+ PAGE_FIRST, PAGE_SIZE);
return getAll(request);
}
/**
* Page metadata for downloads for given repository
- *
+ *
* @param repository
* @return iterator over pages of downloads
*/
public PageIterator<Download> pageDownloads(IRepositoryIdProvider repository) {
- return pageDownloads(repository, PagedRequest.PAGE_SIZE);
+ return pageDownloads(repository, PAGE_SIZE);
}
/**
* Page downloads for given repository
- *
+ *
* @param repository
* @param size
* @return iterator over pages of downloads
*/
public PageIterator<Download> pageDownloads(
IRepositoryIdProvider repository, int size) {
- return pageDownloads(repository, PagedRequest.PAGE_FIRST, size);
+ return pageDownloads(repository, PAGE_FIRST, size);
}
/**
* Page downloads for given repository
- *
+ *
* @param repository
* @param start
* @param size
@@ -203,7 +206,7 @@ public Download getDownload(IRepositoryIdProvider repository, int id)
/**
* Delete download with given id from given repository
- *
+ *
* @param repository
* @param id
* @throws IOException
@@ -211,16 +214,16 @@ public Download getDownload(IRepositoryIdProvider repository, int id)
public void deleteDownload(IRepositoryIdProvider repository, int id)
throws IOException {
final String repoId = getId(repository);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_DOWNLOADS);
+ uri.append(SEGMENT_DOWNLOADS);
uri.append('/').append(id);
client.delete(uri.toString());
}
/**
* Create a new resource for download associated with the given repository
- *
+ *
* @param repository
* @param download
* @return download resource
@@ -229,10 +232,12 @@ public void deleteDownload(IRepositoryIdProvider repository, int id)
public DownloadResource createResource(IRepositoryIdProvider repository,
Download download) throws IOException {
final String repoId = getId(repository);
- Assert.notNull("Download cannot be null", download);
- StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ if (download == null)
+ throw new IllegalArgumentException("Download cannot be null"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
uri.append('/').append(repoId);
- uri.append(IGitHubConstants.SEGMENT_DOWNLOADS);
+ uri.append(SEGMENT_DOWNLOADS);
return (DownloadResource) client.post(uri.toString(), download,
DownloadResource.class);
}
@@ -240,7 +245,7 @@ public DownloadResource createResource(IRepositoryIdProvider repository,
/**
* Upload a resource to be available as the download described by the given
* resource.
- *
+ *
* @param resource
* @param content
* @param size
@@ -248,7 +253,10 @@ public DownloadResource createResource(IRepositoryIdProvider repository,
*/
public void uploadResource(DownloadResource resource, InputStream content,
long size) throws IOException {
- Assert.notNull("Download resource cannot be null", resource);
+ if (resource == null)
+ throw new IllegalArgumentException(
+ "Download resource cannot be null"); //$NON-NLS-1$
+
DefaultHttpClient client = new DefaultHttpClient();
client.setRoutePlanner(new ProxySelectorRoutePlanner(client
.getConnectionManager().getSchemeRegistry(), ProxySelector
@@ -283,7 +291,7 @@ public void uploadResource(DownloadResource resource, InputStream content,
* {@link #createResource(IRepositoryIdProvider, Download)} followed by a
* {@link #uploadResource(DownloadResource, InputStream, long)} with the
* results.
- *
+ *
* @param repository
* @param download
* metadata about the download
@@ -302,7 +310,7 @@ public void createDownload(IRepositoryIdProvider repository,
/**
* Create download from content of given file.
- *
+ *
* @see #createDownload(IRepositoryIdProvider, Download, InputStream, long)
* @param repository
* @param download
@@ -313,7 +321,9 @@ public void createDownload(IRepositoryIdProvider repository,
*/
public void createDownload(IRepositoryIdProvider repository,
Download download, File file) throws IOException {
- Assert.notNull("File cannot be null", file);
+ if (file == null)
+ throw new IllegalArgumentException("File cannot be null"); //$NON-NLS-1$
+
createDownload(repository, download, new FileInputStream(file),
file.length());
}
View
80 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GistService.java
@@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
-import org.eclipse.egit.github.core.Assert;
import org.eclipse.egit.github.core.Comment;
import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.client.GitHubClient;
@@ -40,7 +39,7 @@
/**
* Create gist service
- *
+ *
* @param client
*/
public GistService(GitHubClient client) {
@@ -49,7 +48,7 @@ public GistService(GitHubClient client) {
/**
* Check that gist id is non-null and non-empty
- *
+ *
* @param gistId
* @return gist id
*/
@@ -63,7 +62,7 @@ protected String checkGistId(String gistId) {
/**
* Get gist
- *
+ *
* @param id
* @return gist
* @throws IOException
@@ -80,7 +79,7 @@ public Gist getGist(String id) throws IOException {
/**
* Get starred gists for currently authenticated user
- *
+ *
* @return list of gists
* @throws IOException
*/
@@ -94,7 +93,7 @@ public Gist getGist(String id) throws IOException {
/**
* Create user gist paged request
- *
+ *
* @param user
* @param start
* @param size
@@ -102,7 +101,9 @@ public Gist getGist(String id) throws IOException {
*/
protected PagedRequest<Gist> createUserGistRequest(String user, int start,
int size) {
- Assert.notNull("User cannot be null", user); //$NON-NLS-1$
+ if (user == null)
+ throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder(SEGMENT_USERS);
uri.append('/').append(user);
uri.append(SEGMENT_GISTS);
@@ -114,7 +115,7 @@ public Gist getGist(String id) throws IOException {
/**
* Get gists for specified user
- *
+ *
* @param user
* @return list of gists
* @throws IOException
@@ -127,7 +128,7 @@ public Gist getGist(String id) throws IOException {
/**
* Create page iterator for given user's gists
- *
+ *
* @param user
* @return gist page iterator
*/
@@ -137,7 +138,7 @@ public Gist getGist(String id) throws IOException {
/**
* Create page iterator for given user's gists
- *
+ *
* @param user
* @param size
* size of page
@@ -149,7 +150,7 @@ public Gist getGist(String id) throws IOException {
/**
* Create page iterator for given user's gists
- *
+ *
* @param user
* @param size
* size of page
@@ -165,7 +166,7 @@ public Gist getGist(String id) throws IOException {
/**
* Create page iterator for all public gists
- *
+ *
* @return gist page iterator
*/
public PageIterator<Gist> pagePublicGists() {
@@ -174,7 +175,7 @@ public Gist getGist(String id) throws IOException {
/**
* Create page iterator for all public gists
- *
+ *
* @param size
* size of page
* @return gist page iterator
@@ -185,7 +186,7 @@ public Gist getGist(String id) throws IOException {
/**
* Create page iterator for all public gists
- *
+ *
* @param start
* starting page number
* @param size
@@ -202,27 +203,32 @@ public Gist getGist(String id) throws IOException {
/**
* Create a gist
- *
+ *
* @param gist
* @return created gist
* @throws IOException
*/
public Gist createGist(Gist gist) throws IOException {
- Assert.notNull("Gist cannot be null", gist);
+ if (gist == null)
+ throw new IllegalArgumentException("Gist cannot be null"); //$NON-NLS-1$
+
return client.post(SEGMENT_GISTS, gist, Gist.class);
}
/**
* Update a gist
- *
+ *
* @param gist
* @return updated gist
* @throws IOException
*/
public Gist updateGist(Gist gist) throws IOException {
- Assert.notNull("Gist cannot be null", gist); //$NON-NLS-1$
+ if (gist == null)
+ throw new IllegalArgumentException("Gist cannot be null"); //$NON-NLS-1$
String id = gist.getId();
- Assert.notNull("Gist id cannot be null", id); //$NON-NLS-1$
+ if (id == null)
+ throw new IllegalArgumentException("Gist id cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder(SEGMENT_GISTS);
uri.append('/').append(id);
return client.post(uri.toString(), gist, Gist.class);
@@ -230,7 +236,7 @@ public Gist updateGist(Gist gist) throws IOException {
/**
* Create comment on specified gist id
- *
+ *
* @param gistId
* @param comment
* @return created issue
@@ -238,8 +244,11 @@ public Gist updateGist(Gist gist) throws IOException {
*/
public Comment createComment(String gistId, String comment)
throws IOException {
- Assert.notNull("Gist id cannot be null", gistId); //$NON-NLS-1$
- Assert.notNull("Gist comment cannot be null", comment);
+ if (gistId == null)
+ throw new IllegalArgumentException("Gist id cannot be null"); //$NON-NLS-1$
+ if (comment == null)
+ throw new IllegalArgumentException("Gist comment cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder(SEGMENT_GISTS);
uri.append('/').append(gistId);
uri.append(SEGMENT_COMMENTS);
@@ -251,13 +260,15 @@ public Comment createComment(String gistId, String comment)
/**
* Get comments for specified gist id
- *
+ *
* @param gistId
* @return list of comments
* @throws IOException
*/
public List<Comment> getComments(String gistId) throws IOException {
- Assert.notNull("Gist id cannot be null", gistId); //$NON-NLS-1$
+ if (gistId == null)
+ throw new IllegalArgumentException("Gist id cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder(SEGMENT_GISTS);
uri.append('/').append(gistId);
uri.append(SEGMENT_COMMENTS);
@@ -269,12 +280,14 @@ public Comment createComment(String gistId, String comment)
/**
* Delete the Gist with the given id
- *
+ *
* @param gistId
* @throws IOException
*/
public void deleteGist(String gistId) throws IOException {
- Assert.notNull("Gist id cannot be null", gistId); //$NON-NLS-1$
+ if (gistId == null)
+ throw new IllegalArgumentException("Gist id cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder(SEGMENT_GISTS);
uri.append('/').append(gistId);
client.delete(uri.toString());
@@ -282,12 +295,14 @@ public void deleteGist(String gistId) throws IOException {
/**
* Delete the Gist comment with the given id
- *
+ *
* @param commentId
* @throws IOException
*/
public void deleteComment(String commentId) throws IOException {
- Assert.notNull("Gist comment id cannot be null", commentId); //$NON-NLS-1$
+ if (commentId == null)
+ throw new IllegalArgumentException("Gist comment id cannot be null"); //$NON-NLS-1$
+
StringBuilder uri = new StringBuilder(SEGMENT_GISTS + SEGMENT_COMMENTS);
uri.append('/').append(commentId);
client.delete(uri.toString());
@@ -295,13 +310,12 @@ public void deleteComment(String commentId) throws IOException {
/**
* Star the gist with the given id
- *
+ *
* @param gistId
* @throws IOException
*/
public void starGist(String gistId) throws IOException {
checkGistId(gistId);
- Assert.notNull("Gist id cannot be null", gistId); //$NON-NLS-1$
StringBuilder uri = new StringBuilder(SEGMENT_GISTS);
uri.append('/').append(gistId);
uri.append(SEGMENT_STAR);
@@ -310,7 +324,7 @@ public void starGist(String gistId) throws IOException {
/**
* Unstar the gist with the given id
- *
+ *
* @param gistId
* @throws IOException
*/
@@ -324,7 +338,7 @@ public void unstarGist(String gistId) throws IOException {
/**
* Check if a gist is starred
- *
+ *
* @param gistId
* @return true if starred, false if not starred
* @throws IOException
@@ -339,7 +353,7 @@ public boolean isStarred(String gistId) throws IOException {
/**
* Fork gist with given id
- *
+ *
* @param gistId
* @return forked gist
* @throws IOException
View
42 org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
@@ -10,12 +10,14 @@
*******************************************************************************/
package org.eclipse.egit.github.core.service;
+import static org.apache.http.HttpStatus.SC_NOT_FOUND;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.http.HttpStatus;
-import org.eclipse.egit.github.core.Assert;
import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
@@ -36,18 +38,19 @@
/**
* Create service for client
- *
+ *
* @param client
*/
public GitHubService(GitHubClient client) {
- Assert.notNull("Client cannot be null", client); //$NON-NLS-1$
+ if (client == null)
+ throw new IllegalArgumentException("Client cannot be null"); //$NON-NLS-1$
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() {
@@ -57,18 +60,17 @@ protected GitHubRequest createRequest() {
/**
* Unified paged request creation method that all sub-classes should use so
* overriding classes can extend and configure the default request.
- *
+ *
* @return request
*/
protected <V> PagedRequest<V> createPagedRequest() {
- return createPagedRequest(PagedRequest.PAGE_FIRST,
- PagedRequest.PAGE_SIZE);
+ return createPagedRequest(PAGE_FIRST, PAGE_SIZE);
}
/**
* Unified paged request creation method that all sub-classes should use so
* overriding classes can extend and configure the default request.
- *
+ *
* @param start