aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java19
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java6
3 files changed, 28 insertions, 4 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java
index 254cffdcc97..fc35319a17f 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java
@@ -83,7 +83,12 @@ public class ScmInfoDbLoader {
}
if (isReferenceBranch()) {
- return Optional.ofNullable(newCodeReferenceBranchComponentUuids.getComponentUuid(file.getDbKey()));
+ var referencedBranchComponentUuid = newCodeReferenceBranchComponentUuids.getComponentUuid(file.getDbKey());
+ if (referencedBranchComponentUuid != null) {
+ return Optional.of(referencedBranchComponentUuid);
+ }
+ // no file to diff was found or missing reference branch changeset - use existing file
+ return Optional.of(file.getUuid());
}
// at this point, it's the first analysis of a branch with copyFromPrevious flag true or any analysis of a PR
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java
index fdd502b82fb..12a2ac8948c 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java
@@ -162,6 +162,25 @@ public class ScmInfoDbLoaderTest {
}
@Test
+ public void read_from_db_if_not_exist_in_reference_branch() {
+ periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), null, null));
+
+ Branch branch = mock(Branch.class);
+ when(branch.getType()).thenReturn(BranchType.BRANCH);
+ analysisMetadataHolder.setBaseAnalysis(null);
+ analysisMetadataHolder.setBranch(branch);
+
+ String hash = computeSourceHash(1);
+
+ addFileSourceInDb("henry", DATE_1, "rev-1", hash, FILE.getUuid());
+
+ DbScmInfo scmInfo = underTest.getScmInfo(FILE).get();
+ assertThat(scmInfo.getAllChangesets()).hasSize(1);
+ assertThat(scmInfo.fileHash()).isEqualTo(hash);
+ assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'FILE_UUID'");
+ }
+
+ @Test
public void return_empty_if_no_dto_available() {
analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
analysisMetadataHolder.setBranch(null);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
index aebe65007de..ca4a9cae98a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
@@ -44,9 +44,9 @@ import org.sonar.scanner.bootstrap.ExtensionMatcher;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.PostJobExtensionDictionary;
import org.sonar.scanner.cache.AnalysisCacheEnabled;
-import org.sonar.scanner.cache.DefaultAnalysisCacheLoader;
import org.sonar.scanner.cache.AnalysisCacheMemoryStorage;
import org.sonar.scanner.cache.AnalysisCacheProvider;
+import org.sonar.scanner.cache.DefaultAnalysisCacheLoader;
import org.sonar.scanner.ci.CiConfigurationProvider;
import org.sonar.scanner.ci.vendors.AppVeyor;
import org.sonar.scanner.ci.vendors.AwsCodeBuild;
@@ -81,6 +81,7 @@ import org.sonar.scanner.postjob.PostJobOptimizer;
import org.sonar.scanner.postjob.PostJobsExecutor;
import org.sonar.scanner.qualitygate.QualityGateCheck;
import org.sonar.scanner.report.ActiveRulesPublisher;
+import org.sonar.scanner.report.AnalysisCachePublisher;
import org.sonar.scanner.report.AnalysisContextReportPublisher;
import org.sonar.scanner.report.AnalysisWarningsPublisher;
import org.sonar.scanner.report.CeTaskReportDataHolder;
@@ -88,7 +89,6 @@ import org.sonar.scanner.report.ChangedLinesPublisher;
import org.sonar.scanner.report.ComponentsPublisher;
import org.sonar.scanner.report.ContextPropertiesPublisher;
import org.sonar.scanner.report.MetadataPublisher;
-import org.sonar.scanner.report.AnalysisCachePublisher;
import org.sonar.scanner.report.ReportPublisher;
import org.sonar.scanner.report.SourcePublisher;
import org.sonar.scanner.report.TestExecutionPublisher;
@@ -241,12 +241,12 @@ public class SpringProjectScanContainer extends SpringComponentContainer {
AnalysisContextReportPublisher.class,
MetadataPublisher.class,
ActiveRulesPublisher.class,
- AnalysisWarningsPublisher.class,
ComponentsPublisher.class,
AnalysisCachePublisher.class,
TestExecutionPublisher.class,
SourcePublisher.class,
ChangedLinesPublisher.class,
+ AnalysisWarningsPublisher.class,
CeTaskReportDataHolder.class,