use of org.sonar.api.batch.sensor.issue.NewIssue in project sonar-web by SonarSource.
the class HtmlSensor method saveMetrics.
private static void saveMetrics(SensorContext context, HtmlSourceCode sourceCode) {
InputFile inputFile = sourceCode.inputFile();
for (Map.Entry<Metric<Integer>, Integer> entry : sourceCode.getMeasures().entrySet()) {
context.<Integer>newMeasure().on(inputFile).forMetric(entry.getKey()).withValue(entry.getValue()).save();
}
for (HtmlIssue issue : sourceCode.getIssues()) {
NewIssue newIssue = context.newIssue().forRule(issue.ruleKey()).gap(issue.cost());
NewIssueLocation location = locationForIssue(inputFile, issue, newIssue);
newIssue.at(location);
newIssue.save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarlint-core by SonarSource.
the class GlobalSensor method execute.
@Override
public void execute(final SensorContext context) {
long timeBefore = clock.millis();
RuleKey globalRuleKey = RuleKey.of(GlobalRulesDefinition.KEY, GlobalRulesDefinition.RULE_KEY);
ActiveRule activeGlobalRule = context.activeRules().find(globalRuleKey);
if (activeGlobalRule != null) {
Stream.of("stringParam", "textParam", "intParam", "boolParam", "floatParam", "enumParam", "enumListParam", "multipleIntegersParam").map(k -> Arrays.asList(k, activeGlobalRule.param(k))).forEach(kv -> LOGGER.info("Param {} has value {}", kv.get(0), kv.get(1)));
} else {
LOGGER.error("Rule is not active");
}
for (InputFile f : context.fileSystem().inputFiles(context.fileSystem().predicates().all())) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(globalRuleKey).at(newIssue.newLocation().on(f).message("Issue number " + GlobalExtension.getInstance().getAndInc())).save();
}
long timeAfter = clock.millis();
LOGGER.info(String.format("Executed Global Sensor in %d ms", timeAfter - timeBefore));
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarlint-core by SonarSource.
the class OneIssuePerLineSensor method execute.
@Override
public void execute(final SensorContext context) {
for (InputFile f : context.fileSystem().inputFiles(context.fileSystem().predicates().all())) {
for (int i = 1; i < f.lines(); i++) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(RuleKey.of(FooLintRulesDefinition.KEY, "ExampleRule1")).at(newIssue.newLocation().on(f).at(f.selectLine(i)).message("Issue at line " + i)).save();
}
}
}
Aggregations