From ea906c4f2b2d9b404b141aeeebf5d54f5148bdcf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Gianinetti?= Date: Thu, 1 Nov 2018 10:53:00 +0100 Subject: [PATCH] SONAR-11421 Add sha1 to ProjectAnalysis --- .../posttask/PostProjectAnalysisTasksExecutor.java | 13 +++++++++++-- .../PostProjectAnalysisTasksExecutorTest.java | 2 ++ .../api/ce/posttask/PostProjectAnalysisTask.java | 5 +++++ .../ce/posttask/PostProjectAnalysisTaskTester.java | 5 +++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java index 4556743b147..4e14bc38d18 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java @@ -125,7 +125,9 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor getAnalysis().map(a -> a.getDate().getTime()).orElse(system2.now()), ScannerContextImpl.from(reportReader.readContextProperties()), status == SUCCESS ? createQualityGate() : null, - createBranch()); + createBranch(), + reportReader.readMetadata().getScmRevisionId() + ); } @CheckForNull @@ -223,10 +225,11 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor private final Branch branch; @Nullable private final Analysis analysis; + private final String scmRevisionId; private ProjectAnalysisImpl(@Nullable Organization organization, CeTask ceTask, Project project, @Nullable Analysis analysis, long date, - ScannerContext scannerContext, @Nullable QualityGate qualityGate, @Nullable Branch branch) { + ScannerContext scannerContext, @Nullable QualityGate qualityGate, @Nullable Branch branch, String scmRevisionId) { this.organization = organization; this.ceTask = requireNonNull(ceTask, "ceTask can not be null"); this.project = requireNonNull(project, "project can not be null"); @@ -235,6 +238,7 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor this.scannerContext = requireNonNull(scannerContext, "scannerContext can not be null"); this.qualityGate = qualityGate; this.branch = branch; + this.scmRevisionId = scmRevisionId; } @Override @@ -283,6 +287,11 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor return scannerContext; } + @Override + public String getScmRevisionId() { + return scmRevisionId; + } + @Override public String toString() { return "ProjectAnalysis{" + diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java index e03fc741893..5ee2b694d31 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java @@ -114,6 +114,8 @@ public class PostProjectAnalysisTasksExecutorTest { .setOrganizationsEnabled(new Random().nextBoolean()) .setOrganization(Organization.from( new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo"))); + + reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build()); } @Test 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 b89cbfdfd8a..ec1b4be349a 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 @@ -122,5 +122,10 @@ public interface PostProjectAnalysisTask { * @since 6.1 */ ScannerContext getScannerContext(); + + /** + * Revision Id that has been analysed + */ + String getScmRevisionId(); } } 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 35670ce5da8..c049497d2aa 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 @@ -781,6 +781,11 @@ public class PostProjectAnalysisTaskTester { return scannerContext; } + @Override + public String getScmRevisionId() { + return null; + } + @Override public String toString() { return "ProjectAnalysis{" + -- 2.39.5