Пример #1
0
 private static void handleIssue(
     IssueDoc issue,
     BatchInput.ServerIssue.Builder issueBuilder,
     Map<String, String> keysByUUid,
     OutputStream out) {
   issueBuilder.setKey(issue.key());
   issueBuilder.setModuleKey(keysByUUid.get(issue.moduleUuid()));
   String path = issue.filePath();
   if (path != null) {
     issueBuilder.setPath(path);
   }
   issueBuilder.setRuleRepository(issue.ruleKey().repository());
   issueBuilder.setRuleKey(issue.ruleKey().rule());
   String checksum = issue.checksum();
   if (checksum != null) {
     issueBuilder.setChecksum(checksum);
   }
   String assigneeLogin = issue.assignee();
   if (assigneeLogin != null) {
     issueBuilder.setAssigneeLogin(assigneeLogin);
   }
   Integer line = issue.line();
   if (line != null) {
     issueBuilder.setLine(line);
   }
   String message = issue.message();
   if (message != null) {
     issueBuilder.setMsg(message);
   }
   issueBuilder.setSeverity(org.sonar.batch.protocol.Constants.Severity.valueOf(issue.severity()));
   issueBuilder.setManualSeverity(issue.isManualSeverity());
   issueBuilder.setStatus(issue.status());
   String resolution = issue.resolution();
   if (resolution != null) {
     issueBuilder.setResolution(resolution);
   }
   issueBuilder.setCreationDate(issue.creationDate().getTime());
   try {
     issueBuilder.build().writeDelimitedTo(out);
   } catch (IOException e) {
     throw new IllegalStateException("Unable to serialize issue", e);
   }
   issueBuilder.clear();
 }
  private BatchReport.Measure toReportMeasure(
      BatchReport.Measure.Builder builder, Measure measure) {
    builder.clear();

    builder.setValueType(getMeasureValueType(measure.getMetric().getType()));
    setValueAccordingToType(builder, measure);
    // Because some numeric measures also have a data (like Sqale rating)
    String data = measure.getData();
    if (data != null) {
      builder.setStringValue(data);
    }
    builder.setMetricKey(measure.getMetricKey());

    // temporary fields during development of computation stack
    String description = measure.getDescription();
    if (description != null) {
      builder.setDescription(description);
    }
    if (measure instanceof RuleMeasure) {
      RuleMeasure ruleMeasure = (RuleMeasure) measure;
      RuleKey ruleKey = ruleMeasure.ruleKey();
      if (ruleKey != null) {
        builder.setRuleKey(ruleKey.toString());
      }
      RulePriority severity = ruleMeasure.getSeverity();
      if (severity != null) {
        builder.setSeverity(Constants.Severity.valueOf(severity.toString()));
      }
    }
    Level alertStatus = measure.getAlertStatus();
    if (alertStatus != null) {
      builder.setAlertStatus(alertStatus.toString());
    }
    String alertText = measure.getAlertText();
    if (alertText != null) {
      builder.setAlertText(alertText);
    }
    Double variation1 = measure.getVariation1();
    if (variation1 != null) {
      builder.setVariationValue1(variation1);
    }
    Double variation2 = measure.getVariation2();
    if (variation2 != null) {
      builder.setVariationValue2(variation2);
    }
    Double variation3 = measure.getVariation3();
    if (variation3 != null) {
      builder.setVariationValue3(variation3);
    }
    Double variation4 = measure.getVariation4();
    if (variation4 != null) {
      builder.setVariationValue4(variation4);
    }
    Double variation5 = measure.getVariation5();
    if (variation5 != null) {
      builder.setVariationValue5(variation5);
    }
    Integer tendency = measure.getTendency();
    if (tendency != null) {
      builder.setTendency(tendency);
    }
    Characteristic charac = measure.getCharacteristic();
    if (charac != null) {
      builder.setCharactericId(charac.id());
    }
    Integer personId = measure.getPersonId();
    if (personId != null) {
      builder.setPersonId(personId);
    }
    return builder.build();
  }