*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
+import org.sonar.api.batch.fs.internal.AbstractFilePredicate;
+
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.batch.fs;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import org.sonar.api.batch.fs.FileSystem.Index;
-
-/**
- * Partial implementation of {@link FilePredicate}.
- * @since 5.1
- */
-public abstract class AbstractFilePredicate implements FilePredicate {
-
- protected static final int DEFAULT_PRIORITY = 10;
- protected static final int USE_INDEX = 20;
-
- @Override
- public Iterable<InputFile> filter(Iterable<InputFile> target) {
- return Iterables.filter(target, new Predicate<InputFile>() {
- @Override
- public boolean apply(InputFile input) {
- return AbstractFilePredicate.this.apply(input);
- }
- });
- }
-
- @Override
- public Iterable<InputFile> get(Index index) {
- return filter(index.inputFiles());
- }
-
- @Override
- public int priority() {
- return DEFAULT_PRIORITY;
- }
-
- @Override
- public int compareTo(FilePredicate o) {
- return o.priority() - priority();
- }
-
-}
*/
package org.sonar.api.batch.fs;
-import org.sonar.api.batch.fs.internal.RelativePathPredicate;
/**
* Determines if a file must be kept in search results. See {@link org.sonar.api.batch.fs.FileSystem}
* and {@link org.sonar.api.batch.fs.FilePredicates}.
* @since 4.2
*/
-public interface FilePredicate extends Comparable<FilePredicate> {
+public interface FilePredicate {
/**
* Test if provided file is valid for this predicate
*/
boolean apply(InputFile inputFile);
- /**
- * Filter provided files to keep only the ones that are valid for this predicate
- */
- Iterable<InputFile> filter(Iterable<InputFile> inputFiles);
-
- /**
- * Get all files that are valid for this predicate.
- */
- Iterable<InputFile> get(FileSystem.Index index);
-
- /**
- * For optimization. FilePredicates will be applied in priority order. For example when doing
- * p.and(p1, p2, p3) then p1, p2 and p3 will be applied according to their priority value. Higher priority value
- * are applied first.
- * Assign a high priority when the predicate will likely highly reduce the set of InputFiles to filter. Also
- * {@link RelativePathPredicate} and AbsolutePathPredicate have a high priority since they are using cache index.
- */
- int priority();
}
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.scan.filesystem.PathResolver;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.FileSystem.Index;
+import org.sonar.api.batch.fs.InputFile;
+
+/**
+ * Partial implementation of {@link FilePredicate}.
+ * @since 5.1
+ */
+public abstract class AbstractFilePredicate implements OptimizedFilePredicate {
+
+ protected static final int DEFAULT_PRIORITY = 10;
+ protected static final int USE_INDEX = 20;
+
+ @Override
+ public Iterable<InputFile> filter(Iterable<InputFile> target) {
+ return Iterables.filter(target, new Predicate<InputFile>() {
+ @Override
+ public boolean apply(InputFile input) {
+ return AbstractFilePredicate.this.apply(input);
+ }
+ });
+ }
+
+ @Override
+ public Iterable<InputFile> get(Index index) {
+ return filter(index.inputFiles());
+ }
+
+ @Override
+ public int priority() {
+ return DEFAULT_PRIORITY;
+ }
+
+ @Override
+ public final int compareTo(OptimizedFilePredicate o) {
+ return o.priority() - priority();
+ }
+
+}
package org.sonar.api.batch.fs.internal;
import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.InputFile;
*/
class AndPredicate extends AbstractFilePredicate {
- private final List<FilePredicate> predicates = new ArrayList<>();
+ private final List<OptimizedFilePredicate> predicates = new ArrayList<>();
private AndPredicate() {
}
} else if (filePredicate instanceof AndPredicate) {
result.predicates.addAll(((AndPredicate) filePredicate).predicates);
} else {
- result.predicates.add(filePredicate);
+ result.predicates.add(OptimizedFilePredicateAdapter.create(filePredicate));
}
}
Collections.sort(result.predicates);
@Override
public boolean apply(InputFile f) {
- for (FilePredicate predicate : predicates) {
+ for (OptimizedFilePredicate predicate : predicates) {
if (!predicate.apply(f)) {
return false;
}
@Override
public Iterable<InputFile> filter(Iterable<InputFile> target) {
Iterable<InputFile> result = target;
- for (FilePredicate predicate : predicates) {
+ for (OptimizedFilePredicate predicate : predicates) {
result = predicate.filter(result);
}
return result;
}
@VisibleForTesting
- Collection<FilePredicate> predicates() {
+ Collection<OptimizedFilePredicate> predicates() {
return predicates;
}
@Override
public Iterable<InputFile> inputFiles(FilePredicate predicate) {
doPreloadFiles();
- return predicate.get(cache);
+ return OptimizedFilePredicateAdapter.create(predicate).get(cache);
}
@Override
public boolean hasFiles(FilePredicate predicate) {
- doPreloadFiles();
- return predicate.get(cache).iterator().hasNext();
+ return inputFiles(predicate).iterator().hasNext();
}
@Override
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.InputFile;
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
import org.sonar.api.batch.fs.InputFile;
/**
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.InputFile;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
+
+/**
+ * Optimized version of FilePredicate allowing to speed up query by looking at InputFile by index.
+ */
+public interface OptimizedFilePredicate extends FilePredicate, Comparable<OptimizedFilePredicate> {
+
+ /**
+ * Filter provided files to keep only the ones that are valid for this predicate
+ */
+ Iterable<InputFile> filter(Iterable<InputFile> inputFiles);
+
+ /**
+ * Get all files that are valid for this predicate.
+ */
+ Iterable<InputFile> get(FileSystem.Index index);
+
+ /**
+ * For optimization. FilePredicates will be applied in priority order. For example when doing
+ * p.and(p1, p2, p3) then p1, p2 and p3 will be applied according to their priority value. Higher priority value
+ * are applied first.
+ * Assign a high priority when the predicate will likely highly reduce the set of InputFiles to filter. Also
+ * {@link RelativePathPredicate} and AbsolutePathPredicate have a high priority since they are using cache index.
+ */
+ int priority();
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.InputFile;
+
+class OptimizedFilePredicateAdapter extends AbstractFilePredicate {
+
+ private FilePredicate unoptimizedPredicate;
+
+ private OptimizedFilePredicateAdapter(FilePredicate unoptimizedPredicate) {
+ this.unoptimizedPredicate = unoptimizedPredicate;
+ }
+
+ @Override
+ public boolean apply(InputFile inputFile) {
+ return unoptimizedPredicate.apply(inputFile);
+ }
+
+ public static OptimizedFilePredicate create(FilePredicate predicate) {
+ if (predicate instanceof OptimizedFilePredicate) {
+ return (OptimizedFilePredicate) predicate;
+ } else {
+ return new OptimizedFilePredicateAdapter(predicate);
+ }
+ }
+
+}
package org.sonar.api.batch.fs.internal;
import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.InputFile;
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
import org.sonar.api.batch.fs.InputFile;
/**
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.PathUtils;
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
import org.sonar.api.batch.fs.InputFile;
/**
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.InputFile;
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
import org.sonar.api.batch.fs.InputFile;
/**