private static String buildDirectoryProjectRelativePath(Map<String, String> pathByModuleKey, ComponentDto c, ComponentDto parentModule) { String moduleProjectRelativePath = buildModuleProjectRelativePath(pathByModuleKey, parentModule); return Stream.of(moduleProjectRelativePath, c.path()) .map(StringUtils::trimToNull) .filter(s -> s != null && !"/".equals(s)) .collect(Collectors.joining("/")); }
private static String buildModuleProjectRelativePath(Map<String, String> pathByModuleKey, ComponentDto parentModule) { return Optional.ofNullable(pathByModuleKey.get(parentModule.getKey())) // If module is not in the scanner report, we can't guess the path accurately. Fallback on what we have in DB .orElse(trimToEmpty(parentModule.path())); }
private static void addDirectories(IssueQuery.Builder builder, List<ComponentDto> directories) { Collection<String> directoryModuleUuids = new HashSet<>(); Collection<String> directoryPaths = new HashSet<>(); for (ComponentDto directory : directories) { directoryModuleUuids.add(directory.moduleUuid()); directoryPaths.add(directory.path()); } builder.moduleUuids(directoryModuleUuids); builder.directories(directoryPaths); }
static Component.Builder componentDtoToWsComponent(ComponentDto component) { Component.Builder wsComponent = Component.newBuilder() .setId(component.uuid()) .setKey(component.getKey()) .setName(component.name()) .setQualifier(component.qualifier()); ofNullable(component.getBranch()).ifPresent(wsComponent::setBranch); ofNullable(component.getPullRequest()).ifPresent(wsComponent::setPullRequest); ofNullable(component.path()).ifPresent(wsComponent::setPath); ofNullable(component.description()).ifPresent(wsComponent::setDescription); ofNullable(component.language()).ifPresent(wsComponent::setLanguage); return wsComponent; } }
public IssueDto setComponent(ComponentDto component) { this.componentKey = component.getDbKey(); this.componentUuid = component.uuid(); this.moduleUuid = component.moduleUuid(); this.moduleUuidPath = component.moduleUuidPath(); this.filePath = component.path(); return this; }
private static void verifyFileMoveRowDto(RecordingResultHandler resultHander, ComponentAndSource componentAndSource) { FileMoveRowDto dto = resultHander.getById(componentAndSource.component.getId()).get(); assertThat(dto.getKey()).isEqualTo(componentAndSource.component.getDbKey()); assertThat(dto.getUuid()).isEqualTo(componentAndSource.component.uuid()); assertThat(dto.getPath()).isEqualTo(componentAndSource.component.path()); assertThat(dto.getLineCount()).isEqualTo(componentAndSource.source.getLineCount()); }
private static void verifyLinesHashes(LineHashesWithKeyDtoHandler handler, ComponentDto file, FileSourceDto fileSource) { LineHashesWithUuidDto dto = handler.getByUuid(file.uuid()).get(); assertThat(dto.getPath()).isEqualTo(file.path()); assertThat(dto.getRawLineHashes()).isEqualTo(fileSource.getRawLineHashes()); assertThat(dto.getLineHashes()).isEqualTo(fileSource.getLineHashes()); }
private void assertDtoIsProjectView1(ComponentDto pv1Dto, ComponentDto viewDto, ComponentDto parentViewDto, ComponentDto project) { assertThat(pv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); assertThat(pv1Dto.name()).isEqualTo(PROJECT_VIEW_1_NAME); assertThat(pv1Dto.longName()).isEqualTo(PROJECT_VIEW_1_NAME); assertThat(pv1Dto.description()).isNull(); assertThat(pv1Dto.path()).isNull(); assertThat(pv1Dto.uuid()).isEqualTo(PROJECT_VIEW_1_UUID); assertThat(pv1Dto.projectUuid()).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.getCopyResourceUuid()).isEqualTo(project.uuid()); assertThat(pv1Dto.getCreatedAt()).isEqualTo(now); }
/** * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} */ private void assertDtoIsView(ComponentDto dto) { assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); assertThat(dto.name()).isEqualTo(VIEW_NAME); assertThat(dto.longName()).isEqualTo(VIEW_NAME); assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); assertThat(dto.path()).isNull(); assertThat(dto.uuid()).isEqualTo(VIEW_UUID); assertThat(dto.projectUuid()).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.getCopyResourceUuid()).isNull(); assertThat(dto.getCreatedAt()).isEqualTo(now); }
/** * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} */ private void assertDtoIsApplication(ComponentDto dto) { assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); assertThat(dto.name()).isEqualTo(VIEW_NAME); assertThat(dto.longName()).isEqualTo(VIEW_NAME); assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); assertThat(dto.path()).isNull(); assertThat(dto.uuid()).isEqualTo(VIEW_UUID); assertThat(dto.projectUuid()).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.getCopyResourceUuid()).isNull(); assertThat(dto.getCreatedAt()).isEqualTo(now); }
/** * Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)} */ private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) { assertThat(sv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME); assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME); assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION); assertThat(sv1Dto.path()).isNull(); assertThat(sv1Dto.uuid()).isEqualTo(SUBVIEW_1_UUID); assertThat(sv1Dto.projectUuid()).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.getCopyResourceUuid()).isNull(); assertThat(sv1Dto.getCreatedAt()).isEqualTo(now); }
public static ComponentDto newFileDto(ComponentDto module, @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) .setDbKey(generateKey("FILE_KEY_" + fileUuid, module)) .setName(filename) .setLongName(path) .setScope(Scopes.FILE) .setQualifier(Qualifiers.FILE) .setPath(path) .setCreatedAt(new Date()) .setLanguage("xoo"); }
@Test public void param_componentUuids_enables_search_in_directory_tree() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto dir = db.components().insertComponent(newDirectory(project, "src/main/java/foo")); SearchRequest request = new SearchRequest() .setComponentUuids(asList(dir.uuid())); IssueQuery query = underTest.create(request); assertThat(query.moduleUuids()).containsOnly(dir.moduleUuid()); assertThat(query.directories()).containsOnly(dir.path()); assertThat(query.onComponentOnly()).isFalse(); }
@Test public void persist_file_directly_attached_on_root_directory() { ComponentDto projectDto = prepareProject(); treeRootHolder.setRoot( asTreeRoot(projectDto) .addChildren( builder(FILE, 2).setUuid("DEFG").setKey(projectDto.getDbKey() + ":pom.xml") .setName("pom.xml") .build()) .build()); underTest.execute(new TestComputationStepContext()); assertThat(dbClient.componentDao().selectByKey(db.getSession(), projectDto.getDbKey() + ":/")).isNotPresent(); ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), projectDto.getDbKey() + ":pom.xml").get(); assertThat(file.name()).isEqualTo("pom.xml"); assertThat(file.path()).isEqualTo("pom.xml"); }
@Test public void return_file_data_from_single_project() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organizationDto); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); ComponentDto file = db.components().insertComponent(newFileDto(project)); dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(file).setSrcHash("123456")); db.commit(); ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setProjectKey(project.getKey())); assertTrue(ref instanceof SingleProjectRepository); SingleProjectRepository singleProjectRepository = ((SingleProjectRepository) ref); assertThat(singleProjectRepository.fileData()).hasSize(1); FileData fileData = singleProjectRepository.fileDataByPath(file.path()); assertThat(fileData).isNotNull(); assertThat(fileData.hash()).isEqualTo("123456"); }
@Test public void display_directory_facet_using_project() { ComponentDto project = db.components().insertPublicProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "src/main/java/dir")); ComponentDto file = db.components().insertComponent(newFileDto(project, directory)); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, file); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam("resolved", "false") .setParam(PARAM_COMPONENT_KEYS, project.getKey()) .setParam(WebService.Param.FACETS, "directories") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(tuple("directories", of(directory.path(), 1L))); }
public static IssueDoc newDoc(String key, ComponentDto componentDto) { String mainBranchProjectUuid = componentDto.getMainBranchProjectUuid(); return newDoc() .setKey(key) .setBranchUuid(componentDto.projectUuid()) .setComponentUuid(componentDto.uuid()) .setModuleUuid(!componentDto.scope().equals(Scopes.PROJECT) ? componentDto.moduleUuid() : componentDto.uuid()) .setModuleUuidPath(componentDto.moduleUuidPath()) .setProjectUuid(mainBranchProjectUuid == null ? componentDto.projectUuid() : mainBranchProjectUuid) .setOrganizationUuid(componentDto.getOrganizationUuid()) // File path make no sens on modules and projects .setFilePath(!componentDto.scope().equals(Scopes.PROJECT) ? componentDto.path() : null) .setIsMainBranch(mainBranchProjectUuid == null); }
@Test public void return_file_data_from_multi_modules() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organizationDto); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); ComponentDto module = db.components().insertComponent(newModuleDto(project)); // File on project ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(projectFile).setSrcHash("123456")); // File on module ComponentDto moduleFile = db.components().insertComponent(newFileDto(module)); dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(moduleFile).setSrcHash("789456")); dbSession.commit(); ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setProjectKey(project.getKey())); assertTrue(ref instanceof MultiModuleProjectRepository); MultiModuleProjectRepository repository = ((MultiModuleProjectRepository) ref); assertThat(repository.fileData(project.getKey(), projectFile.path()).hash()).isEqualTo("123456"); assertThat(repository.fileData(module.getKey(), moduleFile.path()).hash()).isEqualTo("789456"); }
@Test public void return_file_data_from_branch() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organizationDto); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); ComponentDto moduleBranch = db.components().insertComponent(newModuleDto(branch)); // File on branch ComponentDto projectFile = db.components().insertComponent(newFileDto(branch)); dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(projectFile).setSrcHash("123456")); // File on moduleBranch branch ComponentDto moduleFile = db.components().insertComponent(newFileDto(moduleBranch)); dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(moduleFile).setSrcHash("789456")); dbSession.commit(); ProjectRepositories ref = underTest.load(ProjectDataQuery.create() .setProjectKey(project.getKey()) .setBranch("my_branch")); assertTrue(ref instanceof MultiModuleProjectRepository); MultiModuleProjectRepository repository = ((MultiModuleProjectRepository) ref); assertThat(repository.fileData(branch.getKey(), projectFile.path()).hash()).isEqualTo("123456"); assertThat(repository.fileData(moduleBranch.getKey(), moduleFile.path()).hash()).isEqualTo("789456"); }
@Test public void return_bread_crumbs_on_several_levels() { ComponentDto project = insertOrganizationAndProject(); ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo")); ComponentDto file = componentDbTester.insertComponent(newFileDto(directory, directory, "cdef").setName("Source.xoo") .setDbKey("palap:src/main/xoo/Source.xoo") .setPath(directory.path())); userSession.addProjectPermission(UserRole.USER, project); init(); executeAndVerify(file.getDbKey(), "return_bread_crumbs_on_several_levels.json"); }