public T at(NewIssueLocation primaryLocation) { Preconditions.checkArgument(primaryLocation != null, "Cannot use a location that is null"); checkState(this.primaryLocation == null, "at() already called"); this.primaryLocation = rewriteLocation((DefaultIssueLocation) primaryLocation); Preconditions.checkArgument(this.primaryLocation.inputComponent() != null, "Cannot use a location with no input component"); return (T) this; }
@Override public void doSave() { requireNonNull(this.engineId, "Engine id is mandatory on external issue"); requireNonNull(this.ruleId, "Rule id is mandatory on external issue"); checkState(primaryLocation != null, "Primary location is mandatory on every external issue"); checkState(primaryLocation.inputComponent().isFile(), "External issues must be located in files"); checkState(primaryLocation.message() != null, "External issues must have a message"); checkState(severity != null, "Severity is mandatory on every external issue"); checkState(type != null, "Type is mandatory on every external issue"); storage.store(this); }
/** * Thread safe assuming that each issues for each file are only written once. */ @Override public void store(DefaultExternalIssue externalIssue) { if (externalIssue.primaryLocation().inputComponent() instanceof DefaultInputFile) { DefaultInputFile defaultInputFile = (DefaultInputFile) externalIssue.primaryLocation().inputComponent(); defaultInputFile.setPublished(true); } moduleIssues.initAndAddExternalIssue(externalIssue); }
/** * Thread safe assuming that each issues for each file are only written once. */ @Override public void store(Issue issue) { if (issue.primaryLocation().inputComponent() instanceof DefaultInputFile) { DefaultInputFile defaultInputFile = (DefaultInputFile) issue.primaryLocation().inputComponent(); if (shouldSkipStorage(defaultInputFile)) { return; } defaultInputFile.setPublished(true); } moduleIssues.initAndAddIssue(issue); }
public void initAndAddExternalIssue(ExternalIssue issue) { DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent(); ScannerReport.ExternalIssue rawExternalIssue = createReportExternalIssue(issue, inputComponent.scannerId()); write(inputComponent.scannerId(), rawExternalIssue); }
@Test public void move_directory_issue_to_project_root() { SensorStorage storage = mock(SensorStorage.class); DefaultIssue issue = new DefaultIssue(project, storage) .at(new DefaultIssueLocation() .on(new DefaultInputDir("foo", "src/main").setModuleBaseDir(project.getBaseDir())) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) .overrideSeverity(Severity.BLOCKER); assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule")); assertThat(issue.primaryLocation().textRange()).isNull(); assertThat(issue.primaryLocation().message()).isEqualTo("[src/main] Wrong way!"); assertThat(issue.overriddenSeverity()).isEqualTo(Severity.BLOCKER); issue.save(); verify(storage).store(issue); }
private static void applyFlows(Consumer<ScannerReport.Flow> consumer, ScannerReport.IssueLocation.Builder locationBuilder, ScannerReport.TextRange.Builder textRangeBuilder, Collection<Flow> flows) { ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder(); for (Flow flow : flows) { if (flow.locations().isEmpty()) { return; } flowBuilder.clear(); for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) { int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).scannerId(); locationBuilder.clear(); locationBuilder.setComponentRef(locationComponentRef); String message = location.message(); if (message != null) { locationBuilder.setMsg(message); } TextRange textRange = location.textRange(); if (textRange != null) { locationBuilder.setTextRange(toProtobufTextRange(textRangeBuilder, textRange)); } flowBuilder.addLocation(locationBuilder.build()); } consumer.accept(flowBuilder.build()); } }
@Test public void build_file_issue() { SensorStorage storage = mock(SensorStorage.class); DefaultExternalIssue issue = new DefaultExternalIssue(project, storage) .at(new DefaultIssueLocation() .on(inputFile) .at(inputFile.selectLine(1)) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) .remediationEffortMinutes(10l) .type(RuleType.BUG) .severity(Severity.BLOCKER); assertThat(issue.primaryLocation().inputComponent()).isEqualTo(inputFile); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("external_repo", "rule")); assertThat(issue.engineId()).isEqualTo("repo"); assertThat(issue.ruleId()).isEqualTo("rule"); assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); assertThat(issue.remediationEffort()).isEqualTo(10l); assertThat(issue.type()).isEqualTo(RuleType.BUG); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); issue.save(); verify(storage).store(issue); }
public boolean initAndAddIssue(Issue issue) { DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent(); if (noSonar(inputComponent, issue)) { return false; } ActiveRule activeRule = activeRules.find(issue.ruleKey()); if (activeRule == null) { // rule does not exist or is not enabled -> ignore the issue return false; } ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity()); if (filters.accept(inputComponent, rawIssue)) { write(inputComponent.scannerId(), rawIssue); return true; } return false; }
@Test public void move_submodule_issue_to_project_root() { File subModuleDirectory = new File(project.getBaseDir().toString(), "bar"); subModuleDirectory.mkdir(); ProjectDefinition subModuleDefinition = ProjectDefinition.create() .setKey("foo/bar") .setBaseDir(subModuleDirectory) .setWorkDir(subModuleDirectory); project.definition().addSubProject(subModuleDefinition); DefaultInputModule subModule = new DefaultInputModule(subModuleDefinition); SensorStorage storage = mock(SensorStorage.class); DefaultIssue issue = new DefaultIssue(project, storage) .at(new DefaultIssueLocation() .on(subModule) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) .overrideSeverity(Severity.BLOCKER); assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule")); assertThat(issue.primaryLocation().textRange()).isNull(); assertThat(issue.primaryLocation().message()).isEqualTo("[bar] Wrong way!"); assertThat(issue.overriddenSeverity()).isEqualTo(Severity.BLOCKER); issue.save(); verify(storage).store(issue); }
@Test public void build_file_issue() { SensorStorage storage = mock(SensorStorage.class); DefaultIssue issue = new DefaultIssue(project, storage) .at(new DefaultIssueLocation() .on(inputFile) .at(inputFile.selectLine(1)) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) .gap(10.0); assertThat(issue.primaryLocation().inputComponent()).isEqualTo(inputFile); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule")); assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); assertThat(issue.gap()).isEqualTo(10.0); assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); issue.save(); verify(storage).store(issue); }
@Test public void build_project_issue() throws IOException { SensorStorage storage = mock(SensorStorage.class); DefaultInputModule inputModule = new DefaultInputModule(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())); DefaultIssue issue = new DefaultIssue(project, storage) .at(new DefaultIssueLocation() .on(inputModule) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) .gap(10.0); assertThat(issue.primaryLocation().inputComponent()).isEqualTo(inputModule); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule")); assertThat(issue.primaryLocation().textRange()).isNull(); assertThat(issue.gap()).isEqualTo(10.0); assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); issue.save(); verify(storage).store(issue); }
public DefaultFlow(List<IssueLocation> issueLocations) { this.locations = issueLocations.stream() .map(i -> new DefaultLocation( i.inputComponent().isFile() ? ((SonarLintInputFile) i.inputComponent()).getClientInputFile() : null, i.textRange(), i.message())) .collect(Collectors.toList()); }
/** * Thread safe assuming that each issues for each file are only written once. */ @Override public void store(DefaultExternalIssue externalIssue) { if (externalIssue.primaryLocation().inputComponent() instanceof DefaultInputFile) { DefaultInputFile defaultInputFile = (DefaultInputFile) externalIssue.primaryLocation().inputComponent(); defaultInputFile.setPublished(true); } moduleIssues.initAndAddExternalIssue(externalIssue); }
/** * Thread safe assuming that each issues for each file are only written once. */ @Override public void store(Issue issue) { if (issue.primaryLocation().inputComponent() instanceof DefaultInputFile) { DefaultInputFile defaultInputFile = (DefaultInputFile) issue.primaryLocation().inputComponent(); if (shouldSkipStorage(defaultInputFile)) { return; } defaultInputFile.setPublished(true); } moduleIssues.initAndAddIssue(issue); }
public T at(NewIssueLocation primaryLocation) { Preconditions.checkArgument(primaryLocation != null, "Cannot use a location that is null"); checkState(this.primaryLocation == null, "at() already called"); this.primaryLocation = rewriteLocation((DefaultIssueLocation) primaryLocation); Preconditions.checkArgument(this.primaryLocation.inputComponent() != null, "Cannot use a location with no input component"); return (T) this; }
@Override public void doSave() { requireNonNull(this.engineId, "Engine id is mandatory on external issue"); requireNonNull(this.ruleId, "Rule id is mandatory on external issue"); checkState(primaryLocation != null, "Primary location is mandatory on every external issue"); checkState(primaryLocation.inputComponent().isFile(), "External issues must be located in files"); checkState(primaryLocation.message() != null, "External issues must have a message"); checkState(severity != null, "Severity is mandatory on every external issue"); checkState(type != null, "Type is mandatory on every external issue"); storage.store(this); }
public void initAndAddExternalIssue(ExternalIssue issue) { DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent(); ScannerReport.ExternalIssue rawExternalIssue = createReportExternalIssue(issue, inputComponent.scannerId()); write(inputComponent.scannerId(), rawExternalIssue); }
public boolean initAndAddIssue(Issue issue) { DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent(); if (noSonar(inputComponent, issue)) { return false; } ActiveRule activeRule = activeRules.find(issue.ruleKey()); if (activeRule == null) { // rule does not exist or is not enabled -> ignore the issue return false; } ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity()); if (filters.accept(inputComponent, rawIssue)) { write(inputComponent.scannerId(), rawIssue); return true; } return false; }
private void applyFlows(Issue issue) { for (Flow flow : issue.flows()) { if (!flow.locations().isEmpty()) { flowBuilder.clear(); for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) { locationBuilder.clear(); locationBuilder.setComponentRef(componentCache.get(location.inputComponent()).batchId()); String message = location.message(); if (message != null) { locationBuilder.setMsg(message); } TextRange textRange = location.textRange(); if (textRange != null) { locationBuilder.setTextRange(toProtobufTextRange(textRange)); } flowBuilder.addLocation(locationBuilder.build()); } builder.addFlow(flowBuilder.build()); } } }