@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"); } }
private static WsProjectResponse buildResponse(ProjectRepositories data) { WsProjectResponse.Builder response = WsProjectResponse.newBuilder(); ofNullable(data.lastAnalysisDate()).map(Date::getTime).ifPresent(response::setLastAnalysisDate); response.setTimestamp(data.timestamp()); if (data instanceof SingleProjectRepository) { response.putAllFileDataByPath(buildFileDataByPath((SingleProjectRepository) data)); } else { response.putAllFileDataByModuleAndPath(buildFileDataByModuleAndPath((MultiModuleProjectRepository) data)); } return response.build(); }
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())); } }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/batch/project">Further information about this action online (including a response example)</a> * @since 4.5 */ public WsProjectResponse project(ProjectRequest request) { return call( new GetRequest(path("project")) .setParam("branch", request.getBranch()) .setParam("issues_mode", request.getIssuesMode()) .setParam("key", request.getKey()) .setParam("profile", request.getProfile()), WsProjectResponse.parser()); } }
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())); } }
private static WsProjectResponse buildResponse(ProjectRepositories data) { WsProjectResponse.Builder response = WsProjectResponse.newBuilder(); setNullable(data.lastAnalysisDate(), response::setLastAnalysisDate, Date::getTime); response.setTimestamp(data.timestamp()); response.getMutableFileDataByModuleAndPath() .putAll(buildFileDataByModuleAndPath(data)); response.getMutableSettingsByModule() .putAll(buildSettingsByModule(data)); return response.build(); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/batch/project">Further information about this action online (including a response example)</a> * @since 4.5 */ public WsProjectResponse project(ProjectRequest request) { return call( new GetRequest(path("project")) .setParam("branch", request.getBranch()) .setParam("issues_mode", request.getIssuesMode()) .setParam("key", request.getKey()) .setParam("profile", request.getProfile()), WsProjectResponse.parser()); } }
/** * SONAR-7084 */ @Test public void do_not_fail_when_a_path_is_null() { String projectKey = "org.codehaus.sonar:sonar"; ProjectRepositories projectRepositories = new MultiModuleProjectRepository() .addFileDataToModule("module-1", null, new FileData(null, null)); 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(); }
private InputStream mockData() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); WsProjectResponse.Builder projectResponseBuilder = WsProjectResponse.newBuilder(); WsProjectResponse response = projectResponseBuilder.build(); response.writeTo(os); return new ByteArrayInputStream(os.toByteArray()); }
@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(); }