use of org.sonarqube.ws.WsBatch.WsProjectResponse in project sonarqube by SonarSource.
the class DefaultProjectRepositoriesLoaderTest method mockData.
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());
}
use of org.sonarqube.ws.WsBatch.WsProjectResponse in project sonarqube by SonarSource.
the class ProjectAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
ProjectRepositories data = projectDataLoader.load(ProjectDataQuery.create().setModuleKey(wsRequest.mandatoryParam(PARAM_KEY)).setProfileName(wsRequest.param(PARAM_PROFILE)).setIssuesMode(wsRequest.mandatoryParamAsBoolean(PARAM_ISSUES_MODE)));
WsProjectResponse projectResponse = buildResponse(data);
writeProtobuf(projectResponse, wsRequest, wsResponse);
}
use of org.sonarqube.ws.WsBatch.WsProjectResponse in project sonarqube by SonarSource.
the class ProjectActionTest method do_not_fail_when_a_path_is_null.
/**
* SONAR-7084
*/
@Test
public void do_not_fail_when_a_path_is_null() throws Exception {
String projectKey = "org.codehaus.sonar:sonar";
ProjectRepositories projectRepositories = new ProjectRepositories().addFileData("module-1", null, new FileData(null, null));
when(projectDataLoader.load(any(ProjectDataQuery.class))).thenReturn(projectRepositories);
TestResponse result = ws.newRequest().setMediaType(MediaTypes.PROTOBUF).setParam("key", projectKey).setParam("profile", "Default").execute();
WsProjectResponse wsProjectResponse = WsProjectResponse.parseFrom(result.getInputStream());
assertThat(wsProjectResponse.getFileDataByModuleAndPath()).isEmpty();
}
use of org.sonarqube.ws.WsBatch.WsProjectResponse in project sonarqube by SonarSource.
the class DefaultProjectRepositoriesLoader method processStream.
private static ProjectRepositories processStream(InputStream is, String projectKey) {
try {
WsProjectResponse response = WsProjectResponse.parseFrom(is);
Table<String, String, FileData> fileDataTable = HashBasedTable.create();
Table<String, String, String> settings = HashBasedTable.create();
Map<String, Settings> settingsByModule = response.getSettingsByModule();
for (Map.Entry<String, Settings> e1 : settingsByModule.entrySet()) {
for (Map.Entry<String, String> e2 : e1.getValue().getSettings().entrySet()) {
settings.put(e1.getKey(), e2.getKey(), e2.getValue());
}
}
Map<String, FileDataByPath> fileDataByModuleAndPath = response.getFileDataByModuleAndPath();
for (Map.Entry<String, FileDataByPath> e1 : fileDataByModuleAndPath.entrySet()) {
for (Map.Entry<String, WsBatch.WsProjectResponse.FileData> e2 : e1.getValue().getFileDataByPath().entrySet()) {
FileData fd = new FileData(e2.getValue().getHash(), e2.getValue().getRevision());
fileDataTable.put(e1.getKey(), e2.getKey(), fd);
}
}
return new ProjectRepositories(settings, fileDataTable, new Date(response.getLastAnalysisDate()));
} catch (IOException e) {
throw new IllegalStateException("Couldn't load project repository for " + projectKey, e);
} finally {
IOUtils.closeQuietly(is);
}
}
Aggregations