}
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) {
assertThat(underTest.getOrCreateForKey(file2.getDbKey())).isNotIn(project.uuid(), module1.uuid(), module2.uuid(), file1.uuid(), file2.uuid());
}
+ @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";
assertThat(underTest.getOrCreateForKey("project:module1")).isNotIn(project.uuid(), module1.uuid(), dir1.uuid());
}
- @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"));
verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1);
}
- @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();
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) {
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc(@Param("organizationUuid") String organizationUuid);
- List<ComponentWithModuleUuidDto> selectComponentsWithModuleUuidFromProjectKey(String projectKey);
+ List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(String projectKey);
}
</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">
}
@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));
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()
);
}