Package org.sonar.api.utils.text

Examples of org.sonar.api.utils.text.JsonWriter


  @Override
  public void handle(Request request, Response response) {
    long idToRename = QGatesWs.parseId(request, QGatesWs.PARAM_ID);
    QualityGateDto renamedQualityGate = qualityGates.rename(idToRename, request.mandatoryParam(QGatesWs.PARAM_NAME));
    JsonWriter writer = response.newJsonWriter();
    QGatesWs.writeQualityGate(renamedQualityGate, writer).close();
  }
View Full Code Here


    request.setParam("f", "name,repo");
    request.setParam("severities", "BLOCKER");

    SearchOptions options = SearchOptions.create(request);
    StringWriter json = new StringWriter();
    JsonWriter jsonWriter = JsonWriter.of(json).beginObject();
    Result result = mock(Result.class);
    when(result.getTotal()).thenReturn(42L);
    options.writeStatistics(jsonWriter, result);
    jsonWriter.endObject().close();

    JSONAssert.assertEquals("{\"total\": 42, \"p\": 3, \"ps\": 10}", json.toString(), true);
  }
View Full Code Here

  }

  @VisibleForTesting
  void writeJson(Writer writer) {
    try {
      JsonWriter json = JsonWriter.of(writer);
      json.beginObject();
      json.prop("version", server.getVersion());

      Set<RuleKey> ruleKeys = newHashSet();
      Set<String> userLogins = newHashSet();
      writeJsonIssues(json, ruleKeys, userLogins);
      writeJsonComponents(json);
      writeJsonRules(json, ruleKeys);
      List<User> users = userFinder.findByLogins(new ArrayList<String>(userLogins));
      writeUsers(json, users);
      json.endObject().close();

    } catch (IOException e) {
      throw new SonarException("Unable to write JSON report", e);
    }
  }
View Full Code Here

            date = (Date)ObjectUtils.defaultIfNull(
              mapper.selectProfileVersionDate(profileMeasure.getProfileId(), version), now);
          }
          // see format of JSON in org.sonar.batch.rule.UsedQProfiles
          StringWriter writer = new StringWriter();
          JsonWriter json = JsonWriter.of(writer);
          json
            .beginArray()
            .beginObject()
            .prop("key", profile.getKee())
            .prop("language", profile.getLanguage())
            .prop("name", profile.getName())
View Full Code Here

  private void exportIssues(File exportDir) {
    File issuesFile = new File(exportDir, "issues.json");
    FileWriter issueWriter = null;
    try {
      issueWriter = new FileWriter(issuesFile);
      JsonWriter jsonWriter = JsonWriter.of(issueWriter);
      jsonWriter
        .beginObject().name("issues")
        .beginArray();
      for (Issue issue : issueCache.byModule(def.getKey())) {
        jsonWriter.beginObject()
          .prop("repository", issue.ruleKey().repository())
          .prop("rule", issue.ruleKey().rule());
        InputPath inputPath = issue.inputPath();
        if (inputPath != null) {
          jsonWriter.prop("path", inputPath.relativePath());
        }
        jsonWriter.prop("message", issue.message())
          .prop("effortToFix", issue.effortToFix())
          .prop("line", issue.line());
        Severity overridenSeverity = issue.overridenSeverity();
        if (overridenSeverity != null) {
          jsonWriter.prop("severity", overridenSeverity.name());
        }
        jsonWriter.endObject();
      }
      jsonWriter.endArray()
        .endObject()
        .close();
    } catch (IOException e) {
      throw unableToExport(e);
    } finally {
View Full Code Here

  private void exportMeasures(File exportDir) {
    File measuresFile = new File(exportDir, "measures.json");
    FileWriter measureWriter = null;
    try {
      measureWriter = new FileWriter(measuresFile);
      JsonWriter jsonWriter = JsonWriter.of(measureWriter);
      jsonWriter
        .beginObject().name("measures")
        .beginArray();
      for (Measure<?> measure : measureCache.byModule(def.getKey())) {
        jsonWriter.beginObject()
          .prop("metricKey", measure.metric().key());
        InputFile inputFile = measure.inputFile();
        if (inputFile != null) {
          jsonWriter.prop("filePath", inputFile.relativePath());
        }
        jsonWriter.prop("value", String.valueOf(measure.value()))
          .endObject();
      }
      jsonWriter.endArray()
        .endObject()
        .close();
    } catch (IOException e) {
      throw unableToExport(e);
    } finally {
View Full Code Here

TOP

Related Classes of org.sonar.api.utils.text.JsonWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.