]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11421 Add sha1 to ProjectAnalysis
authorBenoît Gianinetti <benoit.gianinetti@sonarsource.com>
Thu, 1 Nov 2018 09:53:00 +0000 (10:53 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 8 Jan 2019 19:21:04 +0000 (20:21 +0100)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java
sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTester.java

index 4556743b147838a2fe7b7354f800070af3d56194..4e14bc38d18a2ac511f6ef0e1da01c4381d1822d 100644 (file)
@@ -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{" +
index e03fc74189379e726c0e38c3eebdb45dd521e482..5ee2b694d31cc93566de8c9210044292abf95090 100644 (file)
@@ -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
index b89cbfdfd8a6d04c446aae987bdc73fa1e944bfe..ec1b4be349a9362769b93798d8572e24ce692b83 100644 (file)
@@ -122,5 +122,10 @@ public interface PostProjectAnalysisTask {
      * @since 6.1
      */
     ScannerContext getScannerContext();
+
+    /**
+     * Revision Id that has been analysed
+     */
+    String getScmRevisionId();
   }
 }
index 35670ce5da8db7e169332066652157b371ff6606..c049497d2aa91e7fe8dce3b88aa98fbc660356da 100644 (file)
@@ -781,6 +781,11 @@ public class PostProjectAnalysisTaskTester {
           return scannerContext;
         }
 
+        @Override
+        public String getScmRevisionId() {
+          return null;
+        }
+
         @Override
         public String toString() {
           return "ProjectAnalysis{" +