From 1715a09211e7adef88a99952d3a0265c485cb68a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 23 Feb 2014 22:39:43 +0100 Subject: [PATCH] SONAR-926 Preload files in DefaultModuleFileSystem --- .../scan/filesystem/DefaultModuleFileSystem.java | 13 +++++++++---- .../api/batch/fs/internal/DefaultFileSystem.java | 12 ++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java index 26477df4011..7cbc39852b5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java @@ -184,10 +184,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module @Override public List files(FileQuery query) { - if (!initialized) { - LOG.warn("Accessing the filesystem before the Sensor phase is deprecated and will not be supported in the future. Please update your plugin."); - indexer.index(this); - } + doPreloadFiles(); Collection predicates = Lists.newArrayList(); for (Map.Entry> entry : query.attributes().entrySet()) { predicates.add(fromDeprecatedAttribute(entry.getKey(), entry.getValue())); @@ -195,6 +192,14 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module return ImmutableList.copyOf(files(FilePredicates.and(predicates))); } + @Override + protected void doPreloadFiles() { + if (!initialized) { + LOG.warn("Accessing the filesystem before the Sensor phase is deprecated and will not be supported in the future. Please update your plugin."); + indexer.index(this); + } + } + public void resetDirs(File basedir, File buildDir, List sourceDirs, List testDirs, List binaryDirs) { if (initialized) { throw new SonarException("Module filesystem is already initialized. Modifications of filesystem are only allowed during Initializer phase."); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java index e5c201e211c..ad5486a21e3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java @@ -109,6 +109,7 @@ public class DefaultFileSystem implements FileSystem { @Override public InputFile inputFile(FilePredicate predicate) { + doPreloadFiles(); if (predicate instanceof UniqueIndexPredicate) { return cache.inputFile((UniqueIndexPredicate) predicate); } @@ -122,16 +123,19 @@ public class DefaultFileSystem implements FileSystem { @Override public Iterable inputFiles(FilePredicate predicate) { + doPreloadFiles(); return Iterables.filter(cache.inputFiles(), new GuavaPredicate(predicate)); } @Override public boolean hasFiles(FilePredicate predicate) { + doPreloadFiles(); return Iterables.indexOf(cache.inputFiles(), new GuavaPredicate(predicate)) >= 0; } @Override public Iterable files(FilePredicate predicate) { + doPreloadFiles(); return Iterables.transform(inputFiles(predicate), new Function() { @Override public File apply(@Nullable InputFile input) { @@ -149,9 +153,17 @@ public class DefaultFileSystem implements FileSystem { @Override public Set languages() { + doPreloadFiles(); return languages; } + /** + * This method is called before each search of files. + */ + protected void doPreloadFiles() { + + } + public static abstract class Cache { protected abstract Iterable inputFiles(); -- 2.39.5