@Override
public List<File> 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<FilePredicate> predicates = Lists.newArrayList();
for (Map.Entry<String, Collection<String>> entry : query.attributes().entrySet()) {
predicates.add(fromDeprecatedAttribute(entry.getKey(), entry.getValue()));
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<File> sourceDirs, List<File> testDirs, List<File> binaryDirs) {
if (initialized) {
throw new SonarException("Module filesystem is already initialized. Modifications of filesystem are only allowed during Initializer phase.");
@Override
public InputFile inputFile(FilePredicate predicate) {
+ doPreloadFiles();
if (predicate instanceof UniqueIndexPredicate) {
return cache.inputFile((UniqueIndexPredicate) predicate);
}
@Override
public Iterable<InputFile> 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<File> files(FilePredicate predicate) {
+ doPreloadFiles();
return Iterables.transform(inputFiles(predicate), new Function<InputFile, File>() {
@Override
public File apply(@Nullable InputFile input) {
@Override
public Set<String> languages() {
+ doPreloadFiles();
return languages;
}
+ /**
+ * This method is called before each search of files.
+ */
+ protected void doPreloadFiles() {
+
+ }
+
public static abstract class Cache {
protected abstract Iterable<InputFile> inputFiles();