public ProjectRepositories addFileData(@Nullable String path, FileData fileData) { if (path == null || (fileData.hash() == null && fileData.revision() == null)) { return this; } fileDataByPath.put(path, fileData); return this; }
private static WsProjectResponse.FileData toFileDataResponse(FileData fileData) { Builder fileDataBuilder = WsProjectResponse.FileData.newBuilder(); ofNullable(fileData.hash()).ifPresent(fileDataBuilder::setHash); ofNullable(fileData.revision()).ifPresent(fileDataBuilder::setRevision); return fileDataBuilder.build(); } }
public ProjectRepositories addFileDataToModule(String moduleKey, @Nullable String path, FileData fileData) { if (path == null || (fileData.hash() == null && fileData.revision() == null)) { return this; } SingleProjectRepository repository = repositoryPerModule.computeIfAbsent(moduleKey, k -> new SingleProjectRepository()); repository.addFileData(path, fileData); return this; }
@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 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"); }
public ProjectRepositories addFileData(@Nullable String path, FileData fileData) { if (path == null || (fileData.hash() == null && fileData.revision() == null)) { return this; } fileDataByPath.put(path, fileData); return this; }
public ProjectRepositories addFileDataToModule(String moduleKey, @Nullable String path, FileData fileData) { if (path == null || (fileData.hash() == null && fileData.revision() == null)) { return this; } SingleProjectRepository repository = repositoryPerModule.computeIfAbsent(moduleKey, k -> new SingleProjectRepository()); repository.addFileData(path, fileData); return this; }
private static WsProjectResponse.FileData toFileDataResponse(FileData fileData) { Builder fileDataBuilder = WsProjectResponse.FileData.newBuilder(); setNullable(fileData.hash(), fileDataBuilder::setHash); setNullable(fileData.revision(), fileDataBuilder::setRevision); return fileDataBuilder.build(); } }