List of usage examples for org.apache.commons.io.filefilter FalseFileFilter FALSE
IOFileFilter FALSE
To view the source code for org.apache.commons.io.filefilter FalseFileFilter FALSE.
Click Source Link
From source file:org.sonar.batch.scan.filesystem.LanguageFiltersTest.java
@Test public void forLang() throws Exception { LanguageFilters filters = new LanguageFilters(new Languages(new Java(), new Php())); IOFileFilter filter = filters.forLang("php"); assertThat(filter).isInstanceOf(SuffixFileFilter.class); assertThat(suffixes((SuffixFileFilter) filter)).containsOnly("php"); filter = filters.forLang("java"); assertThat(filter).isInstanceOf(SuffixFileFilter.class); assertThat(suffixes((SuffixFileFilter) filter)).containsOnly("java", "jav"); assertThat(filters.forLang("unknown")).isSameAs(FalseFileFilter.FALSE); }
From source file:org.sonar.java.JavaClasspath.java
private List<File> getMatchingFiles(String pattern, File dir, boolean libraryProperty) { WilcardPatternFileFilter wilcardPatternFileFilter = new WilcardPatternFileFilter(dir, pattern); FileFilter fileFilter = wilcardPatternFileFilter; List<File> files = Lists.newArrayList(); if (libraryProperty) { if (pattern.endsWith("*")) { fileFilter = new AndFileFilter((IOFileFilter) fileFilter, new OrFileFilter(Lists.newArrayList(suffixFileFilter(".jar", IOCase.INSENSITIVE), suffixFileFilter(".zip", IOCase.INSENSITIVE)))); }//from w w w .ja v a 2 s . co m //find jar and zip files files.addAll( Lists.newArrayList(FileUtils.listFiles(dir, (IOFileFilter) fileFilter, TrueFileFilter.TRUE))); } //find directories matching pattern. IOFileFilter subdirectories = pattern.isEmpty() ? FalseFileFilter.FALSE : TrueFileFilter.TRUE; Collection<File> dirs = FileUtils.listFilesAndDirs(dir, new AndFileFilter(wilcardPatternFileFilter, DirectoryFileFilter.DIRECTORY), subdirectories); //remove searching dir from matching as listFilesAndDirs always includes it in the list see https://issues.apache.org/jira/browse/IO-328 if (!pattern.isEmpty()) { dirs.remove(dir); //remove subdirectories that were included during search Iterator<File> iterator = dirs.iterator(); while (iterator.hasNext()) { File matchingDir = iterator.next(); if (!wilcardPatternFileFilter.accept(matchingDir)) { iterator.remove(); } } } if (libraryProperty) { for (File directory : dirs) { files.addAll(getMatchingFiles("**/*.jar", directory, true)); files.addAll(getMatchingFiles("**/*.zip", directory, true)); } } files.addAll(dirs); return files; }
From source file:org.sonatype.nexus.testsuite.task.nexus2692.AbstractEvictTaskIt.java
@SuppressWarnings("unchecked") protected SortedSet<String> getDirectoryPaths(File basedir) throws IOException { SortedSet<String> result = new TreeSet<String>(); Collection<File> files = FileUtils.listFilesAndDirs(basedir, FalseFileFilter.FALSE, TrueFileFilter.TRUE); for (File file : files) { if (!file.equals(basedir)) { String path = file.getPath(); if (path.startsWith(basedir.getAbsolutePath())) { path = path.substring(basedir.getAbsolutePath().length() + 1); }/*www . j a v a 2 s . c o m*/ result.add(path.replaceAll(Pattern.quote("\\"), "/")); } } return result; }
From source file:xmlconverter.controller.logic.GetFileCount.java
/** * Creates Document so that XML file can be filled with information. Here * where it all begins. Those if statements will first check if files[] is * not empty then loop trough files[] and get path of every directory. In * the process it passes list of child files/directories paths ("depending * on the filter that is used") of a parent file to method called * writeFile(). Before that happens it checks if here are any duplicate * files that have been handed to the method(It should not happen). After * this operation is done it call itself again. Till every folder has been * visited.//from w w w. j av a2 s. c om * * @param site * @throws javax.xml.transform.TransformerException * @throws javax.xml.parsers.ParserConfigurationException * @throws org.xml.sax.SAXException * @throws java.io.IOException */ public void writeFile(Site site) throws TransformerException, DOMException, ParserConfigurationException, IOException, SAXException { ArrayList<String> detectionList = site.getSiteAsArrayList(); File startPath = bean.getEnvBean().getSiteDir(); Collection<File> startFiles = FileUtils.listFilesAndDirs(startPath, FalseFileFilter.FALSE, DirectoryFileFilter.DIRECTORY); File[] startFilesSorted = startFiles.toArray(new File[startFiles.size()]); Arrays.sort(startFilesSorted); for (File path : startFilesSorted) { //Start of the file CreateGraphicsNode createGraphicsNode = new CreateGraphicsNode(); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element root = doc.createElement("GraphicsContainerNode"); Element startMelder = doc.createElement("GraphicsNode"); Element endMelder = doc.createElement("GraphicsNode"); doc.appendChild(root); //This method also does update. It is actually enables other method to //do update if flag is set to 1 File[] pathFiles = path.listFiles(directoryFilter); Arrays.sort(pathFiles); for (File desc : pathFiles) { root.appendChild(createGraphicsNode.getGraphicsNode(doc, desc, home)); } if (path.getName().contains("Automatische Gruppe") || path.getName().contains("Manuelle Gruppe")) { ArrayList<String> detectionObjects = new ArrayList<>(); String pattern = path.getName().trim(); int index = detectionList.indexOf(pattern); while (detectionList.get(index + 1).contains("Manual") || detectionList.get(index + 1).contains("Automatic")) { detectionObjects.add(detectionList.get(index + 1)); detectionObjects.add(detectionList.get(index + 2)); index += 2; } //This is more efficient way to retrieve information! o guess that helped. if (!detectionObjects.isEmpty()) { int end = path.getName().indexOf("_"); String mg = path.getName().substring(0, end); String start; String ending; if ((maNumber + 1) >= 10) { start = (maNumber + 1) + "/11*" + mg + " .."; ending = (maNumber + 1) + "/11*" + mg + " 00"; } else { start = "0" + (maNumber + 1) + "/11*" + mg + " .."; ending = "0" + (maNumber + 1) + "/11*" + mg + " 00"; } startMelder.setAttribute("id", start); startMelder.setAttribute("name", start); root.appendChild(startMelder); for (int i = 0; i < detectionObjects.size(); i += 2) { root.appendChild(createGraphicsNode.getMelderGruppeNode(doc, detectionObjects.get(i), path.getName(), maNumber, detectionObjects.get(i + 1))); } endMelder.setAttribute("id", ending); endMelder.setAttribute("name", ending); root.appendChild(endMelder); } } String formatedFileName = path.getAbsolutePath().replace("", "ae").replace("", "ss") .replace("", "ue").replace("", "oe"); String formatedName = path.getName().replace("", "ae").replace("", "ss").replace("", "ue") .replace("", "oe"); File toCheck; if (path.getAbsolutePath().endsWith(".xml")) { toCheck = path; } else { toCheck = new File(formatedFileName + slash + formatedName + ".xml"); } //End Of the File //Flag 0 - Default 1 - Override 2 - Update if (flag != 2) { writeDocument(doc, path); } if (flag == 2) { if (toCheck.exists()) { //If it existas that measns it could need some updating updateSite(doc, toCheck); } else { //if not then file can be created and doesnt need to be updated. writeDocument(doc, path); } } } }