Search in sources :

Example 1 with Directory

use of org.sonar.api.resources.Directory in project sonarqube by SonarSource.

the class ComponentKeysTest method create_effective_key.

@Test
public void create_effective_key() {
    Project project = new Project(ProjectDefinition.create().setKey("my_project"));
    assertThat(ComponentKeys.createEffectiveKey("my_project", project)).isEqualTo("my_project");
    Directory dir = Directory.create("src/org/foo");
    assertThat(ComponentKeys.createEffectiveKey("my_project", dir)).isEqualTo("my_project:src/org/foo");
    InputFile file = mock(InputFile.class);
    when(file.relativePath()).thenReturn("foo/Bar.php");
    assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php");
}
Also used : Project(org.sonar.api.resources.Project) Directory(org.sonar.api.resources.Directory) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 2 with Directory

use of org.sonar.api.resources.Directory 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)

Aggregations

Directory (org.sonar.api.resources.Directory)2 File (java.io.File)1 Test (org.junit.Test)1 InputFile (org.sonar.api.batch.fs.InputFile)1 Issuable (org.sonar.api.issue.Issuable)1 Project (org.sonar.api.resources.Project)1 PathResolver (org.sonar.api.scan.filesystem.PathResolver)1