当前位置: 首页>>代码示例>>Java>>正文


Java SensorContext.newIssue方法代码示例

本文整理汇总了Java中org.sonar.api.batch.sensor.SensorContext.newIssue方法的典型用法代码示例。如果您正苦于以下问题:Java SensorContext.newIssue方法的具体用法?Java SensorContext.newIssue怎么用?Java SensorContext.newIssue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.sonar.api.batch.sensor.SensorContext的用法示例。


在下文中一共展示了SensorContext.newIssue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createIssuesForMutants

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private void createIssuesForMutants(List<MutantResult> mutantResults, SensorContext context, MutantStatus targetStatus, String ruleKey) throws IOException {
    if (isRuleActive(ruleKey)) {
        int count = 0;
        for (MutantResult mutantResult : mutantResults) {
            if (mutantResult.getStatus() == targetStatus) {
                count++;
                InputFile file = locateSourceFile(mutantResult.getSourceFilePath());

                NewIssue issue = context.newIssue();
                NewIssueLocation location = issue.newLocation()
                        .on(file)
                        .at(mutantResult.getLocation().getRange(file))
                        .message(formatIssueMessage(mutantResult));
                issue.at(location);
                issue.forRule(RuleKey.of(RULE_REPOSITORY_KEY, ruleKey));
                issue.save();
            }
        }
        log.info("Reported {} issue(s) as {}.", count, targetStatus);
    } else {
        log.info("Skip reporting {} mutant(s), because rule {} is inactive", targetStatus, ruleKey);
    }
}
 
开发者ID:stryker-mutator,项目名称:sonar-stryker-plugin,代码行数:24,代码来源:StrykerSensor.java

示例2: processParseException

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private static void processParseException(ParseException e, SensorContext context, CompatibleInputFile inputFile, Optional<RuleKey> parsingErrorKey) {
  reportAnalysisError(e, context, inputFile);

  LOG.warn("Unable to parse file {}", inputFile.absolutePath());
  LOG.warn("Cause: {}", e.getMessage());

  if (parsingErrorKey.isPresent()) {
    // the ParsingErrorCheck rule is activated: we create a beautiful issue
    NewIssue newIssue = context.newIssue();
    NewIssueLocation primaryLocation = newIssue.newLocation()
      .message("Parse error: " + e.getMessage())
      .on(inputFile.wrapped());
    newIssue
      .forRule(parsingErrorKey.get())
      .at(primaryLocation)
      .save();
  }
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:19,代码来源:XmlSensor.java

示例3: processRecognitionException

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:antowski,项目名称:sonar-onec,代码行数:16,代码来源:OneCSensor.java

示例4: processRecognitionException

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
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();
  }
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:16,代码来源:AbstractLanguageAnalyzerSensor.java

示例5: createMissingIssues

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@VisibleForTesting
private void createMissingIssues(SensorContext context, InputComponent resource) {
  Multiset<IssueKey> componentIssues = checker.getByComponentKey(resource.key());
  if (!componentIssues.isEmpty()) {
    checker.disabled = true;
    for (IssueKey issueKey : checker.getByComponentKey(resource.key())) {
      // missing issue => create
      checker.different = true;
      RuleKey ruleKey = RuleKey.parse(issueKey.ruleKey);
      ActiveRule activeRule = profile.getActiveRule(ruleKey.repository(), ruleKey.rule());
      if (activeRule == null) {
        // rule not active => skip it
        checker.inactiveRule(issueKey.ruleKey);
        continue;
      }
      checker.differences++;
      NewIssue newIssue = context.newIssue();
      NewIssueLocation location = newIssue.newLocation()
        .on(resource)
        .message("Missing");
      if (issueKey.line != 0) {
        location.at(((InputFile) resource).selectLine(issueKey.line));
      }
      newIssue
        .forRule(ruleKey)
        .overrideSeverity(Severity.BLOCKER)
        .at(location)
        .save();
    }
    checker.disabled = false;
    componentIssues.clear();
  }
}
 
开发者ID:SonarSource,项目名称:sonar-lits,代码行数:34,代码来源:DumpPhase.java

示例6: createParserErrorIssue

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private void createParserErrorIssue(SensorContext sensorContext, InputFile inputFile, ParserException pe) {
  RuleKey ruleKey = RuleKey.of(GherkinRulesDefinition.REPOSITORY_NAME, "ParserError");

  ActiveRule activeRule = sensorContext.activeRules().find(ruleKey);
  if (activeRule == null) {
    LOG.debug("Parser Error rule is deactivated. RuleKey: " + ruleKey);
    return;
  }

  TextRange textRange = inputFile.newRange(1,1,1,1);
  //TODO Parser error message contains an address - add it


  NewIssue newIssue = sensorContext.newIssue();

  NewIssueLocation primaryLocation = newIssue.newLocation()
          .message(pe.getMessage())
          .on(inputFile)
          .at(textRange);

  newIssue.forRule(ruleKey).at(primaryLocation);
  newIssue.save();


}
 
开发者ID:silverbulleters,项目名称:sonar-gherkin,代码行数:26,代码来源:GherkinSquidSensor.java

示例7: createSpellCheckIssueObject

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private void createSpellCheckIssueObject(SensorContext sensorContext,
                                         InputFile inputFile,
                                         Node node,
                                         RuleMatch match) {

  // TODO: Don't hardcode the ruleKey
  RuleKey ruleKey = RuleKey.of(GherkinRulesDefinition.REPOSITORY_NAME, "SpellCheck");

  try {

    TextRange textRange = inputFile.newRange(
            node.getLocation().getLine(),
            match.getColumn(),
            node.getLocation().getLine(),
            match.getEndColumn()
    );

    NewIssue newIssue = sensorContext.newIssue();

    String suggestedReplace = "";

    if (!match.getSuggestedReplacements().isEmpty()) {
      suggestedReplace = " - replace it with:";
      for (String suggest: match.getSuggestedReplacements()
              ) {
        suggestedReplace = suggestedReplace + " " + suggest + ";";
      }
    }

    NewIssueLocation primaryLocation = newIssue.newLocation()
            .message(match.getMessage() + suggestedReplace)
            .on(inputFile)
            .at(textRange);

    newIssue.forRule(ruleKey).at(primaryLocation);
    newIssue.save();

  } catch (IllegalArgumentException iarg) {
    LOG.error("SpellCheck rule is an error when create issue: \n" +
            "file is: " + inputFile.relativePath() + "\n" +
            "match is:" + match.getMessage() + "\n" +
            "line is:" + node.getLocation().getLine() + "\n" +
            "offsets is: start - " + match.getColumn() + " to " + match.getEndColumn(),
            iarg);
  }

}
 
开发者ID:silverbulleters,项目名称:sonar-gherkin,代码行数:48,代码来源:GherkinSquidSensor.java

示例8: createNewIssue

import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private boolean createNewIssue(final InputFile inputFile, final XMLReportFinding xanFinding,
		final SensorContext sensorContext) {

	final GeneratedProblemType pt = xanFinding.getProblemType();
	final RuleKey ruleKey = RuleKey.of(XanitizerRulesDefinition.REPOSITORY_KEY, pt.name());
	final int lineNo = normalizeLineNo(xanFinding.getLocation().getLineNoOrMinus1());
	final Severity severity = SensorUtil.mkSeverity(xanFinding);

	final String issueKey = mkIssueKey(ruleKey, inputFile, lineNo);
	final NewIssue alreadyCreatedIssue = alreadyCreatedIssues.get(issueKey);
	if (alreadyCreatedIssue != null) {

		addSecondaryLocation(alreadyCreatedIssue, xanFinding, sensorContext);

		LOG.debug("Issue already exists: " + inputFile + ":" + lineNo + " - "
				+ pt.getPresentationName());
		return false;
	}

	final NewIssue newIssue = sensorContext.newIssue();
	newIssue.forRule(ruleKey);
	newIssue.overrideSeverity(severity);

	final NewIssueLocation newIssueLocation = newIssue.newLocation();
	newIssueLocation.on(inputFile);

	// If line number exceeds the current length of the file,
	// SonarQube will crash. So check length for robustness.
	if (lineNo <= inputFile.lines()) {
		final TextRange textRange = inputFile.selectLine(lineNo);
		newIssueLocation.at(textRange);
	}

	newIssueLocation.message(pt.getMessage());
	newIssue.at(newIssueLocation);
	addSecondaryLocation(newIssue, xanFinding, sensorContext);

	alreadyCreatedIssues.put(issueKey, newIssue);

	LOG.debug("Issue saved: " + inputFile + ":" + lineNo + " - " + pt.getPresentationName());
	return true;
}
 
开发者ID:RIGS-IT,项目名称:sonar-xanitizer,代码行数:43,代码来源:XanitizerSensor.java


注:本文中的org.sonar.api.batch.sensor.SensorContext.newIssue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。