@Test public void or() { // empty assertThat(predicates.or().apply(javaFile)).isTrue(); assertThat(predicates.or(new FilePredicate[0]).apply(javaFile)).isTrue(); assertThat(predicates.or(Collections.<FilePredicate>emptyList()).apply(javaFile)).isTrue(); // two arguments assertThat(predicates.or(predicates.all(), predicates.all()).apply(javaFile)).isTrue(); assertThat(predicates.or(predicates.all(), predicates.none()).apply(javaFile)).isTrue(); assertThat(predicates.or(predicates.none(), predicates.all()).apply(javaFile)).isTrue(); assertThat(predicates.or(predicates.none(), predicates.none()).apply(javaFile)).isFalse(); // collection assertThat(predicates.or(Arrays.asList(predicates.all(), predicates.all())).apply(javaFile)).isTrue(); assertThat(predicates.or(Arrays.asList(predicates.all(), predicates.none())).apply(javaFile)).isTrue(); assertThat(predicates.or(Arrays.asList(predicates.none(), predicates.none())).apply(javaFile)).isFalse(); // array assertThat(predicates.or(new FilePredicate[] {predicates.all(), predicates.all()}).apply(javaFile)).isTrue(); assertThat(predicates.or(new FilePredicate[] {predicates.all(), predicates.none()}).apply(javaFile)).isTrue(); assertThat(predicates.or(new FilePredicate[] {predicates.none(), predicates.none()}).apply(javaFile)).isFalse(); }
private static FilePredicate getFileNamePredicateFromSuffixes(FilePredicates p, String fileName, String[] suffixes) { List<FilePredicate> fileNamePredicates = new ArrayList<>(suffixes.length); for (String suffix : suffixes) { fileNamePredicates.add(p.matchesPathPattern("**/" + fileName + suffix)); } return p.or(fileNamePredicates); }
private static FilePredicate filterTypePredicate(FileSystem fileSystem, Type... types) { FilePredicates predicatesFactory = fileSystem.predicates(); Collection<FilePredicate> typePredicates = new ArrayList<FilePredicate>(types.length); for (Type type : types) { typePredicates.add(predicatesFactory.hasType(type)); } return typePredicates.isEmpty() ? predicatesFactory.all() : predicatesFactory.or(typePredicates); }
private FilePredicate fromDeprecatedAttribute(String key, Collection<String> value) { if ("TYPE".equals(key)) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) {
private FilePredicate fromDeprecatedAttribute(String key, Collection<String> value) { if ("TYPE".equals(key)) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) { return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() { @Override public FilePredicate apply(@Nullable String s) {
private static FilePredicate searchFilePredicate(FileSystem fileSystem, String path) { FilePredicates predicatesFactory = fileSystem.predicates(); Collection<FilePredicate> searchPredicates = new ArrayList<FilePredicate>(); // try to find the file directly using the provided path (absolute or // relative) searchPredicates.add(predicatesFactory.hasPath(path)); // if not found, maybe the path starts with '/' // in this case, Sonar thinks it's an absolute path => manually try // relative if (path.startsWith("/")) { searchPredicates.add(predicatesFactory.hasRelativePath(path.substring(1))); } // if not found, try to search it everywhere searchPredicates.add(predicatesFactory.matchesPathPattern("**" + path)); return predicatesFactory.or(searchPredicates); }
public static FilePredicate createFilePredicate(Configuration configuration, SensorContext sensorContext) { FilePredicates predicates = sensorContext.fileSystem().predicates(); List<FilePredicate> fileExtensions = getFileExtensionsPredicates(predicates, configuration); List<FilePredicate> relativePaths = getPathsPredicate(predicates, configuration); return predicates.and( predicates.hasType(InputFile.Type.MAIN), predicates.or( predicates.hasLanguages(Htl.KEY), predicates.or(fileExtensions) ), predicates.or(relativePaths) ); }
private FilePredicate mainFilePredicate(FileSystem fileSystem) { String[] suffixes = getSettings().getStringArray(Plugin.EMBEDDED_CSS_FILE_SUFFIXES_KEY); if (suffixes == null || suffixes.length == 0) { suffixes = StringUtils.split(Plugin.CSS_FILE_SUFFIXES_DEFAULT_VALUE, ","); } List<FilePredicate> filePredicates = new ArrayList<>(); for (String suffix : suffixes) { filePredicates.add(fileSystem.predicates().matchesPathPattern("**/*." + suffix)); } return fileSystem.predicates().or(filePredicates); }
private FilePredicate newHasLanguagesPredicate(Language... languages) { List<FilePredicate> list = Lists.newArrayList(); for (Language language : languages) { list.add(target.predicates().hasLanguage(language.getKey())); } return target.predicates().or(list); } }
public static List<InputFile> searchFileWithTypeMainOrTest(final SensorContext context) { FilePredicates predicate = context.fileSystem().predicates(); Iterable<InputFile> iter = context.fileSystem().inputFiles(predicate.and(predicate.hasLanguage(GoLanguage.KEY), predicate.or(predicate.hasType(InputFile.Type.MAIN), predicate.hasType(InputFile.Type.TEST)))); final List<InputFile> listFiles = new ArrayList<>(); iter.forEach(listFiles::add); return listFiles; }
private static InputFile getInputFile(SensorContext context, String fileName) { FilePredicates predicates = context.fileSystem().predicates(); InputFile inputFile = context.fileSystem().inputFile(predicates.or(predicates.hasRelativePath(fileName), predicates.hasAbsolutePath(fileName))); if (inputFile == null) { LOG.warn("No input file found for {}. No {} issues will be imported on this file.", fileName, LINTER_NAME); return null; } return inputFile; }
private static InputFile getInputFile(SensorContext context, String fileName) { FilePredicates predicates = context.fileSystem().predicates(); InputFile inputFile = context.fileSystem().inputFile(predicates.or(predicates.hasRelativePath(fileName), predicates.hasAbsolutePath(fileName))); if (inputFile == null) { LOG.warn("No input file found for {}. No {} issues will be imported on this file.", fileName, LINTER_NAME); return null; } return inputFile; }
InputFile getInputFile(SensorContext context, String filePath) { FilePredicates predicates = context.fileSystem().predicates(); InputFile inputFile = context.fileSystem().inputFile(predicates.or(predicates.hasRelativePath(filePath), predicates.hasAbsolutePath(filePath))); if (inputFile == null) { LOG.warn(logPrefix() + "No input file found for {}. No {} issues will be imported on this file.", filePath, linterName()); return null; } return inputFile; }
/** * Determine if the project has Java source files. This is used to determine if the project has no compiled classes on * purpose or because the compilation was omit from the process. * @return If at least one Java file is present */ private boolean hasSourceFiles() { FilePredicates pred = fileSystem.predicates(); return fileSystem.hasFiles( pred.and( pred.hasType(Type.MAIN), pred.or(FindbugsPlugin.getSupportedLanguagesFilePredicate(pred)), //package-info.java will not generate any class files. //See: https://github.com/SonarQubeCommunity/sonar-findbugs/issues/36 pred.not(pred.matchesPathPattern("**/package-info.java")), pred.not(pred.matchesPathPattern("**/module-info.java")), pred.not(pred.matchesPathPattern("**/*.jsp")) ) ); }