List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE
IOFileFilter INSTANCE
To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.
Click Source Link
From source file:org.testeditor.teamshare.svn.SVNTeamShareServiceLocalTest.java
/** * Tests the ignore list.//from w ww . ja va2s .c o m * * @throws SystemException * System failure */ @Test public void testIgnoreListPositive() throws SystemException { TestProject testProject = createTestProject(REPOSITORY_PATH, "", ""); teamService.share(testProject, translationService, ""); String[] ignoreList = SVNTeamShareService.IGNORE_LIST; Collection<File> listFiles = FileUtils.listFilesAndDirs(new File(targetWorkspacePath), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : listFiles) { for (String ignoreItem : ignoreList) { assertNotEquals("File/Directory: " + file.getName() + " must not be shared !", file.getName(), ignoreItem); } } }
From source file:org.testeditor.teamshare.svn.SVNTeamShareServiceLocalTest.java
/** * Negative test for ignore list. Directory "DemoWebTests" must not be * found.//from w w w . j a va 2 s. c om * * @throws SystemException * System failure */ @Test public void testIgnoreListNegative() throws SystemException { TestProject testProject = createTestProject(REPOSITORY_PATH, "", ""); teamService.share(testProject, translationService, ""); String[] ignoreList = { "DemoWebTests" }; Collection<File> listFiles = FileUtils.listFilesAndDirs(new File(targetWorkspacePath), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); boolean found = false; // traverse Filelist and check if ignoreList matches. for (File file : listFiles) { for (String ignoreItem : ignoreList) { if (file.getName().equals(ignoreItem)) { found = true; break; } } } assertTrue("Directory 'DemoWebTests' was not found", found); }
From source file:org.testeditor.teamshare.svn.SVNTeamShareServiceRemoteTest.java
/** * Tests the ignore list.//from w w w. j a va 2 s.co m * * @throws SystemException * System failure */ @Ignore("only for debugging") public void testIgnoreListPositive() throws SystemException { TestProject testProject = createTestProject(REPOSITORY_PATH, "", ""); teamService.share(testProject, translationService, ""); String[] ignoreList = SVNTeamShareService.IGNORE_LIST; Collection<File> listFiles = FileUtils.listFilesAndDirs(new File(TARGET_WORKSPACE_PATH), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : listFiles) { for (String ignoreItem : ignoreList) { assertNotEquals("File/Directory: " + file.getName() + " must not be shared !", file.getName(), ignoreItem); } } }
From source file:org.testeditor.teamshare.svn.SVNTeamShareServiceRemoteTest.java
/** * Negative test for ignore list. Directory "DemoWebTests" must not be * found.// ww w .ja v a2 s . c o m * * @throws SystemException * System failure */ @Ignore("only for debugging") public void testIgnoreListNegative() throws SystemException { TestProject testProject = createTestProject(REPOSITORY_PATH, "", ""); String[] ignoreList = { "DemoWebTests" }; Collection<File> listFiles = FileUtils.listFilesAndDirs(new File(TARGET_WORKSPACE_PATH), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); boolean found = false; // traverse Filelist and check if ignoreList matches. for (File file : listFiles) { for (String ignoreItem : ignoreList) { if (file.getName().equals(ignoreItem)) { found = true; break; } } } assertTrue("Directory 'DemoWebTests' was not found", found); }
From source file:org.uimafit.examples.LicenseTest.java
private void test(File directory) throws IOException { List<String> filesMissingLicense = new ArrayList<String>(); Iterator<?> files = org.apache.commons.io.FileUtils.iterateFiles(directory, new SuffixFileFilter(".java"), TrueFileFilter.INSTANCE); while (files.hasNext()) { File file = (File) files.next(); if (file.getParentFile().getName().equals("type") || file.getName().equals("Files.java")) { continue; }//from www . jav a2s . c o m String fileText = FileUtils.file2String(file); // // boolean hasCopyright = fileText.indexOf("Copyright") != -1; boolean hasLicense = (fileText.indexOf("Licensed under the Apache License, Version 2.0") != -1) || (fileText.indexOf("Licensed to the Apache Software Foundation") != -1); boolean hasAuthor = fileText.indexOf("@author") != -1; boolean isPackageDoc = "package-info.java".equals(file.getName()); if ( /*!hasCopyright ||*/ !hasLicense || (!isPackageDoc && !hasAuthor)) { filesMissingLicense.add(file.getPath()); } } if (filesMissingLicense.size() > 0) { StringBuilder sb = new StringBuilder(); sb.append(filesMissingLicense.size()); sb.append(" source file missing license or author attribution:\n"); Collections.sort(filesMissingLicense); for (String path : filesMissingLicense) { sb.append(path).append('\n'); } Assert.fail(sb.toString()); } }
From source file:org.uimafit.LicenseTest.java
private void test(File directory) throws IOException { List<String> filesMissingLicense = new ArrayList<String>(); Iterator<?> files = org.apache.commons.io.FileUtils.iterateFiles(directory, new SuffixFileFilter(".java"), TrueFileFilter.INSTANCE); while (files.hasNext()) { File file = (File) files.next(); if (file.getParentFile().getName().equals("type") || file.getName().equals("Files.java")) { continue; }/*from w w w .j a va 2 s . c o m*/ String fileText = FileUtils.file2String(file); boolean hasCopyright = fileText.indexOf("Copyright") != -1; boolean hasLicense = fileText.indexOf("Licensed under the Apache License, Version 2.0") != -1; boolean hasAuthor = fileText.indexOf("@author") != -1; boolean isPackageDoc = "package-info.java".equals(file.getName()); if (!hasCopyright || !hasLicense || (!isPackageDoc && !hasAuthor)) { filesMissingLicense.add(file.getPath()); } } if (filesMissingLicense.size() > 0) { StringBuilder sb = new StringBuilder(); sb.append(filesMissingLicense.size()); sb.append(" source file missing license or author attribution:\n"); Collections.sort(filesMissingLicense); for (String path : filesMissingLicense) { sb.append(path).append('\n'); } Assert.fail(sb.toString()); } }
From source file:org.walkmod.util.FileResource.java
@Override public Iterator<File> iterator() { String fileNormalized = FilenameUtils.normalize(file.getAbsolutePath(), true); if (includes != null) { for (int i = 0; i < includes.length; i++) { if (!includes[i].startsWith(fileNormalized)) { includes[i] = fileNormalized + "/" + includes[i]; }//from w ww. ja va2 s. c o m if (includes[i].endsWith("**")) { includes[i] = includes[i].substring(0, includes[i].length() - 3); } } } if (excludes != null) { for (int i = 0; i < excludes.length; i++) { if (!excludes[i].startsWith(fileNormalized)) { excludes[i] = fileNormalized + "/" + excludes[i]; } if (excludes[i].endsWith("**")) { excludes[i] = excludes[i].substring(0, excludes[i].length() - 3); } } } if (file.isDirectory()) { IOFileFilter filter = null; IOFileFilter directoryFilter = TrueFileFilter.INSTANCE; if (excludes != null || includes != null) { directoryFilter = new IOFileFilter() { @Override public boolean accept(File dir, String name) { boolean excludesEval = false; boolean includesEval = false; String aux = FilenameUtils.normalize(name, true); if (excludes != null) { for (int i = 0; i < excludes.length && !excludesEval; i++) { excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || dir.getAbsolutePath().startsWith(excludes[i])); } } if (includes != null) { for (int i = 0; i < includes.length && !includesEval; i++) { includesEval = matches(aux, includes[i]); } } else { includesEval = true; } return (includesEval && !excludesEval) || (includes == null && excludes == null); } @Override public boolean accept(File file) { boolean excludesEval = false; boolean includesEval = false; String aux = FilenameUtils.normalize(file.getAbsolutePath(), true); if (excludes != null) { for (int i = 0; i < excludes.length && !excludesEval; i++) { excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || file.getParentFile().getAbsolutePath().startsWith(excludes[i])); } } if (includes != null) { for (int i = 0; i < includes.length && !includesEval; i++) { includesEval = matches(aux, includes[i]); } } else { includesEval = true; } boolean result = (includesEval && !excludesEval) || (includes == null && excludes == null); return result; } }; if (extensions == null) { filter = directoryFilter; } else { String[] suffixes = toSuffixes(extensions); filter = new SuffixFileFilter(suffixes); } } else { if (extensions == null) { filter = TrueFileFilter.INSTANCE; } else { String[] suffixes = toSuffixes(extensions); filter = new SuffixFileFilter(suffixes); } } return FileUtils.listFiles(file, filter, directoryFilter).iterator(); } Collection<File> aux = new LinkedList<File>(); if (extensions == null) { aux.add(file); } return aux.iterator(); }
From source file:org.wisdom.maven.mojos.JavaCompilerMojo.java
/** * A new (accepted) file was deleted. This methods triggers the Java compilation. * * @param file the file/*from w w w . ja v a 2 s . c om*/ * @return {@literal true} * @throws WatchingException thrown on compilation error. The thrown exception contains the file, line, * character and reason of the compilation error. */ @Override public boolean fileDeleted(final File file) throws WatchingException { // Delete the associated class file. // We delete more than required... but the inner class case is very tricky. Collection<File> files = FileUtils.listFiles(classes, new IOFileFilter() { @Override public boolean accept(File test) { String classname = FilenameUtils.getBaseName(test.getName()); String filename = FilenameUtils.getBaseName(file.getName()); return classname.equals(filename) || classname.startsWith(filename + "$"); } @Override public boolean accept(File dir, String name) { return accept(new File(dir, name)); } }, TrueFileFilter.INSTANCE); for (File clazz : files) { getLog().debug("Deleting " + clazz.getAbsolutePath() + " : " + clazz.delete()); } compile(); return true; }
From source file:org.wisdom.maven.pipeline.Pipeline.java
/** * Starts the watching./*from w w w.j a v a 2 s . com*/ * * @return the current pipeline. */ public Pipeline watch() { // Delete all error reports before starting the watcher. error = new File(baseDir, "target/pipeline"); FileUtils.deleteQuietly(error); mojo.getLog().debug("Creating the target/pipeline directory : " + error.mkdirs()); // Start the watching process. watcher = new FileAlterationMonitor(Integer.getInteger("watch.period", 2) * 1000); watcher.setThreadFactory(new DefensiveThreadFactory("wisdom-pipeline-watcher", mojo)); FileAlterationObserver srcObserver = new FileAlterationObserver(new File(baseDir, "src"), TrueFileFilter.INSTANCE); PipelineWatcher listener = new PipelineWatcher(this); srcObserver.addListener(listener); watcher.addObserver(srcObserver); if (pomFileMonitoring) { FileAlterationObserver pomObserver = new FileAlterationObserver(baseDir, new FileFilter() { @Override public boolean accept(File file) { return file.equals(new File(baseDir, "pom.xml")); } }); pomObserver.addListener(listener); watcher.addObserver(pomObserver); } try { mojo.getLog().info("Start watching " + baseDir.getAbsolutePath()); watcher.start(); } catch (Exception e) { mojo.getLog().error("Cannot start the watcher", e); } return this; }
From source file:org.wisdom.resources.AssetController.java
/** * @return the list of provided assets.//from w w w . j a v a 2 s .c o m */ @Override public Collection<Asset<?>> assets() { Map<String, Asset<?>> map = new HashMap<>(); if (directory != null && directory.isDirectory()) { // First insert the FS assets // For this iterate over the file present on the file system. Collection<File> files = FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : files) { if (file.getName().startsWith(".")) { // Skip file starting with . - there are hidden. continue; } if (file.getName().startsWith(".")) { // Skip file starting with . - there are hidden. continue; } // The path is computed as follows: // root (ending with /) and the path of the file relative to the directory. As these path may contain // \ on Windows we replace them by /. String path = root + file.getAbsolutePath().substring(directory.getAbsolutePath().length()).replace("\\", "/"); // TODO Do we really need computing the ETAG here ? map.put(path, new DefaultAsset<>(path, file, file.getAbsolutePath(), file.lastModified(), null)); } } if (!manageAssetsFromBundles) { return map.values(); } // No add the bundle things. Bundle[] bundles = context.getBundles(); // Skip bundle 0 for (int i = 1; i < bundles.length; i++) { // Remove the last "/" - we are sure to have one. URL root = bundles[i].getEntry(pathInBundles.substring(0, pathInBundles.length() - 1)); Enumeration<URL> urls = bundles[i].findEntries(pathInBundles, "*", true); if (urls != null) { while (urls.hasMoreElements()) { URL url = urls.nextElement(); String path = url.toExternalForm().substring(root.toExternalForm().length()); if (path.startsWith("/")) { path = this.root + path; } else { path = this.root + "/" + path; } if (!map.containsKey(path)) { // We should not replace assets overridden by files. map.put(path, new DefaultAsset<>(path, url, url.toExternalForm(), bundles[i].getLastModified(), null)); } } } } return map.values(); }