Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-25 09:49:23 +0000
committerTomasz Zarna2013-10-04 10:29:13 +0000
commit66dbae71697648a9cde990855ae94c8550e24513 (patch)
tree94a9af900f6c252353049a4b064a56cc0c8778bf
parente9dc59989d59c9824ee72cf4c6e1b0e4c0237c79 (diff)
downloadorg.eclipse.mylyn.reviews-66dbae71697648a9cde990855ae94c8550e24513.tar.gz
org.eclipse.mylyn.reviews-66dbae71697648a9cde990855ae94c8550e24513.tar.xz
org.eclipse.mylyn.reviews-66dbae71697648a9cde990855ae94c8550e24513.zip
remove JsonSupport#getGson
Change-Id: I2f53956d6bfa1aa8f3358b83a3627a5574a01bad Signed-off-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java4
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java4
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java2
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java4
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java10
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java4
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java4
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java10
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInputTest.java2
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/SubmitInputTest.java2
10 files changed, 24 insertions, 22 deletions
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java
index b9a1f414b..127e6a5b1 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java
@@ -357,7 +357,7 @@ public class GerritConnector extends ReviewsConnector {
private static GerritConfiguration configurationFromString(String token) {
try {
JSonSupport support = new JSonSupport();
- return support.getGson().fromJson(token, GerritConfiguration.class);
+ return support.parseResponse(token, GerritConfiguration.class);
} catch (Exception e) {
StatusHandler.log(new Status(IStatus.ERROR, GerritCorePlugin.PLUGIN_ID,
"Failed to deserialize configuration: '" + token + "'", e));
@@ -368,7 +368,7 @@ public class GerritConnector extends ReviewsConnector {
private static String configurationToString(GerritConfiguration config) {
try {
JSonSupport support = new JSonSupport();
- return support.getGson().toJson(config);
+ return support.toJson(config);
} catch (Exception e) {
StatusHandler.log(new Status(IStatus.ERROR, GerritCorePlugin.PLUGIN_ID,
"Failed to serialize configuration", e));
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
index d3e43d4c7..aeea8d283 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
@@ -176,7 +176,7 @@ public class GerritClient extends ReviewsClient {
public static GerritAuthenticationState authStateFromString(String token) {
try {
JSonSupport support = new JSonSupport();
- return support.getGson().fromJson(token, GerritAuthenticationState.class);
+ return support.parseResponse(token, GerritAuthenticationState.class);
} catch (Exception e) {
// ignore
return null;
@@ -190,7 +190,7 @@ public class GerritClient extends ReviewsClient {
}
try {
JSonSupport support = new JSonSupport();
- return support.getGson().toJson(authState);
+ return support.toJson(authState);
} catch (Exception e) {
// ignore
return null;
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java
index efcc193f6..633e65250 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java
@@ -36,7 +36,7 @@ public class GerritHtmlProcessor {
private static GerritConfigX gerritConfigFromString(String token) {
try {
JSonSupport support = new JSonSupport();
- return support.getGson().fromJson(token, GerritConfigX.class);
+ return support.parseResponse(token, GerritConfigX.class);
} catch (Exception e) {
StatusHandler.log(new Status(IStatus.ERROR, GerritCorePlugin.PLUGIN_ID,
"Failed to deserialize Gerrit configuration: '" + token + "'", e));
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
index 8a700744d..730c78996 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
@@ -4,7 +4,7 @@
* 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:
* Sony Ericsson/ST Ericsson - initial API and implementation
* Tasktop Technologies - improvements
@@ -148,7 +148,7 @@ public class GerritHttpClient {
private HttpMethodBase createPostMethod() throws IOException {
PostMethod method = new PostMethod(getUrl() + serviceUri);
- String content = json.getGson().toJson(input);
+ String content = json.toJson(input);
RequestEntity requestEntity = new StringRequestEntity(content, "application/json", null); //$NON-NLS-1$
method.setRequestEntity(requestEntity);
return method;
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java
index a33cbe904..3782a9001 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java
@@ -187,10 +187,6 @@ public class JSonSupport {
.create();
}
- public Gson getGson() {
- return gson;
- }
-
String createRequest(int id, String xsrfKey, String methodName, Collection<Object> args) {
JsonRequest msg = new JsonRequest();
msg.method = methodName;
@@ -218,9 +214,15 @@ public class JSonSupport {
Assert.isLegal(responseMessage != null);
Assert.isLegal(!responseMessage.isEmpty());
+ // Gerrit 2.5 prepends the output with bogus characters
+ // see http://code.google.com/p/gerrit/issues/detail?id=1648
if (responseMessage.startsWith(")]}'\n")) { //$NON-NLS-1$
responseMessage = responseMessage.substring(5);
}
return gson.fromJson(responseMessage, resultType);
}
+
+ public String toJson(Object src) {
+ return gson.toJson(src);
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java
index 39523f759..80aa38c2d 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java
@@ -37,7 +37,7 @@ public class AbandonInputTest extends TestCase {
public void testFromEmpty() throws Exception {
AbandonInput abandonInput = new AbandonInput("");
- String json = new JSonSupport().getGson().toJson(abandonInput);
+ String json = new JSonSupport().toJson(abandonInput);
assertNotNull(json);
assertFalse(json.isEmpty());
@@ -48,7 +48,7 @@ public class AbandonInputTest extends TestCase {
public void testFromValid() throws Exception {
AbandonInput abandonInput = new AbandonInput("Whatever");
- String json = new JSonSupport().getGson().toJson(abandonInput);
+ String json = new JSonSupport().toJson(abandonInput);
assertNotNull(json);
assertFalse(json.isEmpty());
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java
index c81d74d64..9cdec0e38 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java
@@ -37,7 +37,7 @@ public class RestoreInputTest extends TestCase {
public void testFromEmpty() throws Exception {
RestoreInput restoreInput = new RestoreInput("");
- String json = new JSonSupport().getGson().toJson(restoreInput);
+ String json = new JSonSupport().toJson(restoreInput);
assertNotNull(json);
assertFalse(json.isEmpty());
@@ -48,7 +48,7 @@ public class RestoreInputTest extends TestCase {
public void testFromValid() throws Exception {
RestoreInput restoreInput = new RestoreInput("Whatever");
- String json = new JSonSupport().getGson().toJson(restoreInput);
+ String json = new JSonSupport().toJson(restoreInput);
assertNotNull(json);
assertFalse(json.isEmpty());
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java
index 36a545ace..75b925e81 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java
@@ -42,7 +42,7 @@ public class ReviewInputTest extends TestCase {
public void testFromEmpty() throws Exception {
ReviewInput reviewInput = new ReviewInput("");
- String json = new JSonSupport().getGson().toJson(reviewInput);
+ String json = new JSonSupport().toJson(reviewInput);
assertNotNull(json);
assertFalse(json.isEmpty());
@@ -53,7 +53,7 @@ public class ReviewInputTest extends TestCase {
public void testFromValid() throws Exception {
ReviewInput reviewInput = new ReviewInput("Looking good!");
- String json = new JSonSupport().getGson().toJson(reviewInput);
+ String json = new JSonSupport().toJson(reviewInput);
assertNotNull(json);
assertFalse(json.isEmpty());
@@ -65,7 +65,7 @@ public class ReviewInputTest extends TestCase {
ReviewInput reviewInput = new ReviewInput("");
reviewInput.setApprovals(null);
- String json = new JSonSupport().getGson().toJson(reviewInput);
+ String json = new JSonSupport().toJson(reviewInput);
assertNotNull(json);
assertFalse(json.isEmpty());
@@ -77,7 +77,7 @@ public class ReviewInputTest extends TestCase {
ReviewInput reviewInput = new ReviewInput("");
reviewInput.setApprovals(Collections.<ApprovalCategoryValue.Id> emptySet());
- String json = new JSonSupport().getGson().toJson(reviewInput);
+ String json = new JSonSupport().toJson(reviewInput);
assertNotNull(json);
assertFalse(json.isEmpty());
@@ -91,7 +91,7 @@ public class ReviewInputTest extends TestCase {
approvals.add(ApprovalUtil.CRVW.getValue((short) 1).getId());
reviewInput.setApprovals(approvals);
- String json = new JSonSupport().getGson().toJson(reviewInput);
+ String json = new JSonSupport().toJson(reviewInput);
assertNotNull(json);
assertFalse(json.isEmpty());
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInputTest.java
index fa38f72be..822794961 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInputTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInputTest.java
@@ -46,7 +46,7 @@ public class ReviewerInputTest extends TestCase {
public void testFromValid() throws Exception {
ReviewerInput reviewerInput = new ReviewerInput("john.doe@example.com");
- String json = new JSonSupport().getGson().toJson(reviewerInput);
+ String json = new JSonSupport().toJson(reviewerInput);
assertNotNull(json);
assertFalse(json.isEmpty());
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/SubmitInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/SubmitInputTest.java
index 24cf25cbf..8f1166295 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/SubmitInputTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/SubmitInputTest.java
@@ -26,7 +26,7 @@ public class SubmitInputTest extends TestCase {
SubmitInput submitInput = new SubmitInput(true);
assertTrue(submitInput.isWaitForMerge());
- String json = new JSonSupport().getGson().toJson(submitInput);
+ String json = new JSonSupport().toJson(submitInput);
assertNotNull(json);
assertFalse(json.isEmpty());

Back to the top