Search in sources :

Example 6 with NewIssue

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

the class OneIssueOnDirPerFileSensor method createIssues.

private static void createIssues(InputFile file, SensorContext context) {
    RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
    InputDir inputDir = context.fileSystem().inputDir(file.file().getParentFile());
    if (inputDir != null) {
        NewIssue newIssue = context.newIssue();
        newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputDir).message("This issue is generated for file " + file.relativePath())).save();
    }
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) InputDir(org.sonar.api.batch.fs.InputDir)

Example 7 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 8 with NewIssue

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

the class HasTagSensor method processFile.

@Override
protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
    org.sonar.api.batch.rule.ActiveRule activeRule = activeRules.find(ruleKey);
    String tag = activeRule.param("tag");
    if (tag == null) {
        throw new IllegalStateException("Rule is badly configured. The parameter 'tag' is missing.");
    }
    try {
        int[] lineCounter = { 1 };
        Files.lines(inputFile.path(), inputFile.charset()).forEachOrdered(lineStr -> {
            int startIndex = -1;
            while ((startIndex = lineStr.indexOf(tag, startIndex + 1)) != -1) {
                NewIssue newIssue = context.newIssue();
                newIssue.forRule(ruleKey).gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)).at(newIssue.newLocation().on(inputFile).at(inputFile.newRange(lineCounter[0], startIndex, lineCounter[0], startIndex + tag.length()))).save();
            }
            lineCounter[0]++;
        });
    } catch (IOException e) {
        throw new IllegalStateException("Fail to process " + inputFile, e);
    }
}
Also used : NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) IOException(java.io.IOException)

Example 9 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.settings().getString(FORCE_SEVERITY_PROPERTY);
    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.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
        } else {
            newIssue.effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
        }
        newIssue.save();
    }
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 10 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)13 RuleKey (org.sonar.api.rule.RuleKey)9 IOException (java.io.IOException)1 Map (java.util.Map)1 Objects (java.util.Objects)1 StreamSupport (java.util.stream.StreamSupport)1 Test (org.junit.Test)1 FilePredicate (org.sonar.api.batch.fs.FilePredicate)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 InputDir (org.sonar.api.batch.fs.InputDir)1 InputFile (org.sonar.api.batch.fs.InputFile)1 Type (org.sonar.api.batch.fs.InputFile.Type)1 TextPointer (org.sonar.api.batch.fs.TextPointer)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 ActiveRule (org.sonar.api.batch.rule.ActiveRule)1 Sensor (org.sonar.api.batch.sensor.Sensor)1 SensorContext (org.sonar.api.batch.sensor.SensorContext)1 SensorDescriptor (org.sonar.api.batch.sensor.SensorDescriptor)1 NewIssueLocation (org.sonar.api.batch.sensor.issue.NewIssueLocation)1