Java Code Examples for org.sonar.api.batch.sensor.issue.NewIssue#save()
The following examples show how to use
org.sonar.api.batch.sensor.issue.NewIssue#save() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSensor.java From sonar-clojure with MIT License | 6 votes |
protected void saveIssue(Issue issue, SensorContext context) { try { Optional<InputFile> fileOptional = getFile(issue.getFilePath(), context.fileSystem()); if (fileOptional.isPresent()) { InputFile file = fileOptional.get(); RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, issue.getExternalRuleId().trim()); NewIssue newIssue = context.newIssue().forRule(ruleKey); NewIssueLocation primaryLocation = newIssue .newLocation() .on(file) .message(issue.getDescription().trim()); primaryLocation.at(file.selectLine(issue.getLine())); newIssue.at(primaryLocation); newIssue.save(); } else { LOG.warn("Not able to find a file with path '{}'", issue.getFilePath()); } } catch (Exception e) { LOG.error("Can not save the issue due to: " + e.getMessage()); } }
Example 2
Source File: IssueSaver.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void savePreciseIssue(PreciseIssue issue) { NewIssue newIssue = sensorContext.newIssue(); InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.primaryLocation().file()))); newIssue .forRule(ruleKey(issue.check())) .at(newLocation(primaryFile, newIssue, issue.primaryLocation())); if (issue.cost() != null) { newIssue.gap(issue.cost()); } InputFile secondaryFile; for (IssueLocation secondary : issue.secondaryLocations()) { secondaryFile = fileSystem.inputFile(fileSystem.predicates().is(secondary.file())); if (secondaryFile == null) { secondaryFile = primaryFile; } newIssue.addLocation(newLocation(secondaryFile, newIssue, secondary)); } newIssue.save(); }
Example 3
Source File: IssueSaver.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void saveLineIssue(LineIssue issue) { NewIssue newIssue = sensorContext.newIssue(); InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.file()))); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(primaryFile) .at(primaryFile.selectLine(issue.line())); newIssue .forRule(ruleKey(issue.check())) .at(primaryLocation); if (issue.cost() != null) { newIssue.gap(issue.cost()); } newIssue.save(); }
Example 4
Source File: RubocopSensor.java From sonar-ruby-plugin with MIT License | 6 votes |
private void saveNewIssue(RubocopIssue issue, InputFile inputFile, Set<String> ruleNames, SensorContext sensorContext) { // Make sure the rule we're violating is one we recognise - if not, we'll // fall back to the generic 'rubocop-issue' rule String ruleName = issue.getRuleName(); if (!ruleNames.contains(ruleName)) { ruleName = RubyRulesDefinition.RUBY_LINT_UNKNOWN_RULE.key; } NewIssue newIssue = sensorContext .newIssue() .forRule(RuleKey.of("rubocop", ruleName)); NewIssueLocation newIssueLocation = newIssue .newLocation() .on(inputFile) .message(issue.getFailure()) .at(inputFile.selectLine(issue.getPosition().getLine())); newIssue.at(newIssueLocation); newIssue.save(); }
Example 5
Source File: IssueSaver.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void savePreciseIssue(PreciseIssue issue) { NewIssue newIssue = sensorContext.newIssue(); InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.primaryLocation().file()))); newIssue .forRule(ruleKey(issue.check())) .at(newLocation(primaryFile, newIssue, issue.primaryLocation())); if (issue.cost() != null) { newIssue.gap(issue.cost()); } InputFile secondaryFile; for (IssueLocation secondary : issue.secondaryLocations()) { secondaryFile = fileSystem.inputFile(fileSystem.predicates().is(secondary.file())); if (secondaryFile == null) { secondaryFile = primaryFile; } newIssue.addLocation(newLocation(secondaryFile, newIssue, secondary)); } newIssue.save(); }
Example 6
Source File: IssueSaver.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void saveLineIssue(LineIssue issue) { NewIssue newIssue = sensorContext.newIssue(); InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.file()))); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(primaryFile) .at(primaryFile.selectLine(issue.line())); newIssue .forRule(ruleKey(issue.check())) .at(primaryLocation); if (issue.cost() != null) { newIssue.gap(issue.cost()); } newIssue.save(); }
Example 7
Source File: MetricsSaver.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 6 votes |
public static void saveIssues(SensorContext context, HtmlSourceCode sourceCode) { InputFile inputFile = sourceCode.inputFile(); for (HtmlIssue issue : sourceCode.getIssues()) { NewIssue newIssue = context.newIssue() .forRule(issue.ruleKey()) .gap(issue.cost()); Integer line = issue.line(); NewIssueLocation location = newIssue.newLocation() .on(inputFile) .message(issue.message()); if (line != null && line > 0) { location.at(inputFile.selectLine(line)); } newIssue.at(location); newIssue.save(); } }
Example 8
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
private static void savePreciseIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, PreciseIssue issue) { NewIssue newIssue = sensorContext.newIssue(); newIssue .forRule(ruleKey) .at(newLocation(inputFile, newIssue, issue.primaryLocation())); if (issue.cost() != null) { newIssue.gap(issue.cost()); } for (IssueLocation secondary : issue.secondaryLocations()) { newIssue.addLocation(newLocation(inputFile, newIssue, secondary)); } newIssue.save(); }
Example 9
Source File: LuaSquidSensor.java From sonar-lua with GNU Lesser General Public License v3.0 | 6 votes |
private void saveViolations(SensorContext context, InputFile inputFile, SourceFile squidFile) { Collection<CheckMessage> messages = squidFile.getCheckMessages(); if (messages != null) { for (CheckMessage message : messages) { RuleKey ruleKey = checks.ruleKey((SquidCheck<LexerlessGrammar>) message.getCheck()); NewIssue newIssue = context.newIssue() .forRule(ruleKey) .gap(message.getCost()); Integer line = message.getLine(); NewIssueLocation location = newIssue.newLocation() .on(inputFile) .message(message.getText(Locale.ENGLISH)); if (line != null) { location.at(inputFile.selectLine(line)); } newIssue.at(location); newIssue.save(); } } }
Example 10
Source File: IssueSaver.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void saveFileIssue(FileIssue issue) { NewIssue newIssue = sensorContext.newIssue(); InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.file()))); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(primaryFile); newIssue .forRule(ruleKey(issue.check())) .at(primaryLocation); if (issue.cost() != null) { newIssue.gap(issue.cost()); } InputFile secondaryFile; for (IssueLocation secondary : issue.secondaryLocations()) { secondaryFile = fileSystem.inputFile(fileSystem.predicates().is(secondary.file())); if (secondaryFile == null) { secondaryFile = primaryFile; } newIssue.addLocation(newLocation(secondaryFile, newIssue, secondary)); } newIssue.save(); }
Example 11
Source File: CFLintAnalysisResultImporter.java From sonar-coldfusion with Apache License 2.0 | 5 votes |
private void createNewIssue(IssueAttributes issueAttributes, LocationAttributes locationAttributes, InputFile inputFile) { if(issueAttributes == null){ logger.debug("Problem creating issue for file {} issueAttributes is null", inputFile); } if(locationAttributes == null){ logger.debug("Problem creating issue for file {} locationAttributes is null", inputFile); } if(inputFile==null){ logger.debug("Problem creating issue for file inputFile is null"); } if(issueAttributes == null || locationAttributes == null || inputFile == null){ return; } if(locationAttributes.getLine().isPresent() && locationAttributes.getLine().get()>inputFile.lines()){ logger .error("Problem creating issue for file {}, issue is line {} but file has {} lines", inputFile, locationAttributes.getLine().get(), inputFile.lines()); return; } logger.debug("create New Issue {} for file {}", issueAttributes, inputFile.filename()); final NewIssue issue = sensorContext.newIssue(); final NewIssueLocation issueLocation = issue.newLocation(); issueLocation.on(inputFile); issueLocation.at(inputFile.selectLine(locationAttributes.getLine().get())); issueLocation.message(locationAttributes.getMessage().get()); issue.forRule(RuleKey.of(ColdFusionPlugin.REPOSITORY_KEY, issueAttributes.getId().get())); issue.at(issueLocation); issue.save(); }
Example 12
Source File: ValidateLicenses.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
private void licenseNotAllowedIssue(SensorContext context, Dependency dependency, String notAllowedLicense) { LOGGER.info("Dependency " + dependency.getName() + " uses a not allowed license " + notAllowedLicense); NewIssue issue = context .newIssue() .forRule(RuleKey.of(LicenseCheckMetrics.LICENSE_CHECK_KEY, LicenseCheckMetrics.LICENSE_CHECK_NOT_ALLOWED_LICENSE_KEY)) .at(new DefaultIssueLocation().on(context.module()).message( "Dependency " + dependency.getName() + " uses a not allowed license " + dependency.getLicense())); issue.save(); }
Example 13
Source File: ValidateLicenses.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
private static void licenseNotFoundIssue(SensorContext context, Dependency dependency) { LOGGER.info("No License found for Dependency " + dependency.getName()); NewIssue issue = context .newIssue() .forRule(RuleKey.of(LicenseCheckMetrics.LICENSE_CHECK_KEY, LicenseCheckMetrics.LICENSE_CHECK_UNLISTED_KEY)) .at(new DefaultIssueLocation() .on(context.module()) .message("No License found for Dependency: " + dependency.getName())); issue.save(); }
Example 14
Source File: IssueSaver.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void saveFileIssue(FileIssue issue) { NewIssue newIssue = sensorContext.newIssue(); InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.file()))); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(primaryFile); newIssue .forRule(ruleKey(issue.check())) .at(primaryLocation); if (issue.cost() != null) { newIssue.gap(issue.cost()); } InputFile secondaryFile; for (IssueLocation secondary : issue.secondaryLocations()) { secondaryFile = fileSystem.inputFile(fileSystem.predicates().is(secondary.file())); if (secondaryFile == null) { secondaryFile = primaryFile; } newIssue.addLocation(newLocation(secondaryFile, newIssue, secondary)); } newIssue.save(); }
Example 15
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private static void saveIssue(NewIssue newIssue, NewIssueLocation primaryLocation, RuleKey ruleKey, Issue issue) { newIssue .forRule(ruleKey) .at(primaryLocation); if (issue.cost() != null) { newIssue.gap(issue.cost()); } newIssue.save(); }