org.sonar.api.batch.sensor.issue.NewIssue Java Examples
The following examples show how to use
org.sonar.api.batch.sensor.issue.NewIssue.
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: LeinNvdSensor.java From sonar-clojure with MIT License | 6 votes |
private void saveVulnerabilities(List<Vulnerability> vulnerabilities, SensorContext context) { Optional<InputFile> fileOptional = getFile("project.clj", context.fileSystem()); fileOptional.ifPresent(projectFile -> { for (Vulnerability v : vulnerabilities) { LOG.debug("Processing vulnerability: " +v.toString()); RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, "nvd-" + v.getSeverity().toLowerCase()); NewIssue newIssue = context.newIssue().forRule(ruleKey); NewIssueLocation primaryLocation = newIssue .newLocation() .on(projectFile) .message(v.getName() + ";" + v.getCwes() + ";" + v.getFileName()) .at(projectFile.selectLine(1)); newIssue.at(primaryLocation); newIssue.save(); } }); }
Example #2
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 #3
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 #4
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(ParsingErrorCheck.MESSAGE) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } sensorContext.newAnalysisError() .onFile(inputFile) .at(inputFile.newPointer(e.getLine(), 0)) .message(e.getMessage()) .save(); }
Example #5
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 #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: 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 #8
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 #9
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 #10
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 #11
Source File: AbstractAnsibleSensor.java From sonar-ansible with Apache License 2.0 | 6 votes |
/** * Saves the found issues in SonarQube * * @param context the context * @param inputFile the file where the issue was found * @param line the line where the issue was found * @param ruleId the Id of the rule that raised the issue * @param message a message describing the issue */ protected void saveIssue(SensorContext context, InputFile inputFile, int line, String ruleId, String message) { RuleKey ruleKey = getRuleKey(context, ruleId); // Old rules (ansible-lint < 3.5) had id ANSIBLE... but now it is E... so we may need to add the heading E back if (ruleKey == null) { ruleKey = getRuleKey(context, "E" + ruleId); } if (ruleKey == null) { LOGGER.debug("Rule " + ruleId + " ignored, not found in repository"); return; } NewIssue newIssue = context.newIssue().forRule(ruleKey); NewIssueLocation location = newIssue.newLocation() .on(inputFile) .message(message) .at(inputFile.selectLine(line)); newIssue.at(location).save(); LOGGER.debug("Issue {} saved for {}", ruleId, inputFile.filename()); }
Example #12
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 #13
Source File: CheckstyleAuditListener.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void addError(AuditEvent event) { final String ruleKey = getRuleKey(event); if (Objects.nonNull(ruleKey)) { final String message = getMessage(event); // In Checkstyle 5.5 exceptions are reported as an events from // TreeWalker if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) { LOG.warn("{} : {}", event.getFileName(), message); } initResource(event); final NewIssue issue = context.newIssue(); final ActiveRule rule = ruleFinder.find( RuleKey.of(CheckstyleConstants.REPOSITORY_KEY, ruleKey)); if (Objects.nonNull(issue) && Objects.nonNull(rule)) { final NewIssueLocation location = issue.newLocation() .on(currentResource) .at(currentResource.selectLine(getLineId(event))) .message(message); issue.forRule(rule.ruleKey()) .at(location) .save(); } } }
Example #14
Source File: AncientSensor.java From sonar-clojure with MIT License | 5 votes |
private void saveOutdated(List<OutdatedDependency> outdatedDependencies, SensorContext context) { Optional<InputFile> fileOptional = getFile("project.clj", context.fileSystem()); fileOptional.ifPresent(projectFile -> outdatedDependencies.forEach(outdatedDependency -> { ProjectFile pr; try { pr = new ProjectFile(projectFile.contents()); } catch (IOException e) { LOG.warn("project.clj could not be read"); return; } LOG.debug("Processing outdated dependencies"); RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, "ancient-clj-dependency"); NewIssue newIssue = context.newIssue().forRule(ruleKey); int lineNumber = pr.findLineNumber( outdatedDependency.getName() + " \"" + outdatedDependency.getCurrentVersion() + "\""); NewIssueLocation primaryLocation = newIssue .newLocation() .on(projectFile) .message(outdatedDependency.toString()) .at(projectFile.selectLine(lineNumber)); newIssue.at(primaryLocation); 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(); }
Example #16
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private static void saveFileIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, FileIssue issue) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(inputFile); saveIssue(newIssue, primaryLocation, ruleKey, issue); }
Example #17
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private static void saveLineIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, LineIssue issue) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(inputFile) .at(inputFile.selectLine(issue.line())); saveIssue(newIssue, primaryLocation, ruleKey, issue); }
Example #18
Source File: AbstractLanguageAnalyzerSensor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(e.getMessage()) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } }
Example #19
Source File: HtlFilesAnalyzer.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private void processRecognitionExceptionForCustomRule(SightlyCompilerException e, SensorContext sensorContext, InputFile inputFile) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message("Parse error: " + e.getMessage()) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); }
Example #20
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 #21
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 #22
Source File: GherkinSquidSensor.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(e.getMessage()) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } }
Example #23
Source File: ValidateLicensesTest.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
@Test public void licenseUnknown() { SensorContext context = createContext(); NewIssue issue = new DefaultIssue(mock(DefaultInputProject.class), mock(SensorStorage.class)); when(context.newIssue()).thenReturn(issue); validateLicenses.validateLicenses(deps(new Dependency("thing", "1.0", "Mamamia")), context); verify(context).newIssue(); assertThat(issue.toString(), containsString(LicenseCheckMetrics.LICENSE_CHECK_UNLISTED_KEY)); }
Example #24
Source File: ValidateLicensesTest.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
@Test public void licenseNull() { SensorContext context = createContext(); NewIssue issue = new DefaultIssue(mock(DefaultInputProject.class), mock(SensorStorage.class)); when(context.newIssue()).thenReturn(issue); validateLicenses.validateLicenses(deps(new Dependency("thing", "1.0", null)), context); verify(context).newIssue(); assertThat(issue.toString(), containsString(LicenseCheckMetrics.LICENSE_CHECK_UNLISTED_KEY)); }
Example #25
Source File: ValidateLicensesTest.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
@Test public void checkSpdxAndCombinationNotFound() { SensorContext context = createContext(); NewIssue issue = new DefaultIssue(mock(DefaultInputProject.class), mock(SensorStorage.class)); when(context.newIssue()).thenReturn(issue); validateLicenses.validateLicenses(deps(new Dependency("thing", "1.0", "(Apache-2.0 AND Apache-1.1)")), context); verify(context).newIssue(); assertThat(issue.toString(), containsString(LicenseCheckMetrics.LICENSE_CHECK_UNLISTED_KEY)); }
Example #26
Source File: ValidateLicensesTest.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
@Test public void checkSpdxAndCombinationNotAllowed() { SensorContext context = createContext(); NewIssue issue = new DefaultIssue(mock(DefaultInputProject.class), mock(SensorStorage.class)); when(context.newIssue()).thenReturn(issue); validateLicenses.validateLicenses( deps(new Dependency("another", "2.0", "LGPL"), new Dependency("thing", "1.0", "(Apache-2.0 AND MIT)")), context); verify(context).newIssue(); assertThat(issue.toString(), containsString(LicenseCheckMetrics.LICENSE_CHECK_NOT_ALLOWED_LICENSE_KEY)); }
Example #27
Source File: ValidateLicensesTest.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
@Test public void licenseNotAllowed() { SensorContext context = createContext(); NewIssue issue = new DefaultIssue(mock(DefaultInputProject.class), mock(SensorStorage.class)); when(context.newIssue()).thenReturn(issue); validateLicenses.validateLicenses(deps(new Dependency("thing", "1.0", "MIT")), context); verify(context).newIssue(); assertThat(issue.toString(), containsString(LicenseCheckMetrics.LICENSE_CHECK_NOT_ALLOWED_LICENSE_KEY)); }
Example #28
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 #29
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 #30
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(); }