use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class LinesAction method handle.
@Override
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto file = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_UUID), request.param(PARAM_KEY), UUID_AND_KEY);
userSession.checkComponentPermission(UserRole.CODEVIEWER, file);
int from = request.mandatoryParamAsInt(PARAM_FROM);
int to = MoreObjects.firstNonNull(request.paramAsInt(PARAM_TO), Integer.MAX_VALUE);
Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.key());
JsonWriter json = response.newJsonWriter().beginObject();
writeSource(lines, json);
json.endObject().close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class ListAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
checkState(context != null && !context.controllers().isEmpty(), "Web service controllers must be loaded before calling the action");
boolean includeInternals = request.mandatoryParamAsBoolean("include_internals");
JsonWriter writer = response.newJsonWriter();
writer.beginObject();
writer.name("webServices").beginArray();
// sort controllers by path
Ordering<WebService.Controller> ordering = Ordering.natural().onResultOf(WebService.Controller::path);
for (WebService.Controller controller : ordering.sortedCopy(context.controllers())) {
writeController(writer, controller, includeInternals);
}
writer.endArray();
writer.endObject();
writer.close();
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class AppAction method handle.
@Override
public void handle(Request request, Response response) {
try (DbSession session = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(session, request.param(PARAM_COMPONENT_ID), request.param(PARAM_COMPONENT), ParamNames.COMPONENT_ID_AND_COMPONENT);
userSession.checkComponentPermission(UserRole.USER, component);
JsonWriter json = response.newJsonWriter();
json.beginObject();
Map<String, MeasureDto> measuresByMetricKey = measuresByMetricKey(component, session);
appendComponent(json, component, userSession, session);
appendPermissions(json, component, userSession);
appendMeasures(json, measuresByMetricKey);
json.endObject();
json.close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class WebhookPayloadFactoryImpl method create.
@Override
public WebhookPayload create(PostProjectAnalysisTask.ProjectAnalysis analysis) {
Writer string = new StringWriter();
try (JsonWriter writer = JsonWriter.of(string)) {
writer.beginObject();
writeServer(writer);
writeTask(writer, analysis.getCeTask());
analysis.getAnalysisDate().ifPresent(date -> writer.propDateTime("analysedAt", date));
writeProject(analysis, writer, analysis.getProject());
writeQualityGate(writer, analysis.getQualityGate());
writeAnalysisProperties(writer, analysis.getScannerContext());
writer.endObject().close();
return new WebhookPayload(analysis.getProject().getKey(), string.toString());
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false);
JsonWriter json = response.newJsonWriter()) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param("uuid"), request.param("key"), UUID_AND_KEY);
userSession.checkComponentPermission(UserRole.CODEVIEWER, component);
json.beginObject();
String duplications = findDataFromComponent(dbSession, component);
List<DuplicationsParser.Block> blocks = parser.parse(component, duplications, dbSession);
duplicationsJsonWriter.write(blocks, json, dbSession);
json.endObject();
}
}
Aggregations