@Test public void matches_inclusion_patterns() { assertThat(predicates.matchesPathPatterns(new String[] {"src/other/**.java", "src/main/**/Action.java"}).apply(javaFile)).isTrue(); assertThat(predicates.matchesPathPatterns(new String[] {}).apply(javaFile)).isTrue(); assertThat(predicates.matchesPathPatterns(new String[] {"src/other/**.java", "src/**/*.php"}).apply(javaFile)).isFalse(); }
private static boolean checkMissing(PluginContext pluginContext, Object sonarFile, String path, String message) { if (sonarFile == null) { if (pluginContext.getSettings().getBoolean(pluginContext.getConstants().getMissingFileFailKey())) { // check if the file doesn't exist in Sonar due to exclusion patterns InputFile inputFile = new FakeInputFile(path); FilePredicate predicate = pluginContext.getFilesystem().predicates().matchesPathPatterns(new FileExclusions(pluginContext.getSettings()).sourceExclusions()); // if this is an excluded file => just log it // otherwise, throw an error to indicate that the file is required if(predicate.apply(inputFile)) { LOG.info("The file " + path + " is marked as excluded. " + message); } else { throw new SaveException("The file " + path + " doesn't exist"); } } else { LOG.warn("The file " + path + " doesn't exist. " + message); } return false; } else { return true; } }