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");
}
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);
}
}