Search in sources :

Example 16 with NewIssue

use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.

the class OneBlockerIssuePerFileSensor method processFile.

@Override
protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
    NewIssue newIssue = context.newIssue().overrideSeverity(Severity.BLOCKER).forRule(ruleKey);
    newIssue.at(newIssue.newLocation().on(inputFile).message("This issue is generated on each file. Severity is blocker, whatever quality profile")).save();
}
Also used : NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 17 with NewIssue

use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.

the class OneCodeSmellIssuePerTestLineSensor method createIssues.

private static void createIssues(InputFile file, SensorContext context, String repo) {
    RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
    for (int line = 1; line <= file.lines(); line++) {
        TextRange text = file.selectLine(line);
        // do not count empty lines, which can be a pain with end-of-file return
        if (text.end().lineOffset() == 0) {
            continue;
        }
        NewIssue newIssue = context.newIssue();
        newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(text).message("This code smell issue is generated on each line of a test file")).save();
    }
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) TextRange(org.sonar.api.batch.fs.TextRange)

Example 18 with NewIssue

use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.

the class OneCodeSmellIssuePerLineSensor method createIssues.

private static void createIssues(InputFile file, SensorContext context, String repo) {
    RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
    for (int line = 1; line <= file.lines(); line++) {
        TextRange text = file.selectLine(line);
        // do not count empty lines, which can be a pain with end-of-file return
        if (text.end().lineOffset() == 0) {
            continue;
        }
        NewIssue newIssue = context.newIssue();
        newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(text).message("This code smell issue is generated on each line")).save();
    }
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) TextRange(org.sonar.api.batch.fs.TextRange)

Example 19 with NewIssue

use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.

the class OneIssuePerFileSensor method processFile.

@Override
protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
    NewIssue newIssue = context.newIssue().forRule(ruleKey).gap(settings.getDouble(EFFORT_TO_FIX_PROPERTY).orElse(0.0));
    newIssue.at(newIssue.newLocation().on(inputFile).message("This issue is generated on each file")).save();
}
Also used : NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 20 with NewIssue

use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.

the class OneIssuePerModuleSensor method analyse.

private void analyse(SensorContext context, String language, 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)

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