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.

CeTaskSubmit.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.ce.queue;
  21. import java.util.Map;
  22. import java.util.Objects;
  23. import java.util.Optional;
  24. import javax.annotation.CheckForNull;
  25. import javax.annotation.Nullable;
  26. import javax.annotation.concurrent.Immutable;
  27. import org.sonar.db.component.ComponentDto;
  28. import static com.google.common.base.MoreObjects.firstNonNull;
  29. import static com.google.common.base.Strings.emptyToNull;
  30. import static com.google.common.base.Strings.nullToEmpty;
  31. import static java.util.Collections.unmodifiableMap;
  32. import static java.util.Objects.requireNonNull;
  33. @Immutable
  34. public final class CeTaskSubmit {
  35. private final String uuid;
  36. private final String type;
  37. private final Component component;
  38. private final String submitterUuid;
  39. private final Map<String, String> characteristics;
  40. private CeTaskSubmit(Builder builder) {
  41. this.uuid = requireNonNull(builder.uuid);
  42. this.type = requireNonNull(builder.type);
  43. this.component = builder.component;
  44. this.submitterUuid = builder.submitterUuid;
  45. this.characteristics = unmodifiableMap(builder.characteristics);
  46. }
  47. public String getType() {
  48. return type;
  49. }
  50. public String getUuid() {
  51. return uuid;
  52. }
  53. public Optional<Component> getComponent() {
  54. return Optional.ofNullable(component);
  55. }
  56. @CheckForNull
  57. public String getSubmitterUuid() {
  58. return submitterUuid;
  59. }
  60. public Map<String, String> getCharacteristics() {
  61. return characteristics;
  62. }
  63. public static final class Builder {
  64. private final String uuid;
  65. private String type;
  66. private Component component;
  67. private String submitterUuid;
  68. private Map<String, String> characteristics = null;
  69. public Builder(String uuid) {
  70. this.uuid = emptyToNull(uuid);
  71. }
  72. public String getUuid() {
  73. return uuid;
  74. }
  75. public Builder setType(String s) {
  76. this.type = emptyToNull(s);
  77. return this;
  78. }
  79. public Builder setComponent(@Nullable Component component) {
  80. this.component = component;
  81. return this;
  82. }
  83. public Builder setSubmitterUuid(@Nullable String s) {
  84. this.submitterUuid = s;
  85. return this;
  86. }
  87. public Builder setCharacteristics(Map<String, String> m) {
  88. this.characteristics = m;
  89. return this;
  90. }
  91. public CeTaskSubmit build() {
  92. requireNonNull(uuid, "uuid can't be null");
  93. requireNonNull(type, "type can't be null");
  94. requireNonNull(characteristics, "characteristics can't be null");
  95. return new CeTaskSubmit(this);
  96. }
  97. }
  98. public static class Component {
  99. private String uuid;
  100. private String mainComponentUuid;
  101. public Component(String uuid, String mainComponentUuid) {
  102. this.uuid = requireNonNull(nullToEmpty(uuid), "uuid can't be null");
  103. this.mainComponentUuid = requireNonNull(nullToEmpty(mainComponentUuid), "mainComponentUuid can't be null");
  104. }
  105. public static Component fromDto(ComponentDto dto) {
  106. String uuid = dto.uuid();
  107. return new Component(uuid, firstNonNull(dto.getMainBranchProjectUuid(), uuid));
  108. }
  109. public String getUuid() {
  110. return uuid;
  111. }
  112. public String getMainComponentUuid() {
  113. return mainComponentUuid;
  114. }
  115. @Override
  116. public String toString() {
  117. return "Component{" +
  118. "uuid='" + uuid + '\'' +
  119. ", mainComponentUuid='" + mainComponentUuid + '\'' +
  120. '}';
  121. }
  122. @Override
  123. public boolean equals(Object o) {
  124. if (this == o) {
  125. return true;
  126. }
  127. if (o == null || getClass() != o.getClass()) {
  128. return false;
  129. }
  130. Component component = (Component) o;
  131. return uuid.equals(component.uuid) && mainComponentUuid.equals(component.mainComponentUuid);
  132. }
  133. @Override
  134. public int hashCode() {
  135. return Objects.hash(uuid, mainComponentUuid);
  136. }
  137. }
  138. }