// (in which case base issue belongs to original file and raw issue to component)
raw.setComponentUuid(base.componentUuid());
raw.setComponentKey(base.componentKey());
- raw.setModuleUuidPath(base.moduleUuidPath());
// fields coming from raw
updater.setPastLine(raw, base.getLine());
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
-import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
/**
existingComponent.setUuidPath(updateDto.getBUuidPath());
existingComponent.setLanguage(updateDto.getBLanguage());
existingComponent.setLongName(updateDto.getBLongName());
- existingComponent.setModuleUuid(updateDto.getBModuleUuid());
- existingComponent.setModuleUuidPath(updateDto.getBModuleUuidPath());
existingComponent.setName(updateDto.getBName());
existingComponent.setPath(updateDto.getBPath());
// We don't have a b_scope. The applyBChangesForRootComponentUuid query is using a case ... when to infer scope from the qualifier
res.setBranchUuid(res.uuid());
res.setRootUuid(res.uuid());
res.setUuidPath(UUID_PATH_OF_ROOT);
- res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR);
return res;
}
res.setLongName(directory.getName());
res.setPath(directory.getName());
- setParentModuleProperties(res, path);
+ setParentProperties(res, path);
return res;
}
res.setPath(file.getName());
res.setLanguage(file.getFileAttributes().getLanguageKey());
- setParentModuleProperties(res, path);
+ setParentProperties(res, path);
return res;
}
res.setBranchUuid(res.uuid());
res.setRootUuid(res.uuid());
res.setUuidPath(UUID_PATH_OF_ROOT);
- res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR);
return res;
}
}
/**
- * Applies to a node of type either MODULE, SUBVIEW, PROJECT_VIEW
+ * Applies to a node of type either SUBVIEW or PROJECT_VIEW
*/
private void setRootAndParentModule(ComponentDto res, PathAwareVisitor.Path<ComponentDtoHolder> path) {
ComponentDto rootDto = path.root().getDto();
res.setRootUuid(rootDto.uuid());
res.setBranchUuid(rootDto.uuid());
- ComponentDto parentModule = path.parent().getDto();
- res.setUuidPath(formatUuidPathFromParent(parentModule));
- res.setModuleUuid(parentModule.uuid());
- res.setModuleUuidPath(parentModule.moduleUuidPath() + res.uuid() + UUID_PATH_SEPARATOR);
+ ComponentDto parent = path.parent().getDto();
+ res.setUuidPath(formatUuidPathFromParent(parent));
}
}
/**
* Applies to a node of type either DIRECTORY or FILE
*/
- private static void setParentModuleProperties(ComponentDto componentDto, PathAwareVisitor.Path<ComponentDtoHolder> path) {
+ private static void setParentProperties(ComponentDto componentDto, PathAwareVisitor.Path<ComponentDtoHolder> path) {
componentDto.setBranchUuid(path.root().getDto().uuid());
- ComponentDto parentModule = StreamSupport.stream(path.getCurrentPath().spliterator(), false)
+ ComponentDto parent = StreamSupport.stream(path.getCurrentPath().spliterator(), false)
.filter(p -> p.component().getType() == Component.Type.PROJECT)
.findFirst()
.get()
.element().getDto();
componentDto.setUuidPath(formatUuidPathFromParent(path.parent().getDto()));
- componentDto.setRootUuid(parentModule.uuid());
- componentDto.setModuleUuid(parentModule.uuid());
- componentDto.setModuleUuidPath(parentModule.moduleUuidPath());
+ componentDto.setRootUuid(parent.uuid());
}
!StringUtils.equals(existing.getUuidPath(), target.getUuidPath()) ||
!StringUtils.equals(existing.language(), target.language()) ||
!StringUtils.equals(existing.longName(), target.longName()) ||
- !StringUtils.equals(existing.moduleUuid(), target.moduleUuid()) ||
- !StringUtils.equals(existing.moduleUuidPath(), target.moduleUuidPath()) ||
!StringUtils.equals(existing.name(), target.name()) ||
!StringUtils.equals(existing.path(), target.path()) ||
!StringUtils.equals(existing.scope(), target.scope()) ||
defaultIssue.setType(RuleType.valueOf(next.getRuleType()));
defaultIssue.setComponentUuid(next.hasComponentUuid() ? next.getComponentUuid() : null);
defaultIssue.setComponentKey(next.getComponentKey());
- defaultIssue.setModuleUuidPath(next.hasModuleUuidPath() ? next.getModuleUuidPath() : null);
defaultIssue.setProjectUuid(next.getProjectUuid());
defaultIssue.setProjectKey(next.getProjectKey());
defaultIssue.setRuleKey(RuleKey.parse(next.getRuleKey()));
builder.setRuleType(defaultIssue.type().getDbConstant());
ofNullable(defaultIssue.componentUuid()).ifPresent(builder::setComponentUuid);
builder.setComponentKey(defaultIssue.componentKey());
- ofNullable(defaultIssue.moduleUuidPath()).ifPresent(builder::setModuleUuidPath);
builder.setProjectUuid(defaultIssue.projectUuid());
builder.setProjectKey(defaultIssue.projectKey());
builder.setRuleKey(defaultIssue.ruleKey().toString());
private static final String QUERY = "select" +
" p.uuid, p.qualifier, p.uuid_path, p.kee, p.name," +
" p.description, p.scope, p.language, p.long_name, p.path," +
- " p.module_uuid, p.module_uuid_path, p.deprecated_kee, p.branch_uuid, p.main_branch_project_uuid" +
+ " p.deprecated_kee, p.branch_uuid, p.main_branch_project_uuid" +
" from components p" +
" join components pp on pp.uuid = p.branch_uuid" +
" join project_branches pb on pb.uuid = pp.uuid" +
.setLanguage(defaultString(getString(rs, 8)))
.setLongName(defaultString(getString(rs, 9)))
.setPath(defaultString(getString(rs, 10)))
- .setModuleUuid(defaultString(getString(rs, 11)))
- .setModuleUuidPath(defaultString(getString(rs, 12)))
- .setDeprecatedKey(defaultString(getString(rs, 13)))
- .setProjectUuid(getString(rs, 14))
- .setMainBranchProjectUuid(defaultString(getString(rs, 15)))
+ .setDeprecatedKey(defaultString(getString(rs, 11)))
+ .setProjectUuid(getString(rs, 12))
+ .setMainBranchProjectUuid(defaultString(getString(rs, 13)))
.build();
output.write(component);
ref++;
optional string componentUuid = 3;
optional string componentKey = 4;
reserved 5; //moduleUuid
- optional string moduleUuidPath = 6;
+ reserved 6; // moduleUuidPath
optional string projectUuid = 7;
optional string projectKey = 8;
optional string ruleKey = 9;
string path = 9;
string uuid = 10;
string uuid_path = 12;
- string module_uuid = 13;
- string module_uuid_path = 14;
+ reserved 13; // module_uuid
+ reserved 14; // module_uuid_path
string deprecated_key = 15;
string project_uuid = 16;
string main_branch_project_uuid = 17;
verify(issue).setComponentUuid(FILE.getUuid());
verify(issue).setComponentKey(FILE.getKey());
- verify(issue).setModuleUuidPath(null);
verify(issue).setUpdateDate(new Date(ANALYSIS_DATE));
verify(issue).setChanged(true);
}
import org.sonar.db.rule.RuleDto;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
import static org.sonar.api.utils.DateUtils.parseDate;
-import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
public class ProjectTrackerBaseLazyInputTest {
String projectVersion = randomAlphabetic(10);
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project");
dbTester.components().insertComponent(projectDto);
- ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module");
- dbTester.components().insertComponent(moduleDto);
- ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir");
+ ComponentDto directoryDto = ComponentTesting.newDirectory(projectDto, "CDEF", "src/main/java/dir").setKey("PROJECT_KEY:src/main/java/dir");
dbTester.components().insertComponent(directoryDto);
- ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java");
+ ComponentDto fileDto = ComponentTesting.newFileDto(projectDto, directoryDto, "DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java");
dbTester.components().insertComponent(fileDto);
dbTester.getSession().commit();
- Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
- Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
+ Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java").build();
+ Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir").addChildren(file).build();
String buildString = Optional.ofNullable(projectVersion).map(v -> randomAlphabetic(7)).orElse(null);
Component project = ReportComponent.builder(Component.Type.PROJECT, 1)
.setUuid("ABCD")
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto);
dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot);
- ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module");
- dbTester.components().insertComponent(moduleDto);
-
- ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir");
+ ComponentDto directoryDto = ComponentTesting.newDirectory(projectDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir");
dbTester.components().insertComponent(directoryDto);
- ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java");
+ ComponentDto fileDto = ComponentTesting.newFileDto(projectDto, directoryDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java");
dbTester.components().insertComponent(fileDto);
dbTester.getSession().commit();
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
import static org.sonar.db.component.ComponentTesting.newDirectory;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.uuid()).isEqualTo("CDEF");
assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + projectDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(directoryDto.moduleUuid()).isEqualTo(projectDto.uuid());
- assertThat(directoryDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath());
assertThat(directoryDto.getMainBranchProjectUuid()).isNull();
assertThat(directoryDto.branchUuid()).isEqualTo(projectDto.uuid());
assertThat(directoryDto.qualifier()).isEqualTo("DIR");
assertThat(fileDto.language()).isEqualTo("java");
assertThat(fileDto.uuid()).isEqualTo("DEFG");
assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(fileDto.moduleUuid()).isEqualTo(projectDto.uuid());
- assertThat(fileDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath());
assertThat(fileDto.getMainBranchProjectUuid()).isNull();
assertThat(fileDto.branchUuid()).isEqualTo(projectDto.uuid());
assertThat(fileDto.qualifier()).isEqualTo("FIL");
assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.uuid()).isEqualTo("CDEF");
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(analysisMetadataHolder.getProject().getUuid());
assertThat(directoryDto.branchUuid()).isEqualTo(branch.uuid());
assertThat(directoryDto.qualifier()).isEqualTo("DIR");
assertThat(fileDto.language()).isEqualTo("java");
assertThat(fileDto.uuid()).isEqualTo("DEFG");
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(analysisMetadataHolder.getProject().getUuid());
assertThat(fileDto.branchUuid()).isEqualTo(branch.uuid());
assertThat(fileDto.qualifier()).isEqualTo("FIL");
assertThat(dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/foo").get().scope()).isEqualTo("DIR");
}
- @Test
- public void update_module_to_directory_change_scope() {
- ComponentDto project = prepareProject();
- ComponentDto module = ComponentTesting.newModuleDto(project).setUuid("CDEF").setKey("MODULE_KEY").setPath("module");
- dbClient.componentDao().insert(db.getSession(), module);
- db.getSession().commit();
-
- assertThat(dbClient.componentDao().selectByUuid(db.getSession(), "CDEF").get().scope()).isEqualTo("PRJ");
-
- treeRootHolder.setRoot(
- asTreeRoot(project)
- .addChildren(
- builder(DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":module")
- .setName("module")
- .addChildren(
- builder(FILE, 3).setUuid("HIJK").setKey(PROJECT_KEY + ":module/FooTest.java")
- .setName("module/FooTest.java")
- .setShortName("FooTest.java")
- .setFileAttributes(new FileAttributes(false, null, 1))
- .build())
- .build())
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- // commit the functional transaction
- dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
- db.commit();
-
- assertThat(dbClient.componentDao().selectByUuid(db.getSession(), "CDEF").get().scope()).isEqualTo("DIR");
- }
-
@Test
public void persist_only_new_components() {
// Project and module already exists
ComponentDto directory = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directory.getUuidPath()).isEqualTo(directory.getUuidPath());
- assertThat(directory.moduleUuid()).isEqualTo(project.uuid());
- assertThat(directory.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(directory.branchUuid()).isEqualTo(project.uuid());
assertThat(directory.getRootUuid()).isEqualTo(project.uuid());
assertThat(directory.getMainBranchProjectUuid()).isNull();
ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(file.getUuidPath()).isEqualTo(file.getUuidPath());
- assertThat(file.moduleUuid()).isEqualTo(project.uuid());
- assertThat(file.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(file.branchUuid()).isEqualTo(project.uuid());
assertThat(file.getRootUuid()).isEqualTo(project.uuid());
assertThat(file.getMainBranchProjectUuid()).isNull();
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get();
assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
- assertThat(projectReloaded.moduleUuid()).isEqualTo(project.moduleUuid());
- assertThat(projectReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(projectReloaded.branchUuid()).isEqualTo(project.branchUuid());
assertThat(projectReloaded.getRootUuid()).isEqualTo(project.getRootUuid());
ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directoryReloaded.uuid()).isEqualTo(directory.uuid());
assertThat(directoryReloaded.getUuidPath()).isEqualTo(directory.getUuidPath());
- assertThat(directoryReloaded.moduleUuid()).isEqualTo(directory.moduleUuid());
- assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(directory.moduleUuidPath());
assertThat(directoryReloaded.branchUuid()).isEqualTo(directory.branchUuid());
assertThat(directoryReloaded.getRootUuid()).isEqualTo(directory.getRootUuid());
assertThat(directoryReloaded.name()).isEqualTo(directory.name());
ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(fileReloaded.uuid()).isEqualTo(file.uuid());
assertThat(fileReloaded.getUuidPath()).isEqualTo(file.getUuidPath());
- assertThat(fileReloaded.moduleUuid()).isEqualTo(file.moduleUuid());
- assertThat(fileReloaded.moduleUuidPath()).isEqualTo(file.moduleUuidPath());
assertThat(fileReloaded.branchUuid()).isEqualTo(file.branchUuid());
assertThat(fileReloaded.getRootUuid()).isEqualTo(file.getRootUuid());
assertThat(fileReloaded.name()).isEqualTo(file.name());
assertThat(fileReloaded.path()).isEqualTo(file.path());
}
- @Test
- public void update_module_uuid_when_moving_a_module() {
- ComponentDto project = prepareProject();
- ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir");
- ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
- .setKey("PROJECT_KEY:src/main/java/dir/Foo.java");
- dbClient.componentDao().insert(db.getSession(), directory, file);
- db.getSession().commit();
-
- treeRootHolder.setRoot(
- builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey())
- .setName("Project")
- .addChildren(
- builder(DIRECTORY, 4).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
- .setName("src/main/java/dir")
- .addChildren(
- builder(FILE, 5).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
- .setName("src/main/java/dir/Foo.java")
- .build())
- .build())
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- // commit the functional transaction
- dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
- db.commit();
-
- assertThat(db.countRowsOfTable("components")).isEqualTo(3);
-
- ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
- assertThat(directoryReloaded).isNotNull();
- assertThat(directoryReloaded.uuid()).isEqualTo(directory.uuid());
- assertThat(directoryReloaded.getUuidPath()).isEqualTo(directoryReloaded.getUuidPath());
- assertThat(directoryReloaded.moduleUuid()).isEqualTo(project.uuid());
- assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
- assertThat(directoryReloaded.branchUuid()).isEqualTo(project.uuid());
- assertThat(directoryReloaded.getRootUuid()).isEqualTo(project.uuid());
-
- ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
- assertThat(fileReloaded).isNotNull();
- assertThat(fileReloaded.uuid()).isEqualTo(file.uuid());
- assertThat(fileReloaded.getUuidPath()).isEqualTo(fileReloaded.getUuidPath());
- assertThat(fileReloaded.moduleUuid()).isEqualTo(project.uuid());
- assertThat(fileReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
- assertThat(fileReloaded.branchUuid()).isEqualTo(project.uuid());
- assertThat(fileReloaded.getRootUuid()).isEqualTo(project.uuid());
- }
-
@Test
public void do_not_update_created_at_on_existing_component() {
Date oldDate = DateUtils.parseDate("2015-01-01");
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get();
assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
assertThat(projectReloaded.getUuidPath()).isEqualTo(project.getUuidPath());
- assertThat(projectReloaded.moduleUuid()).isEqualTo(project.moduleUuid());
- assertThat(projectReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(projectReloaded.branchUuid()).isEqualTo(project.branchUuid());
assertThat(projectReloaded.getRootUuid()).isEqualTo(project.getRootUuid());
assertThat(projectReloaded.isEnabled()).isTrue();
ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directoryReloaded.uuid()).isEqualTo(removedDirectory.uuid());
assertThat(directoryReloaded.getUuidPath()).isEqualTo(removedDirectory.getUuidPath());
- assertThat(directoryReloaded.moduleUuid()).isEqualTo(removedDirectory.moduleUuid());
- assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(removedDirectory.moduleUuidPath());
assertThat(directoryReloaded.branchUuid()).isEqualTo(removedDirectory.branchUuid());
assertThat(directoryReloaded.getRootUuid()).isEqualTo(removedDirectory.getRootUuid());
assertThat(directoryReloaded.name()).isEqualTo(removedDirectory.name());
ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(fileReloaded.uuid()).isEqualTo(removedFile.uuid());
assertThat(fileReloaded.getUuidPath()).isEqualTo(removedFile.getUuidPath());
- assertThat(fileReloaded.moduleUuid()).isEqualTo(removedFile.moduleUuid());
- assertThat(fileReloaded.moduleUuidPath()).isEqualTo(removedFile.moduleUuidPath());
assertThat(fileReloaded.branchUuid()).isEqualTo(removedFile.branchUuid());
assertThat(fileReloaded.getRootUuid()).isEqualTo(removedFile.getRootUuid());
assertThat(fileReloaded.name()).isEqualTo(removedFile.name());
@Test
public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
ComponentDto project = prepareProject(p -> p.setPrivate(true));
- ComponentDto module = newModuleDto(project).setPrivate(false);
- db.components().insertComponent(module);
- ComponentDto dir = db.components().insertComponent(newDirectory(module, "DEFG", "Directory").setKey("DIR").setPrivate(true));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "DEFG", "Directory").setKey("DIR").setPrivate(true));
treeRootHolder.setRoot(createSampleProjectComponentTree(project));
underTest.execute(new TestComputationStepContext());
- Stream.of(project.uuid(), module.uuid(), dir.uuid())
+ Stream.of(project.uuid(), dir.uuid())
.forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(db.getSession(), uuid).get().isPrivate())
.describedAs("for uuid " + uuid)
.isEqualTo(true));
private final ValidateProjectStep underTest = new ValidateProjectStep(dbClient, treeRootHolder, analysisMetadataHolder);
- @Test
- public void dont_fail_for_long_forked_from_master_with_modules() {
- ComponentDto masterProject = db.components().insertPublicProject();
- dbClient.componentDao().insert(db.getSession(), ComponentTesting.newModuleDto(masterProject));
- setBranch(BranchType.BRANCH, masterProject.uuid());
- db.getSession().commit();
-
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("DEFG")
- .setKey("branch")
- .build());
-
- underTest.execute(new TestComputationStepContext());
- }
-
@Test
public void not_fail_if_analysis_date_is_after_last_analysis() {
ComponentDto project = db.components().insertPrivateProject("ABCD", c -> c.setKey(PROJECT_KEY));
assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
assertThat(dto.branchUuid()).isEqualTo(VIEW_UUID);
assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
- assertThat(dto.moduleUuid()).isNull();
- assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
assertThat(dto.qualifier()).isEqualTo(Qualifiers.VIEW);
assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
assertThat(dto.getCopyComponentUuid()).isNull();
assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
assertThat(dto.branchUuid()).isEqualTo(VIEW_UUID);
assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
- assertThat(dto.moduleUuid()).isNull();
- assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
assertThat(dto.qualifier()).isEqualTo(Qualifiers.APP);
assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
assertThat(dto.getCopyComponentUuid()).isNull();
assertThat(sv1Dto.uuid()).isEqualTo(SUBVIEW_1_UUID);
assertThat(sv1Dto.branchUuid()).isEqualTo(viewDto.uuid());
assertThat(sv1Dto.getRootUuid()).isEqualTo(viewDto.uuid());
- assertThat(sv1Dto.moduleUuid()).isEqualTo(viewDto.uuid());
- assertThat(sv1Dto.moduleUuidPath()).isEqualTo(viewDto.moduleUuidPath() + sv1Dto.uuid() + ".");
assertThat(sv1Dto.qualifier()).isEqualTo(Qualifiers.SUBVIEW);
assertThat(sv1Dto.scope()).isEqualTo(Scopes.PROJECT);
assertThat(sv1Dto.getCopyComponentUuid()).isNull();
assertThat(pv1Dto.uuid()).isEqualTo(PROJECT_VIEW_1_UUID);
assertThat(pv1Dto.branchUuid()).isEqualTo(viewDto.uuid());
assertThat(pv1Dto.getRootUuid()).isEqualTo(viewDto.uuid());
- assertThat(pv1Dto.moduleUuid()).isEqualTo(parentViewDto.uuid());
- assertThat(pv1Dto.moduleUuidPath()).isEqualTo(parentViewDto.moduleUuidPath() + pv1Dto.uuid() + ".");
assertThat(pv1Dto.qualifier()).isEqualTo(Qualifiers.PROJECT);
assertThat(pv1Dto.scope()).isEqualTo(Scopes.FILE);
assertThat(pv1Dto.getCopyComponentUuid()).isEqualTo(project.uuid());
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
.setRootUuid(PROJECT_UUID)
- .setModuleUuid(null)
- .setModuleUuidPath("." + PROJECT_UUID + ".")
.setBranchUuid(PROJECT_UUID);
- private static final String MODULE_UUID = "MODULE_UUID";
- private static final String MODULE_UUID_PATH = UUID_PATH_OF_ROOT + UUID_PATH_SEPARATOR + MODULE_UUID;
- private static final ComponentDto MODULE = new ComponentDto()
+ private static final String DIR_UUID = "DIR_UUID";
+ private static final String UUID_PATH = UUID_PATH_OF_ROOT + UUID_PATH_SEPARATOR + DIR_UUID;
+ private static final ComponentDto DIR = new ComponentDto()
// no id yet
.setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.MODULE)
- .setKey("the_module")
- .setName("The Module")
- .setDescription("description of module")
+ .setQualifier(Qualifiers.DIRECTORY)
+ .setKey("the_dir")
+ .setName("The Dir")
+ .setDescription("description of dir")
.setEnabled(true)
- .setUuid(MODULE_UUID)
- .setUuidPath(MODULE_UUID_PATH)
- .setRootUuid(MODULE_UUID)
- .setModuleUuid(PROJECT_UUID)
- .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.")
+ .setUuid(DIR_UUID)
+ .setUuidPath(UUID_PATH)
+ .setRootUuid(PROJECT_UUID)
.setBranchUuid(PROJECT_UUID);
private static final String FILE_UUID = "FILE_UUID";
.setKey("the_file")
.setName("The File")
.setUuid(FILE_UUID)
- .setUuidPath(MODULE_UUID_PATH + UUID_PATH_SEPARATOR + FILE_UUID)
- .setRootUuid(MODULE_UUID)
+ .setUuidPath(UUID_PATH + UUID_PATH_SEPARATOR + FILE_UUID)
+ .setRootUuid(PROJECT_UUID)
.setEnabled(true)
- .setModuleUuid(MODULE_UUID)
- .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.")
.setBranchUuid(PROJECT_UUID);
@Rule
public void setUp() {
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT);
componentRepository.register(1, projectDto.uuid(), false);
- dbTester.getDbClient().componentDao().insert(dbTester.getSession(), MODULE, FILE);
+ dbTester.getDbClient().componentDao().insert(dbTester.getSession(), DIR, FILE);
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(projectDto));
}
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
.setRootUuid(PROJECT_UUID)
- .setModuleUuid(null)
- .setModuleUuidPath("." + PROJECT_UUID + ".")
.setBranchUuid(PROJECT_UUID);
@Rule
.setUuid(PROJECT_UUID)
.setRootUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
- .setModuleUuid(null)
- .setModuleUuidPath("." + PROJECT_UUID + ".")
.setCreatedAt(new Date(1596749115856L))
.setBranchUuid(PROJECT_UUID);
- private static final String MODULE_UUID = "MODULE_UUID";
- private static final String MODULE_UUID_PATH = UUID_PATH_OF_ROOT + MODULE_UUID + UUID_PATH_SEPARATOR;
- private static final ComponentDto MODULE = new ComponentDto()
- // no id yet
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.MODULE)
- .setKey("the_module")
- .setName("The Module")
- .setDescription("description of module")
- .setEnabled(true)
- .setUuid(MODULE_UUID)
- .setRootUuid(PROJECT_UUID)
- .setUuidPath(MODULE_UUID_PATH)
- .setModuleUuid(PROJECT_UUID)
- .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.")
- .setCreatedAt(new Date(1596749132539L))
- .setBranchUuid(PROJECT_UUID);
-
private static final String FILE_UUID = "FILE_UUID";
- private static final String FILE_UUID_PATH = MODULE_UUID_PATH + FILE_UUID + UUID_PATH_SEPARATOR;
+ private static final String FILE_UUID_PATH = PROJECT_UUID + FILE_UUID + UUID_PATH_SEPARATOR;
private static final ComponentDto FILE = new ComponentDto()
// no id yet
.setScope(Scopes.FILE)
.setKey("the_file")
.setName("The File")
.setUuid(FILE_UUID)
- .setRootUuid(MODULE_UUID)
+ .setRootUuid(PROJECT_UUID)
.setUuidPath(FILE_UUID_PATH)
.setEnabled(true)
- .setModuleUuid(MODULE_UUID)
- .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.")
.setCreatedAt(new Date(1596749148406L))
.setBranchUuid(PROJECT_UUID);
@Test
public void export_components_including_project() {
dbTester.components().insertPublicProject(PROJECT);
- dbTester.getDbClient().componentDao().insert(dbTester.getSession(), MODULE, FILE);
+ dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE);
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
underTest.execute(new TestComputationStepContext());
- assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("3 components exported");
+ assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 components exported");
List<ProjectDump.Component> components = dumpWriter.getWrittenMessagesOf(DumpElement.COMPONENTS);
assertThat(components).extracting(ProjectDump.Component::getQualifier, ProjectDump.Component::getUuid, ProjectDump.Component::getUuidPath)
.containsExactlyInAnyOrder(
tuple(Qualifiers.FILE, FILE_UUID, FILE_UUID_PATH),
- tuple(Qualifiers.MODULE, MODULE_UUID, MODULE_UUID_PATH),
tuple(Qualifiers.PROJECT, PROJECT_UUID, UUID_PATH_OF_ROOT));
}
@Test
public void execute_register_all_components_uuids_as_their_id_in_ComponentRepository() {
dbTester.components().insertPublicProject(PROJECT);
- dbTester.getDbClient().componentDao().insert(dbTester.getSession(), MODULE, FILE);
+ dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE);
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
assertThat(ImmutableSet.of(
componentRepository.getRef(PROJECT.uuid()),
- componentRepository.getRef(MODULE.uuid()),
- componentRepository.getRef(FILE.uuid()))).containsExactlyInAnyOrder(1L, 2L, 3L);
+ componentRepository.getRef(FILE.uuid()))).containsExactlyInAnyOrder(1L, 2L);
}
@Test
public void throws_ISE_if_error() {
dbTester.components().insertPublicProject(PROJECT);
- dbTester.getDbClient().componentDao().insert(dbTester.getSession(), MODULE, FILE);
+ dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE);
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
dumpWriter.failIfMoreThan(1, DumpElement.COMPONENTS);
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
.setRootUuid(PROJECT_UUID)
- .setModuleUuid(null)
- .setModuleUuidPath("." + PROJECT_UUID + ".")
.setBranchUuid(PROJECT_UUID);
private static final List<BranchDto> BRANCHES = ImmutableList.of(
.setUuid(PROJECT_UUID)
.setRootUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
- .setModuleUuid(null)
- .setModuleUuidPath("." + PROJECT_UUID + ".")
.setBranchUuid(PROJECT_UUID);
@Rule
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.ComponentTesting.newDirectory;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
public class ReportAnalysisFailureNotificationExecutionListenerTest {
@Rule
public void onEnd_fails_with_IAE_if_component_is_not_a_project() {
when(ceTaskMock.getType()).thenReturn(CeTaskTypes.REPORT);
ComponentDto project = dbTester.components().insertPrivateProject();
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
- ComponentDto directory = dbTester.components().insertComponent(newDirectory(module, randomAlphanumeric(12)));
+ ComponentDto directory = dbTester.components().insertComponent(newDirectory(project, randomAlphanumeric(12)));
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project));
ComponentDto view = dbTester.components().insertComponent(ComponentTesting.newPortfolio());
ComponentDto subView = dbTester.components().insertComponent(ComponentTesting.newSubPortfolio(view));
ComponentDto projectCopy = dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project, subView));
ComponentDto application = dbTester.components().insertComponent(ComponentTesting.newApplication());
- Arrays.asList(module, directory, file, view, subView, projectCopy, application)
+ Arrays.asList(directory, file, view, subView, projectCopy, application)
.forEach(component -> {
when(ceTaskMock.getComponent()).thenReturn(Optional.of(new CeTask.Component(component.uuid(), null, null)));
i -> i);
}
- public List<String> selectProjectsFromView(DbSession session, String viewUuid, String projectViewUuid) {
+ public List<String> selectProjectsFromView(DbSession session, String viewUuid, String rootViewUuid) {
var escapedViewUuid = viewUuid.replace("_", "\\_").replace("%", "\\%");
- return mapper(session).selectProjectsFromView("%." + escapedViewUuid + ".%", projectViewUuid);
+ return mapper(session).selectProjectsFromView("%." + escapedViewUuid + ".%", rootViewUuid);
}
/**
* order to support LIKE conditions when requesting descendants of a component
* and to avoid Oracle NULL on root components.
* Example:
- * - on root module: UUID="1" UUID_PATH="."
- * - on module: UUID="2" UUID_PATH=".1."
+ * - on root: UUID="1" UUID_PATH="."
* - on directory: UUID="3" UUID_PATH=".1.2."
* - on file: UUID="4" UUID_PATH=".1.2.3."
* - on view: UUID="5" UUID_PATH="."
/**
* Non-null UUID of root component. Equals UUID column on root components
* Example:
- * - on root module: UUID="1" PROJECT_UUID="1"
- * - on module: UUID="2" PROJECT_UUID="1"
+ * - on root: UUID="1" PROJECT_UUID="1"
* - on directory: UUID="3" PROJECT_UUID="1"
* - on file: UUID="4" PROJECT_UUID="1"
* - on view: UUID="5" PROJECT_UUID="5"
* - on sub-view: UUID="6" PROJECT_UUID="5"
- */
+ */
private String branchUuid;
/**
* Badly named, it is not the root !
- * - on root module: UUID="1" ROOT_UUID="1"
- * - on modules, whatever depth, value is the root module: UUID="2" ROOT_UUID="1"
+ * - on root: UUID="1" ROOT_UUID="1"
* - on directory, value is the closest module: UUID="3" ROOT_UUID="2"
* - on file, value is the closest module: UUID="4" ROOT_UUID="2"
* - on view: UUID="5" ROOT_UUID="5"
* - on sub-view: UUID="6" ROOT_UUID="5"
+ *
* @since 6.0
*/
private String rootUuid;
* On non-main branches only, {@link #uuid} of the main branch that represents
* the project ({@link #qualifier}="TRK").
* It is propagated to all the components of the branch.
- *
* Value is null on the main-branch components and on other kinds of components
* (applications, portfolios).
- *
* Value must be used for loading settings, checking permissions, running webhooks,
* selecting Quality profiles/gates and any other project-related operations.
- *
* Example:
* - project P : kee=P, uuid=U1, qualifier=TRK, project_uuid=U1, main_branch_project_uuid=NULL
* - file F of project P : kee=P:F, uuid=U2, qualifier=FIL, project_uuid=U1, main_branch_project_uuid=NULL
@Nullable
private String mainBranchProjectUuid;
- private String moduleUuid;
- private String moduleUuidPath;
private String copyComponentUuid;
private String scope;
private String qualifier;
return UUID_PATH_OF_ROOT.equals(uuidPath);
}
- /**
- * Return the direct module of a component. Will be null on projects
- */
- @CheckForNull
- public String moduleUuid() {
- return moduleUuid;
- }
-
- public ComponentDto setModuleUuid(@Nullable String moduleUuid) {
- this.moduleUuid = moduleUuid;
- return this;
- }
-
- /**
- * Return the path from the project to the last modules
- */
- public String moduleUuidPath() {
- return moduleUuidPath;
- }
-
- public ComponentDto setModuleUuidPath(String moduleUuidPath) {
- this.moduleUuidPath = moduleUuidPath;
- return this;
- }
-
@CheckForNull
public String path() {
return path;
}
/**
- * Use {@link #branchUuid()}, {@link #moduleUuid()} or {@link #moduleUuidPath()}
+ * Use {@link #branchUuid()}
*/
@Deprecated
public String getRootUuid() {
}
public boolean isRootProject() {
- return moduleUuid == null && Scopes.PROJECT.equals(scope);
+ return uuid.equals(branchUuid) && Scopes.PROJECT.equals(scope);
}
public boolean isPrivate() {
.append("scope", scope)
.append("qualifier", qualifier)
.append("branchUuid", branchUuid)
- .append("moduleUuid", moduleUuid)
- .append("moduleUuidPath", moduleUuidPath)
.append("rootUuid", rootUuid)
.append("mainBranchProjectUuid", mainBranchProjectUuid)
.append("copyComponentUuid", copyComponentUuid)
copy.branchUuid = branchUuid;
copy.rootUuid = rootUuid;
copy.mainBranchProjectUuid = mainBranchProjectUuid;
- copy.moduleUuid = moduleUuid;
- copy.moduleUuidPath = moduleUuidPath;
copy.copyComponentUuid = copyComponentUuid;
copy.scope = scope;
copy.qualifier = qualifier;
/**
* Return technical projects from a view or a sub-view
*/
- List<String> selectProjectsFromView(@Param("viewUuidLikeQuery") String viewUuidLikeQuery, @Param("projectViewUuid") String projectViewUuid);
+ List<String> selectProjectsFromView(@Param("viewUuidLikeQuery") String viewUuidLikeQuery, @Param("rootViewUuid") String rootViewUuid);
void scrollForIndexing(@Param("projectUuid") @Nullable String projectUuid, ResultHandler<ComponentDto> handler);
private String bUuidPath;
private String bLanguage;
private String bLongName;
- private String bModuleUuid;
- private String bModuleUuidPath;
private String bName;
private String bPath;
private String bQualifier;
return bLongName;
}
- @CheckForNull
- public String getBModuleUuid() {
- return bModuleUuid;
- }
-
- @CheckForNull
- public String getBModuleUuidPath() {
- return bModuleUuidPath;
- }
-
@CheckForNull
public String getBName() {
return bName;
return this;
}
- public ComponentUpdateDto setBModuleUuid(@Nullable String s) {
- this.bModuleUuid = s;
- return this;
- }
-
- public ComponentUpdateDto setBModuleUuidPath(@Nullable String s) {
- this.bModuleUuidPath = s;
- return this;
- }
-
public ComponentUpdateDto setBPath(@Nullable String s) {
this.bPath = s;
return this;
.setBUuidPath(from.getUuidPath())
.setBLanguage(from.language())
.setBLongName(from.longName())
- .setBModuleUuid(from.moduleUuid())
- .setBModuleUuidPath(from.moduleUuidPath())
.setBName(from.name())
.setBPath(from.path())
// We don't have a b_scope. The applyBChangesForRootComponentUuid query is using a case ... when to infer scope from the qualifier
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.component;
-
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public class ComponentWithModuleUuidDto {
- private final String uuid;
- private final String moduleUuid;
- private final String path;
- private final String scope;
-
- public ComponentWithModuleUuidDto(String uuid, String moduleUuid, String path, String scope) {
- this.uuid = uuid;
- this.moduleUuid = moduleUuid;
- this.path = path;
- this.scope = scope;
- }
-
- public String path() {
- return path;
- }
-
- public String moduleUuid() {
- return moduleUuid;
- }
-
- public String uuid() {
- return uuid;
- }
-
- public String scope() {
- return scope;
- }
-}
public class FilePathWithHashDto {
private String uuid;
- private String moduleUuid;
private String path;
private String srcHash;
private String revision;
this.srcHash = srcHash;
}
- public String getModuleUuid() {
- return moduleUuid;
- }
-
- public void setModuleUuid(String moduleUuid) {
- this.moduleUuid = moduleUuid;
- }
-
@CheckForNull
public String getPath() {
return path;
private String uuid;
private String projectUuid;
- private String moduleUuid;
- private String moduleUuidPath;
private String key;
private String deprecatedKey;
private String name;
return this;
}
- public String getModuleUuid() {
- return moduleUuid;
- }
-
- public ResourceDto setModuleUuid(String moduleUuid) {
- this.moduleUuid = moduleUuid;
- return this;
- }
-
- public String getModuleUuidPath() {
- return moduleUuidPath;
- }
-
- public ResourceDto setModuleUuidPath(String moduleUuidPath) {
- this.moduleUuidPath = moduleUuidPath;
- return this;
- }
-
public String getName() {
return name;
}
return mapper(session).selectComponentUuidsOfOpenIssuesForProjectUuid(projectUuid);
}
- public List<IssueDto> selectNonClosedByComponentUuidExcludingExternalsAndSecurityHotspots(DbSession dbSession, String componentUuid) {
- return mapper(dbSession).selectNonClosedByComponentUuidExcludingExternals(componentUuid);
- }
-
- public List<IssueDto> selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(DbSession dbSession, ComponentDto module) {
- String likeModuleUuidPath = buildLikeValue(module.moduleUuidPath(), WildcardPosition.AFTER);
- return mapper(dbSession).selectNonClosedByModuleOrProject(module.branchUuid(), likeModuleUuidPath);
- }
-
public List<PrIssueDto> selectOpenByComponentUuids(DbSession dbSession, Collection<String> componentUuids) {
return executeLargeInputs(componentUuids, mapper(dbSession)::selectOpenByComponentUuids);
}
private boolean isExternal;
private String language;
private String componentKey;
- private String moduleUuidPath;
private String projectKey;
private String filePath;
private String tags;
.setRuleDescriptionContextKey(issue.getRuleDescriptionContextKey().orElse(null))
.setComponentUuid(issue.componentUuid())
.setComponentKey(issue.componentKey())
- .setModuleUuidPath(issue.moduleUuidPath())
.setProjectUuid(issue.projectUuid())
.setProjectKey(issue.projectKey())
.setAuthorLogin(issue.authorLogin())
.setRuleDescriptionContextKey(issue.getRuleDescriptionContextKey().orElse(null))
.setComponentUuid(issue.componentUuid())
.setComponentKey(issue.componentKey())
- .setModuleUuidPath(issue.moduleUuidPath())
.setProjectUuid(issue.projectUuid())
.setProjectKey(issue.projectKey())
.setIssueCreationDate(issue.creationDate())
public IssueDto setComponent(ComponentDto component) {
this.componentKey = component.getKey();
this.componentUuid = component.uuid();
- this.moduleUuidPath = component.moduleUuidPath();
this.filePath = component.path();
return this;
}
return this;
}
- @CheckForNull
- public String getModuleUuidPath() {
- return moduleUuidPath;
- }
-
- /**
- * Should only be used to persist in E/S
- * <p/>
- * Please use {@link #setComponent(ComponentDto)} instead
- */
- public IssueDto setModuleUuidPath(@Nullable String moduleUuidPath) {
- this.moduleUuidPath = moduleUuidPath;
- return this;
- }
-
/**
* Used by the issue tracking mechanism, but it should used the component uuid instead
*/
issue.setAssigneeUuid(assigneeUuid);
issue.setComponentKey(componentKey);
issue.setComponentUuid(componentUuid);
- issue.setModuleUuidPath(moduleUuidPath);
issue.setProjectUuid(projectUuid);
issue.setProjectKey(projectKey);
issue.setManualSeverity(manualSeverity);
void scrollClosedByComponentUuid(@Param("componentUuid") String componentUuid, @Param("closeDateAfter") long closeDateAfter, ResultHandler<IssueDto> handler);
- List<IssueDto> selectNonClosedByComponentUuidExcludingExternals(@Param("componentUuid") String componentUuid);
-
- List<IssueDto> selectNonClosedByModuleOrProject(@Param("projectUuid") String projectUuid, @Param("likeModuleUuidPath") String likeModuleUuidPath);
-
Collection<IssueGroupDto> selectIssueGroupsByComponent(@Param("component") ComponentDto component, @Param("leakPeriodBeginningDate") long leakPeriodBeginningDate);
List<IssueDto> selectByBranch(@Param("keys") Set<String> keys, @Nullable @Param("changedSince") Long changedSince);
profiler.stop();
}
- void deleteByRootAndModulesOrSubviews(List<String> rootAndModulesOrSubviewsUuids) {
- if (rootAndModulesOrSubviewsUuids.isEmpty()) {
+ void deleteByRootAndSubviews(List<String> rootAndSubviewsUuids) {
+ if (rootAndSubviewsUuids.isEmpty()) {
return;
}
- List<List<String>> uuidsPartitions = Lists.partition(rootAndModulesOrSubviewsUuids, MAX_RESOURCES_PER_QUERY);
+ List<List<String>> uuidsPartitions = Lists.partition(rootAndSubviewsUuids, MAX_RESOURCES_PER_QUERY);
- profiler.start("deleteByRootAndModulesOrSubviews (properties)");
+ profiler.start("deleteByRootAndSubviews (properties)");
uuidsPartitions.forEach(purgeMapper::deletePropertiesByComponentUuids);
session.commit();
profiler.stop();
*/
package org.sonar.db.purge;
-import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.Date;
import java.util.List;
public class PurgeDao implements Dao {
private static final Logger LOG = Loggers.get(PurgeDao.class);
- private static final Set<String> QUALIFIERS_PROJECT_VIEW = ImmutableSet.of("TRK", "VW");
- private static final Set<String> QUALIFIERS_MODULE_SUBVIEW = ImmutableSet.of("BRC", "SVW");
+ private static final Set<String> QUALIFIERS_PROJECT_VIEW = Set.of("TRK", "VW");
+ private static final Set<String> QUALIFIER_SUBVIEW = Set.of("SVW");
private static final String SCOPE_PROJECT = "PRJ";
private final System2 system2;
}
private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) {
- List<String> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid);
+ List<String> rootAndSubviews = mapper.selectRootAndSubviewsByProjectUuid(rootUuid);
commands.deleteLinks(rootUuid);
commands.deleteScannerCache(rootUuid);
commands.deleteAnalyses(rootUuid);
- commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews);
+ commands.deleteByRootAndSubviews(rootAndSubviews);
commands.deleteIssues(rootUuid);
commands.deleteFileSources(rootUuid);
commands.deleteCeActivity(rootUuid);
private static void deleteNonRootComponentsInView(Set<ComponentDto> nonRootComponents, PurgeCommands purgeCommands) {
List<String> subviewsOrProjectCopies = nonRootComponents.stream()
- .filter(PurgeDao::isModuleOrSubview)
+ .filter(PurgeDao::isSubview)
.map(ComponentDto::uuid)
.collect(MoreCollectors.toList());
- purgeCommands.deleteByRootAndModulesOrSubviews(subviewsOrProjectCopies);
+ purgeCommands.deleteByRootAndSubviews(subviewsOrProjectCopies);
List<String> nonRootComponentUuids = nonRootComponents.stream().map(ComponentDto::uuid).collect(MoreCollectors.toList(nonRootComponents.size()));
purgeCommands.deleteComponentMeasures(nonRootComponentUuids);
purgeCommands.deleteComponents(nonRootComponentUuids);
return !(SCOPE_PROJECT.equals(dto.scope()) && QUALIFIERS_PROJECT_VIEW.contains(dto.qualifier()));
}
- private static boolean isModuleOrSubview(ComponentDto dto) {
- return SCOPE_PROJECT.equals(dto.scope()) && QUALIFIERS_MODULE_SUBVIEW.contains(dto.qualifier());
+ private static boolean isSubview(ComponentDto dto) {
+ return SCOPE_PROJECT.equals(dto.scope()) && QUALIFIER_SUBVIEW.contains(dto.qualifier());
}
public void deleteAnalyses(DbSession session, PurgeProfiler profiler, List<String> analysisUuids) {
List<String> selectAnalysisUuids(PurgeSnapshotQuery query);
/**
- * Returns the list of modules/subviews and the application/view/project for the specified project_uuid.
+ * Returns the list of subviews and the application/view/project for the specified project_uuid.
*/
- List<String> selectRootAndModulesOrSubviewsByProjectUuid(@Param("rootUuid") String rootUuid);
+ List<String> selectRootAndSubviewsByProjectUuid(@Param("rootUuid") String rootUuid);
Set<String> selectDisabledComponentsWithFileSource(@Param("branchUuid") String branchUuid);
p.uuid as uuid,
p.uuid_path as uuidPath,
p.branch_uuid as branchUuid,
- p.module_uuid as moduleUuid,
- p.module_uuid_path as moduleUuidPath,
p.main_branch_project_uuid as mainBranchProjectUuid,
p.kee as kee,
p.name as name,
p.uuid as uuid,
p.uuid_path as uuidPath,
p.branch_uuid as branchUuid,
- p.module_uuid as moduleUuid,
- p.module_uuid_path as moduleUuidPath,
p.main_branch_project_uuid as mainBranchProjectUuid,
p.kee as kee,
case
SELECT
p.uuid,
p.path,
- p.module_uuid as moduleUuid,
fs.src_hash as srcHash,
fs.revision
FROM components root
from components p
where
p.enabled = ${_true}
- and p.branch_uuid = #{projectViewUuid,jdbcType=VARCHAR}
+ and p.branch_uuid = #{rootViewUuid,jdbcType=VARCHAR}
<choose>
<when test="_databaseId == 'mssql'">
- and p.module_uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR} {escape '\'}
+ and p.uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR} {escape '\'}
</when>
<otherwise>
- and p.module_uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR} ESCAPE '\'
+ and p.uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR} ESCAPE '\'
</otherwise>
</choose>
and p.qualifier = 'TRK'
uuid,
uuid_path,
branch_uuid,
- module_uuid,
- module_uuid_path,
main_branch_project_uuid,
name,
long_name,
b_enabled,
b_language,
b_long_name,
- b_module_uuid,
- b_module_uuid_path,
b_name,
b_path,
b_qualifier
#{uuid,jdbcType=VARCHAR},
#{uuidPath,jdbcType=VARCHAR},
#{branchUuid,jdbcType=VARCHAR},
- #{moduleUuid,jdbcType=VARCHAR},
- #{moduleUuidPath,jdbcType=VARCHAR},
#{mainBranchProjectUuid, jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR},
#{longName,jdbcType=VARCHAR},
null,
null,
null,
- null,
- null,
null
)
</insert>
b_uuid_path = #{bUuidPath,jdbcType=VARCHAR},
b_language = #{bLanguage,jdbcType=VARCHAR},
b_long_name = #{bLongName,jdbcType=VARCHAR},
- b_module_uuid = #{bModuleUuid,jdbcType=VARCHAR},
- b_module_uuid_path = #{bModuleUuidPath,jdbcType=VARCHAR},
b_name = #{bName,jdbcType=VARCHAR},
b_path = #{bPath,jdbcType=VARCHAR},
b_qualifier = #{bQualifier,jdbcType=VARCHAR}
b_uuid_path = uuid_path,
b_language = language,
b_long_name = long_name,
- b_module_uuid = module_uuid,
- b_module_uuid_path = module_uuid_path,
b_name = name,
b_path = path,
b_qualifier = qualifier
uuid_path = b_uuid_path,
language = b_language,
long_name = b_long_name,
- module_uuid = b_module_uuid,
- module_uuid_path = b_module_uuid_path,
name = b_name,
path = b_path,
qualifier = b_qualifier,
b_enabled = ${_false},
b_language = null,
b_long_name = null,
- b_module_uuid = null,
- b_module_uuid_path = null,
b_name = null,
b_path = null,
b_qualifier = null
r.security_standards as securityStandards,
p.kee as componentKey,
i.component_uuid as componentUuid,
- p.module_uuid_path as moduleUuidPath,
p.path as filePath,
root.kee as projectKey,
i.project_uuid as projectUuid,
i.status <> 'CLOSED'
</select>
- <select id="selectNonClosedByComponentUuidExcludingExternals" parameterType="String" resultType="Issue">
- select
- <include refid="issueColumns"/>
- from issues i
- inner join rules r on r.uuid=i.rule_uuid
- inner join components p on p.uuid=i.component_uuid
- inner join components root on root.uuid=i.project_uuid
- left join new_code_reference_issues n on i.kee = n.issue_key
- where
- (r.is_external is NULL or r.is_external = ${_false}) and
- i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
- i.status <> 'CLOSED' and
- i.issue_type <> 4
- </select>
-
<select id="scrollClosedByComponentUuid" resultType="Issue" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
select
<include refid="issueColumns"/>,
and i.status <> 'CLOSED'
</select>
- <select id="selectNonClosedByModuleOrProject" parameterType="map" resultType="Issue">
- select
- <include refid="issueColumns"/>
- from issues i
- inner join rules r on r.uuid = i.rule_uuid
- inner join components p on p.uuid = i.component_uuid
- inner join components root on root.uuid = i.project_uuid
- left join new_code_reference_issues n on i.kee = n.issue_key
- where
- (r.is_external is NULL or r.is_external = ${_false}) and
- i.project_uuid = #{projectUuid, jdbcType=VARCHAR} and
- p.module_uuid_path like #{likeModuleUuidPath, jdbcType=VARCHAR} escape '/' and
- i.status <> 'CLOSED' and
- i.issue_type <> 4
- </select>
-
<select id="selectIssueGroupsByComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map">
select i.issue_type as ruleType, i.severity as severity, i.resolution as resolution, i.status as status, sum(i.effort) as effort, count(i.issue_type) as "count",
<if test="leakPeriodBeginningDate >= 0">
</select>
- <select id="selectRootAndModulesOrSubviewsByProjectUuid" resultType="String" parameterType="String">
+ <select id="selectRootAndSubviewsByProjectUuid" resultType="String" parameterType="String">
select
p.uuid
from
where
(
p.branch_uuid=#{rootUuid,jdbcType=VARCHAR}
- and p.scope = 'PRJ' and p.qualifier in ('SVW','BRC')
+ and p.scope = 'PRJ' and p.qualifier = 'SVW'
)
or (
uuid=#{rootUuid,jdbcType=VARCHAR}
"PATH" CHARACTER VARYING(2000),
"UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
"BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
- "MODULE_UUID" CHARACTER VARYING(50),
- "MODULE_UUID_PATH" CHARACTER VARYING(1500),
"MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
"B_CHANGED" BOOLEAN,
"B_NAME" CHARACTER VARYING(500),
"B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
"B_PATH" CHARACTER VARYING(2000),
"B_UUID_PATH" CHARACTER VARYING(1500),
- "B_MODULE_UUID" CHARACTER VARYING(50),
- "B_MODULE_UUID_PATH" CHARACTER VARYING(1500),
"CREATED_AT" TIMESTAMP
);
-CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID" NULLS FIRST);
CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST);
CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST);
import static org.sonar.db.component.ComponentTesting.newBranchDto;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPortfolio;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
public class ComponentDaoTest {
private static final String PROJECT_UUID = "project-uuid";
- private static final String MODULE_UUID = "module-uuid";
+ private static final String DIR_UUID = "dir-uuid";
private static final String FILE_1_UUID = "file-1-uuid";
private static final String FILE_2_UUID = "file-2-uuid";
private static final String FILE_3_UUID = "file-3-uuid";
assertThat(result).isNotNull();
assertThat(result.uuid()).isEqualTo(project.uuid());
assertThat(result.getUuidPath()).isEqualTo(".");
- assertThat(result.moduleUuid()).isNull();
- assertThat(result.moduleUuidPath()).isEqualTo("." + project.uuid() + ".");
assertThat(result.branchUuid()).isEqualTo(project.uuid());
assertThat(result.getKey()).isEqualTo("org.struts:struts");
assertThat(result.path()).isNull();
ComponentDto result = underTest.selectByUuid(dbSession, projectCopy.uuid()).get();
assertThat(result.uuid()).isEqualTo(projectCopy.uuid());
- assertThat(result.moduleUuid()).isEqualTo(view.uuid());
- assertThat(result.moduleUuidPath()).isEqualTo("." + view.uuid() + ".");
assertThat(result.branchUuid()).isEqualTo(view.uuid());
assertThat(result.getKey()).isEqualTo(view.getKey() + project.getKey());
assertThat(result.path()).isNull();
@Test
public void select_component_keys_by_qualifiers() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "src"));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
ComponentDto file = db.components().insertComponent(newFileDto(directory));
assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("TRK"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(project.getKey());
- assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("BRC"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(module.getKey());
assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("DIR"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(directory.getKey());
assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("FIL"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(file.getKey());
assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("unknown"))).isEmpty();
public void find_sub_projects_by_component_keys() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto removedSubModule = db.components().insertComponent(newModuleDto(module).setEnabled(false));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(subModule, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
+ ComponentDto removedDirectory = db.components().insertComponent(newDirectory(project, "src2").setEnabled(false));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
+ ComponentDto removedFile = db.components().insertComponent(newFileDto(project, directory).setEnabled(false));
// Sub project of a file
assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, singletonList(file.uuid())))
.extracting(ComponentDto::getKey)
- .containsExactlyInAnyOrder(subModule.getKey());
+ .containsExactlyInAnyOrder(project.getKey());
// Sub project of a directory
assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, singletonList(directory.uuid())))
- .extracting(ComponentDto::uuid)
- .containsExactlyInAnyOrder(subModule.uuid());
-
- // Sub project of a sub module
- assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, singletonList(subModule.uuid())))
- .extracting(ComponentDto::uuid)
- .containsExactlyInAnyOrder(module.uuid());
-
- // Sub project of a module
- assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, singletonList(module.uuid())))
.extracting(ComponentDto::uuid)
.containsExactlyInAnyOrder(project.uuid());
.extracting(ComponentDto::uuid)
.containsExactlyInAnyOrder(project.uuid());
- // SUb projects of a component and a sub module
- assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, asList(file.uuid(), subModule.uuid())))
- .extracting(ComponentDto::uuid)
- .containsExactlyInAnyOrder(subModule.uuid(), module.uuid());
-
assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, singletonList("unknown"))).isEmpty();
-
assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, Collections.emptyList())).isEmpty();
}
@Test
public void select_enabled_files_from_project() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto fileDirectlyOnModule = db.components().insertComponent(newFileDto(module));
- FileSourceDto fileSourceDirectlyOnModule = db.fileSources().insertFileSource(fileDirectlyOnModule);
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
FileSourceDto fileSource = db.fileSources().insertFileSource(file);
// From root project
assertThat(underTest.selectEnabledFilesFromProject(dbSession, project.uuid()))
- .extracting(FilePathWithHashDto::getUuid, FilePathWithHashDto::getModuleUuid, FilePathWithHashDto::getSrcHash, FilePathWithHashDto::getPath, FilePathWithHashDto::getRevision)
+ .extracting(FilePathWithHashDto::getUuid, FilePathWithHashDto::getSrcHash, FilePathWithHashDto::getPath, FilePathWithHashDto::getRevision)
.containsExactlyInAnyOrder(
- tuple(fileDirectlyOnModule.uuid(), module.uuid(), fileSourceDirectlyOnModule.getSrcHash(), fileDirectlyOnModule.path(), fileSourceDirectlyOnModule.getRevision()),
- tuple(file.uuid(), subModule.uuid(), fileSource.getSrcHash(), file.path(), fileSource.getRevision()));
-
- // From module
- assertThat(underTest.selectEnabledFilesFromProject(dbSession, module.uuid())).isEmpty();
-
- // From sub module
- assertThat(underTest.selectEnabledFilesFromProject(dbSession, subModule.uuid())).isEmpty();
+ tuple(file.uuid(), fileSource.getSrcHash(), file.path(), fileSource.getRevision()));
// From directory
assertThat(underTest.selectEnabledFilesFromProject(dbSession, directory.uuid())).isEmpty();
public void select_by_branch_uuid() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto removedSubModule = db.components().insertComponent(newModuleDto(module).setEnabled(false));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(subModule, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
+ ComponentDto removedDirectory = db.components().insertComponent(newDirectory(project, "src2").setEnabled(false));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
+ ComponentDto removedFile = db.components().insertComponent(newFileDto(project, directory).setEnabled(false));
// Removed components are included
assertThat(underTest.selectByBranchUuid(project.uuid(), dbSession))
.extracting(ComponentDto::getKey)
- .containsExactlyInAnyOrder(project.getKey(), module.getKey(), removedModule.getKey(), subModule.getKey(), removedSubModule.getKey(),
- directory.getKey(), removedDirectory.getKey(), file.getKey(), removedFile.getKey());
+ .containsExactlyInAnyOrder(project.getKey(), directory.getKey(), removedDirectory.getKey(), file.getKey(), removedFile.getKey());
assertThat(underTest.selectByBranchUuid("UNKNOWN", dbSession)).isEmpty();
}
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project);
ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto removedSubModule = db.components().insertComponent(newModuleDto(module).setEnabled(false));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(subModule, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
+ ComponentDto removedDirectory = db.components().insertComponent(newDirectory(project, "src2").setEnabled(false));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
+ ComponentDto removedFile = db.components().insertComponent(newFileDto(project, directory).setEnabled(false));
Map<String, String> uuidsByKey = underTest.selectUuidsByKeyFromProjectKey(dbSession, project.getKey())
.stream().collect(Collectors.toMap(KeyWithUuidDto::key, KeyWithUuidDto::uuid));
assertThat(uuidsByKey).containsOnly(
entry(project.getKey(), project.uuid()),
- entry(module.getKey(), module.uuid()),
- entry(removedModule.getKey(), removedModule.uuid()),
- entry(subModule.getKey(), subModule.uuid()),
- entry(removedSubModule.getKey(), removedSubModule.uuid()),
entry(directory.getKey(), directory.uuid()),
entry(removedDirectory.getKey(), removedDirectory.uuid()),
entry(file.getKey(), file.uuid()),
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey(branchKey).setBranchType(PULL_REQUEST));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "src"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
ComponentDto projectFile = db.components().insertComponent(newFileDto(project, directory));
Map<String, String> uuidsByKey = underTest.selectUuidsByKeyFromProjectKeyAndBranch(dbSession, project.getKey(), branchKey)
assertThat(uuidsByKey).containsOnly(
entry(branch.getKey(), branch.uuid()),
- entry(module.getKey(), module.uuid()),
- entry(subModule.getKey(), subModule.uuid()),
entry(directory.getKey(), directory.uuid()),
entry(file.getKey(), file.uuid()));
}
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(prKey).setBranchType(PULL_REQUEST));
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey(prKey).setBranchType(BRANCH));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "src"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
ComponentDto projectFile = db.components().insertComponent(newFileDto(project, directory));
Map<String, String> uuidsByKey = underTest.selectUuidsByKeyFromProjectKeyAndPullRequest(dbSession, project.getKey(), prKey)
assertThat(uuidsByKey).containsOnly(
entry(branch.getKey(), branch.uuid()),
- entry(module.getKey(), module.uuid()),
- entry(subModule.getKey(), subModule.uuid()),
entry(directory.getKey(), directory.uuid()),
entry(file.getKey(), file.uuid()));
}
public void selectByProjectUuid() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto removedSubModule = db.components().insertComponent(newModuleDto(module).setEnabled(false));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(subModule, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
+ ComponentDto removedDirectory = db.components().insertComponent(newDirectory(project, "src2").setEnabled(false));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
+ ComponentDto removedFile = db.components().insertComponent(newFileDto(project, directory).setEnabled(false));
assertThat(underTest.selectByBranchUuid(project.uuid(), dbSession))
.extracting(ComponentDto::uuid)
- .containsExactlyInAnyOrder(project.uuid(), module.uuid(), removedModule.uuid(), subModule.uuid(), removedSubModule.uuid(), directory.uuid(), removedDirectory.uuid(),
+ .containsExactlyInAnyOrder(project.uuid(), directory.uuid(), removedDirectory.uuid(),
file.uuid(),
removedFile.uuid());
}
private ListAssert<String> assertSelectForIndexing(@Nullable String projectUuid) {
ComponentDto project = db.components().insertPrivateProject("U1");
ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
- ComponentDto module = db.components().insertComponent(newModuleDto("U2", project));
- ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "U3", "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(module, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(module, directory, "U4"));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(module, directory).setEnabled(false));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "U3", "src"));
+ ComponentDto removedDirectory = db.components().insertComponent(newDirectory(project, "src2").setEnabled(false));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory, "U4"));
+ ComponentDto removedFile = db.components().insertComponent(newFileDto(project, directory).setEnabled(false));
ComponentDto view = db.components().insertPublicPortfolio("VW1", p -> {
});
db.components().insertComponent(newProjectCopy("COPY8", project, view));
ComponentDto project2 = db.components().insertPrivateProject("U5");
- ComponentDto moduleOnProject2 = db.components().insertComponent(newModuleDto("U6", project2));
List<ComponentDto> components = new ArrayList<>();
underTest.scrollForIndexing(dbSession, projectUuid,
.setBUuidPath("uuid_path")
.setBLanguage("lang")
.setBLongName("longName")
- .setBModuleUuid("moduleUuid")
- .setBModuleUuidPath("moduleUuidPath")
.setBName("name")
.setBPath("path")
.setBQualifier("qualifier"), "qualifier");
.containsEntry("bUuidPath", "uuid_path")
.containsEntry("bLanguage", "lang")
.containsEntry("bLongName", "longName")
- .containsEntry("bModuleUuid", "moduleUuid")
- .containsEntry("bModuleUuidPath", "moduleUuidPath")
.containsEntry("bName", "name")
.containsEntry("bPath", "path")
.containsEntry("bQualifier", "qualifier");
.containsEntry("bUuidPath", dto1.getUuidPath())
.containsEntry("bLanguage", dto1.language())
.containsEntry("bLongName", dto1.longName())
- .containsEntry("bModuleUuid", dto1.moduleUuid())
- .containsEntry("bModuleUuidPath", dto1.moduleUuidPath())
.containsEntry("bName", dto1.name())
.containsEntry("bPath", dto1.path())
.containsEntry("bQualifier", dto1.qualifier());
.containsEntry("bUuidPath", dto2.getUuidPath())
.containsEntry("bLanguage", dto2.language())
.containsEntry("bLongName", dto2.longName())
- .containsEntry("bModuleUuid", dto2.moduleUuid())
- .containsEntry("bModuleUuidPath", dto2.moduleUuidPath())
.containsEntry("bName", dto2.name())
.containsEntry("bPath", dto2.path())
.containsEntry("bQualifier", dto2.qualifier());
private Map<String, Object> selectBColumnsForUuid(String uuid) {
return db.selectFirst(
"select b_changed as \"bChanged\", deprecated_kee as \"bKey\", b_copy_component_uuid as \"bCopyComponentUuid\", b_description as \"bDescription\", " +
- "b_enabled as \"bEnabled\", b_uuid_path as \"bUuidPath\", b_language as \"bLanguage\", b_long_name as \"bLongName\"," +
- "b_module_uuid as \"bModuleUuid\", b_module_uuid_path as \"bModuleUuidPath\", b_name as \"bName\", " +
+ "b_enabled as \"bEnabled\", b_uuid_path as \"bUuidPath\", b_language as \"bLanguage\", b_long_name as \"bLongName\", b_name as \"bName\", " +
"b_path as \"bPath\", b_qualifier as \"bQualifier\" " +
"from components where uuid='" + uuid + "'");
}
@Test
public void selectAncestors() {
- // project -> module -> file
+ // project -> dir -> file
ComponentDto project = newPrivateProjectDto(PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
- ComponentDto module = newModuleDto(MODULE_UUID, project);
- db.components().insertComponent(module);
- ComponentDto file = newFileDto(module, null, FILE_1_UUID);
+ ComponentDto dir = newDirectory(project, DIR_UUID, "path");
+ db.components().insertComponent(dir);
+ ComponentDto file = newFileDto(dir, null, FILE_1_UUID);
db.components().insertComponent(file);
db.commit();
List<ComponentDto> ancestors = underTest.selectAncestors(dbSession, project);
assertThat(ancestors).isEmpty();
- // ancestors of module
- ancestors = underTest.selectAncestors(dbSession, module);
+ // ancestors of dir
+ ancestors = underTest.selectAncestors(dbSession, dir);
assertThat(ancestors).extracting("uuid").containsExactly(PROJECT_UUID);
// ancestors of file
ancestors = underTest.selectAncestors(dbSession, file);
- assertThat(ancestors).extracting("uuid").containsExactly(PROJECT_UUID, MODULE_UUID);
+ assertThat(ancestors).extracting("uuid").containsExactly(PROJECT_UUID, DIR_UUID);
}
@Test
public void select_children() {
ComponentDto project = newPrivateProjectDto(PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
- ComponentDto module = newModuleDto(MODULE_UUID, project);
- db.components().insertComponent(module);
+ ComponentDto dir = newDirectory(project, DIR_UUID, "path");
+ db.components().insertComponent(dir);
ComponentDto fileInProject = newFileDto(project, null, FILE_1_UUID).setKey("file-key-1").setName("File One");
db.components().insertComponent(fileInProject);
- ComponentDto file1InModule = newFileDto(module, null, FILE_2_UUID).setKey("file-key-2").setName("File Two");
- db.components().insertComponent(file1InModule);
- ComponentDto file2InModule = newFileDto(module, null, FILE_3_UUID).setKey("file-key-3").setName("File Three");
- db.components().insertComponent(file2InModule);
+ ComponentDto file1InDir = newFileDto(dir, null, FILE_2_UUID).setKey("file-key-2").setName("File Two");
+ db.components().insertComponent(file1InDir);
+ ComponentDto file2InDir = newFileDto(dir, null, FILE_3_UUID).setKey("file-key-3").setName("File Three");
+ db.components().insertComponent(file2InDir);
db.commit();
// test children of root
- assertThat(underTest.selectChildren(dbSession, project.uuid(), List.of(project))).extracting("uuid").containsOnly(FILE_1_UUID, MODULE_UUID);
+ assertThat(underTest.selectChildren(dbSession, project.uuid(), List.of(project))).extracting("uuid").containsOnly(FILE_1_UUID, DIR_UUID);
- // test children of intermediate component (module here)
- assertThat(underTest.selectChildren(dbSession, project.uuid(), List.of(module))).extracting("uuid").containsOnly(FILE_2_UUID, FILE_3_UUID);
+ // test children of intermediate component (dir here)
+ assertThat(underTest.selectChildren(dbSession, project.uuid(), List.of(dir))).extracting("uuid").containsOnly(FILE_2_UUID, FILE_3_UUID);
// test children of leaf component (file here)
assertThat(underTest.selectChildren(dbSession, project.uuid(), List.of(fileInProject))).isEmpty();
// test children of 2 components
- assertThat(underTest.selectChildren(dbSession, project.uuid(), List.of(project, module))).extracting("uuid").containsOnly(FILE_1_UUID, MODULE_UUID, FILE_2_UUID, FILE_3_UUID);
+ assertThat(underTest.selectChildren(dbSession, project.uuid(), List.of(project, dir))).extracting("uuid").containsOnly(FILE_1_UUID, DIR_UUID, FILE_2_UUID, FILE_3_UUID);
}
@Test
public void select_descendants_with_children_strategy() {
- // project has 2 children: module and file 1. Other files are part of module.
+ // project has 2 children: dir and file 1. Other files are part of dir.
ComponentDto project = newPrivateProjectDto(PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
- ComponentDto module = newModuleDto(MODULE_UUID, project);
- db.components().insertComponent(module);
+ ComponentDto dir = newDirectory(project, DIR_UUID, "dir");
+ db.components().insertComponent(dir);
ComponentDto fileInProject = newFileDto(project, null, FILE_1_UUID).setKey("file-key-1").setName("File One");
db.components().insertComponent(fileInProject);
- ComponentDto file1InModule = newFileDto(module, null, FILE_2_UUID).setKey("file-key-2").setName("File Two");
- db.components().insertComponent(file1InModule);
- ComponentDto file2InModule = newFileDto(module, null, FILE_3_UUID).setKey("file-key-3").setName("File Three");
- db.components().insertComponent(file2InModule);
+ ComponentDto file1InDir = newFileDto(project, dir, FILE_2_UUID).setKey("file-key-2").setName("File Two");
+ db.components().insertComponent(file1InDir);
+ ComponentDto file2InDir = newFileDto(project, dir, FILE_3_UUID).setKey("file-key-3").setName("File Three");
+ db.components().insertComponent(file2InDir);
db.commit();
// test children of root
ComponentTreeQuery query = newTreeQuery(PROJECT_UUID).build();
List<ComponentDto> children = underTest.selectDescendants(dbSession, query);
- assertThat(children).extracting("uuid").containsOnly(FILE_1_UUID, MODULE_UUID);
+ assertThat(children).extracting("uuid").containsOnly(FILE_1_UUID, DIR_UUID);
// test children of root, filtered by qualifier
- query = newTreeQuery(PROJECT_UUID).setQualifiers(asList(Qualifiers.MODULE)).build();
+ query = newTreeQuery(PROJECT_UUID).setQualifiers(asList(Qualifiers.DIRECTORY)).build();
children = underTest.selectDescendants(dbSession, query);
- assertThat(children).extracting("uuid").containsOnly(MODULE_UUID);
+ assertThat(children).extracting("uuid").containsOnly(DIR_UUID);
- // test children of intermediate component (module here), default ordering by
- query = newTreeQuery(MODULE_UUID).build();
+ // test children of intermediate component (dir here), default ordering by
+ query = newTreeQuery(DIR_UUID).build();
assertThat(underTest.selectDescendants(dbSession, query)).extracting("uuid").containsOnly(FILE_2_UUID, FILE_3_UUID);
// test children of leaf component (file here)
query = newTreeQuery(PROJECT_UUID).setNameOrKeyQuery("does-not-exist").build();
assertThat(underTest.selectDescendants(dbSession, query)).isEmpty();
- // test children of intermediate component (module here), matching name
- query = newTreeQuery(MODULE_UUID).setNameOrKeyQuery("Two").build();
+ // test children of intermediate component (dir here), matching name
+ query = newTreeQuery(DIR_UUID).setNameOrKeyQuery("Two").build();
assertThat(underTest.selectDescendants(dbSession, query)).extracting("uuid").containsOnly(FILE_2_UUID);
- // test children of intermediate component (module here), without matching name
- query = newTreeQuery(MODULE_UUID).setNameOrKeyQuery("does-not-exist").build();
+ // test children of intermediate component (dir here), without matching name
+ query = newTreeQuery(DIR_UUID).setNameOrKeyQuery("does-not-exist").build();
assertThat(underTest.selectDescendants(dbSession, query)).isEmpty();
// test children of leaf component (file here)
assertThat(underTest.selectDescendants(dbSession, query))
.extracting(ComponentDto::uuid)
.containsExactlyInAnyOrder(fileInProject.uuid());
- query = newTreeQuery(project.uuid()).setScopes(asList(Scopes.PROJECT)).build();
+ query = newTreeQuery(project.uuid()).setScopes(asList(Scopes.DIRECTORY)).build();
assertThat(underTest.selectDescendants(dbSession, query))
.extracting(ComponentDto::uuid)
- .containsExactlyInAnyOrder(module.uuid());
+ .containsExactlyInAnyOrder(dir.uuid());
}
@Test
public void select_descendants_with_leaves_strategy() {
ComponentDto project = newPrivateProjectDto(PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
- db.components().insertComponent(newModuleDto("module-1-uuid", project));
+ db.components().insertComponent(newDirectory(project, "dir-1-uuid", "dir"));
db.components().insertComponent(newFileDto(project, null, "file-1-uuid"));
db.components().insertComponent(newFileDto(project, null, "file-2-uuid"));
db.commit();
ComponentTreeQuery query = newTreeQuery(PROJECT_UUID).setStrategy(LEAVES).build();
List<ComponentDto> result = underTest.selectDescendants(dbSession, query);
- assertThat(result).extracting("uuid").containsOnly("file-1-uuid", "file-2-uuid", "module-1-uuid");
+ assertThat(result).extracting("uuid").containsOnly("file-1-uuid", "file-2-uuid", "dir-1-uuid");
}
@Test
package org.sonar.db.component;
import org.junit.Test;
-import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void is_root_project() {
- assertThat(new ComponentDto().setModuleUuid("ABCD").isRootProject()).isFalse();
- assertThat(new ComponentDto().setModuleUuid("ABCD").setScope(Scopes.DIRECTORY).isRootProject()).isFalse();
- assertThat(new ComponentDto().setModuleUuid(null).setScope(Scopes.PROJECT).setQualifier(Qualifiers.PROJECT).isRootProject()).isTrue();
+ assertThat(new ComponentDto().setUuid("uuid").setBranchUuid("branch").isRootProject()).isFalse();
+ assertThat(new ComponentDto().setScope(Scopes.DIRECTORY).setUuid("uuid").setBranchUuid("uuid").isRootProject()).isFalse();
+ assertThat(new ComponentDto().setScope(Scopes.PROJECT).setUuid("uuid").setBranchUuid("uuid").isRootProject()).isTrue();
}
@Test
ComponentDto project = ComponentTesting.newPrivateProjectDto().setUuidPath(ComponentDto.UUID_PATH_OF_ROOT);
assertThat(project.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + ".%");
- ComponentDto module = ComponentTesting.newModuleDto(project);
- assertThat(module.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + "." + module.uuid() + ".%");
+ ComponentDto dir = ComponentTesting.newDirectory(project, "path");
+ assertThat(dir.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + "." + dir.uuid() + ".%");
- ComponentDto file = ComponentTesting.newFileDto(module);
- assertThat(file.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + "." + module.uuid() + "." + file.uuid() + ".%");
+ ComponentDto file = ComponentTesting.newFileDto(project, dir);
+ assertThat(file.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + "." + dir.uuid() + "." + file.uuid() + ".%");
}
@Test
import static org.sonar.db.component.ComponentKeyUpdaterDao.computeNewKey;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
public class ComponentKeyUpdaterDaoTest {
public void updateKey_changes_the_key_of_tree_of_components() {
populateSomeData();
- underTest.updateKey(dbSession, "B", "struts:core");
+ underTest.updateKey(dbSession, "A", "struts:core");
dbSession.commit();
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components"))
.extracting(t -> t.get("UUID"), t -> t.get("KEE"))
.containsOnly(
- Tuple.tuple("A", "org.struts:struts"),
- Tuple.tuple("B", "struts:core"),
- Tuple.tuple("C", "struts:core:/src/org/struts"),
- Tuple.tuple("D", "struts:core:/src/org/struts/RequestContext.java"),
- Tuple.tuple("E", "org.struts:struts-ui"),
- Tuple.tuple("F", "org.struts:struts-ui:/src/org/struts"),
- Tuple.tuple("G", "org.struts:struts-ui:/src/org/struts/RequestContext.java"),
- Tuple.tuple("H", "foo:struts-core"));
+ Tuple.tuple("A", "struts:core"),
+ Tuple.tuple("B", "struts:core:/src/org/struts"),
+ Tuple.tuple("C", "struts:core:/src/org/struts/RequestContext.java"),
+ Tuple.tuple("D", "foo:struts-core"));
}
@Test
public void updateKey_throws_IAE_if_component_with_specified_key_does_not_exist() {
populateSomeData();
- assertThatThrownBy(() -> underTest.updateKey(dbSession, "B", "org.struts:struts-ui"))
+ assertThatThrownBy(() -> underTest.updateKey(dbSession, "A", "foo:struts-core"))
.isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Impossible to update key: a component with key \"org.struts:struts-ui\" already exists.");
+ .hasMessage("Impossible to update key: a component with key \"foo:struts-core\" already exists.");
}
@Test
private void populateSomeData() {
ComponentDto project1 = db.components().insertPrivateProject(t -> t.setKey("org.struts:struts").setUuid("A"));
- ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setKey("org.struts:struts-core").setUuid("B"));
- ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "/src/org/struts").setUuid("C"));
- db.components().insertComponent(ComponentTesting.newFileDto(module1, directory1).setKey("org.struts:struts-core:/src/org/struts/RequestContext.java").setUuid("D"));
- ComponentDto module2 = db.components().insertComponent(newModuleDto(project1).setKey("org.struts:struts-ui").setUuid("E"));
- ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "/src/org/struts").setUuid("F"));
- db.components().insertComponent(ComponentTesting.newFileDto(module2, directory2).setKey("org.struts:struts-ui:/src/org/struts/RequestContext.java").setUuid("G"));
- ComponentDto project2 = db.components().insertPublicProject(t -> t.setKey("foo:struts-core").setUuid("H"));
+ ComponentDto directory1 = db.components().insertComponent(newDirectory(project1, "/src/org/struts").setUuid("B"));
+ db.components().insertComponent(ComponentTesting.newFileDto(project1, directory1).setKey("org.struts:struts:/src/org/struts/RequestContext.java").setUuid("C"));
+ ComponentDto project2 = db.components().insertPublicProject(t -> t.setKey("foo:struts-core").setUuid("D"));
}
}
@Test
public void scrollAllFilesForFileMove_scrolls_files_of_project() {
ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
+ ComponentDto dir1 = db.components().insertComponent(ComponentTesting.newDirectory(project, "path"));
+ ComponentDto dir2 = db.components().insertComponent(ComponentTesting.newDirectory(dir1, "path2"));
ComponentAndSource file1 = insertFileAndSource(project, FILE);
- ComponentAndSource file2 = insertFileAndSource(module1, FILE);
- ComponentAndSource file3 = insertFileAndSource(module2, FILE);
+ ComponentAndSource file2 = insertFileAndSource(dir1, FILE);
+ ComponentAndSource file3 = insertFileAndSource(dir2, FILE);
RecordingResultHandler resultHandler = new RecordingResultHandler();
underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler);
public void scrollAllFilesForFileMove_ignores_non_file_and_non_ut_component_with_source() {
ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
db.fileSources().insertFileSource(project);
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- db.fileSources().insertFileSource(module);
- ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(module, "foo"));
+ ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "foo"));
db.fileSources().insertFileSource(dir);
- ComponentAndSource file = insertFileAndSource(module, FILE);
+ ComponentAndSource file = insertFileAndSource(project, FILE);
ComponentAndSource ut = insertFileAndSource(dir, UNIT_TEST_FILE);
ComponentDto portfolio = random.nextBoolean() ? db.components().insertPublicPortfolio() : db.components().insertPrivatePortfolio();
db.fileSources().insertFileSource(portfolio);
*/
package org.sonar.db.issue;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.component.ComponentUpdateDto;
import org.sonar.db.protobuf.DbIssues;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang.math.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE;
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
import static org.sonar.api.issue.Issue.RESOLUTION_WONT_FIX;
-import static org.sonar.api.issue.Issue.STATUSES;
import static org.sonar.api.issue.Issue.STATUS_CLOSED;
import static org.sonar.api.issue.Issue.STATUS_CONFIRMED;
import static org.sonar.api.issue.Issue.STATUS_OPEN;
import static org.sonar.api.issue.Issue.STATUS_REOPENED;
import static org.sonar.api.issue.Issue.STATUS_RESOLVED;
import static org.sonar.api.issue.Issue.STATUS_REVIEWED;
-import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.issue.IssueTesting.newCodeReferenceIssue;
import static org.sonar.db.protobuf.DbIssues.MessageFormattingType.CODE;
assertThat(issues).extracting("key").containsOnly("I1", "I2");
}
- @Test
- public void scrollNonClosedByComponentUuid() {
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
- IssueDto openIssue1OnFile = db.issues().insert(rule, project, file, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
- IssueDto openIssue2OnFile = db.issues().insert(rule, project, file, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
- IssueDto closedIssueOnFile = db.issues().insert(rule, project, file, i -> i.setStatus("CLOSED").setResolution("FIXED").setType(randomRuleTypeExceptHotspot()));
- IssueDto openIssueOnProject = db.issues().insert(rule, project, project, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
-
- IssueDto securityHotspot = db.issues().insert(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT));
-
- RuleDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true));
- IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot()));
-
- assertThat(underTest.selectNonClosedByComponentUuidExcludingExternalsAndSecurityHotspots(db.getSession(), file.uuid()))
- .extracting(IssueDto::getKey)
- .containsExactlyInAnyOrder(Arrays.stream(new IssueDto[] {openIssue1OnFile, openIssue2OnFile}).map(IssueDto::getKey).toArray(String[]::new));
-
- assertThat(underTest.selectNonClosedByComponentUuidExcludingExternalsAndSecurityHotspots(db.getSession(), project.uuid()))
- .extracting(IssueDto::getKey)
- .containsExactlyInAnyOrder(Arrays.stream(new IssueDto[] {openIssueOnProject}).map(IssueDto::getKey).toArray(String[]::new));
-
- assertThat(underTest.selectNonClosedByComponentUuidExcludingExternalsAndSecurityHotspots(db.getSession(), "does_not_exist")).isEmpty();
- }
-
- @Test
- public void scrollNonClosedByModuleOrProject() {
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto anotherProject = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
- IssueDto openIssue1OnFile = db.issues().insert(rule, project, file, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
- IssueDto openIssue2OnFile = db.issues().insert(rule, project, file, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
- IssueDto closedIssueOnFile = db.issues().insert(rule, project, file, i -> i.setStatus("CLOSED").setResolution("FIXED").setType(randomRuleTypeExceptHotspot()));
- IssueDto openIssueOnModule = db.issues().insert(rule, project, module, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
- IssueDto openIssueOnProject = db.issues().insert(rule, project, project, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
- IssueDto openIssueOnAnotherProject = db.issues().insert(rule, anotherProject, anotherProject,
- i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot()));
-
- IssueDto securityHotspot = db.issues().insert(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT));
-
- RuleDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true));
- IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot()));
-
- assertThat(underTest.selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(db.getSession(), project))
- .extracting(IssueDto::getKey)
- .containsExactlyInAnyOrder(
- Arrays.stream(new IssueDto[] {openIssue1OnFile, openIssue2OnFile, openIssueOnModule, openIssueOnProject}).map(IssueDto::getKey).toArray(String[]::new));
-
- assertThat(underTest.selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(db.getSession(), module))
- .extracting(IssueDto::getKey)
- .containsExactlyInAnyOrder(Arrays.stream(new IssueDto[] {openIssue1OnFile, openIssue2OnFile, openIssueOnModule}).map(IssueDto::getKey).toArray(String[]::new));
-
- ComponentDto notPersisted = ComponentTesting.newPrivateProjectDto();
- assertThat(underTest.selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(db.getSession(), notPersisted)).isEmpty();
- }
-
@Test
public void selectOpenByComponentUuid() {
RuleDto rule = db.rules().insert();
.setComponentKey("org.sonar.sample:Sample")
.setComponentUuid("CDEF")
.setProjectUuid("GHIJ")
- .setModuleUuidPath("ABCD.BCDE.")
.setProjectKey("org.sonar.sample")
.setStatus(Issue.STATUS_CLOSED)
.setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
assertThat(issue.componentUuid()).isEqualTo("CDEF");
assertThat(issue.projectUuid()).isEqualTo("GHIJ");
assertThat(issue.componentKey()).isEqualTo("org.sonar.sample:Sample");
- assertThat(issue.moduleUuidPath()).isEqualTo("ABCD.BCDE.");
assertThat(issue.projectKey()).isEqualTo("org.sonar.sample");
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
assertThat(issueDto).extracting(IssueDto::isManualSeverity, IssueDto::getChecksum, IssueDto::getAssigneeUuid,
IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey,
- IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey,
- IssueDto::getRuleUuid)
- .containsExactly(true, "123", "123", true, "123", "componentKey",
- "path/to/module/uuid", "123", "projectKey", "ruleUuid");
+ IssueDto::getProjectUuid, IssueDto::getProjectKey, IssueDto::getRuleUuid)
+ .containsExactly(true, "123", "123", true, "123", "componentKey", "123", "projectKey", "ruleUuid");
assertThat(issueDto.isQuickFixAvailable()).isTrue();
assertThat(issueDto.isNewCodeReferenceIssue()).isTrue();
.containsExactly(Set.of("todo"), "admin");
assertThat(issueDto).extracting(IssueDto::isManualSeverity, IssueDto::getChecksum, IssueDto::getAssigneeUuid,
- IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey,
- IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey)
- .containsExactly(true, "123", "123", true, "123", "componentKey",
- "path/to/module/uuid", "123", "projectKey");
+ IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey, IssueDto::getProjectUuid, IssueDto::getProjectKey)
+ .containsExactly(true, "123", "123", true, "123", "componentKey", "123", "projectKey");
assertThat(issueDto.isQuickFixAvailable()).isTrue();
assertThat(issueDto.isNewCodeReferenceIssue()).isTrue();
.setTags(List.of("todo"))
.setComponentUuid("123")
.setComponentKey("componentKey")
- .setModuleUuidPath("path/to/module/uuid")
.setProjectUuid("123")
.setProjectKey("projectKey")
.setAuthorLogin("admin")
private ComponentDto randomComponent() {
ComponentDto project = dbTester.components().insertPublicProject();
- ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project));
ComponentDto dir = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "foo"));
- ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project));
- ComponentDto[] components = new ComponentDto[] {project, module, dir, file};
+ ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project, dir));
+ ComponentDto[] components = new ComponentDto[] {project, dir, file};
return components[random.nextInt(components.length)];
}
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.utils.DateUtils.parseDate;
+import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
public class MeasureDaoTest {
private MetricDto complexity;
private MetricDto ncloc;
-
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
private DbClient dbClient = db.getDbClient();
@Before
public void before() {
- coverage =db.measures().insertMetric(m -> m.setKey("coverage"));
- complexity = db.measures().insertMetric(m -> m.setKey( "complexity"));
+ coverage = db.measures().insertMetric(m -> m.setKey("coverage"));
+ complexity = db.measures().insertMetric(m -> m.setKey("complexity"));
ncloc = db.measures().insertMetric(m -> m.setKey("ncloc"));
}
@Test
public void test_selects() {
ComponentDto project1 = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project1));
- db.components().insertComponent(newFileDto(module).setUuid("C1"));
- db.components().insertComponent(newFileDto(module).setUuid("C2"));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project1, "path"));
+ db.components().insertComponent(newFileDto(dir).setUuid("C1"));
+ db.components().insertComponent(newFileDto(dir).setUuid("C2"));
SnapshotDto lastAnalysis = insertAnalysis(project1.uuid(), true);
SnapshotDto pastAnalysis = insertAnalysis(project1.uuid(), false);
verifyNoMeasure("MISSING_COMPONENT", ncloc.getKey(), pastAnalysis.getUuid());
// ncloc measure of component C1 of last analysis
- verifyMeasure("C1", ncloc.getKey(), "M2");
+ verifyMeasure("C1", ncloc.getKey(), "M2");
// ncloc measure of component C1 of non last analysis
- verifyMeasure("C1", ncloc.getKey(), pastAnalysis.getUuid(), "M1");
+ verifyMeasure("C1", ncloc.getKey(), pastAnalysis.getUuid(), "M1");
// ncloc measure of component C1 of last analysis by UUID
- verifyMeasure("C1", ncloc.getKey(), lastAnalysis.getUuid(), "M2");
+ verifyMeasure("C1", ncloc.getKey(), lastAnalysis.getUuid(), "M2");
// missing measure of component C1 of last analysis
verifyNoMeasure("C1", complexity.getKey());
verifyNoMeasure("C1", complexity.getKey(), lastAnalysis.getUuid());
// projects measures of last analysis
- verifyMeasure(project1.uuid(), ncloc.getKey(), "P1_M1");
+ verifyMeasure(project1.uuid(), ncloc.getKey(), "P1_M1");
// projects measures of none last analysis
- verifyMeasure(project1.uuid(), ncloc.getKey(), pastAnalysis.getUuid(), "P1_M3");
+ verifyMeasure(project1.uuid(), ncloc.getKey(), pastAnalysis.getUuid(), "P1_M3");
}
@Test
dbTester.components().insertComponent(project);
ComponentDto otherProject = dbTester.components().insertPrivateProject();
Stream.of(project, otherProject).forEach(prj -> {
- ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(prj));
- ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(module, "a"));
+ ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(prj, "a"));
ComponentDto directory2 = dbTester.components().insertComponent(ComponentTesting.newDirectory(prj, "b"));
dbTester.components().insertComponent(newFileDto(prj));
- dbTester.components().insertComponent(newFileDto(module));
dbTester.components().insertComponent(newFileDto(directory1));
dbTester.components().insertComponent(newFileDto(directory2));
});
underTest.deleteComponents(project.uuid());
assertThat(countComponentOfRoot(project)).isZero();
- assertThat(countComponentOfRoot(otherProject)).isEqualTo(8);
+ assertThat(countComponentOfRoot(otherProject)).isEqualTo(6);
}
@Test
dbTester.components().insertComponent(project);
ComponentDto branch = dbTester.components().insertProjectBranch(project);
Stream.of(project, branch).forEach(prj -> {
- ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(prj));
- ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(module, "a"));
+ ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(prj, "a"));
ComponentDto directory2 = dbTester.components().insertComponent(ComponentTesting.newDirectory(prj, "b"));
dbTester.components().insertComponent(newFileDto(prj));
- dbTester.components().insertComponent(newFileDto(module));
dbTester.components().insertComponent(newFileDto(directory1));
dbTester.components().insertComponent(newFileDto(directory2));
});
underTest.deleteComponentsByMainBranchProjectUuid(project.uuid());
- assertThat(countComponentOfRoot(project)).isEqualTo(8);
+ assertThat(countComponentOfRoot(project)).isEqualTo(6);
assertThat(countComponentOfRoot(branch)).isZero();
}
@DataProvider
public static Object[] projects() {
- return new Object[]{
+ return new Object[] {
ComponentTesting.newPrivateProjectDto(), ComponentTesting.newPublicProjectDto(),
};
}
@DataProvider
public static Object[] views() {
- return new Object[]{
+ return new Object[] {
ComponentTesting.newPortfolio(), ComponentTesting.newApplication()
};
}
import static org.sonar.db.component.ComponentTesting.newBranchDto;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.component.SnapshotDto.STATUS_PROCESSED;
// pull request with other components and issues, updated 31 days ago
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
db.components().insertSnapshot(pullRequest, dto -> dto.setCreatedAt(DateUtils.addDays(new Date(), -31).getTime()));
- ComponentDto module = db.components().insertComponent(newModuleDto(pullRequest));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+ ComponentDto dir = db.components().insertComponent(newDirectory(pullRequest, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(pullRequest, dir));
db.issues().insert(rule, pullRequest, file);
- db.issues().insert(rule, pullRequest, subModule);
- db.issues().insert(rule, pullRequest, module);
underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, project.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
db.components().insertSnapshot(project);
db.components().insertSnapshot(project, s -> s.setLast(false));
- ComponentDto module = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto dir = db.components().insertComponent(newDirectory(module, "sub").setEnabled(false));
- ComponentDto srcFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
- ComponentDto testFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
- ComponentDto enabledFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(true));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "sub").setEnabled(false));
+ ComponentDto srcFile = db.components().insertComponent(newFileDto(project, dir).setEnabled(false));
+ ComponentDto testFile = db.components().insertComponent(newFileDto(project, dir).setEnabled(false));
+ ComponentDto enabledFile = db.components().insertComponent(newFileDto(project, dir).setEnabled(true));
IssueDto openOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("OPEN"));
IssueDto confirmOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("CONFIRM"));
IssueDto openOnDir = db.issues().insert(rule, project, dir, issue -> issue.setStatus("OPEN"));
PurgeListener purgeListener = mock(PurgeListener.class);
// back to present
- Set<String> selectedComponentUuids = ImmutableSet.of(module.uuid(), srcFile.uuid(), testFile.uuid());
+ Set<String> selectedComponentUuids = ImmutableSet.of(srcFile.uuid(), testFile.uuid());
underTest.purge(dbSession, newConfigurationWith30Days(system2, project.uuid(), project.uuid(), selectedComponentUuids),
purgeListener, new PurgeProfiler());
dbSession.commit();
public void delete_project_and_associated_data() {
RuleDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "a/b"));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "a/b"));
ComponentDto file = db.components().insertComponent(newFileDto(directory));
SnapshotDto analysis = db.components().insertSnapshot(project);
IssueDto issue1 = db.issues().insert(rule, project, file);
db.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue1));
ComponentDto otherProject = db.components().insertPrivateProject();
- ComponentDto otherModule = db.components().insertComponent(newModuleDto(otherProject));
- ComponentDto otherDirectory = db.components().insertComponent(newDirectory(otherModule, "a/b"));
+ ComponentDto otherDirectory = db.components().insertComponent(newDirectory(otherProject, "a/b"));
ComponentDto otherFile = db.components().insertComponent(newFileDto(otherDirectory));
SnapshotDto otherAnalysis = db.components().insertSnapshot(otherProject);
IssueDto otherIssue1 = db.issues().insert(rule, otherProject, otherFile);
underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
dbSession.commit();
- assertThat(uuidsIn("components")).containsOnly(otherProject.uuid(), otherModule.uuid(), otherDirectory.uuid(), otherFile.uuid());
+ assertThat(uuidsIn("components")).containsOnly(otherProject.uuid(), otherDirectory.uuid(), otherFile.uuid());
assertThat(uuidsIn("projects")).containsOnly(otherProject.uuid());
assertThat(uuidsIn("snapshots")).containsOnly(otherAnalysis.getUuid());
assertThat(uuidsIn("issues", "kee")).containsOnly(otherIssue1.getKey(), otherIssue2.getKey());
RuleDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+ ComponentDto dir = db.components().insertComponent(newDirectory(branch, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, dir));
db.issues().insert(rule, branch, file);
- db.issues().insert(rule, branch, subModule);
- db.issues().insert(rule, branch, module);
+ db.issues().insert(rule, branch, dir);
return project;
}
RuleDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, dir));
IssueDto oldClosed = db.issues().insert(rule, project, file, issue -> {
issue.setStatus("CLOSED");
MetricDto metric = db.measures().insertMetric();
ComponentDto project1 = db.components().insertPublicProject();
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project1));
+ ComponentDto dir1 = db.components().insertComponent(newDirectory(project1, "path"));
db.measures().insertLiveMeasure(project1, metric);
- db.measures().insertLiveMeasure(module1, metric);
+ db.measures().insertLiveMeasure(dir1, metric);
ComponentDto project2 = db.components().insertPublicProject();
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project2));
+ ComponentDto dir2 = db.components().insertComponent(newDirectory(project2, "path"));
db.measures().insertLiveMeasure(project2, metric);
- db.measures().insertLiveMeasure(module2, metric);
+ db.measures().insertLiveMeasure(dir2, metric);
underTest.deleteProject(dbSession, project1.uuid(), project1.qualifier(), project1.name(), project1.getKey());
- assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project1.uuid(), module1.uuid()), asList(metric.getUuid()))).isEmpty();
- assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project2.uuid(), module2.uuid()), asList(metric.getUuid()))).hasSize(2);
+ assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project1.uuid(), dir1.uuid()), asList(metric.getUuid()))).isEmpty();
+ assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project2.uuid(), dir2.uuid()), asList(metric.getUuid()))).hasSize(2);
}
private void verifyNoEffect(ComponentDto firstRoot, ComponentDto... otherRoots) {
@Test
public void deleteNonRootComponents_deletes_only_non_root_components_of_a_project_from_table_components() {
ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject();
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
- ComponentDto dir1 = db.components().insertComponent(newDirectory(module1, "A/B"));
+ ComponentDto dir1 = db.components().insertComponent(newDirectory(project, "A/B"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(project, dir1));
List<ComponentDto> components = asList(
project,
- module1,
- module2,
dir1,
- db.components().insertComponent(newDirectory(module2, "A/C")),
+ file1,
db.components().insertComponent(newFileDto(dir1)),
- db.components().insertComponent(newFileDto(module2)),
+ db.components().insertComponent(newFileDto(file1)),
db.components().insertComponent(newFileDto(project)));
Collections.shuffle(components);
@Test
public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_project_from_table_components() {
ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject();
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
- ComponentDto dir1 = db.components().insertComponent(newDirectory(module1, "A/B"));
- ComponentDto dir2 = db.components().insertComponent(newDirectory(module2, "A/C"));
- ComponentDto file1 = db.components().insertComponent(newFileDto(dir1));
- ComponentDto file2 = db.components().insertComponent(newFileDto(module2));
+ ComponentDto dir1 = db.components().insertComponent(newDirectory(project, "A/B"));
+ ComponentDto dir2 = db.components().insertComponent(newDirectory(project, "A/C"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(project, dir1));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(project));
ComponentDto file3 = db.components().insertComponent(newFileDto(project));
underTest.deleteNonRootComponentsInView(dbSession, singletonList(file3));
assertThat(uuidsIn("components"))
- .containsOnly(project.uuid(), module1.uuid(), module2.uuid(), dir1.uuid(), dir2.uuid(), file1.uuid(), file2.uuid());
+ .containsOnly(project.uuid(), dir1.uuid(), dir2.uuid(), file1.uuid(), file2.uuid());
- underTest.deleteNonRootComponentsInView(dbSession, asList(module1, dir2, file1));
+ underTest.deleteNonRootComponentsInView(dbSession, asList(dir2, file1));
assertThat(uuidsIn("components"))
- .containsOnly(project.uuid(), module2.uuid(), dir1.uuid(), file2.uuid());
+ .containsOnly(project.uuid(), dir1.uuid(), file2.uuid());
}
@Test
private void addComponentsSnapshotsAndIssuesToBranch(ComponentDto branch, RuleDto rule, int branchAge) {
db.components().insertSnapshot(branch, dto -> dto.setCreatedAt(DateUtils.addDays(new Date(), -branchAge).getTime()));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+ ComponentDto dir = db.components().insertComponent(newDirectory(branch, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, dir));
db.issues().insert(rule, branch, file);
- db.issues().insert(rule, branch, subModule);
- db.issues().insert(rule, branch, module);
}
}
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_returns_empty_when_table_is_empty() {
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid("foo")).isEmpty();
+ public void selectRootAndSubviewsByProjectUuid_returns_empty_when_table_is_empty() {
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid("foo")).isEmpty();
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_returns_project_with_specified_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_returns_project_with_specified_uuid() {
ComponentDto project = randomPublicOrPrivateProject();
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(project.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(project.uuid()))
.containsOnly(project.uuid());
}
- @Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_returns_modules_with_specified_project_uuid_and_project() {
- ComponentDto project = randomPublicOrPrivateProject();
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- ComponentDto module3 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
-
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(project.uuid()))
- .containsOnly(project.uuid(), module1.uuid(), module2.uuid(), module3.uuid());
- }
-
private ComponentDto randomPublicOrPrivateProject() {
return new Random().nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_returns_view_with_specified_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_returns_view_with_specified_uuid() {
ComponentDto view = db.components().insertPrivatePortfolio();
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(view.uuid()))
.containsOnly(view.uuid());
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_returns_application_with_specified_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_returns_application_with_specified_uuid() {
ComponentDto view = db.components().insertPublicApplication();
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(view.uuid()))
.containsOnly(view.uuid());
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_returns_subviews_with_specified_project_uuid_and_view() {
+ public void selectRootAndSubviewsByProjectUuid_returns_subviews_with_specified_project_uuid_and_view() {
ComponentDto view = db.components().insertPublicPortfolio();
ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubPortfolio(view));
ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubPortfolio(view));
ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubPortfolio(view));
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(view.uuid()))
.containsOnly(view.uuid(), subview1.uuid(), subview2.uuid(), subview3.uuid());
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_project_copy_with_specified_project_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_does_not_return_project_copy_with_specified_project_uuid() {
ComponentDto privateProject = db.components().insertPrivateProject();
ComponentDto view = db.components().insertPrivatePortfolio();
db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject));
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(view.uuid()))
.containsOnly(view.uuid());
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_module_with_specified_uuid() {
- ComponentDto privateProject = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(privateProject));
-
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(module.uuid()))
- .isEmpty();
- }
-
- @Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_directory_with_specified_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_does_not_return_directory_with_specified_uuid() {
ComponentDto privateProject = db.components().insertPrivateProject();
ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(privateProject, "A/B"));
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(directory.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(directory.uuid()))
.isEmpty();
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_file_with_specified_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_does_not_return_file_with_specified_uuid() {
ComponentDto privateProject = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(privateProject));
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(file.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(file.uuid()))
.isEmpty();
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_subview_with_specified_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_does_not_return_subview_with_specified_uuid() {
ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubPortfolio(view));
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(subview.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(subview.uuid()))
.isEmpty();
}
@Test
- public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_technicalCopy_with_specified_uuid() {
+ public void selectRootAndSubviewsByProjectUuid_does_not_return_technicalCopy_with_specified_uuid() {
ComponentDto privateProject = db.components().insertPrivateProject();
ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto technicalCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject));
- assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(technicalCopy.uuid()))
+ assertThat(purgeMapper.selectRootAndSubviewsByProjectUuid(technicalCopy.uuid()))
.isEmpty();
}
}
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
-import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
import static org.sonar.db.component.ComponentDto.generateBranchKey;
public class ComponentTesting {
- public static ComponentDto newFileDto(ComponentDto subProjectOrProject) {
- return newFileDto(subProjectOrProject, null);
+ public static ComponentDto newFileDto(ComponentDto project) {
+ return newFileDto(project, null);
}
- public static ComponentDto newFileDto(ComponentDto subProjectOrProject, @Nullable ComponentDto directory) {
- return newFileDto(subProjectOrProject, directory, Uuids.createFast());
+ public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory) {
+ return newFileDto(project, directory, Uuids.createFast());
}
- public static ComponentDto newFileDto(ComponentDto module, @Nullable ComponentDto directory, String fileUuid) {
+ public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory, String fileUuid) {
String filename = "NAME_" + fileUuid;
- String path = directory != null ? directory.path() + "/" + filename : module.path() + "/" + filename;
- return newChildComponent(fileUuid, module, directory == null ? module : directory)
+ String path = directory != null ? directory.path() + "/" + filename : project.path() + "/" + filename;
+ return newChildComponent(fileUuid, project, directory == null ? project : directory)
.setKey("FILE_KEY_" + fileUuid)
.setName(filename)
.setLongName(path)
.setLanguage("xoo");
}
- public static ComponentDto newDirectory(ComponentDto module, String path) {
- return newDirectory(module, Uuids.createFast(), path);
+ public static ComponentDto newDirectory(ComponentDto project, String path) {
+ return newDirectory(project, Uuids.createFast(), path);
}
- public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) {
- String key = !path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/";
- return newChildComponent(uuid, module, module)
+ public static ComponentDto newDirectory(ComponentDto project, String uuid, String path) {
+ String key = !path.equals("/") ? project.getKey() + ":" + path : project.getKey() + ":/";
+ return newChildComponent(uuid, project, project)
.setKey(key)
.setName(path)
.setLongName(path)
}
public static ComponentDto newSubPortfolio(ComponentDto portfolioOrSubPortfolio, String uuid, String key) {
- return newModuleDto(uuid, portfolioOrSubPortfolio)
+ return newChildComponent(uuid, portfolioOrSubPortfolio, portfolioOrSubPortfolio)
.setKey(key)
.setName(key)
.setLongName(key)
return newSubPortfolio(viewOrSubView, uuid, "KEY_" + uuid);
}
- public static ComponentDto newModuleDto(String uuid, ComponentDto parentModuleOrProject) {
- return newChildComponent(uuid, parentModuleOrProject, parentModuleOrProject)
- .setModuleUuidPath(parentModuleOrProject.moduleUuidPath() + uuid + UUID_PATH_SEPARATOR)
- .setKey("MODULE_KEY_" + uuid)
- .setName("NAME_" + uuid)
- .setLongName("LONG_NAME_" + uuid)
- .setPath("module")
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.MODULE)
- .setLanguage(null);
- }
-
- public static ComponentDto newModuleDto(ComponentDto subProjectOrProject) {
- return newModuleDto(Uuids.createFast(), subProjectOrProject);
- }
-
public static ComponentDto newPrivateProjectDto() {
return newProjectDto(Uuids.createFast(), true);
}
.setUuid(uuid)
.setUuidPath(UUID_PATH_OF_ROOT)
.setBranchUuid(uuid)
- .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
.setRootUuid(uuid)
.setKey("KEY_" + uuid)
.setName("NAME_" + uuid)
.setLanguage(null);
}
- public static ComponentDto newChildComponent(String uuid, ComponentDto moduleOrProject, ComponentDto parent) {
- checkArgument(moduleOrProject.isPrivate() == parent.isPrivate(),
+ public static ComponentDto newChildComponent(String uuid, ComponentDto project, ComponentDto parent) {
+ checkArgument(project.isPrivate() == parent.isPrivate(),
"private flag inconsistent between moduleOrProject (%s) and parent (%s)",
- moduleOrProject.isPrivate(), parent.isPrivate());
+ project.isPrivate(), parent.isPrivate());
return new ComponentDto()
.setUuid(uuid)
.setUuidPath(formatUuidPathFromParent(parent))
.setKey(uuid)
- .setBranchUuid(moduleOrProject.branchUuid())
- .setRootUuid(moduleOrProject.uuid())
- .setModuleUuid(moduleOrProject.uuid())
- .setModuleUuidPath(moduleOrProject.moduleUuidPath())
- .setMainBranchProjectUuid(moduleOrProject.getMainBranchProjectUuid())
+ .setBranchUuid(project.branchUuid())
+ .setRootUuid(project.uuid())
+ .setMainBranchProjectUuid(project.getMainBranchProjectUuid())
.setCreatedAt(new Date())
.setEnabled(true)
- .setPrivate(moduleOrProject.isPrivate());
+ .setPrivate(project.isPrivate());
}
public static BranchDto newBranchDto(@Nullable String projectUuid, BranchType branchType) {
.setUuid(uuid)
.setUuidPath(UUID_PATH_OF_ROOT)
.setBranchUuid(uuid)
- .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
.setRootUuid(uuid)
.setKey(project.getKey())
.setMainBranchProjectUuid(project.getUuid())
.setUuid(uuid)
.setUuidPath(UUID_PATH_OF_ROOT)
.setBranchUuid(uuid)
- .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
.setRootUuid(uuid)
.setKey(project.getKey())
.setMainBranchProjectUuid(project.uuid())
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
import org.sonar.server.platform.db.migration.version.DbVersion;
-// ignoring bad number formating, as it's indented that we align the migration numbers to SQ versions
+// ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions
@SuppressWarnings("java:S3937")
public class DbVersion100 implements DbVersion {
public void addSteps(MigrationStepRegistry registry) {
registry
.add(10_0_000, "Remove orphan rules in Quality Profiles", RemoveOrphanRulesFromQualityProfiles.class)
+ .add(10_0_001, "Drop index 'projects_module_uuid' in the 'Components' table", DropIndexProjectsModuleUuidInComponents.class)
+ .add(10_0_002, "Drop column 'module_uuid' in the 'Components' table", DropModuleUuidInComponents.class)
+ .add(10_0_003, "Drop column 'module_uuid_path' in the 'Components' table", DropModuleUuidPathInComponents.class)
+ .add(10_0_004, "Drop column 'b_module_uuid' in the 'Components' table", DropBModuleUuidInComponents.class)
+ .add(10_0_005, "Drop column 'b_module_uuid_path' in the 'Components' table", DropBModuleUuidPathInComponents.class)
;
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+public class DropBModuleUuidInComponents extends DropColumnChange {
+ private static final String COLUMN_NAME = "b_module_uuid";
+ private static final String TABLE_NAME = "components";
+
+ public DropBModuleUuidInComponents(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+public class DropBModuleUuidPathInComponents extends DropColumnChange {
+ private static final String COLUMN_NAME = "b_module_uuid_path";
+ private static final String TABLE_NAME = "components";
+
+ public DropBModuleUuidPathInComponents(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropIndexChange;
+
+public class DropIndexProjectsModuleUuidInComponents extends DropIndexChange {
+ private static final String INDEX_NAME = "projects_module_uuid";
+ private static final String TABLE_NAME = "components";
+
+ public DropIndexProjectsModuleUuidInComponents(Database db) {
+ super(db, INDEX_NAME, TABLE_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+public class DropModuleUuidInComponents extends DropColumnChange {
+ private static final String COLUMN_NAME = "module_uuid";
+ private static final String TABLE_NAME = "components";
+
+ public DropModuleUuidInComponents(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+public class DropModuleUuidPathInComponents extends DropColumnChange {
+ private static final String COLUMN_NAME = "module_uuid_path";
+ private static final String TABLE_NAME = "components";
+
+ public DropModuleUuidPathInComponents(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropBModuleUuidInComponentsTest {
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "b_module_uuid";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropBModuleUuidInComponentsTest.class, "schema.sql");
+ private final DdlChange underTest = new DropBModuleUuidInComponents(db.database());
+
+ @Test
+ public void drops_column() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true);
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropBModuleUuidPathInComponentsTest {
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "b_module_uuid_path";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropBModuleUuidPathInComponentsTest.class, "schema.sql");
+ private final DdlChange underTest = new DropBModuleUuidPathInComponents(db.database());
+
+ @Test
+ public void drops_column() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true);
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexProjectsModuleUuidInComponentsTest {
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "module_uuid";
+ private static final String INDEX_NAME = "projects_module_uuid";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexProjectsModuleUuidInComponentsTest.class, "schema.sql");
+ private final DdlChange underTest = new DropIndexProjectsModuleUuidInComponents(db.database());
+
+ @Test
+ public void drops_index() throws SQLException {
+ db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+ underTest.execute();
+ db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropModuleUuidInComponentsTest {
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "module_uuid";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropModuleUuidInComponentsTest.class, "schema.sql");
+ private final DdlChange underTest = new DropModuleUuidInComponents(db.database());
+
+ @Test
+ public void drops_column() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true);
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropModuleUuidPathInComponentsTest {
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "module_uuid_path";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropModuleUuidPathInComponentsTest.class, "schema.sql");
+ private final DdlChange underTest = new DropModuleUuidPathInComponents(db.database());
+
+ @Test
+ public void drops_column() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true);
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MODULE_UUID" CHARACTER VARYING(50),
+ "MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "B_MODULE_UUID" CHARACTER VARYING(50),
+ "B_MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST);
+CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
--- /dev/null
+
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MODULE_UUID" CHARACTER VARYING(50),
+ "MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "B_MODULE_UUID" CHARACTER VARYING(50),
+ "B_MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST);
+CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
--- /dev/null
+
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MODULE_UUID" CHARACTER VARYING(50),
+ "MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "B_MODULE_UUID" CHARACTER VARYING(50),
+ "B_MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP
+);
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID" NULLS FIRST);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST);
+CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
--- /dev/null
+
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MODULE_UUID" CHARACTER VARYING(50),
+ "MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "B_MODULE_UUID" CHARACTER VARYING(50),
+ "B_MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST);
+CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
--- /dev/null
+
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MODULE_UUID" CHARACTER VARYING(50),
+ "MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "B_MODULE_UUID" CHARACTER VARYING(50),
+ "B_MODULE_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST);
+CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
// other fields (such as module, modulePath, componentKey) are read-only and set/reset for consistency only
issue.setComponentKey(newComponentKey);
- issue.setModuleUuidPath(null);
}
private static boolean relevantDateDifference(@Nullable Date left, @Nullable Date right) {
return getField(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID);
}
- public String modulePath() {
- return getField(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH);
- }
-
public String projectUuid() {
return getField(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID);
}
return this;
}
- public IssueDoc setModuleUuidPath(@Nullable String s) {
- setField(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, s);
- return this;
- }
-
@CheckForNull
public Collection<String> getTags() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_TAGS);
public static final String FIELD_ISSUE_SCOPE = "scope";
public static final String FIELD_ISSUE_LANGUAGE = "language";
public static final String FIELD_ISSUE_LINE = "line";
- public static final String FIELD_ISSUE_MODULE_PATH = "modulePath";
/**
* The (real) project, equivalent of projects.main_branch_project_uuid | projects.project_uuid, so
mapping.keywordFieldBuilder(FIELD_ISSUE_SCOPE).disableNorms().build();
mapping.keywordFieldBuilder(FIELD_ISSUE_LANGUAGE).disableNorms().build();
mapping.createIntegerField(FIELD_ISSUE_LINE);
- mapping.createUuidPathField(FIELD_ISSUE_MODULE_PATH);
mapping.keywordFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
mapping.keywordFieldBuilder(FIELD_ISSUE_BRANCH_UUID).disableNorms().build();
mapping.createBooleanField(FIELD_ISSUE_IS_MAIN_BRANCH);
"r.uuid",
"r.language",
"c.uuid",
- "c.module_uuid_path",
"c.path",
"c.scope",
"c.branch_uuid",
doc.setRuleUuid(rs.getString(12));
doc.setLanguage(rs.getString(13));
doc.setComponentUuid(rs.getString(14));
- String moduleUuidPath = rs.getString(15);
- doc.setModuleUuidPath(moduleUuidPath);
- String scope = rs.getString(17);
- String filePath = extractFilePath(rs.getString(16), scope);
+ String scope = rs.getString(16);
+ String filePath = extractFilePath(rs.getString(15), scope);
doc.setFilePath(filePath);
doc.setDirectoryPath(extractDirPath(doc.filePath(), scope));
- String branchUuid = rs.getString(18);
- String mainBranchProjectUuid = DatabaseUtils.getString(rs, 19);
+ String branchUuid = rs.getString(17);
+ String mainBranchProjectUuid = DatabaseUtils.getString(rs, 18);
doc.setBranchUuid(branchUuid);
if (mainBranchProjectUuid == null) {
doc.setProjectUuid(branchUuid);
doc.setProjectUuid(mainBranchProjectUuid);
doc.setIsMainBranch(false);
}
- String tags = rs.getString(20);
+ String tags = rs.getString(19);
doc.setTags(IssueIteratorForSingleChunk.TAGS_SPLITTER.splitToList(tags == null ? "" : tags));
- doc.setType(RuleType.valueOf(rs.getInt(21)));
+ doc.setType(RuleType.valueOf(rs.getInt(20)));
- SecurityStandards securityStandards = fromSecurityStandards(deserializeSecurityStandardsString(rs.getString(22)));
+ SecurityStandards securityStandards = fromSecurityStandards(deserializeSecurityStandardsString(rs.getString(21)));
SecurityStandards.SQCategory sqCategory = securityStandards.getSqCategory();
doc.setOwaspTop10(securityStandards.getOwaspTop10());
doc.setOwaspTop10For2021(securityStandards.getOwaspTop10For2021());
doc.setSonarSourceSecurityCategory(sqCategory);
doc.setVulnerabilityProbability(sqCategory.getVulnerability());
- doc.setScope(Qualifiers.UNIT_TEST_FILE.equals(rs.getString(23)) ? IssueScope.TEST : IssueScope.MAIN);
- doc.setIsNewCodeReference(!isNullOrEmpty(rs.getString(24)));
+ doc.setScope(Qualifiers.UNIT_TEST_FILE.equals(rs.getString(22)) ? IssueScope.TEST : IssueScope.MAIN);
+ doc.setIsNewCodeReference(!isNullOrEmpty(rs.getString(23)));
return doc;
}
*/
public void index(String rootViewUuid) {
try (DbSession dbSession = dbClient.openSession(false)) {
- Map<String, String> viewAndProjectViewUuidMap = new HashMap<>();
+ Map<String, String> viewAndRootViewUuidMap = new HashMap<>();
for (ComponentDto viewOrSubView : dbClient.componentDao().selectEnabledViewsFromRootView(dbSession, rootViewUuid)) {
- viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.branchUuid());
+ viewAndRootViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.branchUuid());
}
- index(dbSession, viewAndProjectViewUuidMap, true, Size.REGULAR);
+ index(dbSession, viewAndRootViewUuidMap, true, Size.REGULAR);
}
}
bulk.stop();
}
- private void index(DbSession dbSession, Map<String, String> viewAndProjectViewUuidMap, boolean needClearCache, Size bulkSize) {
+ private void index(DbSession dbSession, Map<String, String> viewAndRootViewUuidMap, boolean needClearCache, Size bulkSize) {
BulkIndexer bulk = new BulkIndexer(esClient, TYPE_VIEW, bulkSize);
bulk.start();
- for (Map.Entry<String, String> entry : viewAndProjectViewUuidMap.entrySet()) {
+ for (Map.Entry<String, String> entry : viewAndRootViewUuidMap.entrySet()) {
String viewUuid = entry.getKey();
List<String> projects = dbClient.componentDao().selectProjectsFromView(dbSession, viewUuid, entry.getValue());
doIndex(bulk, new ViewDoc()
assertThat(underTest.calls).containsExactly(project.uuid());
}
- @Test
- public void commitAndIndex_of_module_indexes_the_project() {
- ComponentDto project = ComponentTesting.newPublicProjectDto();
- ComponentDto module = ComponentTesting.newModuleDto(project);
-
- FakeIndexers underTest = new FakeIndexers();
- underTest.commitAndIndexComponents(mock(DbSession.class), singletonList(module), Cause.PROJECT_CREATION);
-
- assertThat(underTest.calls).containsExactly(project.uuid());
- }
-
private static class FakeIndexers implements ProjectIndexers {
private final List<String> calls = new ArrayList<>();
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.issue.IssueTesting.newCodeReferenceIssue;
public class IssueIteratorFactoryTest {
assertThat(issue.ruleUuid()).isEqualTo(rule.getUuid());
assertThat(issue.componentUuid()).isEqualTo(file.uuid());
assertThat(issue.projectUuid()).isEqualTo(file.branchUuid());
- assertThat(issue.modulePath()).isEqualTo(file.moduleUuidPath());
assertThat(issue.directoryPath()).isEqualTo("src/main/java");
assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
public void iterator_over_issues() {
RuleDto rule = dbTester.rules().insert();
ComponentDto project = dbTester.components().insertPrivateProject();
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
- ComponentDto directory = dbTester.components().insertComponent(newDirectory(module, "src/main/java"));
- ComponentDto file = dbTester.components().insertComponent(newFileDto(module, directory)
+ ComponentDto directory = dbTester.components().insertComponent(newDirectory(project, "src/main/java"));
+ ComponentDto file = dbTester.components().insertComponent(newFileDto(directory, directory)
.setPath("src/main/java/Action.java"));
IssueDto fileIssue = dbTester.issues().insert(rule, project, file,
t -> t
.setAuthorLogin("guy2")
.setEffort(10L)
.setType(1));
- IssueDto moduleIssue = dbTester.issues().insert(rule, project, module, t -> t
+ IssueDto moduleIssue = dbTester.issues().insert(rule, project, file, t -> t
.setAssigneeUuid("uuid-of-guy2")
.setAuthorLogin("guy2")
.setRuleUuid(rule.getUuid()));
public void iterator_over_issue_from_project() {
RuleDto rule = dbTester.rules().insert();
ComponentDto project1 = dbTester.components().insertPrivateProject();
- ComponentDto module1 = dbTester.components().insertComponent(newModuleDto(project1));
- ComponentDto file1 = dbTester.components().insertComponent(newFileDto(module1));
- String[] project1IssueKeys = Stream.of(project1, module1, file1)
+ ComponentDto dir = dbTester.components().insertComponent(newDirectory(project1, "path"));
+ ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1, dir));
+ String[] project1IssueKeys = Stream.of(project1, dir, file1)
.map(project1Component -> dbTester.issues().insert(rule, project1, project1Component).getKey())
.toArray(String[]::new);
ComponentDto project2 = dbTester.components().insertPrivateProject();
- ComponentDto module2 = dbTester.components().insertComponent(newModuleDto(project2));
- ComponentDto file2 = dbTester.components().insertComponent(newFileDto(module2));
- String[] project2IssueKeys = Stream.of(project2, module2, file2)
+ ComponentDto dir2 = dbTester.components().insertComponent(newDirectory(project2, "path"));
+ ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2, dir2));
+ String[] project2IssueKeys = Stream.of(project2, dir2, file2)
.map(project2Component -> dbTester.issues().insert(rule, project2, project2Component).getKey())
.toArray(String[]::new);
public void extract_directory_path() {
RuleDto rule = dbTester.rules().insert();
ComponentDto project = dbTester.components().insertPrivateProject();
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
- ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml"));
- ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java"));
+ ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(project).setPath("pom.xml"));
+ ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(project).setPath("src/main/java/Action.java"));
IssueDto projectIssue = dbTester.issues().insert(rule, project, project);
IssueDto fileInSubDirIssue = dbTester.issues().insert(rule, project, fileInSubDir);
IssueDto fileInRootDirIssue = dbTester.issues().insert(rule, project, fileInRootDir);
- IssueDto moduleIssue = dbTester.issues().insert(rule, project, module);
Map<String, IssueDoc> issuesByKey = issuesByKey();
- assertThat(issuesByKey).hasSize(4);
+ assertThat(issuesByKey).hasSize(3);
assertThat(issuesByKey.get(fileInSubDirIssue.getKey()).directoryPath()).isEqualTo("src/main/java");
assertThat(issuesByKey.get(fileInRootDirIssue.getKey()).directoryPath()).isEqualTo("/");
- assertThat(issuesByKey.get(moduleIssue.getKey()).directoryPath()).isNull();
assertThat(issuesByKey.get(projectIssue.getKey()).directoryPath()).isNull();
}
public void extract_file_path() {
RuleDto rule = dbTester.rules().insert();
ComponentDto project = dbTester.components().insertPrivateProject();
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
- ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml"));
- ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java"));
+ ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(project).setPath("pom.xml"));
+ ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(project).setPath("src/main/java/Action.java"));
IssueDto projectIssue = dbTester.issues().insert(rule, project, project);
IssueDto fileInSubDirIssue = dbTester.issues().insert(rule, project, fileInSubDir);
IssueDto fileInRootDirIssue = dbTester.issues().insert(rule, project, fileInRootDir);
- IssueDto moduleIssue = dbTester.issues().insert(rule, project, module);
Map<String, IssueDoc> issuesByKey = issuesByKey();
- assertThat(issuesByKey).hasSize(4);
+ assertThat(issuesByKey).hasSize(3);
assertThat(issuesByKey.get(fileInSubDirIssue.getKey()).filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issuesByKey.get(fileInRootDirIssue.getKey()).filePath()).isEqualTo("pom.xml");
- assertThat(issuesByKey.get(moduleIssue.getKey()).filePath()).isNull();
assertThat(issuesByKey.get(projectIssue.getKey()).filePath()).isNull();
}
.setKey(key)
.setBranchUuid(componentDto.branchUuid())
.setComponentUuid(componentDto.uuid())
- .setModuleUuidPath(componentDto.moduleUuidPath())
.setProjectUuid(mainBranchProjectUuid == null ? componentDto.branchUuid() : mainBranchProjectUuid)
// File path make no sens on modules and projects
.setFilePath(!componentDto.scope().equals(Scopes.PROJECT) ? componentDto.path() : null)
doc.setComponentUuid(Uuids.createFast());
doc.setFilePath("filePath_" + randomAlphabetic(5));
doc.setDirectoryPath("directory_" + randomAlphabetic(5));
- doc.setModuleUuidPath(Uuids.createFast());
doc.setProjectUuid(Uuids.createFast());
doc.setLine(nextInt(1_000) + 1);
doc.setStatus(STATUS_OPEN);
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_KEY;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_LANGUAGE;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_LINE;
-import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_NEW_CODE_REFERENCE;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_OWASP_ASVS_40;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_OWASP_TOP_10;
filters.addFilter(
FIELD_ISSUE_PROJECT_UUID, new SimpleFieldFilterScope(FIELD_ISSUE_PROJECT_UUID),
createTermsFilter(FIELD_ISSUE_PROJECT_UUID, query.projectUuids()));
- filters.addFilter(
- "__module", new SimpleFieldFilterScope(FIELD_ISSUE_MODULE_PATH),
- createTermsFilter(FIELD_ISSUE_MODULE_PATH, query.moduleRootUuids()));
filters.addFilter(
FIELD_ISSUE_DIRECTORY_PATH, new SimpleFieldFilterScope(FIELD_ISSUE_DIRECTORY_PATH),
createTermsFilter(FIELD_ISSUE_DIRECTORY_PATH, query.directories()));
private final Collection<String> statuses;
private final Collection<String> resolutions;
private final Collection<String> components;
- private final Collection<String> moduleRoots;
private final Collection<String> projects;
private final Collection<String> directories;
private final Collection<String> files;
this.statuses = defaultCollection(builder.statuses);
this.resolutions = defaultCollection(builder.resolutions);
this.components = defaultCollection(builder.components);
- this.moduleRoots = defaultCollection(builder.moduleRoots);
this.projects = defaultCollection(builder.projects);
this.directories = defaultCollection(builder.directories);
this.files = defaultCollection(builder.files);
return components;
}
- public Collection<String> moduleRootUuids() {
- return moduleRoots;
- }
public Collection<String> projectUuids() {
return projects;
private Collection<String> statuses;
private Collection<String> resolutions;
private Collection<String> components;
- private Collection<String> moduleRoots;
private Collection<String> projects;
private Collection<String> directories;
private Collection<String> files;
return this;
}
- public Builder moduleRootUuids(@Nullable Collection<String> l) {
- this.moduleRoots = l;
- return this;
- }
-
public Builder projectUuids(@Nullable Collection<String> l) {
this.projects = l;
return this;
case Qualifiers.PROJECT:
builder.projectUuids(components.stream().map(IssueQueryFactory::toProjectUuid).collect(toList()));
break;
- case Qualifiers.MODULE:
- builder.moduleRootUuids(components.stream().map(ComponentDto::uuid).collect(toList()));
- break;
case Qualifiers.DIRECTORY:
addDirectories(builder, components);
break;
import static org.sonar.api.utils.DateUtils.parseDate;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.rule.RuleTesting.newRule;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
@Test
public void filter_by_projects() {
ComponentDto project = newPrivateProjectDto();
- ComponentDto module = newModuleDto(project);
- ComponentDto subModule = newModuleDto(module);
indexIssues(
newDoc("I1", project),
- newDoc("I2", newFileDto(project, null)),
- newDoc("I3", module),
- newDoc("I4", newFileDto(module, null)),
- newDoc("I5", subModule),
- newDoc("I6", newFileDto(subModule, null)));
+ newDoc("I2", newFileDto(project, null)));
- assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2", "I3", "I4", "I5", "I6");
+ assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2");
assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList("unknown")));
}
@Test
public void filter_by_components_on_contextualized_search() {
ComponentDto project = newPrivateProjectDto();
- ComponentDto module = newModuleDto(project);
- ComponentDto subModule = newModuleDto(module);
ComponentDto file1 = newFileDto(project, null);
- ComponentDto file2 = newFileDto(module, null);
- ComponentDto file3 = newFileDto(subModule, null);
String view = "ABCD";
indexView(view, singletonList(project.uuid()));
indexIssues(
newDoc("I1", project),
- newDoc("I2", file1),
- newDoc("I3", module),
- newDoc("I4", file2),
- newDoc("I5", subModule),
- newDoc("I6", file3));
+ newDoc("I2", file1));
- assertThatSearchReturnsOnly(IssueQuery.builder().files(asList(file1.path(), file2.path(), file3.path())), "I2", "I4", "I6");
+ assertThatSearchReturnsOnly(IssueQuery.builder().files(asList(file1.path())), "I2");
assertThatSearchReturnsOnly(IssueQuery.builder().files(singletonList(file1.path())), "I2");
- assertThatSearchReturnsOnly(IssueQuery.builder().moduleRootUuids(singletonList(subModule.uuid())), "I5", "I6");
- assertThatSearchReturnsOnly(IssueQuery.builder().moduleRootUuids(singletonList(module.uuid())), "I3", "I4", "I5", "I6");
- assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2", "I3", "I4", "I5", "I6");
- assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(view)), "I1", "I2", "I3", "I4", "I5", "I6");
+ assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2");
+ assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(view)), "I1", "I2");
assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList("unknown")));
}
public void filter_by_components_on_non_contextualized_search() {
ComponentDto project = newPrivateProjectDto("project");
ComponentDto file1 = newFileDto(project, null, "file1");
- ComponentDto module = newModuleDto(project).setUuid("module");
- ComponentDto file2 = newFileDto(module, null, "file2");
- ComponentDto subModule = newModuleDto(module).setUuid("subModule");
- ComponentDto file3 = newFileDto(subModule, null, "file3");
String view = "ABCD";
indexView(view, singletonList(project.uuid()));
indexIssues(
newDoc("I1", project),
- newDoc("I2", file1),
- newDoc("I3", module),
- newDoc("I4", file2),
- newDoc("I5", subModule),
- newDoc("I6", file3));
+ newDoc("I2", file1));
assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList("unknown")));
- assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2", "I3", "I4", "I5", "I6");
- assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(view)), "I1", "I2", "I3", "I4", "I5", "I6");
+ assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())), "I1", "I2");
+ assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(view)), "I1", "I2");
assertThatSearchReturnsOnly(IssueQuery.builder().files(singletonList(file1.path())), "I2");
- assertThatSearchReturnsOnly(IssueQuery.builder().files(asList(file1.path(), file2.path(), file3.path())), "I2", "I4", "I6");
+ assertThatSearchReturnsOnly(IssueQuery.builder().files(asList(file1.path())), "I2");
}
@Test
assertThatSearchReturnsOnly(
IssueQuery.builder().componentUuids(singletonList(branch.uuid())).projectUuids(singletonList(project.uuid())).branchUuid(branch.uuid()).mainBranch(false),
issueOnBranch.key());
- assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())).mainBranch(null), issueOnProject.key(), issueOnBranch.key(), issueOnAnotherBranch.key());
+ assertThatSearchReturnsOnly(IssueQuery.builder().projectUuids(singletonList(project.uuid())).mainBranch(null), issueOnProject.key(), issueOnBranch.key(),
+ issueOnAnotherBranch.key());
assertThatSearchReturnsEmpty(IssueQuery.builder().branchUuid("unknown"));
}
@Test
public void issues_from_branch_component_children() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto projectModule = db.components().insertComponent(newModuleDto(project));
- ComponentDto projectFile = db.components().insertComponent(newFileDto(projectModule));
+ ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- ComponentDto branchModule = db.components().insertComponent(newModuleDto(branch));
- ComponentDto branchFile = db.components().insertComponent(newFileDto(branchModule));
+ ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
indexIssues(
newDoc("I1", project),
newDoc("I2", projectFile),
- newDoc("I3", projectModule),
- newDoc("I4", branch),
- newDoc("I5", branchModule),
- newDoc("I6", branchFile));
+ newDoc("I3", branch),
+ newDoc("I4", branchFile));
- assertThatSearchReturnsOnly(IssueQuery.builder().branchUuid(branch.uuid()).mainBranch(false), "I4", "I5", "I6");
- assertThatSearchReturnsOnly(IssueQuery.builder().files(singletonList(branchFile.path())).branchUuid(branch.uuid()).mainBranch(false), "I6");
+ assertThatSearchReturnsOnly(IssueQuery.builder().branchUuid(branch.uuid()).mainBranch(false), "I3", "I4");
+ assertThatSearchReturnsOnly(IssueQuery.builder().files(singletonList(branchFile.path())).branchUuid(branch.uuid()).mainBranch(false), "I4");
assertThatSearchReturnsEmpty(IssueQuery.builder().files(singletonList(branchFile.uuid())).mainBranch(false).branchUuid("unknown"));
}
project1Issue1.key(), project2Issue2.key());
}
-
@Test
public void filter_by_new_code_reference_branches() {
ComponentDto project1 = newPrivateProjectDto();
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
String ruleAdHocName = "New Name";
UserDto user = db.users().insertUser(u -> u.setLogin("joanna"));
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
ComponentDto file = db.components().insertComponent(newFileDto(project));
RuleDto rule1 = ruleDbTester.insert(r -> r.setAdHocName(ruleAdHocName));
public void create_with_rule_key_that_does_not_exist_in_the_db() {
db.users().insertUser(u -> u.setLogin("joanna"));
ComponentDto project = db.components().insertPrivateProject();
- db.components().insertComponent(newModuleDto(project));
db.components().insertComponent(newFileDto(project));
newRule(RuleKey.of("findbugs", "NullReference"));
SearchRequest request = new SearchRequest()
assertThat(query.componentUuids()).isEmpty();
assertThat(query.projectUuids()).isEmpty();
- assertThat(query.moduleRootUuids()).isEmpty();
assertThat(query.directories()).isEmpty();
assertThat(query.files()).isEmpty();
assertThat(query.viewUuids()).isEmpty();
assertThat(query.onComponentOnly()).isTrue();
}
- @Test
- public void should_search_in_tree_with_module_uuid() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- SearchRequest request = new SearchRequest()
- .setComponentUuids(asList(module.uuid()));
-
- IssueQuery query = underTest.create(request);
- assertThat(query.moduleRootUuids()).containsExactly(module.uuid());
- assertThat(query.onComponentOnly()).isFalse();
- }
-
@Test
public void param_componentUuids_enables_search_in_directory_tree() {
ComponentDto project = db.components().insertPrivateProject();
BatchIndex.class,
ProjectAction.class,
ProjectDataLoader.class,
- IssuesAction.class,
IndexAction.class,
FileAction.class,
BatchWs.class);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.batch;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.sonar.api.resources.Scopes;
-import org.sonar.api.rules.RuleType;
-import org.sonar.api.server.ws.Change;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-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.user.UserDto;
-import org.sonar.scanner.protocol.input.ScannerInput;
-import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.user.UserSession;
-import org.sonarqube.ws.MediaTypes;
-
-import static java.lang.String.format;
-import static java.util.Optional.ofNullable;
-import static java.util.stream.Collectors.toMap;
-import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
-import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
-
-public class IssuesAction implements BatchWsAction {
-
- private static final String PARAM_KEY = "key";
- private static final String PARAM_BRANCH = "branch";
-
- private final DbClient dbClient;
- private final UserSession userSession;
- private final ComponentFinder componentFinder;
-
- public IssuesAction(DbClient dbClient, UserSession userSession, ComponentFinder componentFinder) {
- this.dbClient = dbClient;
- this.userSession = userSession;
- this.componentFinder = componentFinder;
- }
-
- @Override
- public void define(WebService.NewController controller) {
- WebService.NewAction action = controller.createAction("issues")
- .setDescription("Return open issues")
- .setResponseExample(getClass().getResource("issues-example.proto"))
- .setSince("5.1")
- .setChangelog(new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_KEY)))
- .setInternal(true)
- .setDeprecatedSince("9.5")
- .setHandler(this);
-
- action
- .createParam(PARAM_KEY)
- .setRequired(true)
- .setDescription("Project, module or file key")
- .setExampleValue(KEY_PROJECT_EXAMPLE_001);
-
- action
- .createParam(PARAM_BRANCH)
- .setSince("6.6")
- .setDescription("Branch key")
- .setExampleValue(KEY_BRANCH_EXAMPLE_001);
- }
-
- @Override
- public void handle(Request request, Response response) throws Exception {
- try (DbSession dbSession = dbClient.openSession(false)) {
- ComponentDto component = loadComponent(dbSession, request);
- userSession.checkComponentPermission(USER, component);
-
- ScannerInput.ServerIssue.Builder responseBuilder = ScannerInput.ServerIssue.newBuilder();
- response.stream().setMediaType(MediaTypes.PROTOBUF);
- OutputStream output = response.stream().output();
-
- List<IssueDto> issueDtos = new ArrayList<>();
- switch (component.scope()) {
- case Scopes.PROJECT:
- issueDtos.addAll(dbClient.issueDao().selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(dbSession, component));
- break;
- case Scopes.FILE:
- issueDtos.addAll(dbClient.issueDao().selectNonClosedByComponentUuidExcludingExternalsAndSecurityHotspots(dbSession, component.uuid()));
- break;
- default:
- // only projects, modules and files are supported. Other types of components are not allowed.
- throw new IllegalArgumentException(format("Component of scope '%s' is not allowed", component.scope()));
- }
-
- List<String> usersUuids = issueDtos.stream()
- .filter(issue -> issue.getAssigneeUuid() != null)
- .map(IssueDto::getAssigneeUuid)
- .toList();
-
- Map<String, String> userLoginsByUserUuids = dbClient.userDao().selectByUuids(dbSession, usersUuids)
- .stream().collect(toMap(UserDto::getUuid, UserDto::getLogin));
-
- issueDtos.forEach(issue -> {
- issue.setAssigneeUuid(userLoginsByUserUuids.get(issue.getAssigneeUuid()));
- handleIssue(issue, responseBuilder, output);
- });
- }
- }
-
- private static void handleIssue(IssueDto issue, ScannerInput.ServerIssue.Builder issueBuilder, OutputStream out) {
- issueBuilder.setKey(issue.getKey());
- ofNullable(issue.getFilePath()).ifPresent(issueBuilder::setPath);
- issueBuilder.setRuleRepository(issue.getRuleRepo());
- issueBuilder.setRuleKey(issue.getRule());
- ofNullable(issue.getChecksum()).ifPresent(issueBuilder::setChecksum);
- ofNullable(issue.getAssigneeUuid()).ifPresent(issueBuilder::setAssigneeLogin);
- ofNullable(issue.getLine()).ifPresent(issueBuilder::setLine);
- ofNullable(issue.getMessage()).ifPresent(issueBuilder::setMsg);
- issueBuilder.setSeverity(org.sonar.scanner.protocol.Constants.Severity.valueOf(issue.getSeverity()));
- issueBuilder.setManualSeverity(issue.isManualSeverity());
- issueBuilder.setStatus(issue.getStatus());
- ofNullable(issue.getResolution()).ifPresent(issueBuilder::setResolution);
- issueBuilder.setType(RuleType.valueOf(issue.getType()).name());
- issueBuilder.setCreationDate(issue.getIssueCreationTime());
- try {
- issueBuilder.build().writeDelimitedTo(out);
- } catch (IOException e) {
- throw new IllegalStateException("Unable to serialize issue", e);
- }
- issueBuilder.clear();
- }
-
- private ComponentDto loadComponent(DbSession dbSession, Request request) {
- String componentKey = request.mandatoryParam(PARAM_KEY);
- String branch = request.param(PARAM_BRANCH);
- return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, null);
- }
-}
String pullRequest = query.getPullRequest();
ComponentDto project = componentFinder.getByKey(session, projectKey);
checkRequest(project.isRootProject(), "Key '%s' belongs to a component which is not a Project", projectKey);
- boolean hasScanPerm = userSession.hasComponentPermission(UserRole.SCAN, project) ||
- userSession.hasPermission(GlobalPermission.SCAN);
+ boolean hasScanPerm = userSession.hasComponentPermission(UserRole.SCAN, project) || userSession.hasPermission(GlobalPermission.SCAN);
checkPermission(hasScanPerm);
ComponentDto branchComponent = (branch == null && pullRequest == null) ? project
: componentFinder.getByKeyAndOptionalBranchOrPullRequest(session, projectKey, branch, pullRequest);
.setUuid(uuid)
.setUuidPath(ComponentDto.UUID_PATH_OF_ROOT)
.setRootUuid(uuid)
- .setModuleUuid(null)
- .setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR)
.setBranchUuid(uuid)
.setKey(newComponent.key())
.setName(newComponent.name())
VIEW(Qualifiers.VIEW),
SUBVIEW(Qualifiers.SUBVIEW),
APP(Qualifiers.APP),
- PROJECT(Qualifiers.PROJECT),
- FILE(Qualifiers.FILE),
- UNIT_TEST_FILE(Qualifiers.UNIT_TEST_FILE),;
+ PROJECT(Qualifiers.PROJECT);
private final String qualifier;
.setHandler(this)
.setResponseExample(Resources.getResource(this.getClass(), "suggestions-example.json"))
.setChangelog(
+ new Change("10.0", String.format("The use of 'BRC' as value for parameter '%s' is no longer supported", PARAM_MORE)),
new Change("8.4", String.format("The use of 'DIR', 'FIL','UTS' as values for parameter '%s' is no longer supported", PARAM_MORE)),
new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_MORE)));
private List<String> getQualifiers(@Nullable String more) {
Set<String> availableQualifiers = resourceTypes.getAll().stream()
.map(ResourceType::getQualifier)
- .filter(q -> !q.equals(Qualifiers.MODULE))
- .filter(q -> !q.equals(Qualifiers.DIRECTORY))
- .filter(q -> !q.equals(Qualifiers.FILE))
- .filter(q -> !q.equals(Qualifiers.UNIT_TEST_FILE))
.collect(MoreCollectors.toSet());
if (more == null) {
return stream(SuggestionCategory.values())
import com.google.common.collect.TreeMultimap;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
public class ValuesAction implements SettingsWsAction {
-
private static final Splitter COMMA_SPLITTER = Splitter.on(",");
private static final String COMMA_ENCODED_VALUE = "%2C";
- private static final Splitter DOT_SPLITTER = Splitter.on(".").omitEmptyStrings();
private static final Set<String> SERVER_SETTING_KEYS = Set.of(SERVER_STARTTIME, SERVER_ID);
private final DbClient dbClient;
}
/**
- * Return list of settings by component uuid, sorted from project to lowest module
+ * Return list of settings by component uuid
*/
private Multimap<String, Setting> loadComponentSettings(DbSession dbSession, Set<String> keys, ComponentDto component) {
- List<String> componentUuids = DOT_SPLITTER.splitToList(component.moduleUuidPath());
+ List<String> componentUuids = new LinkedList<>();
+ if (!component.uuid().equals(component.branchUuid())) {
+ componentUuids.add(component.branchUuid());
+ }
+ componentUuids.add(component.uuid());
List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, keys, componentUuids);
List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, getPropertySetKeys(properties), componentUuids);
public void verify_count_of_added_components() {
ListContainer container = new ListContainer();
new BatchWsModule().configure(container);
- assertThat(container.getAddedObjects()).hasSize(7);
+ assertThat(container.getAddedObjects()).hasSize(6);
}
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.batch;
-
-import java.io.IOException;
-import java.util.stream.Stream;
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.rules.RuleType;
-import org.sonar.api.utils.System2;
-import org.sonar.api.web.UserRole;
-import org.sonar.core.util.CloseableIterator;
-import org.sonar.core.util.Protobuf;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.issue.IssueDto;
-import org.sonar.db.rule.RuleDto;
-import org.sonar.db.user.UserDto;
-import org.sonar.scanner.protocol.Constants.Severity;
-import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
-import org.sonar.server.component.TestComponentFinder;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.ws.TestRequest;
-import org.sonar.server.ws.TestResponse;
-import org.sonar.server.ws.WsActionTester;
-
-import static java.lang.String.format;
-import static org.apache.commons.lang.math.RandomUtils.nextInt;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.sonar.api.rules.RuleType.BUG;
-import static org.sonar.db.component.ComponentTesting.newDirectory;
-import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
-
-public class IssuesActionTest {
-
- private static final RuleType[] RULE_TYPES_EXCEPT_HOTSPOT = Stream.of(RuleType.values())
- .filter(r -> r != RuleType.SECURITY_HOTSPOT)
- .toArray(RuleType[]::new);
-
- private System2 system2 = System2.INSTANCE;
-
- @Rule
- public DbTester db = DbTester.create(system2);
- @Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone();
-
- private WsActionTester tester = new WsActionTester(new IssuesAction(db.getDbClient(), userSessionRule, TestComponentFinder.from(db)));
-
- @Test
- public void test_nullable_fields() throws Exception {
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module, null).setPath(null));
- IssueDto issue = db.issues().insert(rule, project, file, i -> i.setSeverity("BLOCKER")
- // non-null fields
- .setStatus("OPEN")
- .setType(BUG)
- .setManualSeverity(true)
-
- // all the nullable fields
- .setResolution(null)
- .setMessage(null)
- .setLine(null)
- .setChecksum(null)
- .setAssigneeUuid(null));
- addPermissionTo(project);
-
- ServerIssue serverIssue = call(project.getKey());
-
- assertThat(serverIssue.getKey()).isEqualTo(issue.getKey());
- assertThat(serverIssue.getRuleRepository()).isEqualTo(rule.getRepositoryKey());
- assertThat(serverIssue.getRuleKey()).isEqualTo(rule.getRuleKey());
- assertThat(serverIssue.getStatus()).isEqualTo("OPEN");
- assertThat(serverIssue.getSeverity()).isEqualTo(Severity.BLOCKER);
- assertThat(serverIssue.getType()).isEqualTo(BUG.name());
- assertThat(serverIssue.getManualSeverity()).isTrue();
-
- assertThat(serverIssue.hasPath()).isFalse();
- assertThat(serverIssue.hasLine()).isFalse();
- assertThat(serverIssue.hasMsg()).isFalse();
- assertThat(serverIssue.hasResolution()).isFalse();
- assertThat(serverIssue.hasChecksum()).isFalse();
- assertThat(serverIssue.hasAssigneeLogin()).isFalse();
- }
-
- @Test
- public void test_fields_with_non_null_values() throws Exception {
- UserDto user = db.users().insertUser(u -> u.setLogin("simon").setName("Simon").setEmail("simon@email.com"));
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module, null));
- IssueDto issue = db.issues().insert(rule, project, file, i -> i.setSeverity("BLOCKER")
- .setStatus("OPEN")
- .setType(BUG)
- .setManualSeverity(true)
- .setResolution("FIXED")
- .setMessage("the message")
- .setLine(10)
- .setChecksum("ABC")
- .setAssigneeUuid(user.getUuid()));
- addPermissionTo(project);
-
- ServerIssue serverIssue = call(project.getKey());
-
- assertThat(serverIssue.getKey()).isEqualTo(issue.getKey());
- assertThat(serverIssue.getRuleRepository()).isEqualTo(rule.getRepositoryKey());
- assertThat(serverIssue.getRuleKey()).isEqualTo(rule.getRuleKey());
- assertThat(serverIssue.getStatus()).isEqualTo("OPEN");
- assertThat(serverIssue.getSeverity()).isEqualTo(Severity.BLOCKER);
- assertThat(serverIssue.getType()).isEqualTo(BUG.name());
- assertThat(serverIssue.getManualSeverity()).isTrue();
- assertThat(serverIssue.getPath()).isEqualTo(file.path());
- assertThat(serverIssue.getLine()).isEqualTo(issue.getLine());
- assertThat(serverIssue.getMsg()).isEqualTo(issue.getMessage());
- assertThat(serverIssue.getResolution()).isEqualTo(issue.getResolution());
- assertThat(serverIssue.getChecksum()).isEqualTo(issue.getChecksum());
- assertThat(serverIssue.getAssigneeLogin()).isEqualTo(user.getLogin());
- }
-
- @Test
- public void return_issues_of_project() {
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module, null));
- IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("ON_FILE").setType(randomRuleTypeExceptHotspot()));
- IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setKee("ON_MODULE").setType(randomRuleTypeExceptHotspot()));
- IssueDto issueOnProject = db.issues().insert(rule, project, project, i -> i.setKee("ON_PROJECT").setType(randomRuleTypeExceptHotspot()));
-
- addPermissionTo(project);
- try (CloseableIterator<ServerIssue> result = callStream(project.getKey(), null)) {
- assertThat(result)
- .toIterable()
- .extracting(ServerIssue::getKey)
- .containsExactlyInAnyOrder(
- issueOnFile.getKey(),
- issueOnModule.getKey(),
- issueOnProject.getKey());
- }
- }
-
- @Test
- public void does_not_return_issues_from_external_rules() {
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module, null));
- IssueDto issueOnProject = db.issues().insert(rule, project, project, i -> i.setKee("ON_PROJECT").setType(randomRuleTypeExceptHotspot()));
- IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setKee("ON_MODULE").setType(randomRuleTypeExceptHotspot()));
- IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("ON_FILE").setType(randomRuleTypeExceptHotspot()));
-
- RuleDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true));
- IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot()));
-
- RuleDto migrated = db.rules().insert();
- db.executeUpdateSql("update rules set is_external=? where rules.uuid = ?", false, migrated.getUuid());
- IssueDto issueFromMigratedRule = db.issues().insert(migrated, project, file, i -> i.setKee("MIGRATED").setType(randomRuleTypeExceptHotspot()));
-
- addPermissionTo(project);
- try (CloseableIterator<ServerIssue> result = callStream(project.getKey(), null)) {
- assertThat(result)
- .toIterable()
- .extracting(ServerIssue::getKey)
- .containsExactlyInAnyOrder(
- issueOnFile.getKey(),
- issueOnModule.getKey(),
- issueOnProject.getKey(),
- issueFromMigratedRule.getKey());
- }
- }
-
- @Test
- public void return_issues_of_file() {
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module, null));
- IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setType(randomRuleTypeExceptHotspot()));
- IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setType(randomRuleTypeExceptHotspot()));
- IssueDto issueOnProject = db.issues().insert(rule, project, project, i -> i.setType(randomRuleTypeExceptHotspot()));
-
- addPermissionTo(project);
- try (CloseableIterator<ServerIssue> result = callStream(file.getKey(), null)) {
- assertThat(result)
- .toIterable()
- .extracting(ServerIssue::getKey)
- .containsExactlyInAnyOrder(issueOnFile.getKey());
- }
- }
-
- @Test
- public void return_issues_by_project_and_branch() {
- RuleDto rule = db.rules().insert();
- ComponentDto project = db.components().insertPrivateProject();
- addPermissionTo(project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- ComponentDto file = db.components().insertComponent(newFileDto(branch));
- IssueDto issueOnFile = db.issues().insert(rule, branch, file, i -> i.setType(randomRuleTypeExceptHotspot()));
- IssueDto issueOnBranch = db.issues().insert(rule, branch, branch, i -> i.setType(randomRuleTypeExceptHotspot()));
-
- assertResult(project.getKey(), "my_branch", issueOnFile.getKey(), issueOnBranch.getKey());
- }
-
- @Test
- public void fail_if_requested_component_is_a_directory() throws IOException {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto directory = db.components().insertComponent(newDirectory(project, "src/main/java"));
- addPermissionTo(project);
-
- assertThatThrownBy(() -> call(directory.getKey()))
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Component of scope 'DIR' is not allowed");
- }
-
- @Test
- public void fail_if_user_does_not_have_permission_on_project() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
-
- assertThatThrownBy(() -> tester.newRequest().setParam("key", file.getKey()).execute())
- .isInstanceOf(ForbiddenException.class);
- }
-
- @Test
- public void fail_if_component_does_not_exist() {
- assertThatThrownBy(() -> tester.newRequest().setParam("key", "does_not_exist").execute())
- .isInstanceOf(NotFoundException.class)
- .hasMessage("Component key 'does_not_exist' not found");
- }
-
- @Test
- public void fail_if_branch_does_not_exist() {
- ComponentDto project = db.components().insertPrivateProject();
- db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- addPermissionTo(project);
-
- assertThatThrownBy(() -> {
- tester.newRequest()
- .setParam("key", project.getKey())
- .setParam("branch", "does_not_exist")
- .execute();
- })
- .isInstanceOf(NotFoundException.class)
- .hasMessage(format("Component '%s' on branch 'does_not_exist' not found", project.getKey()));
- }
-
- private void addPermissionTo(ComponentDto project) {
- userSessionRule.addProjectPermission(UserRole.USER, project);
- }
-
- private ServerIssue call(String componentKey) throws IOException {
- TestResponse response = tester.newRequest().setParam("key", componentKey).execute();
- return ServerIssue.parseDelimitedFrom(response.getInputStream());
- }
-
- private CloseableIterator<ServerIssue> callStream(String componentKey, @Nullable String branch) {
- TestRequest request = tester.newRequest()
- .setParam("key", componentKey);
- if (branch != null) {
- request.setParam("branch", branch);
- }
- return Protobuf.readStream(request.execute().getInputStream(), ServerIssue.parser());
- }
-
- private void assertResult(String componentKey, String branch, String... issueKeys) {
- try (CloseableIterator<ServerIssue> result = callStream(componentKey, branch)) {
- assertThat(result)
- .toIterable()
- .extracting(ServerIssue::getKey)
- .containsExactlyInAnyOrder(issueKeys);
- }
- }
-
- private RuleType randomRuleTypeExceptHotspot() {
- return RULE_TYPES_EXCEPT_HOTSPOT[nextInt(RULE_TYPES_EXCEPT_HOTSPOT.length)];
- }
-}
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
public class ProjectDataLoaderTest {
@Rule
}
@Test
- public void fails_with_BRE_if_component_is_not_a_project() {
- String[][] allScopesAndQualifierButProjectAndModule = {
- {Scopes.PROJECT, "fakeModuleUuid"},
- {Scopes.FILE, null},
- {Scopes.DIRECTORY, null}
- };
-
- for (String[] scopeAndQualifier : allScopesAndQualifierButProjectAndModule) {
- String scope = scopeAndQualifier[0];
- String moduleUuid = scopeAndQualifier[1];
- String key = "theKey_" + scope + "_" + moduleUuid;
- String uuid = "uuid_" + uuidCounter++;
- dbClient.componentDao().insert(dbSession, new ComponentDto()
- .setUuid(uuid)
- .setUuidPath(uuid + ".")
- .setRootUuid(uuid)
- .setBranchUuid(uuid)
- .setScope(scope)
- .setModuleUuid(moduleUuid)
- .setKey(key));
- dbSession.commit();
-
- try {
- underTest.load(ProjectDataQuery.create().setProjectKey(key));
- fail("A NotFoundException should have been raised because component is not project");
- } catch (BadRequestException e) {
- assertThat(e).hasMessage("Key '" + key + "' belongs to a component which is not a Project");
- }
- }
+ public void fails_with_BRE_if_component_is_not_root() {
+ String uuid = "uuid";
+ String key = "key";
+ dbClient.componentDao().insert(dbSession, new ComponentDto()
+ .setUuid(uuid)
+ .setUuidPath(uuid + ".")
+ .setRootUuid(uuid)
+ .setBranchUuid("branchUuid")
+ .setScope(Scopes.PROJECT)
+ .setKey("key"));
+ dbSession.commit();
+
+ ProjectDataQuery query = ProjectDataQuery.create().setProjectKey(key);
+ assertThatThrownBy(() -> underTest.load(query))
+ .isInstanceOf(BadRequestException.class)
+ .hasMessage("Key '" + key + "' belongs to a component which is not a Project");
}
@Test
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
+import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.GlobalPermission.SCAN;
}
@Test
- public void fail_if_project_key_already_exists_as_module() {
+ public void fail_if_project_key_already_exists_as_other_component() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
userSession.logIn().addProjectPermission(SCAN_EXECUTION, project);
mockSuccessfulPrepareSubmitCall();
- String moduleDbKey = module.getKey();
- String name = module.name();
+ String dirDbKey = dir.getKey();
+ String name = dir.name();
Map<String, String> emptyMap = emptyMap();
InputStream inputStream = IOUtils.toInputStream("{binary}", UTF_8);
- assertThatThrownBy(() -> underTest.submit(moduleDbKey, name, emptyMap, inputStream))
+ assertThatThrownBy(() -> underTest.submit(dirDbKey, name, emptyMap, inputStream))
.isInstanceOf(BadRequestException.class)
.extracting(throwable -> ((BadRequestException) throwable).errors())
.asList()
.contains(format("The project '%s' is already defined in SonarQube but as a module of project '%s'. " +
"If you really want to stop directly analysing project '%s', please first delete it from SonarQube and then relaunch the analysis of project '%s'.",
- module.getKey(), project.getKey(), project.getKey(), module.getKey()));
+ dir.getKey(), project.getKey(), project.getKey(), dir.getKey()));
}
@Test
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.component.ComponentFinder.ParamNames.ID_AND_KEY;
public void get_by_key_and_branch() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "scr"));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "scr"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch));
assertThat(underTest.getByKeyAndBranch(dbSession, project.getKey(), "my_branch").uuid()).isEqualTo(branch.uuid());
- assertThat(underTest.getByKeyAndBranch(dbSession, module.getKey(), "my_branch").uuid()).isEqualTo(module.uuid());
assertThat(underTest.getByKeyAndBranch(dbSession, file.getKey(), "my_branch").uuid()).isEqualTo(file.uuid());
assertThat(underTest.getByKeyAndBranch(dbSession, directory.getKey(), "my_branch").uuid()).isEqualTo(directory.uuid());
}
public void get_by_key_and_pull_request() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid()));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "scr"));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "scr"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch));
assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), null, "pr-123").uuid()).isEqualTo(branch.uuid());
- assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, module.getKey(), null, "pr-123").uuid()).isEqualTo(module.uuid());
assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, file.getKey(), null, "pr-123").uuid()).isEqualTo(file.uuid());
assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, directory.getKey(), null, "pr-123").uuid()).isEqualTo(directory.uuid());
}
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
-
assertThat(underTest.getOptionalByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), null, null)).isPresent();
assertThat(underTest.getOptionalByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), null, null).get().uuid())
.isEqualTo(project.uuid());
assertThat(loaded.scope()).isEqualTo(Scopes.PROJECT);
assertThat(loaded.uuid()).isNotNull();
assertThat(loaded.branchUuid()).isEqualTo(loaded.uuid());
- assertThat(loaded.moduleUuid()).isNull();
- assertThat(loaded.moduleUuidPath()).isEqualTo("." + loaded.uuid() + ".");
assertThat(loaded.isPrivate()).isEqualTo(project.isPrivate());
assertThat(loaded.getCreatedAt()).isNotNull();
assertThat(db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY)).isPresent();
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.test.JsonAssert.assertJson;
public class AppActionTest {
@Test
public void file_on_module() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "src"));
- ComponentDto file = db.components().insertComponent(newFileDto(module, directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
userSession.logIn("john").addProjectPermission(USER, project);
String result = ws.newRequest()
userSession.logIn("john").addProjectPermission(USER, project);
String branchName = randomAlphanumeric(248);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "src"));
- ComponentDto file = db.components().insertComponent(newFileDto(module, directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "src"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(95.4d));
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.db.component.ComponentTesting.newDirectory;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newPortfolio;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
@Test
public void return_project_key() {
ComponentDto project = ComponentTesting.newPublicProjectDto();
- ComponentDto module = ComponentTesting.newModuleDto(project);
- ComponentDto dir1 = newDirectory(module, "dir1").setKey("dir1");
- ComponentDto dir2 = newDirectory(module, "dir2").setKey("dir2");
+ ComponentDto dir1 = newDirectory(project, "dir1").setKey("dir1");
+ ComponentDto dir2 = newDirectory(project, "dir2").setKey("dir2");
ComponentDto dir3 = newDirectory(project, "dir3").setKey("dir3");
- db.components().insertComponents(project, module, dir1, dir2, dir3);
+ db.components().insertComponents(project, dir1, dir2, dir3);
setBrowsePermissionOnUserAndIndex(project);
SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, APP)));
public void test_json_example() {
db.components().insertComponent(newPortfolio());
ComponentDto project = newPrivateProjectDto("project-uuid").setName("Project Name").setKey("project-key");
- ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setKey("module-key");
- ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setKey("directory-key").setName("Directory Name");
+ ComponentDto directory = newDirectory(project, "path/to/directoy").setUuid("directory-uuid").setKey("directory-key").setName("Directory Name");
ComponentDto view = newPortfolio();
- db.components().insertComponents(project, module, directory, view);
+ db.components().insertComponents(project, directory, view);
setBrowsePermissionOnUserAndIndex(project);
String response = underTest.newRequest()
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.test.JsonAssert.assertJson;
@Test
public void show_with_ancestors_when_not_project() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "dir"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
userSession.addProjectPermission(USER, project);
ShowWsResponse response = newRequest(file.getKey());
assertThat(response.getComponent().getKey()).isEqualTo(file.getKey());
- assertThat(response.getAncestorsList()).extracting(Component::getKey).containsOnly(directory.getKey(), module.getKey(), project.getKey());
+ assertThat(response.getAncestorsList()).extracting(Component::getKey).containsOnly(directory.getKey(), project.getKey());
}
@Test
public void show_without_ancestors_when_project() {
ComponentDto project = db.components().insertPrivateProject();
- db.components().insertComponent(newModuleDto(project));
userSession.addProjectPermission(USER, project);
ShowWsResponse response = newRequest(project.getKey());
public void show_with_ancestors_and_analysis_date() {
ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true));
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "dir"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
userSession.addProjectPermission(USER, project);
ShowWsResponse response = newRequest(file.getKey());
assertThat(result.getComponent().hasVisibility()).isTrue();
}
- @Test
- public void should_not_return_visibility_for_module() {
- ComponentDto privateProject = db.components().insertPrivateProject();
- userSession.addProjectPermission(USER, privateProject);
- ComponentDto module = db.components().insertComponent(newModuleDto(privateProject));
-
- ShowWsResponse result = newRequest(module.getKey());
- assertThat(result.getComponent().hasVisibility()).isFalse();
- }
-
@Test
public void display_version() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "dir"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
db.components().insertSnapshot(project, s -> s.setProjectVersion("1.1"));
userSession.addProjectPermission(USER, project);
userSession.addProjectPermission(UserRole.USER, project);
String branchKey = "my_branch";
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1"));
ShowWsResponse response = ws.newRequest()
assertThat(response.getAncestorsList()).extracting(Component::getKey, Component::getBranch, Component::getVersion)
.containsExactlyInAnyOrder(
tuple(directory.getKey(), branchKey, "1.1"),
- tuple(module.getKey(), branchKey, "1.1"),
tuple(branch.getKey(), branchKey, "1.1"));
}
userSession.addProjectPermission(UserRole.USER, project);
String pullRequest = "pr-1234";
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(pullRequest).setBranchType(PULL_REQUEST));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, directory));
db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1"));
ShowWsResponse response = ws.newRequest()
assertThat(response.getAncestorsList()).extracting(Component::getKey, Component::getPullRequest, Component::getVersion)
.containsExactlyInAnyOrder(
tuple(directory.getKey(), pullRequest, "1.1"),
- tuple(module.getKey(), pullRequest, "1.1"),
tuple(branch.getKey(), pullRequest, "1.1"));
}
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey1)
.setNeedIssueSync(true));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch1));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch1, "dir"));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch1, directory));
ComponentDto project2 = db.components().insertPrivateProject();
String branchName2 = randomAlphanumeric(248);
ComponentDto project3 = db.components().insertPrivateProject();
String pullRequestKey4 = randomAlphanumeric(100);
ComponentDto branch4 = db.components().insertProjectBranch(project3, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey4).setNeedIssueSync(false));
- ComponentDto moduleOfBranch4 = db.components().insertComponent(newModuleDto(branch4));
- ComponentDto directoryOfBranch4 = db.components().insertComponent(newDirectory(moduleOfBranch4, "dir"));
- ComponentDto fileOfBranch4 = db.components().insertComponent(newFileDto(directoryOfBranch4));
+ ComponentDto directoryOfBranch4 = db.components().insertComponent(newDirectory(branch4, "dir"));
+ ComponentDto fileOfBranch4 = db.components().insertComponent(newFileDto(branch4, directoryOfBranch4));
String branchName5 = randomAlphanumeric(248);
ComponentDto branch5 = db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName5));
// if branch need sync it is propagated to other components
assertNeedIssueSyncEqual(null, null, project1, true);
assertNeedIssueSyncEqual(pullRequestKey1, null, branch1, true);
- assertNeedIssueSyncEqual(pullRequestKey1, null, module, true);
assertNeedIssueSyncEqual(pullRequestKey1, null, directory, true);
assertNeedIssueSyncEqual(pullRequestKey1, null, file, true);
// if all branches are synced, need issue sync on project is is set to false
assertNeedIssueSyncEqual(null, null, project3, false);
assertNeedIssueSyncEqual(pullRequestKey4, null, branch4, false);
- assertNeedIssueSyncEqual(pullRequestKey4, null, moduleOfBranch4, false);
assertNeedIssueSyncEqual(pullRequestKey4, null, directoryOfBranch4, false);
assertNeedIssueSyncEqual(pullRequestKey4, null, fileOfBranch4, false);
assertNeedIssueSyncEqual(null, branchName5, branch5, false);
private void insertJsonExampleComponentsAndSnapshots() {
ComponentDto project = db.components().insertPrivateProject(c -> c.setUuid("AVIF98jgA3Ax6PH2efOW")
- .setBranchUuid("AVIF98jgA3Ax6PH2efOW")
- .setKey("com.sonarsource:java-markdown")
- .setName("Java Markdown")
- .setDescription("Java Markdown Project")
- .setQualifier(Qualifiers.PROJECT),
+ .setBranchUuid("AVIF98jgA3Ax6PH2efOW")
+ .setKey("com.sonarsource:java-markdown")
+ .setName("Java Markdown")
+ .setDescription("Java Markdown Project")
+ .setQualifier(Qualifiers.PROJECT),
p -> p.setTagsString("language, plugin"));
userSession.addProjectPermission(USER, project);
db.components().insertSnapshot(project, snapshot -> snapshot
*/
package org.sonar.server.component.ws;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.FILE;
-import static org.sonar.api.resources.Qualifiers.MODULE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.SUBVIEW;
import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
+import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newPublicProjectDto;
import static org.sonar.server.component.ws.SuggestionsAction.PARAM_MORE;
import static org.sonar.server.component.ws.SuggestionsAction.PARAM_RECENTLY_BROWSED;
import static org.sonar.server.component.ws.SuggestionsAction.SHORT_INPUT_WARNING;
import static org.sonar.test.JsonAssert.assertJson;
-import javax.annotation.Nullable;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
public class SuggestionsActionTest {
private static final String[] SUGGESTION_QUALIFIERS = Stream.of(SuggestionCategory.values())
PARAM_QUERY,
PARAM_RECENTLY_BROWSED);
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
+ tuple("10.0", "The use of 'BRC' as value for parameter 'more' is no longer supported"),
tuple("8.4", "The use of 'DIR', 'FIL','UTS' as values for parameter 'more' is no longer supported"),
tuple("7.6", "The use of 'BRC' as value for parameter 'more' is deprecated"));
@Test
public void suggestions_should_filter_allowed_qualifiers() {
- resourceTypes.setAllQualifiers(PROJECT, MODULE, FILE, UNIT_TEST_FILE);
+ resourceTypes.setAllQualifiers(PROJECT, FILE, UNIT_TEST_FILE);
ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
componentIndexer.indexOnAnalysis(project.branchUuid());
userSessionRule.addProjectPermission(USER, project);
assertThat(response.getResultsList())
.extracting(Category::getQ)
- .containsExactlyInAnyOrder(PROJECT).doesNotContain(MODULE, FILE, UNIT_TEST_FILE);
+ .containsExactlyInAnyOrder(PROJECT).doesNotContain(FILE, UNIT_TEST_FILE);
}
@Test
.containsExactlyInAnyOrder(tuple(project1.getKey(), project1.name()));
}
- @Test
- public void should_not_return_modules() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("ProjectWithModules"));
- db.components().insertComponent(newModuleDto(project).setName("Module1"));
- db.components().insertComponent(newModuleDto(project).setName("Module2"));
- componentIndexer.indexOnAnalysis(project.branchUuid());
- authorizationIndexerTester.allowOnlyAnyone(project);
-
- SuggestionsWsResponse response = ws.newRequest()
- .setMethod("POST")
- .setParam(PARAM_QUERY, "Module")
- .executeProtobuf(SuggestionsWsResponse.class);
-
- assertThat(response.getResultsList())
- .flatExtracting(Category::getItemsList)
- .extracting(Suggestion::getKey)
- .containsOnly(project.getKey());
- }
-
@Test
public void should_mark_recently_browsed_items() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("ProjectModule"));
- ComponentDto module1 = newModuleDto(project).setName("Module1");
- db.components().insertComponent(module1);
- ComponentDto module2 = newModuleDto(project).setName("Module2");
- db.components().insertComponent(module2);
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("ProjectTest"));
+ ComponentDto file1 = newFileDto(project).setName("File1");
+ ComponentDto file2 = newFileDto(project).setName("File2");
componentIndexer.indexOnAnalysis(project.branchUuid());
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
- .setParam(PARAM_QUERY, "Module")
- .setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getKey(), project.getKey()).collect(joining(",")))
+ .setParam(PARAM_QUERY, "Test")
+ .setParam(PARAM_RECENTLY_BROWSED, Stream.of(file1.getKey(), project.getKey()).collect(joining(",")))
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
ComponentDto view = db.components().insertPublicPortfolio(v -> v.setName(query));
ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view).setName(query));
ComponentDto project = db.components().insertPrivateProject(p -> p.setName(query));
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query));
- ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query));
- ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(UNIT_TEST_FILE));
+ ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "path").setName(query));
+ ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project, dir).setName(query));
+ ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(project, dir).setName(query).setQualifier(UNIT_TEST_FILE));
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
authorizationIndexerTester.allowOnlyAnyone(view);
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newChildComponent;
import static org.sonar.db.component.ComponentTesting.newDirectory;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newProjectBranchCopy;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
public void return_children() {
ComponentDto project = newPrivateProjectDto("project-uuid");
db.components().insertProjectAndSnapshot(project);
- ComponentDto module = newModuleDto("module-uuid-1", project);
- db.components().insertComponent(module);
+ ComponentDto dir = newDirectory(project, "dir");
+ db.components().insertComponent(dir);
db.components().insertComponent(newFileDto(project, 1));
for (int i = 2; i <= 9; i++) {
- db.components().insertComponent(newFileDto(module, i));
+ db.components().insertComponent(newFileDto(dir, i));
}
- ComponentDto directory = newDirectory(module, "directory-path-1");
+ ComponentDto directory = newDirectory(dir, "directory-path-1");
db.components().insertComponent(directory);
- db.components().insertComponent(newFileDto(module, directory, 10));
+ db.components().insertComponent(newFileDto(project, directory, 10));
db.commit();
logInWithBrowsePermission(project);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
- .setParam(PARAM_COMPONENT, module.getKey())
+ .setParam(PARAM_COMPONENT, dir.getKey())
.setParam(Param.PAGE, "2")
.setParam(Param.PAGE_SIZE, "3")
.setParam(Param.TEXT_QUERY, "file-name")
public void return_descendants() {
ComponentDto project = newPrivateProjectDto("project-uuid");
db.components().insertProjectAndSnapshot(project);
- ComponentDto module = newModuleDto("module-uuid-1", project);
+ ComponentDto module = newDirectory(project, "path");
db.components().insertComponent(module);
db.components().insertComponent(newFileDto(project, 10));
for (int i = 2; i <= 9; i++) {
db.components().insertProjectAndSnapshot(project);
db.components().insertComponent(newFileDto(project, 1));
db.components().insertComponent(newFileDto(project, 2));
- db.components().insertComponent(newModuleDto("module-uuid-1", project));
db.commit();
logInWithBrowsePermission(project);
public void return_leaves() {
ComponentDto project = newPrivateProjectDto("project-uuid");
db.components().insertProjectAndSnapshot(project);
- ComponentDto module = newModuleDto("module-uuid-1", project);
- db.components().insertComponent(module);
db.components().insertComponent(newFileDto(project, 1));
- db.components().insertComponent(newFileDto(module, 2));
+ db.components().insertComponent(newFileDto(project, 2));
ComponentDto directory = newDirectory(project, "directory-path-1");
db.components().insertComponent(directory);
- db.components().insertComponent(newFileDto(module, directory, 3));
+ db.components().insertComponent(newFileDto(project, directory, 3));
db.commit();
logInWithBrowsePermission(project);
db.components().insertProjectAndSnapshot(project);
db.components().insertComponent(newFileDto(project, 1));
db.components().insertComponent(newFileDto(project, 2));
- ComponentDto module = newModuleDto("module-uuid-1", project);
- db.components().insertComponent(module);
db.components().insertComponent(newDirectory(project, "path/directory/", "directory-uuid-1"));
db.commit();
logInWithBrowsePermission(project);
.setParam(Param.SORT, "qualifier, name")
.setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class);
- assertThat(response.getComponentsList()).extracting("key").containsExactly("MODULE_KEY_module-uuid-1", "KEY_project-uuid:directory-uuid-1", "file-key-1", "file-key-2");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("KEY_project-uuid:directory-uuid-1", "file-key-1", "file-key-2");
}
@Test
userSession.addProjectPermission(UserRole.USER, project);
String branchKey = "my_branch";
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory));
TreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, module.getKey())
+ .setParam(PARAM_COMPONENT, branch.getKey())
.setParam(PARAM_BRANCH, branchKey)
.executeProtobuf(TreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch)
- .containsExactlyInAnyOrder(module.getKey(), branchKey);
+ .containsExactlyInAnyOrder(branch.getKey(), branchKey);
assertThat(response.getComponentsList()).extracting(Component::getKey, Component::getBranch)
.containsExactlyInAnyOrder(
tuple(directory.getKey(), branchKey),
userSession.addProjectPermission(UserRole.USER, project);
String pullRequestId = "pr-123";
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(pullRequestId).setBranchType(PULL_REQUEST));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
+ ComponentDto directory = db.components().insertComponent(newDirectory(branch, "dir"));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory));
TreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, module.getKey())
+ .setParam(PARAM_COMPONENT, directory.getKey())
.setParam(PARAM_PULL_REQUEST, pullRequestId)
.executeProtobuf(TreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getPullRequest)
- .containsExactlyInAnyOrder(module.getKey(), pullRequestId);
+ .containsExactlyInAnyOrder(directory.getKey(), pullRequestId);
assertThat(response.getComponentsList()).extracting(Component::getKey, Component::getPullRequest)
.containsExactlyInAnyOrder(
- tuple(directory.getKey(), pullRequestId),
tuple(file.getKey(), pullRequestId));
}
private ComponentDto initJsonExampleComponents() throws IOException {
ComponentDto project = db.components().insertPrivateProject(c -> c.setUuid("MY_PROJECT_ID")
- .setDescription("MY_PROJECT_DESCRIPTION")
- .setKey("MY_PROJECT_KEY")
- .setName("Project Name")
- .setBranchUuid("MY_PROJECT_ID"),
+ .setDescription("MY_PROJECT_DESCRIPTION")
+ .setKey("MY_PROJECT_KEY")
+ .setName("Project Name")
+ .setBranchUuid("MY_PROJECT_ID"),
p -> p.setTagsString("abc,def"));
db.components().insertSnapshot(project);
import static com.google.common.collect.Lists.newArrayList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
+import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
public class ShowResponseBuilderTest {
@Test
public void write_duplications() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file1 = db.components().insertComponent(newFileDto(module));
- ComponentDto file2 = db.components().insertComponent(newFileDto(module));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(project, dir));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(project, dir));
List<DuplicationsParser.Block> blocks = newArrayList();
blocks.add(new DuplicationsParser.Block(newArrayList(
Duplication.newComponent(file1, 57, 12),
import static org.mockito.Mockito.mock;
import static org.sonar.api.rule.RuleStatus.REMOVED;
import static org.sonar.core.issue.IssueChangeContext.issueChangeContextByUserBuilder;
+import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.issue.IssueTesting.newIssue;
public class WebIssueStorageTest {
public void insert_new_issues() {
RuleDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, dir));
String issueKey = "ABCDE";
DefaultIssueComment comment = DefaultIssueComment.create(issueKey, "user_uuid", "the comment");
public void update_issues() {
RuleDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, dir));
Date date = DateUtils.parseDateTime("2013-05-18T12:00:00+0000");
DefaultIssue issue = new DefaultIssue()
public void rule_uuid_is_set_on_updated_issue() {
RuleDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, dir));
DefaultIssue issue = newIssue(rule, project, file).toDefaultIssue();
Collection<IssueDto> results = underTest.save(db.getSession(), singletonList(issue));
public void rule_uuid_is_not_set_on_updated_issue_when_rule_is_removed() {
RuleDto rule = db.rules().insert(r -> r.setStatus(REMOVED));
ComponentDto project = db.components().insertPublicProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, dir));
DefaultIssue issue = newIssue(rule, project, file).toDefaultIssue();
Collection<IssueDto> results = underTest.save(db.getSession(), singletonList(issue));
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS;
.containsExactlyInAnyOrder(tuple(project.getKey(), true), tuple(file.getKey(), true), tuple(project2.getKey(), true), tuple(file2.getKey(), true));
}
- @Test
- public void search_by_module() {
- ComponentDto project = db.components().insertPublicProject();
- ComponentDto module1 = db.components().insertComponent(newModuleDto(project));
- ComponentDto file1 = db.components().insertComponent(newFileDto(module1));
- ComponentDto module2 = db.components().insertComponent(newModuleDto(project));
- ComponentDto file2 = db.components().insertComponent(newFileDto(module2));
- RuleDto rule = db.rules().insertIssueRule();
- IssueDto issue1 = db.issues().insertIssue(rule, project, file1);
- IssueDto issue2 = db.issues().insertIssue(rule, project, file2);
- allowAnyoneOnProjects(project);
- indexIssues();
-
- assertThat(ws.newRequest()
- .setParam(PARAM_COMPONENT_KEYS, module1.getKey())
- .executeProtobuf(SearchWsResponse.class).getIssuesList()).extracting(Issue::getKey)
- .containsExactlyInAnyOrder(issue1.getKey());
- }
-
@Test
public void search_since_leak_period_on_project() {
ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1"));
.assertJson(this.getClass(), "search_since_leak_period.json");
}
- @Test
- public void search_since_leak_period_on_file_in_module_project() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1"));
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setKey("FK1"));
- db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime()));
- RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
- IssueDto issueAfterLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01)
- .setIssueCreationDate(parseDateTime("2015-09-04T00:00:00+0100"))
- .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
- IssueDto issueBeforeLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_02)
- .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100"))
- .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
- allowAnyoneOnProjects(project);
- indexIssues();
-
- ws.newRequest()
- .setParam(PARAM_COMPONENT_KEYS, project.getKey())
- .setParam(PARAM_FILES, file.path())
- .setParam(PARAM_SINCE_LEAK_PERIOD, "true")
- .execute()
- .assertJson(this.getClass(), "search_since_leak_period.json");
- }
-
@Test
public void search_by_file_uuid() {
ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1"));
import static org.sonar.api.server.ws.WebService.Param.FACETS;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.server.tester.UserSessionRule.standalone;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES;
@Test
public void display_all_facets() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto file = db.components().insertComponent(newFileDto(module));
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
RuleDto rule = db.rules().insertIssueRule();
UserDto user = db.users().insertUser();
db.issues().insertIssue(rule, project, file, i -> i
IntStream.rangeClosed(1, 110)
.forEach(index -> {
UserDto user = db.users().insertUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir" + index));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "dir" + index));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
RuleDto rule = db.rules().insertIssueRule();
db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(user.getUuid())
});
// insert some hotspots which should be filtered by default
- IntStream.rangeClosed(1, 30)
+ IntStream.rangeClosed(201, 230)
.forEach(index -> {
UserDto user = db.users().insertUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir" + index));
- ComponentDto file = db.components().insertComponent(newFileDto(directory));
+ ComponentDto directory = db.components().insertComponent(newDirectory(project, "dir" + index));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
db.issues().insertHotspot(project, file, i -> i.setAssigneeUuid(user.getUuid())
.setStatus(random.nextBoolean() ? Issue.STATUS_TO_REVIEW : Issue.STATUS_REVIEWED));
@Test
public void display_zero_valued_facets_for_selected_items_having_no_issue() {
ComponentDto project1 = db.components().insertPublicProject();
- ComponentDto module1 = db.components().insertComponent(newModuleDto(project1));
- ComponentDto module2 = db.components().insertComponent(newModuleDto(project1));
ComponentDto project2 = db.components().insertPublicProject();
- ComponentDto file1 = db.components().insertComponent(newFileDto(module1));
- ComponentDto file2 = db.components().insertComponent(newFileDto(module1));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(project1));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(project1));
RuleDto rule1 = db.rules().insertIssueRule();
RuleDto rule2 = db.rules().insertIssueRule();
UserDto user1 = db.users().insertUser();
.assertJson(this.getClass(), "apply_paging_with_one_component.json");
}
- @Test
- public void components_contains_sub_projects() {
- ComponentDto project = db.components().insertPublicProject("PROJECT_ID", c -> c.setKey("PROJECT_KEY").setKey("ProjectHavingModule"));
- indexPermissions();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setKey("ModuleHavingFile"));
- ComponentDto file = db.components().insertComponent(newFileDto(module, null, "BCDE").setKey("FileLinkedToModule"));
- IssueDto issue = newDto(newIssueRule(), file, project);
- dbClient.issueDao().insert(session, issue);
- session.commit();
- indexIssues();
-
- ws.newRequest().setParam(PARAM_ADDITIONAL_FIELDS, "_all").execute()
- .assertJson(this.getClass(), "components_contains_sub_projects.json");
- }
-
@Test
public void filter_by_assigned_to_me() {
UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com"));
import static org.sonar.api.measures.Metric.ValueType.INT;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PROJECT_KEYS;
call(keys, singletonList(metric.getKey()));
}
- @Test
- public void fail_if_module() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- userSession.addProjectPermission(UserRole.USER, project);
- MetricDto metric = db.measures().insertMetric();
-
- assertThatThrownBy(() -> call(singletonList(module.getKey()), singletonList(metric.getKey())))
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Only component of qualifiers [TRK, APP, VW, SVW] are allowed");
- }
-
@Test
public void fail_if_directory() {
ComponentDto project = db.components().insertPrivateProject();
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
.isInstanceOf(NotFoundException.class);
}
- @Test
- public void fail_when_component_is_a_module() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
-
- failIfComponentIsNotAProjectOrView(module);
- }
-
@Test
public void fail_when_component_is_a_directory() {
ComponentDto project = db.components().insertPrivateProject();
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
.isInstanceOf(NotFoundException.class);
}
- @Test
- public void fail_when_component_is_a_module() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
-
- failIfComponentIsNotAProjectOrView(module);
- }
-
@Test
public void fail_when_component_is_a_directory() {
ComponentDto project = db.components().insertPrivateProject();
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
.hasMessage("Invalid global permission 'issueadmin'. Valid values are [admin, gateadmin, profileadmin, provisioning, scan]");
}
- @Test
- public void fail_when_component_is_a_module() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
-
- failIfComponentIsNotAProjectOrView(module);
- }
-
@Test
public void fail_when_component_is_a_directory() {
ComponentDto project = db.components().insertPrivateProject();
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
.isInstanceOf(BadRequestException.class);
}
- @Test
- public void fail_when_component_is_a_module() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
-
- failIfComponentIsNotAProjectOrView(module);
- }
-
@Test
public void fail_when_component_is_a_directory() {
ComponentDto project = db.components().insertPrivateProject();
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newPortfolio;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
public void search_projects() {
userSession.addPermission(ADMINISTER);
ComponentDto project = ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_1);
- ComponentDto module = newModuleDto(project);
- ComponentDto directory = newDirectory(module, "dir");
+ ComponentDto directory = newDirectory(project, "dir");
ComponentDto file = newFileDto(directory);
db.components().insertComponents(
- project, module, directory, file,
+ project, directory, file,
ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_2),
newPortfolio());
@Test
public void execute_fails_with_BadRequestException_if_specified_component_is_neither_a_project_a_portfolio_nor_an_application() {
ComponentDto project = randomPublicOrPrivateProject();
- ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto dir = ComponentTesting.newDirectory(project, "path");
ComponentDto file = ComponentTesting.newFileDto(project);
- dbTester.components().insertComponents(module, dir, file);
+ dbTester.components().insertComponents(dir, file);
ComponentDto application = dbTester.components().insertPublicApplication();
ComponentDto portfolio = dbTester.components().insertPrivatePortfolio();
ComponentDto subView = ComponentTesting.newSubPortfolio(portfolio);
.setParam(PARAM_VISIBILITY, randomVisibility)
.execute());
- Stream.of(module, dir, file, subView, projectCopy)
+ Stream.of(dir, file, subView, projectCopy)
.forEach(nonRootComponent -> {
request.setParam(PARAM_PROJECT, nonRootComponent.getKey())
.setParam(PARAM_VISIBILITY, randomVisibility);
dbClient.branchDao().insert(dbSession, branchDto);
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto);
- ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto dir = ComponentTesting.newDirectory(project, "path");
ComponentDto file = ComponentTesting.newFileDto(project);
- dbTester.components().insertComponents(branch, module, dir, file);
+ dbTester.components().insertComponents(branch, dir, file);
userSessionRule.addProjectPermission(UserRole.ADMIN, project);
request.setParam(PARAM_PROJECT, project.getKey())
assertThat(isPrivateInDb(project)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(branch)).isEqualTo(!initiallyPrivate);
- assertThat(isPrivateInDb(module)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(file)).isEqualTo(!initiallyPrivate);
}
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto)
.setPrivate(initiallyPrivate);
- ComponentDto module = ComponentTesting.newModuleDto(project)
- .setPrivate(initiallyPrivate);
ComponentDto dir = ComponentTesting.newDirectory(project, "path")
// child is inconsistent with root (should not occur) and won't be fixed
.setPrivate(!initiallyPrivate);
ComponentDto file = ComponentTesting.newFileDto(project)
.setPrivate(initiallyPrivate);
- dbTester.components().insertComponents(branch, module, dir, file);
+ dbTester.components().insertComponents(branch, dir, file);
userSessionRule.addProjectPermission(UserRole.ADMIN, project);
request.setParam(PARAM_PROJECT, project.getKey())
assertThat(isPrivateInDb(project)).isEqualTo(initiallyPrivate);
assertThat(isPrivateInDb(branch)).isEqualTo(initiallyPrivate);
- assertThat(isPrivateInDb(module)).isEqualTo(initiallyPrivate);
assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(file)).isEqualTo(initiallyPrivate);
}
.isInstanceOf(ForbiddenException.class);
}
- @Test
- public void fail_if_module() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- failIfNotAProjectWithKey(project, module);
- failIfNotAProjectWithUuid(project, module);
- }
-
@Test
public void fail_if_directory() {
ComponentDto project = db.components().insertPrivateProject();
.isInstanceOf(NotFoundException.class);
}
- @Test
- public void fail_if_module() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- failIfNotAProjectWithKey(project, module);
- failIfNotAProjectWithUuid(project, module);
- }
-
@Test
public void fail_if_directory() {
ComponentDto project = db.components().insertPrivateProject();
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
-import static java.lang.String.format;
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static java.util.Optional.ofNullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
public class SetActionTest {
@Rule
.hasMessage("Project 'VIEW_KEY' not found");
}
- @Test
- public void fail_if_component_is_a_module() {
- ComponentDto projectComponent = dbClient.componentDao().selectByUuid(dbSession, project.getUuid()).get();
- ComponentDto module = db.components().insertComponent(newModuleDto(projectComponent).setKey("MODULE_KEY"));
-
- String moduleKey = module.getKey();
- assertThatThrownBy(() -> call(moduleKey, "modz"))
- .isInstanceOf(NotFoundException.class)
- .hasMessage("Project 'MODULE_KEY' not found");
- }
-
@Test
public void fail_if_component_is_a_file() {
ComponentDto projectComponent = dbClient.componentDao().selectByUuid(dbSession, project.getUuid()).get();
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
-import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
succeedForPropertyWithoutDefinitionAndValidComponent(project, project);
}
- @Test
- public void succeed_for_property_without_definition_when_set_on_module_component() {
- ComponentDto project = randomPublicOrPrivateProject();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- succeedForPropertyWithoutDefinitionAndValidComponent(project, module);
- }
-
@Test
public void fail_for_property_without_definition_when_set_on_directory_component() {
ComponentDto project = randomPublicOrPrivateProject();
logInAsProjectAdministrator(project);
callForComponentPropertySet("my.key", newArrayList(
- GSON.toJson(ImmutableMap.of("firstField", "firstValue", "secondField", "secondValue")),
- GSON.toJson(ImmutableMap.of("firstField", "anotherFirstValue", "secondField", "anotherSecondValue"))),
+ GSON.toJson(ImmutableMap.of("firstField", "firstValue", "secondField", "secondValue")),
+ GSON.toJson(ImmutableMap.of("firstField", "anotherFirstValue", "secondField", "anotherSecondValue"))),
project.getKey());
assertThat(dbClient.propertiesDao().selectGlobalProperties(dbSession)).hasSize(3);
succeedForPropertyWithoutDefinitionAndValidComponent(project, project);
}
- @Test
- public void succeed_for_property_without_definition_when_set_on_module_component() {
- ComponentDto project = randomPublicOrPrivateProject();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- succeedForPropertyWithoutDefinitionAndValidComponent(project, module);
- }
-
@Test
public void fail_for_property_without_definition_when_set_on_directory_component() {
ComponentDto project = randomPublicOrPrivateProject();
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.process.ProcessProperties;
import org.sonar.server.component.TestComponentFinder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.groups.Tuple.tuple;
-import static org.sonar.api.resources.Qualifiers.MODULE;
+import static org.sonar.api.resources.Qualifiers.FILE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
+import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.permission.GlobalPermission.SCAN;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
assertThat(result.getSettingsList()).isEmpty();
}
- @Test
- public void return_module_values() {
- logInAsProjectUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT, MODULE).build());
- db.properties().insertProperties(null, null, null, null,
- newGlobalPropertyDto().setKey("property").setValue("one"));
- db.properties().insertProperties(null, module.getKey(), module.name(), module.qualifier(),
- // The property is overriding global value
- newComponentPropertyDto(module).setKey("property").setValue("two"));
-
- ValuesWsResponse result = executeRequestForComponentProperties(module, "property");
-
- assertThat(result.getSettingsList()).hasSize(1);
- assertSetting(result.getSettings(0), "property", "two", false);
- }
-
@Test
public void return_inherited_values_on_module() {
logInAsProjectUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
definitions.addComponents(asList(
- PropertyDefinition.builder("defaultProperty").defaultValue("default").onQualifiers(PROJECT, MODULE).build(),
- PropertyDefinition.builder("globalProperty").onQualifiers(PROJECT, MODULE).build(),
- PropertyDefinition.builder("projectProperty").onQualifiers(PROJECT, MODULE).build(),
- PropertyDefinition.builder("moduleProperty").onQualifiers(PROJECT, MODULE).build()));
+ PropertyDefinition.builder("defaultProperty").defaultValue("default").onQualifiers(PROJECT).build(),
+ PropertyDefinition.builder("globalProperty").onQualifiers(PROJECT).build(),
+ PropertyDefinition.builder("projectProperty").onQualifiers(PROJECT).build(),
+ PropertyDefinition.builder("moduleProperty").onQualifiers(PROJECT).build()));
db.properties().insertProperties(null, null, null, null,
newGlobalPropertyDto().setKey("globalProperty").setValue("global"));
db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
newComponentPropertyDto(project).setKey("projectProperty").setValue("project"));
- db.properties().insertProperties(null, module.getKey(), module.name(), module.qualifier(),
- newComponentPropertyDto(module).setKey("moduleProperty").setValue("module"));
+ db.properties().insertProperties(null, file.getKey(), file.name(), file.qualifier(),
+ newComponentPropertyDto(file).setKey("moduleProperty").setValue("module"));
- ValuesWsResponse result = executeRequestForComponentProperties(module, "defaultProperty", "globalProperty", "projectProperty", "moduleProperty");
+ ValuesWsResponse result = executeRequestForComponentProperties(file, "defaultProperty", "globalProperty", "projectProperty", "moduleProperty");
assertThat(result.getSettingsList()).hasSize(4);
assertSetting(result.getSettings(0), "defaultProperty", "default", true);
@Test
public void return_parent_value() {
logInAsProjectUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
definitions.addComponents(asList(
- PropertyDefinition.builder("foo").defaultValue("default").onQualifiers(PROJECT, MODULE).build()));
+ PropertyDefinition.builder("foo").defaultValue("default").onQualifiers(PROJECT).build()));
db.properties().insertProperties(null, null, null, null,
newGlobalPropertyDto().setKey("foo").setValue("global"));
db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
newComponentPropertyDto(project).setKey("foo").setValue("project"));
- db.properties().insertProperties(null, module.getKey(), module.name(), module.qualifier(),
- newComponentPropertyDto(module).setKey("foo").setValue("module"));
+ db.properties().insertProperties(null, file.getKey(), file.name(), file.qualifier(),
+ newComponentPropertyDto(file).setKey("foo").setValue("file"));
- assertParentValue(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module");
- assertParentValue(executeRequestForComponentProperties(module, "foo").getSettings(0), "project");
+ assertParentValue(executeRequestForComponentProperties(file, "foo").getSettings(0), "project");
assertParentValue(executeRequestForComponentProperties(project, "foo").getSettings(0), "global");
assertParentValue(executeRequestForGlobalProperties("foo").getSettings(0), "default");
}
- @Test
- public void return_parent_values() {
- logInAsProjectUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- definitions.addComponents(asList(
- PropertyDefinition.builder("foo").defaultValue("default1,default2").multiValues(true).onQualifiers(PROJECT, MODULE).build()));
- db.properties().insertProperties(null, null, null, null,
- newGlobalPropertyDto().setKey("foo").setValue("global1,global2"));
- db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
- newComponentPropertyDto(project).setKey("foo").setValue("project1,project2"));
- db.properties().insertProperties(null, module.getKey(), module.name(), module.qualifier(),
- newComponentPropertyDto(module).setKey("foo").setValue("module1,module2"));
-
- assertParentValues(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module1", "module2");
- assertParentValues(executeRequestForComponentProperties(module, "foo").getSettings(0), "project1", "project2");
- assertParentValues(executeRequestForComponentProperties(project, "foo").getSettings(0), "global1", "global2");
- assertParentValues(executeRequestForGlobalProperties("foo").getSettings(0), "default1", "default2");
- }
-
@Test
public void return_parent_field_values() {
logInAsProjectUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
definitions.addComponent(PropertyDefinition
.builder("foo")
- .onQualifiers(PROJECT, MODULE)
+ .onQualifiers(PROJECT)
.type(PropertyType.PROPERTY_SET)
.fields(asList(
PropertyFieldDefinition.build("key").name("Key").build(),
.build());
db.properties().insertPropertySet("foo", null, ImmutableMap.of("key", "keyG1", "size", "sizeG1"));
db.properties().insertPropertySet("foo", project, ImmutableMap.of("key", "keyP1", "size", "sizeP1"));
- db.properties().insertPropertySet("foo", module, ImmutableMap.of("key", "keyM1", "size", "sizeM1"));
+ db.properties().insertPropertySet("foo", file, ImmutableMap.of("key", "keyM1", "size", "sizeM1"));
- assertParentFieldValues(executeRequestForComponentProperties(subModule, "foo").getSettings(0), ImmutableMap.of("key", "keyM1", "size", "sizeM1"));
- assertParentFieldValues(executeRequestForComponentProperties(module, "foo").getSettings(0), ImmutableMap.of("key", "keyP1", "size", "sizeP1"));
+ assertParentFieldValues(executeRequestForComponentProperties(file, "foo").getSettings(0), ImmutableMap.of("key", "keyP1", "size", "sizeP1"));
assertParentFieldValues(executeRequestForComponentProperties(project, "foo").getSettings(0), ImmutableMap.of("key", "keyG1", "size", "sizeG1"));
assertParentFieldValues(executeRequestForGlobalProperties("foo").getSettings(0));
}
@Test
public void return_no_parent_value() {
logInAsProjectUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
definitions.addComponents(asList(
- PropertyDefinition.builder("simple").onQualifiers(PROJECT, MODULE).build(),
- PropertyDefinition.builder("multi").multiValues(true).onQualifiers(PROJECT, MODULE).build(),
+ PropertyDefinition.builder("simple").onQualifiers(PROJECT).build(),
+ PropertyDefinition.builder("multi").multiValues(true).onQualifiers(PROJECT).build(),
PropertyDefinition.builder("set")
.type(PropertyType.PROPERTY_SET)
- .onQualifiers(PROJECT, MODULE)
+ .onQualifiers(PROJECT)
.fields(asList(
PropertyFieldDefinition.build("key").name("Key").build(),
PropertyFieldDefinition.build("size").name("Size").build()))
.build()));
- db.properties().insertProperties(null, module.getKey(), module.name(), module.qualifier(),
- newComponentPropertyDto(module).setKey("simple").setValue("module"),
- newComponentPropertyDto(module).setKey("multi").setValue("module1,module2"));
- db.properties().insertPropertySet("set", module, ImmutableMap.of("key", "keyM1", "size", "sizeM1"));
+ db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
+ newComponentPropertyDto(project).setKey("simple").setValue("module"),
+ newComponentPropertyDto(project).setKey("multi").setValue("module1,module2"));
+ db.properties().insertPropertySet("set", project, ImmutableMap.of("key", "keyM1", "size", "sizeM1"));
- assertParentValue(executeRequestForComponentProperties(subModule, "simple").getSettings(0), null);
- assertParentValues(executeRequestForComponentProperties(subModule, "multi").getSettings(0));
- assertParentFieldValues(executeRequestForComponentProperties(subModule, "set").getSettings(0));
+ assertParentValue(executeRequestForComponentProperties(file, "simple").getSettings(0), null);
+ assertParentValues(executeRequestForComponentProperties(file, "multi").getSettings(0));
+ assertParentFieldValues(executeRequestForComponentProperties(file, "set").getSettings(0));
}
@Test
public void return_parent_value_when_no_definition() {
logInAsProjectUser();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
db.properties().insertProperties(null, null, null, null,
newGlobalPropertyDto().setKey("foo").setValue("global"));
db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
newComponentPropertyDto(project).setKey("foo").setValue("project"));
- assertParentValue(executeRequestForComponentProperties(module, "foo").getSettings(0), "project");
+ assertParentValue(executeRequestForComponentProperties(file, "foo").getSettings(0), "project");
assertParentValue(executeRequestForComponentProperties(project, "foo").getSettings(0), "global");
assertParentValue(executeRequestForGlobalProperties("foo").getSettings(0), null);
}
import static org.sonar.db.component.ComponentDbTester.toProjectDto;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
@Test
public void return_bread_crumbs_on_several_levels() {
ComponentDto project = insertProject();
- ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setKey("palap").setName("Palap"));
- ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo"));
+ ComponentDto directory = componentDbTester.insertComponent(newDirectory(project, "src/main/xoo"));
ComponentDto file = componentDbTester.insertComponent(newFileDto(directory, directory, "cdef").setName("Source.xoo")
- .setKey("palap:src/main/xoo/Source.xoo")
+ .setKey("polop:src/main/xoo/Source.xoo")
.setPath(directory.path()));
userSession.addProjectPermission(UserRole.USER, project);
init();
assertThat(componentId.exampleValue()).isNotNull();
}
- @Test
- public void fail_on_module_key_as_param() {
- ComponentDto project = insertProject();
- ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setKey("palap").setName("Palap"));
- init();
-
- assertThatThrownBy(() -> execute(module.getKey()))
- .isInstanceOf(BadRequestException.class);
- }
-
@Test
public void fail_on_directory_key_as_param() {
ComponentDto project = insertProject();
- ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setKey("palap").setName("Palap"));
- ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo"));
+ ComponentDto directory = componentDbTester.insertComponent(newDirectory(project, "src/main/xoo"));
userSession.addProjectPermission(UserRole.USER, project);
init();
String dirKey = directory.getKey();
+++ /dev/null
-{
- "components": [
- {
- "key": "FileLinkedToModule"
- },
- {
- "key": "ModuleHavingFile"
- },
- {
- "key": "ProjectHavingModule"
- }
- ]
-}
{
- "key": "palap:src/main/xoo/Source.xoo",
+ "key": "polop:src/main/xoo/Source.xoo",
"id": "cdef",
"name": "Source.xoo",
"isFavorite": false,
"qualifier": "TRK"
},
{
- "key": "palap",
- "name": "Palap",
- "qualifier": "BRC"
- },
- {
- "key": "palap:src/main/xoo",
+ "key": "polop:src/main/xoo",
"name": "src/main/xoo",
"qualifier": "DIR"
},
{
- "key": "palap:src/main/xoo/Source.xoo",
+ "key": "polop:src/main/xoo/Source.xoo",
"name": "Source.xoo",
"qualifier": "FIL"
}
private String componentUuid = null;
private String componentKey = null;
- private String moduleUuidPath = null;
-
private String projectUuid = null;
private String projectKey = null;
return this;
}
- @CheckForNull
- public String moduleUuidPath() {
- return moduleUuidPath;
- }
-
- public DefaultIssue setModuleUuidPath(@Nullable String moduleUuidPath) {
- this.moduleUuidPath = moduleUuidPath;
- return this;
- }
-
@Override
public String projectUuid() {
return projectUuid;