aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws/src
diff options
context:
space:
mode:
authorPierre <pierre.guillot@sonarsource.com>2020-04-20 09:53:17 +0200
committersonartech <sonartech@sonarsource.com>2020-05-25 20:05:21 +0000
commitac532a55b9c7ee51b8ad3516103b453f030392d6 (patch)
tree44c32aa7e245542fc1e105f339890e2b0a08d46d /sonar-ws/src
parent16b2b85fc200856e65175663bbe2477012be9275 (diff)
downloadsonarqube-ac532a55b9c7ee51b8ad3516103b453f030392d6.tar.gz
sonarqube-ac532a55b9c7ee51b8ad3516103b453f030392d6.zip
SONAR-13221 change PK of quality gates from id to uuid, update FKs, update API
Diffstat (limited to 'sonar-ws/src')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java6
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualityGatesServiceCreateResponseJsonParser.java188
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java35
-rw-r--r--sonar-ws/src/main/protobuf/ws-qualitygates.proto10
4 files changed, 217 insertions, 22 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java
index ed2a93fb863..7b138c2a382 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java
@@ -42,7 +42,11 @@ public abstract class BaseService {
}
protected <T extends Message> T call(BaseRequest request, Parser<T> parser) {
- request.setMediaType(MediaTypes.PROTOBUF);
+ return call(request, parser, MediaTypes.PROTOBUF);
+ }
+
+ protected <T extends Message> T call(BaseRequest request, Parser<T> parser, String mediaType) {
+ request.setMediaType(mediaType);
WsResponse response = call(request);
return convert(response, parser);
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualityGatesServiceCreateResponseJsonParser.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualityGatesServiceCreateResponseJsonParser.java
new file mode 100644
index 00000000000..3c60184e4d2
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualityGatesServiceCreateResponseJsonParser.java
@@ -0,0 +1,188 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.ws.client.qualitygates;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.CodedInputStream;
+import com.google.protobuf.ExtensionRegistryLite;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.Parser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import org.sonarqube.ws.Qualitygates;
+
+public class QualityGatesServiceCreateResponseJsonParser implements Parser<Qualitygates.CreateResponse> {
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(CodedInputStream input) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(CodedInputStream input) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(ByteBuffer data) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(ByteBuffer data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(ByteString data) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(ByteString data) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(byte[] data) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(byte[] data) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(InputStream input) throws InvalidProtocolBufferException {
+ Qualitygates.CreateResponse.Builder builder = Qualitygates.CreateResponse.newBuilder();
+ String json = readInputStream(input);
+ JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
+ builder.setId(jobj.get("id").getAsString());
+ builder.setName(jobj.get("name").getAsString());
+ return builder.build();
+ }
+
+ private String readInputStream(InputStream input) {
+ StringBuilder textBuilder = new StringBuilder();
+ try (Reader reader = new BufferedReader(new InputStreamReader(input, Charset.forName(StandardCharsets.UTF_8.name())))) {
+ int c = 0;
+ while ((c = reader.read()) != -1) {
+ textBuilder.append((char) c);
+ }
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ return textBuilder.toString();
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(InputStream input) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseDelimitedFrom(InputStream input) throws InvalidProtocolBufferException {
+ return parseFrom(input);
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parseDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialDelimitedFrom(InputStream input) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Qualitygates.CreateResponse parsePartialDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
+ throw new IllegalStateException("not implemented");
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java
index 3214ba6e92c..e878ab79eca 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java
@@ -57,8 +57,7 @@ public class QualitygatesService extends BaseService {
.setParam("id", request.getId())
.setParam("name", request.getName())
.setParam("organization", request.getOrganization())
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
@@ -77,6 +76,17 @@ public class QualitygatesService extends BaseService {
}
/**
+ * Use this for to use a JSON payload, useful to parse the quality gate as Long or String
+ */
+ public CreateResponse createJson(CreateRequest request) {
+ return call(
+ new PostRequest(path("create"))
+ .setParam("name", request.getName())
+ .setParam("organization", request.getOrganization()),
+ new QualityGatesServiceCreateResponseJsonParser(), MediaTypes.JSON);
+ }
+
+ /**
* This is part of the internal API.
* This is a POST request.
*
@@ -106,8 +116,7 @@ public class QualitygatesService extends BaseService {
new PostRequest(path("delete_condition"))
.setParam("id", request.getId())
.setParam("organization", request.getOrganization())
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
@@ -123,8 +132,7 @@ public class QualitygatesService extends BaseService {
.setParam("organization", request.getOrganization())
.setParam("projectId", request.getProjectId())
.setParam("projectKey", request.getProjectKey())
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
@@ -139,8 +147,7 @@ public class QualitygatesService extends BaseService {
new PostRequest(path("destroy"))
.setParam("id", request.getId())
.setParam("organization", request.getOrganization())
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
@@ -203,8 +210,7 @@ public class QualitygatesService extends BaseService {
.setParam("id", request.getId())
.setParam("name", request.getName())
.setParam("organization", request.getOrganization())
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
@@ -240,8 +246,7 @@ public class QualitygatesService extends BaseService {
.setParam("organization", request.getOrganization())
.setParam("projectId", request.getProjectId())
.setParam("projectKey", request.getProjectKey())
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
@@ -256,8 +261,7 @@ public class QualitygatesService extends BaseService {
new PostRequest(path("set_as_default"))
.setParam("id", request.getId())
.setParam("organization", request.getOrganization())
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
@@ -288,8 +292,7 @@ public class QualitygatesService extends BaseService {
public String unsetDefault() {
return call(
new PostRequest(path("unset_default"))
- .setMediaType(MediaTypes.JSON)
- ).content();
+ .setMediaType(MediaTypes.JSON)).content();
}
/**
diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
index 097e3f56723..ced73a13574 100644
--- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto
+++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
@@ -75,7 +75,7 @@ message GetByProjectResponse {
}
message QualityGate {
- optional int64 id = 1;
+ optional string id = 1;
optional string name = 2;
optional bool default = 3;
}
@@ -96,7 +96,7 @@ message AppResponse {
// POST api/qualitygates/create
message CreateResponse {
- optional int64 id = 1;
+ optional string id = 1;
optional string name = 2;
}
@@ -118,7 +118,7 @@ message UpdateConditionResponse {
// GET api/qualitygates/show
message ShowWsResponse {
- optional int64 id = 1;
+ optional string id = 1;
optional string name = 2;
repeated Condition conditions = 3;
optional bool isBuiltIn = 4;
@@ -150,11 +150,11 @@ message SearchResponse {
message ListWsResponse {
repeated QualityGate qualitygates = 1;
// Deprecated since 7.0
- optional int64 default = 2;
+ optional string default = 2;
optional RootActions actions = 3;
message QualityGate {
- optional int64 id = 1;
+ optional string id = 1;
optional string name = 2;
optional bool isDefault = 3;
optional bool isBuiltIn = 4;