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.

Project.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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.alm.client.gitlab;
  21. import com.google.gson.Gson;
  22. import com.google.gson.annotations.SerializedName;
  23. import com.google.gson.reflect.TypeToken;
  24. import java.util.LinkedList;
  25. import java.util.List;
  26. public class Project {
  27. // https://docs.gitlab.com/ee/api/projects.html#get-single-project
  28. // https://docs.gitlab.com/ee/api/projects.html#list-all-projects
  29. @SerializedName("id")
  30. private long id;
  31. @SerializedName("name")
  32. private final String name;
  33. @SerializedName("name_with_namespace")
  34. private String nameWithNamespace;
  35. @SerializedName("path")
  36. private String path;
  37. @SerializedName("path_with_namespace")
  38. private final String pathWithNamespace;
  39. @SerializedName("web_url")
  40. private String webUrl;
  41. public Project(String name, String pathWithNamespace) {
  42. this.name = name;
  43. this.pathWithNamespace = pathWithNamespace;
  44. }
  45. public Project() {
  46. // http://stackoverflow.com/a/18645370/229031
  47. this(0, "", "", "", "", "");
  48. }
  49. public Project(long id, String name, String nameWithNamespace, String path, String pathWithNamespace,
  50. String webUrl) {
  51. this.id = id;
  52. this.name = name;
  53. this.nameWithNamespace = nameWithNamespace;
  54. this.path = path;
  55. this.pathWithNamespace = pathWithNamespace;
  56. this.webUrl = webUrl;
  57. }
  58. public static Project parseJson(String json) {
  59. Gson gson = new Gson();
  60. return gson.fromJson(json, Project.class);
  61. }
  62. public static List<Project> parseJsonArray(String json) {
  63. Gson gson = new Gson();
  64. return gson.fromJson(json, new TypeToken<LinkedList<Project>>() {
  65. });
  66. }
  67. public long getId() {
  68. return id;
  69. }
  70. public String getName() {
  71. return name;
  72. }
  73. public String getNameWithNamespace() {
  74. return nameWithNamespace;
  75. }
  76. public String getPath() {
  77. return path;
  78. }
  79. public String getPathWithNamespace() {
  80. return pathWithNamespace;
  81. }
  82. public String getWebUrl() {
  83. return webUrl;
  84. }
  85. }