Search in sources :

Example 21 with NewIssue

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();
    }
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 22 with NewIssue

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();
    });
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) FilePredicate(org.sonar.api.batch.fs.FilePredicate) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) InputFile(org.sonar.api.batch.fs.InputFile)

Example 23 with NewIssue

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();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 24 with NewIssue

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();
}
Also used : NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 25 with NewIssue

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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) Test(org.junit.Test)

Aggregations

NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)28 RuleKey (org.sonar.api.rule.RuleKey)15 InputFile (org.sonar.api.batch.fs.InputFile)5 NewIssueLocation (org.sonar.api.batch.sensor.issue.NewIssueLocation)5 TextRange (org.sonar.api.batch.fs.TextRange)4 Map (java.util.Map)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 ActiveRule (org.sonar.api.batch.rule.ActiveRule)2 Sensor (org.sonar.api.batch.sensor.Sensor)2 SensorContext (org.sonar.api.batch.sensor.SensorContext)2 SensorDescriptor (org.sonar.api.batch.sensor.SensorDescriptor)2 Metric (org.sonar.api.measures.Metric)2 Clock (java.time.Clock)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1