/** * Test whether a file should be selected. * * @param name the filename to check for selecting. * @param file the java.io.File object for this filename. * @return <code>false</code> when the selectors says that the file * should not be selected, <code>true</code> otherwise. */ protected boolean isSelected(final String name, final File file) { return selectors == null || Stream.of(selectors).allMatch(sel -> sel.isSelected(basedir, name, file)); }
/** * Implement a basic {@link Resource} selection that delegates to this * {@link FileSelector}. * @param r resource * @return whether the resource is selected */ default boolean isSelected(Resource r) { return r.asOptional(FileProvider.class).map(FileProvider::getFile) .map(f -> isSelected(null, null, f)).orElse(false); } }
/** * Returns true (the file is selected) only if all other selectors * agree that the file should be selected. * * @param basedir the base directory the scan is being done from * @param filename the name of the file to check * @param file a java.io.File object for the filename that the selector * can use * @return whether the file should be selected or not */ public boolean isSelected(File basedir, String filename, File file) { validate(); return Stream.of(getSelectors(getProject())) .allMatch(s -> s.isSelected(basedir, filename, file)); }
/** * Allows the custom selector to choose whether to select a file. This * is also where the Parameters are passed to the custom selector, * since we know we must have them all by now. And since we must know * both classpath and classname, creating the class is deferred to here * as well. * @param basedir The the base directory. * @param filename The name of the file to check. * @param file A File object for this filename. * @return whether the file should be selected or not. * @exception BuildException if an error occurs. */ public boolean isSelected(File basedir, String filename, File file) throws BuildException { validate(); if (!parameters.isEmpty() && dynselector instanceof ExtendFileSelector) { // We know that dynselector must be non-null if no error message ((ExtendFileSelector) dynselector).setParameters( parameters.toArray(new Parameter[parameters.size()])); } return dynselector.isSelected(basedir, filename, file); }
/** * Returns true (the file is selected) only if all other selectors * agree that the file should not be selected. * * @param basedir the base directory the scan is being done from * @param filename is the name of the file to check * @param file is a java.io.File object for the filename that the selector * can use * @return whether the file should be selected or not */ public boolean isSelected(File basedir, String filename, File file) { validate(); return Stream.of(getSelectors(getProject())) .noneMatch(s -> s.isSelected(basedir, filename, file)); }
/** * Returns true (the file is selected) if any of the other selectors * agree that the file should be selected. * * @param basedir the base directory the scan is being done from * @param filename the name of the file to check * @param file a java.io.File object for the filename that the selector * can use * @return whether the file should be selected or not */ public boolean isSelected(File basedir, String filename, File file) { validate(); return Stream.of(getSelectors(getProject())) .anyMatch(s -> s.isSelected(basedir, filename, file)); }
if (fs.isSelected(basedir, filename, file)) { yesvotes++; } else {
/** * Returns true (the file is selected) only if the if property (if any) * exists, the unless property (if any) doesn't exist, and the * contained selector (if any) selects the file. If there is no contained * selector, return true (because we assume that the point was to test * the if and unless conditions). * * @param basedir the base directory the scan is being done from * @param filename the name of the file to check * @param file a java.io.File object for the filename that the selector * can use * @return whether the file should be selected or not */ @Override public boolean isSelected(File basedir, String filename, File file) { validate(); // Deal with if and unless properties first if (!passesConditions()) { return false; } Enumeration<FileSelector> e = selectorElements(); return !e.hasMoreElements() || e.nextElement().isSelected(basedir, filename, file); } }
/** * Evaluate the selector with the file. * @return true if the file is selected by the embedded selector. */ public boolean eval() { if (file == null) { throw new BuildException("file attribute not set"); } validate(); File myBaseDir = baseDir; if (myBaseDir == null) { myBaseDir = getProject().getBaseDir(); } FileSelector f = getSelectors(getProject())[0]; return f.isSelected( myBaseDir, FILE_UTILS.removeLeadingPath(myBaseDir, file), file); } }
@Override public boolean isSelected(File basedir, String pathRelativeToBaseDir, File file) throws BuildException { if (originalSelector != null && !originalSelector.isSelected(basedir, pathRelativeToBaseDir, file)) { return false; } if (CONFIGS_TO_MATCH.matcher(pathRelativeToBaseDir).matches()) { return true; } if (JOBS_DIR_NAME.equals(pathRelativeToBaseDir)) { return true; } if (!pathRelativeToBaseDir.endsWith("/")) { pathRelativeToBaseDir += '/'; } if (pathRelativeToBaseDir.endsWith('/' + JOBS_DIR_NAME + '/')) { pathRelativeToBaseDir = StringUtils.removeEnd(pathRelativeToBaseDir, JOBS_DIR_NAME + '/'); return DIRECTORIES_TO_MATCH.matcher(pathRelativeToBaseDir).matches(); } else { // Compare https://github.com/jenkinsci/cloudbees-folder-plugin/blob/70a4d47314a36b54d522cae0a78b3c76d153e627/src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java#L200 // The Cloudbees Folders plugin prunes the hierarchy on directories not containing a config.xml. return DIRECTORIES_TO_MATCH.matcher(pathRelativeToBaseDir).matches() && file.isDirectory() && new File(file, CONFIG_FILE_NAME).exists(); } } };