Search in sources :

Example 11 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 12 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 13 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)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