private static ProjectRepositories processStream(InputStream is) throws IOException { WsProjectResponse response = WsProjectResponse.parseFrom(is); if (response.getFileDataByModuleAndPathCount() == 0) { return new SingleProjectRepository(constructFileDataMap(response.getFileDataByPathMap()), new Date(response.getLastAnalysisDate())); } else { final Map<String, SingleProjectRepository> repositoriesPerModule = new HashMap<>(); response.getFileDataByModuleAndPathMap().keySet().forEach(moduleKey -> { WsProjectResponse.FileDataByPath filePaths = response.getFileDataByModuleAndPathMap().get(moduleKey); repositoriesPerModule.put(moduleKey, new SingleProjectRepository( constructFileDataMap(filePaths.getFileDataByPathMap()), new Date(response.getLastAnalysisDate()))); }); return new MultiModuleProjectRepository(repositoriesPerModule, new Date(response.getLastAnalysisDate())); } }
@Test public void use_old_file_structure_for_projects_with_submodules() { String projectKey = "org.codehaus.sonar:sonar"; ProjectRepositories projectRepositories = new MultiModuleProjectRepository() .addFileDataToModule("module-1", "src/main/java/SomeClass.java", new FileData("789456", "123456789")); when(projectDataLoader.load(any(ProjectDataQuery.class))).thenReturn(projectRepositories); WsProjectResponse wsProjectResponse = ws.newRequest() .setParam("key", projectKey) .setParam("profile", "Default") .executeProtobuf(WsProjectResponse.class); assertThat(wsProjectResponse.getFileDataByPathMap()).isEmpty(); assertThat(wsProjectResponse.getFileDataByModuleAndPathCount()).isEqualTo(1); WsProjectResponse.FileDataByPath moduleData = wsProjectResponse.getFileDataByModuleAndPathMap().get("module-1"); assertThat(moduleData).isNotNull(); assertThat(moduleData.getFileDataByPathCount()).isEqualTo(1); WsProjectResponse.FileData fileData = moduleData.getFileDataByPathMap().get("src/main/java/SomeClass.java"); assertThat(fileData).isNotNull(); assertThat(fileData.getHash()).isEqualTo("789456"); assertThat(fileData.getRevision()).isEqualTo("123456789"); } }
@Test public void use_new_file_structure_for_projects_without_submodules() { String projectKey = "org.codehaus.sonar:sonar"; ProjectRepositories projectRepositories = new SingleProjectRepository() .addFileData("src/main/java/SomeClass.java", new FileData("789456", "123456789")); when(projectDataLoader.load(any(ProjectDataQuery.class))).thenReturn(projectRepositories); WsProjectResponse wsProjectResponse = ws.newRequest() .setParam("key", projectKey) .setParam("profile", "Default") .executeProtobuf(WsProjectResponse.class); assertThat(wsProjectResponse.getFileDataByModuleAndPathMap()).isEmpty(); assertThat(wsProjectResponse.getFileDataByPathCount()).isEqualTo(1); assertThat(wsProjectResponse.getFileDataByPathMap().get("src/main/java/SomeClass.java")).isNotNull(); }
private static ProjectRepositories processStream(InputStream is) throws IOException { WsProjectResponse response = WsProjectResponse.parseFrom(is); if (response.getFileDataByModuleAndPathCount() == 0) { return new SingleProjectRepository(constructFileDataMap(response.getFileDataByPathMap()), new Date(response.getLastAnalysisDate())); } else { final Map<String, SingleProjectRepository> repositoriesPerModule = new HashMap<>(); response.getFileDataByModuleAndPathMap().keySet().forEach(moduleKey -> { WsProjectResponse.FileDataByPath filePaths = response.getFileDataByModuleAndPathMap().get(moduleKey); repositoriesPerModule.put(moduleKey, new SingleProjectRepository( constructFileDataMap(filePaths.getFileDataByPathMap()), new Date(response.getLastAnalysisDate()))); }); return new MultiModuleProjectRepository(repositoriesPerModule, new Date(response.getLastAnalysisDate())); } }