Search in sources :

Example 1 with Issuable

use of org.sonar.api.issue.Issuable in project sonarqube by SonarSource.

the class OneIssuePerFileSensor method processFile.

@Override
protected void processFile(InputFile inputFile, org.sonar.api.resources.File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey) {
    Issuable issuable = perspectives.as(Issuable.class, sonarFile);
    issuable.addIssue(issuable.newIssueBuilder().ruleKey(ruleKey).effortToFix(settings.getDouble(EFFORT_TO_FIX_PROPERTY)).message("This issue is generated on each file").build());
}
Also used : Issuable(org.sonar.api.issue.Issuable)

Example 2 with Issuable

use of org.sonar.api.issue.Issuable in project sonarqube by SonarSource.

the class DeprecatedResourceApiSensor method createIssueOnDir.

private Directory createIssueOnDir(Directory dir) {
    Issuable issuable = perspectives.as(Issuable.class, dir);
    issuable.addIssue(issuable.newIssueBuilder().ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)).message("Issue created using deprecated API").build());
    return dir;
}
Also used : Issuable(org.sonar.api.issue.Issuable)

Example 3 with Issuable

use of org.sonar.api.issue.Issuable in project sonarqube by SonarSource.

the class IssuableFactoryTest method file_should_be_issuable.

@Test
public void file_should_be_issuable() {
    IssuableFactory factory = new IssuableFactory(mock(DefaultSensorContext.class));
    Issuable issuable = factory.loadPerspective(Issuable.class, new TestInputFileBuilder("foo", "src/Foo.java").build());
    assertThat(issuable).isNotNull();
    assertThat(issuable.issues()).isEmpty();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultSensorContext(org.sonar.scanner.sensor.DefaultSensorContext) Issuable(org.sonar.api.issue.Issuable) Test(org.junit.Test)

Example 4 with Issuable

use of org.sonar.api.issue.Issuable in project sonarqube by SonarSource.

the class DeprecatedResourceApiSensor method analyse.

@Override
public void analyse(Project module, org.sonar.api.batch.SensorContext context) {
    for (File f : fs.files(fs.predicates().and(fs.predicates().hasType(Type.MAIN), fs.predicates().hasLanguage(Xoo.KEY)))) {
        String relativePathFromBaseDir = new PathResolver().relativePath(fs.baseDir(), f);
        org.sonar.api.resources.File sonarFile = org.sonar.api.resources.File.create(relativePathFromBaseDir);
        Issuable issuable = perspectives.as(Issuable.class, sonarFile);
        issuable.addIssue(issuable.newIssueBuilder().ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)).message("Issue created using deprecated API").line(1).build());
        // Message and line are nullable
        issuable.addIssue(issuable.newIssueBuilder().ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)).message(null).line(null).build());
        sonarFile = context.getResource(sonarFile);
        Directory parent = sonarFile.getParent();
        createIssueOnDir(parent);
    }
}
Also used : Issuable(org.sonar.api.issue.Issuable) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) Directory(org.sonar.api.resources.Directory)

Example 5 with Issuable

use of org.sonar.api.issue.Issuable in project sonarqube by SonarSource.

the class OneBlockerIssuePerFileSensor method processFile.

@Override
protected void processFile(InputFile inputFile, org.sonar.api.resources.File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey) {
    Issuable issuable = perspectives.as(Issuable.class, sonarFile);
    issuable.addIssue(issuable.newIssueBuilder().ruleKey(ruleKey).severity(Severity.BLOCKER).message("This issue is generated on each file. Severity is blocker, whatever quality profile").build());
}
Also used : Issuable(org.sonar.api.issue.Issuable)

Aggregations

Issuable (org.sonar.api.issue.Issuable)6 Test (org.junit.Test)2 DefaultSensorContext (org.sonar.scanner.sensor.DefaultSensorContext)2 File (java.io.File)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 Directory (org.sonar.api.resources.Directory)1 PathResolver (org.sonar.api.scan.filesystem.PathResolver)1