diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-07-31 17:46:48 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 10:52:52 +0200 |
commit | 7d547a80af1ed289564d0af2e1dfb304cdc9c3f1 (patch) | |
tree | acbce790ca61aed6928f8dd3ce2b9c0b61605873 /sonar-plugin-api | |
parent | 7515f738fb15473d144dd376fac2a1562486c049 (diff) | |
download | sonarqube-7d547a80af1ed289564d0af2e1dfb304cdc9c3f1.tar.gz sonarqube-7d547a80af1ed289564d0af2e1dfb304cdc9c3f1.zip |
SONAR-9616 add branch to CE API and webhook JSON payload
Diffstat (limited to 'sonar-plugin-api')
3 files changed, 109 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/Branch.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/Branch.java new file mode 100644 index 00000000000..a5f0eb0be2f --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/Branch.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.sonar.api.ce.posttask; + +import java.util.Optional; + +/** + * @since 6.6 + */ +public interface Branch { + + enum Type { + LONG, SHORT + } + + boolean isMain(); + + Optional<String> getName(); + + Type getType(); + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java index 8d3cbd56d7f..c63043a85e2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java @@ -63,6 +63,13 @@ public interface PostProjectAnalysisTask { Project getProject(); /** + * The branch that is being analyzed. + * + * @since 6.6 + */ + Optional<Branch> getBranch(); + + /** * Status and details of the Quality Gate of the project (if any was configured on the project). */ @CheckForNull diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTester.java index 5b4b42b2ac7..2c9e358071b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTester.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTester.java @@ -25,6 +25,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -107,6 +108,8 @@ public class PostProjectAnalysisTaskTester { private Date date; @CheckForNull private QualityGate qualityGate; + @CheckForNull + private Branch branch; private ScannerContext scannerContext; private PostProjectAnalysisTaskTester(PostProjectAnalysisTask underTest) { @@ -125,6 +128,10 @@ public class PostProjectAnalysisTaskTester { return new ProjectBuilder(); } + public static BranchBuilder newBranchBuilder() { + return new BranchBuilder(); + } + public static QualityGateBuilder newQualityGateBuilder() { return new QualityGateBuilder(); } @@ -165,6 +172,11 @@ public class PostProjectAnalysisTaskTester { return this; } + public PostProjectAnalysisTaskTester withBranch(@Nullable Branch b) { + this.branch = b; + return this; + } + public void execute() { requireNonNull(ceTask, CE_TASK_CAN_NOT_BE_NULL); requireNonNull(project, PROJECT_CAN_NOT_BE_NULL); @@ -188,6 +200,11 @@ public class PostProjectAnalysisTaskTester { } @Override + public Optional<Branch> getBranch() { + return Optional.ofNullable(branch); + } + + @Override public QualityGate getQualityGate() { return qualityGate; } @@ -323,6 +340,52 @@ public class PostProjectAnalysisTaskTester { } } + public static final class BranchBuilder { + private boolean isMain = true; + private String name = null; + private Branch.Type type = Branch.Type.LONG; + + private BranchBuilder() { + // prevents instantiation outside PostProjectAnalysisTaskTester + } + + public BranchBuilder setName(@Nullable String s) { + this.name = s; + return this; + } + + public BranchBuilder setType(Branch.Type t) { + this.type = Objects.requireNonNull(t); + return this; + } + + public BranchBuilder setIsMain(boolean b) { + this.isMain = b; + return this; + } + + public Branch build() { + return new Branch() { + + + @Override + public boolean isMain() { + return isMain; + } + + @Override + public Optional<String> getName() { + return Optional.ofNullable(name); + } + + @Override + public Type getType() { + return type; + } + }; + } + } + public static final class QualityGateBuilder { private static final String ID_CAN_NOT_BE_NULL = "id cannot be null"; private static final String NAME_CAN_NOT_BE_NULL = "name cannot be null"; |