diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2018-12-12 11:41:20 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-01-16 09:43:09 +0100 |
commit | 8c64cded897a94513f68899f87d5d0e37559c948 (patch) | |
tree | f025891e1324d7beac5963e9d52ddaecced91359 /server/sonar-ce-task-projectanalysis | |
parent | 6bf996af181712c135c0bb1f52c8c9a12d1a6c9c (diff) | |
download | sonarqube-8c64cded897a94513f68899f87d5d0e37559c948.tar.gz sonarqube-8c64cded897a94513f68899f87d5d0e37559c948.zip |
SONAR-11463 Don't consider disabled components during migration
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
3 files changed, 49 insertions, 50 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)); |