Search in sources :

Example 1 with WsProjectResponse

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WsProjectResponse(org.sonarqube.ws.WsBatch.WsProjectResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with WsProjectResponse

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);
}
Also used : WsProjectResponse(org.sonarqube.ws.WsBatch.WsProjectResponse) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories)

Example 3 with WsProjectResponse

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();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsProjectResponse(org.sonarqube.ws.WsBatch.WsProjectResponse) FileData(org.sonar.scanner.protocol.input.FileData) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 4 with WsProjectResponse

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);
    }
}
Also used : IOException(java.io.IOException) Date(java.util.Date) FileDataByPath(org.sonarqube.ws.WsBatch.WsProjectResponse.FileDataByPath) WsBatch(org.sonarqube.ws.WsBatch) WsProjectResponse(org.sonarqube.ws.WsBatch.WsProjectResponse) Map(java.util.Map) Settings(org.sonarqube.ws.WsBatch.WsProjectResponse.Settings)

Aggregations

WsProjectResponse (org.sonarqube.ws.WsBatch.WsProjectResponse)4 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Map (java.util.Map)1 Test (org.junit.Test)1 FileData (org.sonar.scanner.protocol.input.FileData)1 TestResponse (org.sonar.server.ws.TestResponse)1 WsBatch (org.sonarqube.ws.WsBatch)1 FileDataByPath (org.sonarqube.ws.WsBatch.WsProjectResponse.FileDataByPath)1 Settings (org.sonarqube.ws.WsBatch.WsProjectResponse.Settings)1