Codota Logo
org.sonar.scanner.protocol
Code IndexAdd Codota to your IDE (free)

How to use org.sonar.scanner.protocol

Best Java code snippets using org.sonar.scanner.protocol (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
origin: SonarSource/sonarqube

@Override
public String severity() {
 return rawIssue.getSeverity().name();
}
origin: SonarSource/sonarqube

 private static ActiveRule convert(ScannerReport.ActiveRule input, Rule rule) {
  RuleKey key = RuleKey.of(input.getRuleRepository(), input.getRuleKey());
  Map<String, String> params = new HashMap<>(input.getParamsByKeyMap());
  long updatedAt = input.getUpdatedAt();
  return new ActiveRule(key, input.getSeverity().name(), params, updatedAt == 0 ? input.getCreatedAt() : updatedAt, rule.getPluginKey(), emptyToNull(input.getQProfileKey()));
 }
}
origin: SonarSource/sonarqube

public NewAdHocRule(ScannerReport.AdHocRule ruleFromScannerReport) {
 Preconditions.checkArgument(isNotBlank(ruleFromScannerReport.getEngineId()), "'engine id' not expected to be null for an ad hoc rule");
 Preconditions.checkArgument(isNotBlank(ruleFromScannerReport.getRuleId()), "'rule id' not expected to be null for an ad hoc rule");
 Preconditions.checkArgument(isNotBlank(ruleFromScannerReport.getName()), "'name' not expected to be null for an ad hoc rule");
 Preconditions.checkArgument(ruleFromScannerReport.getSeverity() != Constants.Severity.UNSET_SEVERITY , "'severity' not expected to be null for an ad hoc rule");
 Preconditions.checkArgument(ruleFromScannerReport.getType() != ScannerReport.IssueType.UNSET, "'issue type' not expected to be null for an ad hoc rule");
 this.key = RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + ruleFromScannerReport.getEngineId(), ruleFromScannerReport.getRuleId());
 this.engineId = ruleFromScannerReport.getEngineId();
 this.ruleId = ruleFromScannerReport.getRuleId();
 this.name = ruleFromScannerReport.getName();
 this.description = trimToNull(ruleFromScannerReport.getDescription());
 this.severity = ruleFromScannerReport.getSeverity().name();
 this.ruleType = RuleType.valueOf(ruleFromScannerReport.getType().name());
 this.hasDetails = true;
}
origin: SonarSource/sonarqube

public static TrackedIssue toTrackedIssue(ServerIssue serverIssue, String componentKey) {
 TrackedIssue issue = new TrackedIssue();
 issue.setKey(serverIssue.getKey());
 issue.setStatus(serverIssue.getStatus());
 issue.setResolution(serverIssue.hasResolution() ? serverIssue.getResolution() : null);
 issue.setMessage(serverIssue.hasMsg() ? serverIssue.getMsg() : null);
 issue.setStartLine(serverIssue.hasLine() ? serverIssue.getLine() : null);
 issue.setEndLine(serverIssue.hasLine() ? serverIssue.getLine() : null);
 issue.setSeverity(serverIssue.getSeverity().name());
 issue.setAssignee(serverIssue.hasAssigneeLogin() ? serverIssue.getAssigneeLogin() : null);
 // key in serverIssue might have branch, so don't use it
 issue.setComponentKey(componentKey);
 issue.setCreationDate(new Date(serverIssue.getCreationDate()));
 issue.setRuleKey(RuleKey.of(serverIssue.getRuleRepository(), serverIssue.getRuleKey()));
 issue.setNew(false);
 return issue;
}
origin: SonarSource/sonarqube

public static TrackedIssue toTrackedIssue(InputComponent component, ScannerReport.Issue rawIssue, @Nullable SourceHashHolder hashes) {
 RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey());
 Preconditions.checkNotNull(component.key(), "Component key must be set");
 Preconditions.checkNotNull(ruleKey, "Rule key must be set");
 TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null);
 issue.setKey(Uuids.createFast());
 issue.setComponentKey(component.key());
 issue.setRuleKey(ruleKey);
 issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null);
 issue.setSeverity(rawIssue.getSeverity().name());
 issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg()));
 issue.setResolution(null);
 issue.setStatus(Issue.STATUS_OPEN);
 issue.setNew(true);
 if (rawIssue.hasTextRange()) {
  TextRange r = rawIssue.getTextRange();
  issue.setStartLine(r.getStartLine());
  issue.setStartLineOffset(r.getStartOffset());
  issue.setEndLine(r.getEndLine());
  issue.setEndLineOffset(r.getEndOffset());
 }
 return issue;
}
origin: SonarSource/sonarqube

private static ScannerReport.Issue createReportIssue(Issue issue, int componentRef, String activeRuleSeverity) {
 String primaryMessage = nullToEmpty(issue.primaryLocation().message());
 org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
 Severity severity = overriddenSeverity != null ? Severity.valueOf(overriddenSeverity.name()) : Severity.valueOf(activeRuleSeverity);
 ScannerReport.Issue.Builder builder = ScannerReport.Issue.newBuilder();
 ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
 ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
 // non-null fields
 builder.setSeverity(severity);
 builder.setRuleRepository(issue.ruleKey().repository());
 builder.setRuleKey(issue.ruleKey().rule());
 builder.setMsg(primaryMessage);
 locationBuilder.setMsg(primaryMessage);
 locationBuilder.setComponentRef(componentRef);
 TextRange primaryTextRange = issue.primaryLocation().textRange();
 if (primaryTextRange != null) {
  builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
 }
 Double gap = issue.gap();
 if (gap != null) {
  builder.setGap(gap);
 }
 applyFlows(builder::addFlow, locationBuilder, textRangeBuilder, issue.flows());
 return builder.build();
}
origin: SonarSource/sonarqube

private static ScannerReport.ExternalIssue createReportExternalIssue(ExternalIssue issue, int componentRef) {
 // primary location of an external issue must have a message
 String primaryMessage = issue.primaryLocation().message();
 Severity severity = Severity.valueOf(issue.severity().name());
 IssueType issueType = IssueType.valueOf(issue.type().name());
 ScannerReport.ExternalIssue.Builder builder = ScannerReport.ExternalIssue.newBuilder();
 ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
 ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
 // non-null fields
 builder.setSeverity(severity);
 builder.setType(issueType);
 builder.setEngineId(issue.engineId());
 builder.setRuleId(issue.ruleId());
 builder.setMsg(primaryMessage);
 locationBuilder.setMsg(primaryMessage);
 locationBuilder.setComponentRef(componentRef);
 TextRange primaryTextRange = issue.primaryLocation().textRange();
 if (primaryTextRange != null) {
  builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
 }
 Long effort = issue.remediationEffort();
 if (effort != null) {
  builder.setEffort(effort);
 }
 applyFlows(builder::addFlow, locationBuilder, textRangeBuilder, issue.flows());
 return builder.build();
}
origin: SonarSource/sonarqube

private DefaultIssue toIssue(LineHashSequence lineHashSeq, ScannerReport.Issue reportIssue) {
 DefaultIssue issue = new DefaultIssue();
 init(issue);
 RuleKey ruleKey = RuleKey.of(reportIssue.getRuleRepository(), reportIssue.getRuleKey());
 issue.setRuleKey(ruleKey);
 if (reportIssue.hasTextRange()) {
  int startLine = reportIssue.getTextRange().getStartLine();
  issue.setLine(startLine);
  issue.setChecksum(lineHashSeq.getHashForLine(startLine));
 if (isNotEmpty(reportIssue.getMsg())) {
  issue.setMessage(reportIssue.getMsg());
 } else {
  Rule rule = ruleRepository.getByKey(ruleKey);
  issue.setMessage(rule.getName());
 if (reportIssue.getSeverity() != Severity.UNSET_SEVERITY) {
  issue.setSeverity(reportIssue.getSeverity().name());
 if (reportIssue.getGap() != 0) {
  issue.setGap(reportIssue.getGap());
 if (reportIssue.hasTextRange()) {
  dbLocationsBuilder.setTextRange(convertTextRange(reportIssue.getTextRange()));
 for (ScannerReport.Flow flow : reportIssue.getFlowList()) {
  if (flow.getLocationCount() > 0) {
   DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder();
   for (ScannerReport.IssueLocation location : flow.getLocationList()) {
    convertLocation(location).ifPresent(dbFlowBuilder::addLocation);
origin: SonarSource/sonarqube

@Override
public void store(DefaultAdHocRule adHocRule) {
 ScannerReportWriter writer = reportPublisher.getWriter();
 final ScannerReport.AdHocRule.Builder builder = ScannerReport.AdHocRule.newBuilder();
 builder.setEngineId(adHocRule.engineId());
 builder.setRuleId(adHocRule.ruleId());
 builder.setName(adHocRule.name());
 String description = adHocRule.description();
 if (description != null) {
  builder.setDescription(description);
 }
 builder.setSeverity(Constants.Severity.valueOf(adHocRule.severity().name()));
 builder.setType(ScannerReport.IssueType.valueOf(adHocRule.type().name()));
 writer.appendAdHocRule(builder.build());
}
origin: SonarSource/sonarqube

@VisibleForTesting
protected void mergeMatched(Tracking<TrackedIssue, ServerIssueFromWs> result, Collection<TrackedIssue> mergeTo, Collection<TrackedIssue> rawIssues) {
 for (Map.Entry<TrackedIssue, ServerIssueFromWs> e : result.getMatchedRaws().entrySet()) {
  org.sonar.scanner.protocol.input.ScannerInput.ServerIssue dto = e.getValue().getDto();
  TrackedIssue tracked = e.getKey();
  // invariant fields
  tracked.setKey(dto.getKey());
  // non-persisted fields
  tracked.setNew(false);
  // fields to update with old values
  tracked.setResolution(dto.hasResolution() ? dto.getResolution() : null);
  tracked.setStatus(dto.getStatus());
  tracked.setAssignee(dto.hasAssigneeLogin() ? dto.getAssigneeLogin() : null);
  tracked.setCreationDate(new Date(dto.getCreationDate()));
  if (dto.getManualSeverity()) {
   // Severity overridden by user
   tracked.setSeverity(dto.getSeverity().name());
  }
  mergeTo.add(tracked);
 }
}
origin: SonarSource/sonarqube

private static void handleIssue(IssueDto issue, ScannerInput.ServerIssue.Builder issueBuilder, Map<String, String> keysByUUid, OutputStream out) {
 issueBuilder.setKey(issue.getKey());
 String moduleUuid = extractModuleUuid(issue);
 issueBuilder.setModuleKey(keysByUUid.get(moduleUuid));
 ofNullable(issue.getFilePath()).ifPresent(issueBuilder::setPath);
 issueBuilder.setRuleRepository(issue.getRuleRepo());
 issueBuilder.setRuleKey(issue.getRule());
 ofNullable(issue.getChecksum()).ifPresent(issueBuilder::setChecksum);
 ofNullable(issue.getAssigneeUuid()).ifPresent(issueBuilder::setAssigneeLogin);
 ofNullable(issue.getLine()).ifPresent(issueBuilder::setLine);
 ofNullable(issue.getMessage()).ifPresent(issueBuilder::setMsg);
 issueBuilder.setSeverity(org.sonar.scanner.protocol.Constants.Severity.valueOf(issue.getSeverity()));
 issueBuilder.setManualSeverity(issue.isManualSeverity());
 issueBuilder.setStatus(issue.getStatus());
 ofNullable(issue.getResolution()).ifPresent(issueBuilder::setResolution);
 issueBuilder.setType(RuleType.valueOf(issue.getType()).name());
 issueBuilder.setCreationDate(issue.getIssueCreationTime());
 try {
  issueBuilder.build().writeDelimitedTo(out);
 } catch (IOException e) {
  throw new IllegalStateException("Unable to serialize issue", e);
 }
 issueBuilder.clear();
}
origin: SonarSource/sonarqube

init(issue);
RuleKey ruleKey = RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + reportExternalIssue.getEngineId(), reportExternalIssue.getRuleId());
issue.setRuleKey(ruleKey);
if (reportExternalIssue.hasTextRange()) {
 int startLine = reportExternalIssue.getTextRange().getStartLine();
 issue.setLine(startLine);
 issue.setChecksum(lineHashSeq.getHashForLine(startLine));
if (isNotEmpty(reportExternalIssue.getMsg())) {
 issue.setMessage(reportExternalIssue.getMsg());
if (reportExternalIssue.getSeverity() != Severity.UNSET_SEVERITY) {
 issue.setSeverity(reportExternalIssue.getSeverity().name());
issue.setEffort(Duration.create(reportExternalIssue.getEffort() != 0 ? reportExternalIssue.getEffort() : DEFAULT_EXTERNAL_ISSUE_EFFORT));
DbIssues.Locations.Builder dbLocationsBuilder = DbIssues.Locations.newBuilder();
if (reportExternalIssue.hasTextRange()) {
 dbLocationsBuilder.setTextRange(convertTextRange(reportExternalIssue.getTextRange()));
for (ScannerReport.Flow flow : reportExternalIssue.getFlowList()) {
 if (flow.getLocationCount() > 0) {
  DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder();
  for (ScannerReport.IssueLocation location : flow.getLocationList()) {
   convertLocation(location).ifPresent(dbFlowBuilder::addLocation);
issue.setType(toRuleType(reportExternalIssue.getType()));
origin: SonarSource/sonarqube

@Override
public void publish(ScannerReportWriter writer) {
 final ScannerReport.ActiveRule.Builder builder = ScannerReport.ActiveRule.newBuilder();
 writer.writeActiveRules(activeRules.findAll().stream()
  .map(DefaultActiveRule.class::cast)
  .map(input -> {
   builder.clear();
   builder.setRuleRepository(input.ruleKey().repository());
   builder.setRuleKey(input.ruleKey().rule());
   builder.setSeverity(Constants.Severity.valueOf(input.severity()));
   builder.setCreatedAt(input.createdAt());
   builder.setUpdatedAt(input.updatedAt());
   builder.setQProfileKey(input.qpKey());
   builder.getMutableParamsByKey().putAll(input.params());
   return builder.build();
  }).collect(toList()));
}
origin: SonarSource/sonarqube

RuleMetadataDto ruleMetadata = db.rules().insertOrUpdateMetadata(rule, organization);
RuleDto ruleUpdated = underTest.persistAndIndex(dbSession, new NewAdHocRule(ScannerReport.AdHocRule.newBuilder()
 .setEngineId("eslint")
 .setRuleId(rule.getKey().rule())
 .setName(ruleMetadata.getAdHocName())
 .setDescription(ruleMetadata.getAdHocDescription())
 .setSeverity(Constants.Severity.valueOf(ruleMetadata.getAdHocSeverity()))
 .setType(ScannerReport.IssueType.forNumber(ruleMetadata.getAdHocType()))
 .build()),
 organization);
origin: org.sonarsource.sonarqube/sonar-server

 private static ActiveRule convert(ScannerReport.ActiveRule input, Rule rule) {
  RuleKey key = RuleKey.of(input.getRuleRepository(), input.getRuleKey());
  Map<String, String> params = new HashMap<>(input.getParamsByKeyMap());
  return new ActiveRule(key, input.getSeverity().name(), params, input.getCreatedAt(), rule.getPluginKey());
 }
}
origin: SonarSource/sonarqube

private static Map<String, String> readOneFieldValues(String json, String key) {
 Type type = new TypeToken<Map<String, String>>() {
 }.getType();
 Gson gson = GsonHelper.create();
 try {
  return gson.fromJson(json, type);
 } catch (JsonSyntaxException e) {
  throw BadRequestException.create(String.format("JSON '%s' does not respect expected format for setting '%s'. Ex: {\"field1\":\"value1\", \"field2\":\"value2\"}", json, key));
 }
}
origin: org.sonarsource.sonarqube/sonar-scanner-engine

public static TrackedIssue toTrackedIssue(ServerIssue serverIssue, String componentKey) {
 TrackedIssue issue = new TrackedIssue();
 issue.setKey(serverIssue.getKey());
 issue.setStatus(serverIssue.getStatus());
 issue.setResolution(serverIssue.hasResolution() ? serverIssue.getResolution() : null);
 issue.setMessage(serverIssue.hasMsg() ? serverIssue.getMsg() : null);
 issue.setStartLine(serverIssue.hasLine() ? serverIssue.getLine() : null);
 issue.setEndLine(serverIssue.hasLine() ? serverIssue.getLine() : null);
 issue.setSeverity(serverIssue.getSeverity().name());
 issue.setAssignee(serverIssue.hasAssigneeLogin() ? serverIssue.getAssigneeLogin() : null);
 // key in serverIssue might have branch, so don't use it
 issue.setComponentKey(componentKey);
 issue.setCreationDate(new Date(serverIssue.getCreationDate()));
 issue.setRuleKey(RuleKey.of(serverIssue.getRuleRepository(), serverIssue.getRuleKey()));
 issue.setNew(false);
 return issue;
}
origin: org.sonarsource.sonarqube/sonar-scanner-engine

@Override
public String severity() {
 return rawIssue.getSeverity().name();
}
origin: SonarSource/sonarqube

private void loadFromPaginatedWs(List<Metric> metrics) throws IOException {
 int page = 1;
 WsMetricsResponse response;
 do {
  GetRequest getRequest = new GetRequest(METRICS_SEARCH_URL + page);
  try (Reader reader = wsClient.call(getRequest).contentReader()) {
   response = GsonHelper.create().fromJson(reader, WsMetricsResponse.class);
   for (WsMetric metric : response.metrics) {
    metrics.add(new Metric.Builder(metric.getKey(), metric.getName(), ValueType.valueOf(metric.getType()))
     .create()
     .setDirection(metric.getDirection())
     .setQualitative(metric.isQualitative())
     .setUserManaged(metric.isCustom())
     .setDescription(metric.getDescription())
     .setId(metric.getId()));
   }
  }
  page++;
 } while (response.getP() < (response.getTotal() / response.getPs() + 1));
}
origin: org.sonarsource.sonarqube/sonar-server

private static Map<String, String> readOneFieldValues(String json, String key) {
 Type type = new TypeToken<Map<String, String>>() {
 }.getType();
 Gson gson = GsonHelper.create();
 try {
  return gson.fromJson(json, type);
 } catch (JsonSyntaxException e) {
  throw BadRequestException.create(String.format("JSON '%s' does not respect expected format for setting '%s'. Ex: {\"field1\":\"value1\", \"field2\":\"value2\"}", json, key));
 }
}
org.sonar.scanner.protocol

Most used classes

  • FileStructure
    Structure of files in the zipped report
  • ScannerReport$Component
  • ScannerReport$Metadata
  • ScannerReport$CpdTextBlock
  • ScannerReport$Duplication
  • ScannerReport$Issue,
  • ScannerReport$LineCoverage,
  • ScannerReport$ChangedLines,
  • ScannerReport$Changesets,
  • ScannerReport$LineSgnificantCode,
  • ScannerReport$Measure,
  • ScannerReport$Symbol,
  • ScannerReport$SyntaxHighlightingRule,
  • ScannerReportReader,
  • Constants$Severity,
  • ScannerInput$ServerIssue,
  • ScannerReport$ActiveRule,
  • ScannerReport$AdHocRule,
  • ScannerReport$Duplicate
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now