use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class OneIssuePerLineSensor method createIssues.
private void createIssues(InputFile file, SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
String severity = context.config().get(FORCE_SEVERITY_PROPERTY).orElse(null);
for (int line = 1; line <= file.lines(); line++) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(line)).message("This issue is generated on each line")).overrideSeverity(severity != null ? Severity.valueOf(severity) : null);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null));
} else {
newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null));
}
newIssue.save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class OneIssuePerUnknownFileSensor method execute.
@Override
public void execute(SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
FilePredicate unknownFilesPredicate = context.fileSystem().predicates().matchesPathPattern("**/*.unknown");
Iterable<InputFile> unknownFiles = context.fileSystem().inputFiles(unknownFilesPredicate);
unknownFiles.forEach(inputFile -> {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputFile).message("This issue is generated on each file with extension 'unknown'")).save();
});
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class OneVulnerabilityIssuePerModuleSensor method analyse.
private void analyse(SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(context.module()).message("This issue is generated on each module")).save();
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class TemplateRuleCheck method execute.
@Override
public void execute(SensorContext sensorContext, InputFile file, RuleKey ruleKey) {
NewIssue newIssue = sensorContext.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(line))).save();
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class SensorContextTesterTest method testIssues.
@Test
public void testIssues() {
assertThat(tester.allIssues()).isEmpty();
NewIssue newIssue = tester.newIssue();
newIssue.at(newIssue.newLocation().on(new TestInputFileBuilder("foo", "src/Foo.java").build())).forRule(RuleKey.of("repo", "rule")).save();
newIssue = tester.newIssue();
newIssue.at(newIssue.newLocation().on(new TestInputFileBuilder("foo", "src/Foo.java").build())).forRule(RuleKey.of("repo", "rule")).save();
assertThat(tester.allIssues()).hasSize(2);
}
Aggregations