Search in sources :

Example 31 with FileSystem

use of org.sonar.api.batch.fs.FileSystem in project sonar-php by SonarSource.

the class PHPSensor method execute.

@Override
public void execute(SensorContext context) {
    DurationStatistics statistics = new DurationStatistics(context.config());
    FileSystem fileSystem = context.fileSystem();
    FilePredicate phpFilePredicate = fileSystem.predicates().hasLanguage(Php.KEY);
    List<InputFile> inputFiles = new ArrayList<>();
    fileSystem.inputFiles(phpFilePredicate).forEach(inputFiles::add);
    SymbolScanner symbolScanner = new SymbolScanner(context, statistics);
    try {
        symbolScanner.execute(inputFiles);
        ProjectSymbolData projectSymbolData = symbolScanner.getProjectSymbolData();
        new AnalysisScanner(context, projectSymbolData, statistics).execute(inputFiles);
        if (!inSonarLint(context)) {
            processTestsAndCoverage(context);
        }
    } catch (CancellationException e) {
        LOG.info(e.getMessage());
    }
    statistics.log();
}
Also used : ProjectSymbolData(org.sonar.php.symbols.ProjectSymbolData) FilePredicate(org.sonar.api.batch.fs.FilePredicate) DurationStatistics(org.sonar.DurationStatistics) FileSystem(org.sonar.api.batch.fs.FileSystem) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile)

Example 32 with FileSystem

use of org.sonar.api.batch.fs.FileSystem in project sonar-php by SonarSource.

the class PhpIniSensor method execute.

@VisibleForTesting
protected void execute(SensorContext context, Checks<PhpIniCheck> checks) {
    PhpIniParser parser = new PhpIniParser();
    FileSystem fs = context.fileSystem();
    Iterable<InputFile> inputFiles = fs.inputFiles(fs.predicates().matchesPathPattern("**/php.ini"));
    for (InputFile inputFile : inputFiles) {
        PhpIniFile phpIni;
        try {
            phpIni = parser.parse(new PhpFileImpl(inputFile));
        } catch (RecognitionException e) {
            LOG.error("Unable to parse file: " + inputFile.toString());
            LOG.error(e.getMessage());
            continue;
        }
        for (PhpIniCheck check : checks.all()) {
            List<PhpIniIssue> issues = check.analyze(phpIni);
            saveIssues(context, inputFile, checks.ruleKey(check), issues);
        }
    }
}
Also used : PhpIniFile(org.sonar.php.ini.tree.PhpIniFile) PhpIniCheck(org.sonar.php.ini.PhpIniCheck) PhpIniIssue(org.sonar.php.ini.PhpIniIssue) FileSystem(org.sonar.api.batch.fs.FileSystem) PhpFileImpl(org.sonar.php.compat.PhpFileImpl) PhpIniParser(org.sonar.php.ini.PhpIniParser) RecognitionException(com.sonar.sslr.api.RecognitionException) InputFile(org.sonar.api.batch.fs.InputFile) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

FileSystem (org.sonar.api.batch.fs.FileSystem)32 InputFile (org.sonar.api.batch.fs.InputFile)29 FilePredicates (org.sonar.api.batch.fs.FilePredicates)19 File (java.io.File)7 FilePredicate (org.sonar.api.batch.fs.FilePredicate)3 SensorContext (org.sonar.api.batch.sensor.SensorContext)3 RecognitionException (com.sonar.sslr.api.RecognitionException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 CheckFactory (org.sonar.api.batch.rule.CheckFactory)2 NewCoverage (org.sonar.api.batch.sensor.coverage.NewCoverage)2 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)2 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)2 Configuration (org.sonar.api.config.Configuration)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 RuleKey (org.sonar.api.rule.RuleKey)2