use of org.sonar.api.batch.fs.FilePredicates in project sonar-openedge by Riverside-Software.
the class OpenEdgeWarningsSensor method execute.
@Override
public void execute(SensorContext context) {
if (context.runtime().getProduct() == SonarProduct.SONARLINT)
return;
settings.init();
int warningsImportNum = 0;
final RuleKey defaultWarningRuleKey = RuleKey.of(Constants.STD_REPOSITORY_KEY, OpenEdgeRulesDefinition.COMPILER_WARNING_RULEKEY);
if (context.activeRules().find(defaultWarningRuleKey) == null) {
LOG.info("'Compiler warning' rule is not activated in your profile - Warning files analysis skipped");
return;
}
FilePredicates predicates = context.fileSystem().predicates();
for (InputFile file : context.fileSystem().inputFiles(predicates.and(predicates.hasLanguage(Constants.LANGUAGE_KEY), predicates.hasType(Type.MAIN)))) {
LOG.debug("Looking for warnings of {}", file);
processFile(context, file);
warningsImportNum++;
if (context.isCancelled()) {
LOG.info("Analysis cancelled...");
return;
}
}
LOG.info("{} warning files imported", warningsImportNum);
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-web by SonarSource.
the class WebSensor method execute.
@Override
public void execute(SensorContext sensorContext) {
// configure the lexer
final PageLexer lexer = new PageLexer();
FileSystem fileSystem = sensorContext.fileSystem();
// configure page scanner and the visitors
final HtmlAstScanner scanner = setupScanner(sensorContext);
FilePredicates predicates = fileSystem.predicates();
Iterable<InputFile> inputFiles = fileSystem.inputFiles(predicates.and(predicates.hasType(InputFile.Type.MAIN), predicates.hasLanguage(WebConstants.LANGUAGE_KEY)));
for (InputFile inputFile : inputFiles) {
WebSourceCode sourceCode = new WebSourceCode(inputFile);
try (FileReader reader = new FileReader(inputFile.file())) {
scanner.scan(lexer.parse(reader), sourceCode, fileSystem.encoding());
saveMetrics(sensorContext, sourceCode);
saveLineLevelMeasures(inputFile, sourceCode);
} catch (Exception e) {
LOG.error("Cannot analyze file " + inputFile.file().getAbsolutePath(), e);
}
}
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-go by SonarSource.
the class AbstractReportSensor method getInputFile.
InputFile getInputFile(SensorContext context, String filePath) {
FilePredicates predicates = context.fileSystem().predicates();
InputFile inputFile = context.fileSystem().inputFile(predicates.or(predicates.hasRelativePath(filePath), predicates.hasAbsolutePath(filePath)));
if (inputFile == null) {
LOG.warn(logPrefix() + "No input file found for {}. No {} issues will be imported on this file.", filePath, linterName());
return null;
}
return inputFile;
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-go by SonarSource.
the class GoCoverageReport method findInputFile.
/**
* It is possible that absolutePath references a file that does not exist in the file system.
* It happens when go tests where executed on a different computer.
* Even when absolute path does not match a file of the project, this method try to find a valid
* mach using a shorter relative path.
* @see <a href="https://github.com/SonarSource/sonar-go/issues/218">sonar-go/issues/218</a>
*/
private static InputFile findInputFile(String absolutePath, FileSystem fileSystem) {
FilePredicates predicates = fileSystem.predicates();
InputFile inputFile = fileSystem.inputFile(predicates.hasAbsolutePath(absolutePath));
if (inputFile != null) {
return inputFile;
}
LOG.debug("Resolving file {} using relative path", absolutePath);
Path path = Paths.get(absolutePath);
inputFile = fileSystem.inputFile(predicates.hasRelativePath(path.toString()));
while (inputFile == null && path.getNameCount() > 1) {
path = path.subpath(1, path.getNameCount());
inputFile = fileSystem.inputFile(predicates.hasRelativePath(path.toString()));
}
return inputFile;
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-java by SonarSource.
the class Jasper method findWebInfParentDirectory.
private static Optional<Path> findWebInfParentDirectory(FileSystem fs) {
FilePredicates predicates = fs.predicates();
List<InputFile> inputFiles = new ArrayList<>();
fs.inputFiles(predicates.matchesPathPattern("**/WEB-INF/**")).forEach(inputFiles::add);
if (!inputFiles.isEmpty()) {
Path path = Paths.get(inputFiles.get(0).absolutePath());
Path parent = path.getParent();
while (parent != null) {
if (parent.endsWith("WEB-INF")) {
return Optional.ofNullable(parent.getParent());
}
parent = parent.getParent();
}
}
LOG.debug("WEB-INF directory not found, will use basedir as context root");
return Optional.empty();
}
Aggregations