Java Code Examples for org.sonar.api.batch.sensor.issue.NewIssueLocation#at()

The following examples show how to use org.sonar.api.batch.sensor.issue.NewIssueLocation#at() . 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 vote down vote up
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: MetricsSaver.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
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 3
Source File: LuaSquidSensor.java    From sonar-lua with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 4
Source File: CFLintAnalysisResultImporter.java    From sonar-coldfusion with Apache License 2.0 5 votes vote down vote up
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();
}