aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-09-30 12:23:26 -0500
committersonartech <sonartech@sonarsource.com>2022-10-12 20:03:44 +0000
commit50b12df3787d87958fcef7fbf8c00598b141f1ee (patch)
treecbc6fd2927bd89d8f68b84d06e00dd419c4025e5 /server/sonar-ce-task-projectanalysis
parentc85e433a567b8580a1fd5e185b4f5bc73b6e53e6 (diff)
downloadsonarqube-50b12df3787d87958fcef7fbf8c00598b141f1ee.tar.gz
sonarqube-50b12df3787d87958fcef7fbf8c00598b141f1ee.zip
SONAR-17352 Refactor component keys to not include branch suffix
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java13
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImpl.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java25
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryImpl.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java30
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java55
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java6
21 files changed, 121 insertions, 101 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java
index 4d65f853965..abb3952be3a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java
@@ -37,17 +37,18 @@ public class ProjectConfigurationFactory {
this.dbClient = dbClient;
}
- public Configuration newProjectConfiguration(String projectKey, Branch branch) {
+ public Configuration newProjectConfiguration(String projectUuid, String branchUuid) {
Settings projectSettings = new ChildSettings(globalSettings);
- addSettings(projectSettings, projectKey);
- // TODO branch / PR
- addSettings(projectSettings, projectKey);
+ addSettings(projectSettings, projectUuid);
+ if (!projectUuid.equals(branchUuid)) {
+ addSettings(projectSettings, branchUuid);
+ }
return new ConfigurationBridge(projectSettings);
}
- private void addSettings(Settings settings, String componentDbKey) {
+ private void addSettings(Settings settings, String componentUuid) {
dbClient.propertiesDao()
- .selectProjectProperties(componentDbKey)
+ .selectComponentProperties(componentUuid)
.forEach(property -> settings.setProperty(property.getKey(), property.getValue()));
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImpl.java
index 31b044c65e4..26e3fd4feb0 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImpl.java
@@ -22,9 +22,11 @@ package org.sonar.ce.task.projectanalysis.component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchType;
import org.sonar.db.component.KeyWithUuidDto;
public class ComponentUuidFactoryImpl implements ComponentUuidFactory {
@@ -35,6 +37,18 @@ public class ComponentUuidFactoryImpl implements ComponentUuidFactory {
keys.forEach(dto -> uuidsByKey.put(dto.key(), dto.uuid()));
}
+ public ComponentUuidFactoryImpl(DbClient dbClient, DbSession dbSession, String rootKey, Branch branch) {
+ List<KeyWithUuidDto> keys;
+ if (branch.isMain()) {
+ keys = dbClient.componentDao().selectUuidsByKeyFromProjectKey(dbSession, rootKey);
+ } else if (branch.getType() == BranchType.PULL_REQUEST) {
+ keys = dbClient.componentDao().selectUuidsByKeyFromProjectKeyAndPullRequest(dbSession, rootKey, branch.getPullRequestKey());
+ } else {
+ keys = dbClient.componentDao().selectUuidsByKeyFromProjectKeyAndBranch(dbSession, rootKey, branch.getName());
+ }
+ keys.forEach(dto -> uuidsByKey.put(dto.key(), dto.uuid()));
+ }
+
/**
* Get UUID from database if it exists, otherwise generate a new one.
*/
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java
index 894853ba7c6..c8b963690d7 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java
@@ -30,9 +30,11 @@ import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentWithModuleUuidDto;
import org.sonar.db.component.KeyWithUuidDto;
@@ -41,13 +43,22 @@ public class ComponentUuidFactoryWithMigration implements ComponentUuidFactory {
private final Map<String, String> uuidsByDbKey = new HashMap<>();
private final Map<String, String> uuidsByMigratedKey = new HashMap<>();
- public ComponentUuidFactoryWithMigration(DbClient dbClient, DbSession dbSession, String rootKey, Function<String, String> pathToKey, Map<String, String> reportModulesPath) {
+ public ComponentUuidFactoryWithMigration(DbClient dbClient, DbSession dbSession, String rootKey, Branch branch,
+ Function<String, String> pathToKey, Map<String, String> reportModulesPath) {
Map<String, String> modulePathsByUuid;
- List<KeyWithUuidDto> keys = dbClient.componentDao().selectUuidsByKeyFromProjectKey(dbSession, rootKey);
+ List<KeyWithUuidDto> keys;
+ if (branch.isMain()) {
+ keys = dbClient.componentDao().selectUuidsByKeyFromProjectKey(dbSession, rootKey);
+ } else if (branch.getType() == BranchType.PULL_REQUEST) {
+ keys = dbClient.componentDao().selectUuidsByKeyFromProjectKeyAndPullRequest(dbSession, rootKey, branch.getPullRequestKey());
+ } else {
+ keys = dbClient.componentDao().selectUuidsByKeyFromProjectKeyAndBranch(dbSession, rootKey, branch.getName());
+ }
+
keys.forEach(dto -> uuidsByDbKey.put(dto.key(), dto.uuid()));
if (!reportModulesPath.isEmpty()) {
- modulePathsByUuid = loadModulePathsByUuid(dbClient, dbSession, rootKey, reportModulesPath);
+ modulePathsByUuid = loadModulePathsByUuid(dbClient, dbSession, rootKey, branch, reportModulesPath);
if (!modulePathsByUuid.isEmpty()) {
doMigration(dbClient, dbSession, rootKey, pathToKey, modulePathsByUuid);
@@ -96,9 +107,13 @@ public class ComponentUuidFactoryWithMigration implements ComponentUuidFactory {
return dbClient.componentDao().selectEnabledComponentsWithModuleUuidFromProjectKey(dbSession, rootKey);
}
- private static Map<String, String> loadModulePathsByUuid(DbClient dbClient, DbSession dbSession, String rootKey, Map<String, String> pathByModuleKey) {
+ private static Map<String, String> loadModulePathsByUuid(DbClient dbClient, DbSession dbSession, String rootKey,
+ Branch branch, Map<String, String> pathByModuleKey) {
+ String branchKey = branch.getType() == BranchType.BRANCH ? branch.getName() : null;
+ String prKey = branch.getType() == BranchType.PULL_REQUEST ? branch.getPullRequestKey() : null;
+
List<ComponentDto> moduleDtos = dbClient.componentDao()
- .selectProjectAndModulesFromProjectKey(dbSession, rootKey, true).stream()
+ .selectProjectAndModulesFromProjectKey(dbSession, rootKey, true, branchKey, prKey).stream()
.filter(c -> Qualifiers.MODULE.equals(c.qualifier()))
.collect(Collectors.toList());
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryImpl.java
index 04970136a94..02aba3d59fe 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryImpl.java
@@ -32,8 +32,10 @@ public class ConfigurationRepositoryImpl implements ConfigurationRepository {
private final Supplier<Configuration> configuration;
- public ConfigurationRepositoryImpl(AnalysisMetadataHolder analysisMetadataHolder, ProjectConfigurationFactory f) {
- this.configuration = Suppliers.memoize(() -> f.newProjectConfiguration(analysisMetadataHolder.getProject().getKey(), analysisMetadataHolder.getBranch()));
+ public ConfigurationRepositoryImpl(TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder, ProjectConfigurationFactory f) {
+ String branchUuid = treeRootHolder.getRoot().getUuid();
+ String projectUuid = analysisMetadataHolder.getProject().getUuid();
+ this.configuration = Suppliers.memoize(() -> f.newProjectConfiguration(projectUuid, branchUuid));
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java
index f77a898e369..099fbcd4e19 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java
@@ -31,7 +31,6 @@ import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import static com.google.common.base.Preconditions.checkState;
-import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey;
/**
* Cache a map between component keys and uuids in the reference branch
@@ -87,9 +86,8 @@ public class ReferenceBranchComponentUuids {
}
@CheckForNull
- public String getComponentUuid(String dbKey) {
+ public String getComponentUuid(String key) {
lazyInit();
- String cleanComponentKey = removeBranchAndPullRequestFromKey(dbKey);
- return referenceBranchComponentsUuidsByKey.get(cleanComponentKey);
+ return referenceBranchComponentsUuidsByKey.get(key);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java
index ffa537805b2..1bd2e4499a1 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java
@@ -30,8 +30,6 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.KeyWithUuidDto;
-import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey;
-
/**
* Cache a map of component key -> set&lt;uuid&gt; in:
* - sibling PRs that have open issues
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java
index ea027852f83..06c825707e9 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java
@@ -72,7 +72,11 @@ class ProjectTrackerBaseLazyInput extends BaseInputFactory.BaseLazyInput {
if (!dirOrModulesUuidsWithIssues.isEmpty()) {
Map<String, String> pathByModuleKey = reportModulesPath.get();
// Migrate issues that were previously on modules or directories to the root project
- Map<String, ComponentDto> modulesByUuid = dbClient.componentDao().selectProjectAndModulesFromProjectKey(dbSession, component.getKey(), true)
+ String branchKey = analysisMetadataHolder.isBranch() ? analysisMetadataHolder.getBranch().getName() : null;
+ String prKey = analysisMetadataHolder.isPullRequest() ? analysisMetadataHolder.getBranch().getPullRequestKey() : null;
+
+ Map<String, ComponentDto> modulesByUuid = dbClient.componentDao()
+ .selectProjectAndModulesFromProjectKey(dbSession, component.getKey(), true, branchKey, prKey)
.stream().collect(Collectors.toMap(ComponentDto::uuid, Function.identity()));
List<ComponentDto> dirOrModulesWithIssues = dbClient.componentDao().selectByUuids(dbSession, dirOrModulesUuidsWithIssues);
dirOrModulesWithIssues.forEach(c -> {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
index 60c94d1f999..661820926b3 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
@@ -30,7 +30,6 @@ import org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssu
import org.sonar.core.issue.DefaultIssue;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.PrIssueDto;
@@ -52,8 +51,7 @@ public class SiblingsIssuesLoader {
}
public Collection<SiblingIssue> loadCandidateSiblingIssuesForMerging(Component component) {
- String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getKey());
- Set<String> uuids = siblingComponentsWithOpenIssues.getUuids(componentKey);
+ Set<String> uuids = siblingComponentsWithOpenIssues.getUuids(component.getKey());
if (uuids.isEmpty()) {
return Collections.emptyList();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java
index 409c8204d48..bca0a4af370 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java
@@ -30,8 +30,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey;
-
/**
* Cache a map between component keys and uuids in the source branch of a pull request
*/
@@ -79,9 +77,8 @@ public class SourceBranchComponentUuids {
}
@CheckForNull
- public String getSourceBranchComponentUuid(String dbKey) {
+ public String getSourceBranchComponentUuid(String key) {
lazyInit();
- String cleanComponentKey = removeBranchAndPullRequestFromKey(dbKey);
- return sourceBranchComponentsUuidsByKey.get(cleanComponentKey);
+ return sourceBranchComponentsUuidsByKey.get(key);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java
index 725cf52f6da..40ffea79fe2 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java
@@ -30,8 +30,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey;
-
/**
* Cache a map between component keys and uuids in the merge branch and optionally the target branch (for PR and SLB, and only if this target branch is analyzed)
*/
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java
index c45a933d1d3..5833d847ea2 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java
@@ -32,8 +32,6 @@ import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
-import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey;
-
/**
* Cache a map between component keys and uuids in the reference branch
*/
@@ -76,9 +74,8 @@ public class NewCodeReferenceBranchComponentUuids {
}
@CheckForNull
- public String getComponentUuid(String dbKey) {
+ public String getComponentUuid(String key) {
lazyInit();
- String cleanComponentKey = removeBranchAndPullRequestFromKey(dbKey);
- return referenceBranchComponentsUuidsByKey.get(cleanComponentKey);
+ return referenceBranchComponentsUuidsByKey.get(key);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
index 6607b973a75..e27cb71510d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
@@ -79,7 +79,8 @@ public class BuildComponentTreeStep implements ComputationStep {
String rootKey = keyGenerator.generateKey(reportProject.getKey(), null);
Function<String, String> pathToKey = path -> keyGenerator.generateKey(reportProject.getKey(), path);
// loads the UUIDs from database. If they don't exist, then generate new ones
- ComponentUuidFactoryWithMigration componentUuidFactoryWithMigration = new ComponentUuidFactoryWithMigration(dbClient, dbSession, rootKey, pathToKey, reportModulesPath.get());
+ ComponentUuidFactoryWithMigration componentUuidFactoryWithMigration =
+ new ComponentUuidFactoryWithMigration(dbClient, dbSession, rootKey, analysisMetadataHolder.getBranch(), pathToKey, reportModulesPath.get());
String rootUuid = componentUuidFactoryWithMigration.getOrCreateForKey(rootKey);
Optional<SnapshotDto> baseAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, rootUuid);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
index 16adb079fbd..28ff34d9775 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
@@ -149,7 +149,7 @@ public class PersistComponentsStep implements ComputationStep {
* disabled components.
*/
private Map<String, ComponentDto> indexExistingDtosByUuids(DbSession session) {
- return dbClient.componentDao().selectAllComponentsFromProjectKey(session, treeRootHolder.getRoot().getKey())
+ return dbClient.componentDao().selectByBranchUuid(treeRootHolder.getRoot().getUuid(), session)
.stream()
.collect(Collectors.toMap(ComponentDto::uuid, Function.identity()));
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
index 52716dd4e90..ac1a139afc5 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
@@ -67,7 +67,9 @@ public class ValidateProjectStep implements ComputationStep {
validateTargetBranch(dbSession);
Component root = treeRootHolder.getRoot();
// FIXME if module have really be dropped, no more need to load them
- List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey());
+ String branchKey = analysisMetadataHolder.isBranch() ? analysisMetadataHolder.getBranch().getName() : null;
+ String prKey = analysisMetadataHolder.isPullRequest() ? analysisMetadataHolder.getBranch().getPullRequestKey() : null;
+ List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey(), branchKey, prKey);
Map<String, ComponentDto> baseModulesByKey = baseModules.stream().collect(Collectors.toMap(ComponentDto::getKey, x -> x));
ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey);
new DepthTraversalTypeAwareCrawler(visitor).visit(root);
@@ -134,7 +136,7 @@ public class ValidateProjectStep implements ComputationStep {
Long lastAnalysisDate = snapshotDto.map(SnapshotDto::getCreatedAt).orElse(null);
if (lastAnalysisDate != null && currentAnalysisDate <= lastAnalysisDate) {
validationMessages.add(format("Date of analysis cannot be older than the date of the last known analysis on this project. Value: \"%s\". " +
- "Latest analysis: \"%s\". It's only possible to rebuild the past in a chronological order.",
+ "Latest analysis: \"%s\". It's only possible to rebuild the past in a chronological order.",
formatDateTime(new Date(currentAnalysisDate)), formatDateTime(new Date(lastAnalysisDate))));
}
}
@@ -143,7 +145,11 @@ public class ValidateProjectStep implements ComputationStep {
ComponentDto baseComponent = baseModulesByKey.get(rawComponentKey);
if (baseComponent == null) {
// Load component from key to be able to detect issue (try to analyze a module, etc.)
- return componentDao.selectByKey(session, rawComponentKey);
+ if (analysisMetadataHolder.isBranch()) {
+ return componentDao.selectByKeyAndBranch(session, rawComponentKey, analysisMetadataHolder.getBranch().getName());
+ } else {
+ return componentDao.selectByKeyAndPullRequest(session, rawComponentKey, analysisMetadataHolder.getBranch().getPullRequestKey());
+ }
}
return Optional.of(baseComponent);
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java
index f6c512561db..69011ec0095 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java
@@ -31,20 +31,16 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
public class ProjectConfigurationFactoryTest {
-
- private static final String PROJECT_KEY = "PROJECT_KEY";
-
@Rule
public DbTester db = DbTester.create();
private MapSettings settings = new MapSettings();
-
private ProjectConfigurationFactory underTest = new ProjectConfigurationFactory(settings, db.getDbClient());
@Test
public void return_global_settings() {
settings.setProperty("key", "value");
- Configuration config = underTest.newProjectConfiguration(PROJECT_KEY, new DefaultBranchImpl());
+ Configuration config = underTest.newProjectConfiguration("unknown", "unknown");
assertThat(config.get("key")).hasValue("value");
}
@@ -57,7 +53,7 @@ public class ProjectConfigurationFactoryTest {
newComponentPropertyDto(project).setKey("2").setValue("val2"),
newComponentPropertyDto(project).setKey("3").setValue("val3"));
- Configuration config = underTest.newProjectConfiguration(project.getKey(), new DefaultBranchImpl());
+ Configuration config = underTest.newProjectConfiguration(project.uuid(), project.uuid());
assertThat(config.get("1")).hasValue("val1");
assertThat(config.get("2")).hasValue("val2");
@@ -71,7 +67,7 @@ public class ProjectConfigurationFactoryTest {
db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
newComponentPropertyDto(project).setKey("key").setValue("value2"));
- Configuration projectConfig = underTest.newProjectConfiguration(project.getKey(), new DefaultBranchImpl());
+ Configuration projectConfig = underTest.newProjectConfiguration(project.uuid(), project.uuid());
assertThat(projectConfig.get("key")).hasValue("value2");
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java
index 230d04ee3d3..7f3839bab0f 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java
@@ -26,6 +26,7 @@ import java.util.function.Function;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
@@ -33,7 +34,7 @@ import org.sonar.db.component.ComponentTesting;
import static org.assertj.core.api.Assertions.assertThat;
public class ComponentUuidFactoryWithMigrationTest {
-
+ private final Branch mainBranch = new DefaultBranchImpl();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
private Function<String, String> pathToKey = path -> path != null ? "project:" + path : "project";
@@ -45,7 +46,8 @@ public class ComponentUuidFactoryWithMigrationTest {
Map<String, String> reportModulesPath = Collections.singletonMap(module.getKey(), "module1_path");
pathToKey = path -> path != null ? project.getKey() + ":" + path : project.getKey();
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, reportModulesPath);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, reportModulesPath);
assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
assertThat(underTest.getOrCreateForKey(module.getKey())).isEqualTo(module.uuid());
@@ -69,7 +71,8 @@ public class ComponentUuidFactoryWithMigrationTest {
Map<String, String> modulesRelativePaths = new HashMap<>();
modulesRelativePaths.put("project:module1", "module1_path");
modulesRelativePaths.put("project:module1:module2", "module1_path/module2_path");
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
// migrated files
assertThat(underTest.getOrCreateForKey("project:file1_path")).isEqualTo(file1.uuid());
@@ -94,7 +97,8 @@ public class ComponentUuidFactoryWithMigrationTest {
Map<String, String> modulesRelativePaths = new HashMap<>();
modulesRelativePaths.put("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
// migrated files
assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid());
@@ -118,7 +122,8 @@ public class ComponentUuidFactoryWithMigrationTest {
Map<String, String> modulesRelativePaths = new HashMap<>();
modulesRelativePaths.put("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
// migrated files
assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid());
@@ -142,7 +147,8 @@ public class ComponentUuidFactoryWithMigrationTest {
Map<String, String> modulesRelativePaths = new HashMap<>();
modulesRelativePaths.put("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
// in theory we should migrate file1. But since disabledFileSameKey already have the expected migrated key, let's reuse it.
assertThat(underTest.getOrCreateForKey("project:module1/file1")).isEqualTo(disabledFileSameKey.uuid());
@@ -170,7 +176,8 @@ public class ComponentUuidFactoryWithMigrationTest {
Map<String, String> modulesRelativePaths = new HashMap<>();
modulesRelativePaths.put("project:module1", "module1_path");
modulesRelativePaths.put("project:module1:module2", "module1_path/module2_path");
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
// migrated files
assertThat(underTest.getOrCreateForKey("project:file1_path")).isEqualTo(file1.uuid());
@@ -189,7 +196,8 @@ public class ComponentUuidFactoryWithMigrationTest {
.setKey("project:module1:/"));
Map<String, String> modulesRelativePaths = Collections.singletonMap("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
// project remains the same
assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
@@ -210,7 +218,8 @@ public class ComponentUuidFactoryWithMigrationTest {
Map<String, String> modulesRelativePaths = new HashMap<>();
modulesRelativePaths.put("project", "");
modulesRelativePaths.put("project:module2", "module2");
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths);
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
// check root project.
assertThat(underTest.getOrCreateForKey("project")).isEqualTo(project.uuid());
@@ -218,7 +227,8 @@ public class ComponentUuidFactoryWithMigrationTest {
@Test
public void generate_uuid_if_it_does_not_exist_in_db() {
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), "theProjectKey", pathToKey, Collections.emptyMap());
+ ComponentUuidFactoryWithMigration underTest =
+ new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), "theProjectKey", mainBranch, pathToKey, Collections.emptyMap());
String generatedKey = underTest.getOrCreateForKey("foo");
assertThat(generatedKey).isNotEmpty();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java
index 072eec8a5ba..a7e43c2b813 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java
@@ -41,28 +41,30 @@ import static org.mockito.Mockito.when;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
public class ConfigurationRepositoryTest {
-
- private static Project PROJECT = Project.from(newPrivateProjectDto());
-
@Rule
public final DbTester db = DbTester.create(System2.INSTANCE);
+ @Rule
+ public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
+ @Rule
+ public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
- private DbClient dbClient = db.getDbClient();
- private MapSettings globalSettings = new MapSettings();
- private Branch branch = mock(Branch.class);
- private AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
+ private final DbClient dbClient = db.getDbClient();
+ private final MapSettings globalSettings = new MapSettings();
+ private final Project project = Project.from(newPrivateProjectDto());
+ private final Component root = mock(Component.class);
private ConfigurationRepository underTest;
+
@Before
public void setUp() {
- when(branch.getName()).thenReturn("branchName");
- analysisMetadataHolder.setBranch(branch);
- underTest = new ConfigurationRepositoryImpl(analysisMetadataHolder, new ProjectConfigurationFactory(globalSettings, dbClient));
+ analysisMetadataHolder.setProject(project);
+ when(root.getUuid()).thenReturn(project.getUuid());
+ treeRootHolder.setRoot(root);
+ underTest = new ConfigurationRepositoryImpl(treeRootHolder, analysisMetadataHolder, new ProjectConfigurationFactory(globalSettings, dbClient));
}
@Test
public void get_project_settings_from_global_settings() {
- analysisMetadataHolder.setProject(PROJECT);
globalSettings.setProperty("key", "value");
Configuration config = underTest.getConfiguration();
@@ -72,9 +74,7 @@ public class ConfigurationRepositoryTest {
@Test
public void get_project_settings_from_db() {
- ComponentDto project = db.components().insertPrivateProject();
- analysisMetadataHolder.setProject(Project.from(project));
- insertProjectProperty(project, "key", "value");
+ insertComponentProperty(project.getUuid(), "key", "value");
Configuration config = underTest.getConfiguration();
@@ -83,7 +83,6 @@ public class ConfigurationRepositoryTest {
@Test
public void call_twice_get_project_settings() {
- analysisMetadataHolder.setProject(PROJECT);
globalSettings.setProperty("key", "value");
Configuration config = underTest.getConfiguration();
@@ -96,9 +95,7 @@ public class ConfigurationRepositoryTest {
@Test
public void project_settings_override_global_settings() {
globalSettings.setProperty("key", "value1");
- ComponentDto project = db.components().insertPrivateProject();
- insertProjectProperty(project, "key", "value2");
- analysisMetadataHolder.setProject(Project.from(project));
+ insertComponentProperty(project.getUuid(), "key", "value2");
Configuration config = underTest.getConfiguration();
assertThat(config.get("key")).hasValue("value2");
@@ -106,9 +103,7 @@ public class ConfigurationRepositoryTest {
@Test
public void project_settings_are_cached_to_avoid_db_access() {
- ComponentDto project = db.components().insertPrivateProject();
- insertProjectProperty(project, "key", "value");
- analysisMetadataHolder.setProject(Project.from(project));
+ insertComponentProperty(project.getUuid(), "key", "value");
Configuration config = underTest.getConfiguration();
assertThat(config.get("key")).hasValue("value");
@@ -121,17 +116,9 @@ public class ConfigurationRepositoryTest {
@Test
public void branch_settings() {
- ComponentDto project = db.components().insertPublicProject();
- String branchName = randomAlphanumeric(248);
- ComponentDto branchDto = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
- Branch branch = mock(Branch.class);
- when(branch.getName()).thenReturn(branchName);
- analysisMetadataHolder
- .setProject(Project.from(project))
- .setBranch(branch);
globalSettings.setProperty("global", "global value");
- insertProjectProperty(project, "project", "project value");
- insertProjectProperty(branchDto, "branch", "branch value");
+ insertComponentProperty(project.getUuid(), "project", "project value");
+ insertComponentProperty(root.getUuid(), "branch", "branch value");
Configuration config = underTest.getConfiguration();
@@ -140,8 +127,8 @@ public class ConfigurationRepositoryTest {
assertThat(config.get("branch")).hasValue("branch value");
}
- private void insertProjectProperty(ComponentDto project, String propertyKey, String propertyValue) {
- db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
- new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(project.uuid()));
+ private void insertComponentProperty(String componentUuid, String propertyKey, String propertyValue) {
+ db.properties().insertProperties(null, null, null, null,
+ new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(componentUuid));
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java
index ebd2a0573cf..05ebd80be50 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java
@@ -115,9 +115,9 @@ public class SiblingsIssueMergerTest {
branch3Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch3")
.setBranchType(BranchType.PULL_REQUEST)
.setMergeBranchUuid(projectDto.uuid()));
- fileOnBranch1Dto = db.components().insertComponent(newFileDto(branch1Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1"));
- fileOnBranch2Dto = db.components().insertComponent(newFileDto(branch2Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2"));
- fileOnBranch3Dto = db.components().insertComponent(newFileDto(branch3Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3"));
+ fileOnBranch1Dto = db.components().insertComponent(newFileDto(branch1Dto).setKey(FILE_1_KEY));
+ fileOnBranch2Dto = db.components().insertComponent(newFileDto(branch2Dto).setKey(FILE_1_KEY));
+ fileOnBranch3Dto = db.components().insertComponent(newFileDto(branch3Dto).setKey(FILE_1_KEY));
rule = db.rules().insert();
when(branch.getReferenceBranchUuid()).thenReturn(projectDto.uuid());
metadataHolder.setBranch(branch);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java
index b20ca1a6088..fbce8cc4f18 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java
@@ -53,7 +53,7 @@ public class PersistComponentsStepTest {
doReturn(component).when(treeRootHolder).getRoot();
doReturn(projectKey).when(component).getKey();
doReturn(componentDao).when(dbClient).componentDao();
- doReturn(emptyList()).when(componentDao).selectAllComponentsFromProjectKey(any(DbSession.class), eq(projectKey));
+ doReturn(emptyList()).when(componentDao).selectByBranchUuid(eq(projectKey), any(DbSession.class));
assertThatThrownBy(() -> {
new PersistComponentsStep(
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
index 0f8bf052a3d..ec94c781441 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
@@ -184,7 +184,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + branch.uuid() + UUID_PATH_SEPARATOR);
assertThat(directoryDto.moduleUuid()).isEqualTo(branch.uuid());
assertThat(directoryDto.moduleUuidPath()).isEqualTo(branch.moduleUuidPath());
- assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(branch.uuid());
+ assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(analysisMetadataHolder.getProject().getUuid());
assertThat(directoryDto.branchUuid()).isEqualTo(branch.uuid());
assertThat(directoryDto.qualifier()).isEqualTo("DIR");
assertThat(directoryDto.scope()).isEqualTo("DIR");
@@ -201,7 +201,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
assertThat(fileDto.moduleUuid()).isEqualTo(branch.uuid());
assertThat(fileDto.moduleUuidPath()).isEqualTo(branch.moduleUuidPath());
- assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(branch.uuid());
+ assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(analysisMetadataHolder.getProject().getUuid());
assertThat(fileDto.branchUuid()).isEqualTo(branch.uuid());
assertThat(fileDto.qualifier()).isEqualTo("FIL");
assertThat(fileDto.scope()).isEqualTo("FIL");
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
index 0e36782973a..fdc355dfe2a 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
@@ -80,8 +80,7 @@ public class ValidateProjectStepTest {
@Test
public void not_fail_if_analysis_date_is_after_last_analysis() {
- ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY);
- db.components().insertComponent(project);
+ ComponentDto project = db.components().insertPrivateProject("ABCD", c -> c.setKey(PROJECT_KEY));
dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(PAST_ANALYSIS_TIME));
db.getSession().commit();
@@ -112,8 +111,7 @@ public class ValidateProjectStepTest {
public void fail_if_analysis_date_is_before_last_analysis() {
analysisMetadataHolder.setAnalysisDate(DateUtils.parseDate("2015-01-01"));
- ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY);
- db.components().insertComponent(project);
+ ComponentDto project = db.components().insertPrivateProject("ABCD", c -> c.setKey(PROJECT_KEY));
dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1433131200000L)); // 2015-06-01
db.getSession().commit();