Search in sources :

Example 41 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.

the class RandomAccessSensor method execute.

@Override
public void execute(SensorContext context) {
    File f = new File(context.config().get(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS).orElseThrow(() -> new IllegalStateException("Required property")));
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    try {
        for (String path : FileUtils.readLines(f)) {
            createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) IOException(java.io.IOException) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File)

Example 42 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates in project sonar-web by SonarSource.

the class HtmlSensor method execute.

@Override
public void execute(SensorContext sensorContext) {
    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.or(predicates.hasLanguages(HtmlConstants.LANGUAGE_KEY, HtmlConstants.JSP_LANGUAGE_KEY), predicates.or(Stream.of(OTHER_FILE_SUFFIXES).map(predicates::hasExtension).toArray(FilePredicate[]::new)))));
    for (InputFile inputFile : inputFiles) {
        if (sensorContext.isCancelled()) {
            return;
        }
        HtmlSourceCode sourceCode = new HtmlSourceCode(inputFile);
        try (Reader reader = new InputStreamReader(inputFile.inputStream(), inputFile.charset())) {
            PageLexer lexer = inputFile.filename().endsWith(".vue") ? new VueLexer() : new PageLexer();
            scanner.scan(lexer.parse(reader), sourceCode);
            saveMetrics(sensorContext, sourceCode);
            saveLineLevelMeasures(inputFile, sourceCode);
        } catch (Exception e) {
            LOG.error("Cannot analyze file " + inputFile, e);
            sensorContext.newAnalysisError().onFile(inputFile).message(e.getMessage()).save();
        }
    }
}
Also used : VueLexer(org.sonar.plugins.html.lex.VueLexer) PageLexer(org.sonar.plugins.html.lex.PageLexer) InputStreamReader(java.io.InputStreamReader) FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) HtmlAstScanner(org.sonar.plugins.html.visitor.HtmlAstScanner) InputFile(org.sonar.api.batch.fs.InputFile)

Example 43 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates in project sonar-findbugs by spotbugs.

the class FindbugsConfigurationTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    baseDir = new File(temp, "findbugs");
    workDir = new File(temp, "findbugs");
    filePredicates = mock(FilePredicates.class);
    fs = mock(FileSystem.class);
    when(fs.baseDir()).thenReturn(baseDir);
    when(fs.workDir()).thenReturn(workDir);
    when(fs.predicates()).thenReturn(filePredicates);
    activeRules = FakeActiveRules.createWithOnlyFindbugsRules();
    configuration = new SimpleConfiguration();
    javaResourceLocator = mock(JavaResourceLocator.class);
    conf = new FindbugsConfiguration(fs, configuration, activeRules, javaResourceLocator);
}
Also used : FilePredicates(org.sonar.api.batch.fs.FilePredicates) FileSystem(org.sonar.api.batch.fs.FileSystem) SimpleConfiguration(org.sonar.plugins.findbugs.configuration.SimpleConfiguration) JavaResourceLocator(org.sonar.plugins.java.api.JavaResourceLocator) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

FilePredicates (org.sonar.api.batch.fs.FilePredicates)43 InputFile (org.sonar.api.batch.fs.InputFile)38 FileSystem (org.sonar.api.batch.fs.FileSystem)22 File (java.io.File)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Path (java.nio.file.Path)4 FilePredicate (org.sonar.api.batch.fs.FilePredicate)4 SensorContext (org.sonar.api.batch.sensor.SensorContext)4 RuleKey (org.sonar.api.rule.RuleKey)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)3 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 StreamSupport (java.util.stream.StreamSupport)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ActiveRule (org.sonar.api.batch.rule.ActiveRule)2