You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QualityGatesServiceCreateResponseJsonParser.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.ws.client.qualitygates;
  21. import com.google.gson.Gson;
  22. import com.google.gson.JsonObject;
  23. import com.google.protobuf.ByteString;
  24. import com.google.protobuf.CodedInputStream;
  25. import com.google.protobuf.ExtensionRegistryLite;
  26. import com.google.protobuf.InvalidProtocolBufferException;
  27. import com.google.protobuf.Parser;
  28. import java.io.BufferedReader;
  29. import java.io.IOException;
  30. import java.io.InputStream;
  31. import java.io.InputStreamReader;
  32. import java.io.Reader;
  33. import java.nio.ByteBuffer;
  34. import java.nio.charset.Charset;
  35. import java.nio.charset.StandardCharsets;
  36. import org.sonarqube.ws.Qualitygates;
  37. public class QualityGatesServiceCreateResponseJsonParser implements Parser<Qualitygates.CreateResponse> {
  38. @Override
  39. public Qualitygates.CreateResponse parseFrom(CodedInputStream input) throws InvalidProtocolBufferException {
  40. throw new IllegalStateException("not implemented");
  41. }
  42. @Override
  43. public Qualitygates.CreateResponse parseFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  44. throw new IllegalStateException("not implemented");
  45. }
  46. @Override
  47. public Qualitygates.CreateResponse parsePartialFrom(CodedInputStream input) throws InvalidProtocolBufferException {
  48. throw new IllegalStateException("not implemented");
  49. }
  50. @Override
  51. public Qualitygates.CreateResponse parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  52. throw new IllegalStateException("not implemented");
  53. }
  54. @Override
  55. public Qualitygates.CreateResponse parseFrom(ByteBuffer data) throws InvalidProtocolBufferException {
  56. throw new IllegalStateException("not implemented");
  57. }
  58. @Override
  59. public Qualitygates.CreateResponse parseFrom(ByteBuffer data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  60. throw new IllegalStateException("not implemented");
  61. }
  62. @Override
  63. public Qualitygates.CreateResponse parseFrom(ByteString data) throws InvalidProtocolBufferException {
  64. throw new IllegalStateException("not implemented");
  65. }
  66. @Override
  67. public Qualitygates.CreateResponse parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  68. throw new IllegalStateException("not implemented");
  69. }
  70. @Override
  71. public Qualitygates.CreateResponse parsePartialFrom(ByteString data) throws InvalidProtocolBufferException {
  72. throw new IllegalStateException("not implemented");
  73. }
  74. @Override
  75. public Qualitygates.CreateResponse parsePartialFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  76. throw new IllegalStateException("not implemented");
  77. }
  78. @Override
  79. public Qualitygates.CreateResponse parseFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException {
  80. throw new IllegalStateException("not implemented");
  81. }
  82. @Override
  83. public Qualitygates.CreateResponse parseFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  84. throw new IllegalStateException("not implemented");
  85. }
  86. @Override
  87. public Qualitygates.CreateResponse parseFrom(byte[] data) throws InvalidProtocolBufferException {
  88. throw new IllegalStateException("not implemented");
  89. }
  90. @Override
  91. public Qualitygates.CreateResponse parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  92. throw new IllegalStateException("not implemented");
  93. }
  94. @Override
  95. public Qualitygates.CreateResponse parsePartialFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException {
  96. throw new IllegalStateException("not implemented");
  97. }
  98. @Override
  99. public Qualitygates.CreateResponse parsePartialFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  100. throw new IllegalStateException("not implemented");
  101. }
  102. @Override
  103. public Qualitygates.CreateResponse parsePartialFrom(byte[] data) throws InvalidProtocolBufferException {
  104. throw new IllegalStateException("not implemented");
  105. }
  106. @Override
  107. public Qualitygates.CreateResponse parsePartialFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  108. throw new IllegalStateException("not implemented");
  109. }
  110. @Override
  111. public Qualitygates.CreateResponse parseFrom(InputStream input) throws InvalidProtocolBufferException {
  112. Qualitygates.CreateResponse.Builder builder = Qualitygates.CreateResponse.newBuilder();
  113. String json = readInputStream(input);
  114. JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
  115. builder.setName(jobj.get("name").getAsString());
  116. return builder.build();
  117. }
  118. private String readInputStream(InputStream input) {
  119. StringBuilder textBuilder = new StringBuilder();
  120. try (Reader reader = new BufferedReader(new InputStreamReader(input, Charset.forName(StandardCharsets.UTF_8.name())))) {
  121. int c = 0;
  122. while ((c = reader.read()) != -1) {
  123. textBuilder.append((char) c);
  124. }
  125. } catch (IOException e) {
  126. throw new IllegalArgumentException(e);
  127. }
  128. return textBuilder.toString();
  129. }
  130. @Override
  131. public Qualitygates.CreateResponse parseFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  132. throw new IllegalStateException("not implemented");
  133. }
  134. @Override
  135. public Qualitygates.CreateResponse parsePartialFrom(InputStream input) throws InvalidProtocolBufferException {
  136. throw new IllegalStateException("not implemented");
  137. }
  138. @Override
  139. public Qualitygates.CreateResponse parsePartialFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  140. throw new IllegalStateException("not implemented");
  141. }
  142. @Override
  143. public Qualitygates.CreateResponse parseDelimitedFrom(InputStream input) throws InvalidProtocolBufferException {
  144. return parseFrom(input);
  145. }
  146. @Override
  147. public Qualitygates.CreateResponse parseDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  148. throw new IllegalStateException("not implemented");
  149. }
  150. @Override
  151. public Qualitygates.CreateResponse parsePartialDelimitedFrom(InputStream input) throws InvalidProtocolBufferException {
  152. throw new IllegalStateException("not implemented");
  153. }
  154. @Override
  155. public Qualitygates.CreateResponse parsePartialDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
  156. throw new IllegalStateException("not implemented");
  157. }
  158. }