aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-12-12 11:41:20 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:09 +0100
commit8c64cded897a94513f68899f87d5d0e37559c948 (patch)
treef025891e1324d7beac5963e9d52ddaecced91359
parent6bf996af181712c135c0bb1f52c8c9a12d1a6c9c (diff)
downloadsonarqube-8c64cded897a94513f68899f87d5d0e37559c948.tar.gz
sonarqube-8c64cded897a94513f68899f87d5d0e37559c948.zip
SONAR-11463 Don't consider disabled components during migration
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java66
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java31
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java10
7 files changed, 57 insertions, 62 deletions
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 5ffc8b1c360..c42465eb668 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
@@ -99,7 +99,7 @@ public class ComponentUuidFactoryWithMigration implements ComponentUuidFactory {
}
private static List<ComponentWithModuleUuidDto> loadComponentsWithModuleUuid(DbClient dbClient, DbSession dbSession, String rootKey) {
- return dbClient.componentDao().selectComponentsWithModuleUuidFromProjectKey(dbSession, rootKey);
+ return dbClient.componentDao().selectEnabledComponentsWithModuleUuidFromProjectKey(dbSession, rootKey);
}
private static Map<String, String> loadModulePathsByUuid(DbClient dbClient, DbSession dbSession, String rootKey, Map<String, String> pathByModuleKey) {
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 05b6dd760a2..b394b9c600a 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
@@ -86,6 +86,54 @@ public class ComponentUuidFactoryWithMigrationTest {
}
@Test
+ public void migrate_project_with_disabled_components_no_path() {
+ ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project"));
+ ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
+ .setDbKey("project:module1"));
+ ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project)
+ .setDbKey("project:file1")
+ .setPath("file1"));
+ ComponentDto disabledFileNoPath = db.components().insertComponent(ComponentTesting.newFileDto(project)
+ .setDbKey("project:file2")
+ .setPath(null)
+ .setEnabled(false));
+
+ Map<String, String> modulesRelativePaths = new HashMap<>();
+ modulesRelativePaths.put("project:module1", "module1_path");
+ ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths);
+
+ // migrated files
+ assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid());
+
+ // project remains the same
+ assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid());
+ }
+
+ @Test
+ public void migrate_project_with_disabled_components_same_path() {
+ ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project"));
+ ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
+ .setDbKey("project:module1"));
+ ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project)
+ .setDbKey("project:file1")
+ .setPath("file1"));
+ ComponentDto disabledFileSamePath = db.components().insertComponent(ComponentTesting.newFileDto(project)
+ .setDbKey("project:file2")
+ .setPath("file1")
+ .setEnabled(false));
+
+ Map<String, String> modulesRelativePaths = new HashMap<>();
+ modulesRelativePaths.put("project:module1", "module1_path");
+ ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths);
+
+ // migrated files
+ assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid());
+
+ // project remains the same
+ assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid());
+ }
+
+ @Test
public void migrate_branch_with_modules() {
pathToKey = path -> path != null ? "project:" + path + ":BRANCH:branch1" : "project:BRANCH:branch1";
ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project:BRANCH:branch1"));
@@ -144,24 +192,6 @@ public class ComponentUuidFactoryWithMigrationTest {
}
@Test
- public void migrate_project_with_disabled_modules() {
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setDbKey("project:module1")
- .setEnabled(false));
- ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(module1)
- .setDbKey("project:file1")
- .setEnabled(false)
- .setPath("file1_path"));
- Map<String, String> modulesRelativePaths = Collections.singletonMap("project:module1", "module1_path");
-
- ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths);
-
- // migrated file
- assertThat(underTest.getOrCreateForKey("project:module1_path/file1_path")).isEqualTo(file1.uuid());
- }
-
- @Test
public void dont_override_root_uuid_if_module_path_is_not_sent() {
ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project"));
ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java
index 56d4d24a09b..263cd660c5e 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java
@@ -434,37 +434,6 @@ public class BuildComponentTreeStepTest {
}
@Test
- public void return_existing_uuids_when_components_were_removed() {
- setAnalysisMetadataHolder();
- OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD")
- .setDbKey(REPORT_PROJECT_KEY));
- ComponentDto removedModule = insertComponent(newModuleDto("BCDE", project)
- .setDbKey(REPORT_MODULE_KEY).setEnabled(false));
- ComponentDto removedDirectory = insertComponent(newDirectory(removedModule, "CDEF", REPORT_DIR_PATH_1)
- .setDbKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_PATH_1).setEnabled(false));
- insertComponent(newFileDto(removedModule, removedDirectory, "DEFG")
- .setDbKey(REPORT_MODULE_KEY + ":" + REPORT_FILE_PATH_1).setPath(REPORT_FILE_PATH_1).setEnabled(false));
-
- reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, "module/" + REPORT_FILE_PATH_1));
-
- reportReader.setMetadata(ScannerReport.Metadata.newBuilder()
- .putModulesProjectRelativePathByKey(REPORT_PROJECT_KEY, "")
- .putModulesProjectRelativePathByKey(REPORT_MODULE_KEY, "module")
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, "ABCD");
-
- // No new UUID is generated on removed components
- verifyComponentMissingByRef(MODULE_REF);
- verifyComponentByKey(REPORT_PROJECT_KEY + ":module/" + REPORT_DIR_PATH_1, REPORT_PROJECT_KEY + ":module/" + REPORT_DIR_PATH_1, "CDEF");
- verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":module/" + REPORT_FILE_PATH_1, "DEFG");
- }
-
- @Test
public void set_no_base_project_snapshot_when_no_snapshot() {
setAnalysisMetadataHolder();
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index aed5fc1138a..9ff0aa9e174 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -355,8 +355,8 @@ public class ComponentDao implements Dao {
return new HashSet<>(mapper(dbSession).selectComponentsByQualifiers(qualifiers));
}
- public List<ComponentWithModuleUuidDto> selectComponentsWithModuleUuidFromProjectKey(DbSession dbSession, String projectKey) {
- return mapper(dbSession).selectComponentsWithModuleUuidFromProjectKey(projectKey);
+ public List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(DbSession dbSession, String projectKey) {
+ return mapper(dbSession).selectEnabledComponentsWithModuleUuidFromProjectKey(projectKey);
}
public List<ComponentDto> selectProjectsByNameQuery(DbSession dbSession, @Nullable String nameQuery, boolean includeModules) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
index 7be4d074673..86cac939a71 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -167,5 +167,5 @@ public interface ComponentMapper {
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(@Param("organizationUuid") String organizationUuid);
- List<ComponentWithModuleUuidDto> selectComponentsWithModuleUuidFromProjectKey(String projectKey);
+ List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(String projectKey);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index e5c27640043..b0aaf491f63 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -519,13 +519,13 @@
</where>
</select>
- <select id="selectComponentsWithModuleUuidFromProjectKey" resultType="ComponentWithModuleUuid">
+ <select id="selectEnabledComponentsWithModuleUuidFromProjectKey" resultType="ComponentWithModuleUuid">
SELECT
p.uuid as uuid, p.module_uuid as moduleUuid, p.path as path, p.scope as scope
FROM
projects p
INNER JOIN
- projects root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR}
+ projects root ON root.uuid=p.project_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR}
</select>
<select id="selectUuidsByKeyFromProjectKey" parameterType="string" resultType="KeyWithUuid">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index a2a8964e82e..ae64c7f0d11 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -528,7 +528,7 @@ public class ComponentDaoTest {
}
@Test
- public void select_components_with_module_dto() {
+ public void select_enabled_components_with_module_dto() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
@@ -540,18 +540,14 @@ public class ComponentDaoTest {
ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false));
// From root project
- assertThat(underTest.selectComponentsWithModuleUuidFromProjectKey(dbSession, project.getDbKey()))
+ assertThat(underTest.selectEnabledComponentsWithModuleUuidFromProjectKey(dbSession, project.getDbKey()))
.extracting(ComponentWithModuleUuidDto::uuid)
.containsExactlyInAnyOrder(
project.uuid(),
module.uuid(),
- removedModule.uuid(),
subModule.uuid(),
- removedSubModule.uuid(),
directory.uuid(),
- removedDirectory.uuid(),
- file.uuid(),
- removedFile.uuid()
+ file.uuid()
);
}