選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TelemetryDataJsonWriter.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.sonar.server.telemetry;
  21. import java.util.Locale;
  22. import org.sonar.api.utils.text.JsonWriter;
  23. import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
  24. public class TelemetryDataJsonWriter {
  25. private TelemetryDataJsonWriter() {
  26. // static methods
  27. }
  28. public static void writeTelemetryData(JsonWriter json, TelemetryData statistics) {
  29. json.beginObject();
  30. json.prop("id", statistics.getServerId());
  31. json.prop("version", statistics.getVersion());
  32. statistics.getEdition().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
  33. statistics.getLicenseType().ifPresent(e -> json.prop("licenseType", e));
  34. json.name("database");
  35. json.beginObject();
  36. json.prop("name", statistics.getDatabase().getName());
  37. json.prop("version", statistics.getDatabase().getVersion());
  38. json.endObject();
  39. json.name("plugins");
  40. json.beginArray();
  41. statistics.getPlugins().forEach((plugin, version) -> {
  42. json.beginObject();
  43. json.prop("name", plugin);
  44. json.prop("version", version);
  45. json.endObject();
  46. });
  47. json.endArray();
  48. json.prop("userCount", statistics.getUserCount());
  49. json.prop("projectCount", statistics.getProjectCount());
  50. json.prop("usingBranches", statistics.isUsingBranches());
  51. json.prop(NCLOC_KEY, statistics.getNcloc());
  52. json.name("projectCountByLanguage");
  53. json.beginArray();
  54. statistics.getProjectCountByLanguage().forEach((language, count) -> {
  55. json.beginObject();
  56. json.prop("language", language);
  57. json.prop("count", count);
  58. json.endObject();
  59. });
  60. json.endArray();
  61. json.name("nclocByLanguage");
  62. json.beginArray();
  63. statistics.getNclocByLanguage().forEach((language, ncloc) -> {
  64. json.beginObject();
  65. json.prop("language", language);
  66. json.prop("ncloc", ncloc);
  67. json.endObject();
  68. });
  69. json.endArray();
  70. if (statistics.getInstallationDate() != null) {
  71. json.prop("installationDate", statistics.getInstallationDate());
  72. }
  73. if (statistics.getInstallationVersion() != null) {
  74. json.prop("installationVersion", statistics.getInstallationVersion());
  75. }
  76. json.endObject();
  77. }
  78. }