use of org.sonar.api.scan.filesystem.PathResolver 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);
}
}
use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.
the class AbsolutePathPredicate method get.
@Override
public Iterable<InputFile> get(Index index) {
String relative = PathUtils.sanitize(new PathResolver().relativePath(baseDir.toFile(), new File(path)));
if (relative == null) {
return Collections.emptyList();
}
InputFile f = index.inputFile(relative);
return f != null ? Arrays.asList(f) : Collections.<InputFile>emptyList();
}
use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.
the class FileIndexer method indexParentDir.
private void indexParentDir(DefaultModuleFileSystem fileSystem, InputFile inputFile) {
Path parentDir = inputFile.path().getParent();
String relativePath = new PathResolver().relativePath(fileSystem.baseDirPath(), parentDir);
if (relativePath == null) {
throw new IllegalStateException("Failed to compute relative path of file: " + inputFile);
}
DefaultInputDir inputDir = (DefaultInputDir) componentStore.getDir(module.key(), relativePath);
if (inputDir == null) {
inputDir = new DefaultInputDir(fileSystem.moduleKey(), relativePath, batchIdGenerator.get());
inputDir.setModuleBaseDir(fileSystem.baseDirPath());
fileSystem.add(inputDir);
componentTree.index(inputDir, module);
}
componentTree.index(inputFile, inputDir);
}
use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.
the class DefaultPostJobContextTest method prepare.
@Before
public void prepare() {
issueCache = mock(IssueCache.class);
componentStore = new InputComponentStore(new PathResolver());
settings = new MapSettings();
analysisMode = mock(AnalysisMode.class);
context = new DefaultPostJobContext(settings, issueCache, componentStore, analysisMode);
}
use of org.sonar.api.scan.filesystem.PathResolver in project sonarqube by SonarSource.
the class InputFileBuilderTest method setUp.
@Before
public void setUp() throws IOException {
baseDir = temp.newFolder().toPath();
DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create().setKey("module1").setBaseDir(baseDir.toFile()), 0);
PathResolver pathResolver = new PathResolver();
LanguageDetection langDetection = mock(LanguageDetection.class);
MetadataGenerator metadataGenerator = mock(MetadataGenerator.class);
BatchIdGenerator idGenerator = new BatchIdGenerator();
Settings settings = new MapSettings();
builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings);
}
Aggregations