List of usage examples for org.apache.commons.io.filefilter IOFileFilter IOFileFilter
IOFileFilter
From source file:mx.itesm.imb.EcoreImbEditor.java
/** * //from w w w.j a v a 2s.c o m * @param templateProject */ @SuppressWarnings("unchecked") public static void createRooApplication(final File ecoreProject, final File busProject, final File templateProject) { File imbProject; File editProject; String pluginContent; String pomContent; String tomcatConfiguration; Collection<File> pluginFiles; try { editProject = new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit"); imbProject = new File(editProject, "/imb/"); FileUtils.deleteDirectory(imbProject); // Create the roo application FileUtils.copyFile(new File(templateProject, "/templates/install.roo"), new File(imbProject, "install.roo")); EcoreImbEditor.executeCommand("roo script --file install.roo", imbProject); // Update libraries pomContent = FileUtils.readFileToString(new File(imbProject, "pom.xml")); pomContent = pomContent.replaceFirst("</dependencies>", FileUtils.readFileToString(new File(templateProject, "/templates/pom.xml"))); FileUtils.writeStringToFile(new File(imbProject, "pom.xml"), pomContent); // IMB types configuration FileUtils.copyDirectory(new File(busProject, "/src/main/java/imb"), new File(imbProject, "/src/main/java/imb")); FileUtils.copyFile(new File(busProject, "/src/main/resources/schema.xsd"), new File(imbProject, "/src/main/resources/schema.xsd")); FileUtils.copyFile( new File(busProject, "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"), new File(imbProject, "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml")); // Update the plugin configuration pluginFiles = FileUtils.listFiles(new File(editProject, "/src"), new IOFileFilter() { @Override public boolean accept(File file) { return (file.getName().endsWith("Plugin.java")); } @Override public boolean accept(File dir, String file) { return (file.endsWith("Plugin.java")); } }, TrueFileFilter.INSTANCE); for (File plugin : pluginFiles) { pluginContent = FileUtils.readFileToString(plugin); pluginContent = pluginContent.substring(0, pluginContent.indexOf("public static class Implementation extends EclipsePlugin")); // Tomcat configuration tomcatConfiguration = FileUtils .readFileToString(new File(templateProject, "/templates/Plugin.txt")); tomcatConfiguration = tomcatConfiguration.replace("${imbProject}", imbProject.getPath()); FileUtils.writeStringToFile(plugin, pluginContent + tomcatConfiguration); break; } } catch (Exception e) { e.printStackTrace(); System.out.println("Error while configuring Roo application: " + e.getMessage()); } }
From source file:com.websqrd.catbot.setting.CatbotSettings.java
public static Map<String, RepositorySetting> getRepositoryList(boolean reload) { if (reload || repositorySettingList.isEmpty()) { repositorySettingList.clear();//from w ww . j a va2 s . c om String dirFile = HOME + "conf"; Collection list = FileUtils.listFiles(new File(dirFile), new IOFileFilter() { public boolean accept(File dir, String name) { if (name.startsWith("repository")) { return true; } return false; } public boolean accept(File file) { if (file.getName().startsWith("repository")) { return true; } return false; } }, null); Iterator iter = list.iterator(); while (iter.hasNext()) { File file = (File) iter.next(); String fileName = file.getName(); int s = fileName.indexOf('_'); int e = fileName.indexOf('.'); String repositoryName = fileName.substring(s + 1, e); repositorySettingList.put(file.getName(), getRepositorySetting(repositoryName, true)); } } return repositorySettingList; }
From source file:BackupService.java
/** * Explore path on local system and identify files to backup. * It takes into account filters of excluded files and directories. * * @return list of local files and directories to backup *///from w w w . j a v a 2 s . c om private List<VOBackupFile> exploreBackupFiles() { List<VOBackupFile> newFileList = new ArrayList<>(); for (String pathForBackup : pathToBackupList) { logger.info("start explore source path '{}' for backup.", pathForBackup); IOFileFilter symlinkFilter = new IOFileFilter() { @Override public boolean accept(final File file) { try { final File parentFile = file.getParentFile(); final boolean symlink = FileUtils.isSymlink(parentFile); return !symlink; } catch (IOException e) { e.printStackTrace(); //TODO Lebeda - oetit } return false; } @Override public boolean accept(final File dir, final String name) { try { return !FileUtils.isSymlink(dir.getParentFile()); } catch (IOException e) { e.printStackTrace(); //TODO Lebeda - oetit } return false; } }; // http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/WildcardFileFilter.html IOFileFilter fileFilter = FileFilterUtils.and(symlinkFilter, getWildcardsFilter(excludes)); IOFileFilter dirFilter = FileFilterUtils.and(symlinkFilter, getWildcardsFilter(excludeDirs)); //noinspection unchecked final Collection<File> fileColection = FileUtils.listFilesAndDirs(new File(pathForBackup), fileFilter, dirFilter); for (File file : fileColection) { newFileList.add(new VOBackupFile(file)); } logger.info("end of explore source path '{}'.", pathForBackup); } logger.info("end of explore all source paths, found {} items.", newFileList.size()); return newFileList; }
From source file:com.drunkendev.io.recurse.tests.RecursionTest.java
/** * Answer provided by Bozho.// w ww . jav a2 s . c om * * Tests using <a href="https://commons.apache.org/proper/commons-io/">Apache commons-io</a> * {@link FileUtils#iterateFilesAndDirs(File, IOFileFilter, IOFileFilter)} * which uses the {@link java.io.File} API. * * @see <a href="http://stackoverflow.com/a/2056258/140037">Stack-Overflow answer by Bozho</a> */ // @Test public void testFileUtils() { System.out.println("\nTEST: commons-io - FileUtils"); time(() -> { Iterator<File> iter = FileUtils.iterateFilesAndDirs(startPath.toFile(), TrueFileFilter.INSTANCE, new IOFileFilter() { @Override public boolean accept(File file) { try { return isPlainDir(file); } catch (IOException ex) { return false; } } @Override public boolean accept(File dir, String name) { try { return isPlainDir(dir); } catch (IOException ex) { return false; } } }); int files = 0; int dirs = 0; File n; try { while (iter.hasNext()) { n = iter.next(); if (isPlainDir(n)) { dirs++; } else { files++; } } System.out.format("Files: %d, dirs: %d. ", files, dirs); } catch (IOException ex) { fail(ex.getMessage()); } }); }
From source file:com.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java
protected static void reNameResources(final String versionInProjectName, File copyDir, String versionInProjectName2, String version_base, String classifier_base, String version_target, String classifier_target) { System.out.println("PrepareSIDEModulesMigration.reNameResources() " + versionInProjectName + "->" + versionInProjectName2);/* w w w . j av a2 s. c om*/ Collection<?> listFiles = FileUtils.listFiles(copyDir, TrueFileFilter.INSTANCE, new IOFileFilter() { public boolean accept(File dir, String name) { return !name.equals(".svn"); } public boolean accept(File file) { return !file.getName().equals(".svn"); } }); for (Object object : listFiles) { File f = (File) object; replaceVersionInFile(versionInProjectName, versionInProjectName2, version_base, classifier_base, version_target, classifier_target, f, false); renameFile(versionInProjectName, versionInProjectName2, f); } // renameFile(versionInProjectName, versionInProjectName2, copyDir); renameDirectories(copyDir, versionInProjectName, versionInProjectName2); }
From source file:com.teotigraphix.caustk.library.LibraryManager.java
/** * Loads the entire <code>libraries</code> directory into the manager. * <p>/* w w w .j a v a 2 s .c o m*/ * Each sub directory located within the <code>libraries</code> directory * will be created as a {@link Library} instance. */ @Override public void load() { Collection<File> dirs = FileUtils.listFilesAndDirs(librariesDirectory, new IOFileFilter() { @Override public boolean accept(File arg0, String arg1) { return false; } @Override public boolean accept(File arg0) { return false; } }, new IOFileFilter() { @Override public boolean accept(File file, String name) { if (file.getParentFile().getName().equals("libraries")) return true; return false; } @Override public boolean accept(File file) { if (file.getParentFile().getName().equals("libraries")) return true; return false; } }); for (File directory : dirs) { if (directory.equals(librariesDirectory)) continue; loadLibrary(directory.getName()); } }
From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderETSImpl.java
public ArrayList<Connector> initDevices(ObjectBroker objectBroker) { log.info("KNX ETS device loader starting. - connectorsConfig: " + connectorsConfig); setConfiguration(connectorsConfig);//from w w w. j a v a 2 s . co m ArrayList<Connector> connectors = new ArrayList<Connector>(); log.info("connectors config now: " + connectorsConfig); Object knxConnectors = connectorsConfig.getProperty("knx-ets.connector.name"); int connectorsSize = 0; if (knxConnectors != null) { connectorsSize = 1; } if (knxConnectors instanceof Collection<?>) { connectorsSize = ((Collection<?>) knxConnectors).size(); } // Networks List networks = new List(); networks.setName("networks"); networks.setOf(new Contract(Network.CONTRACT)); networks.setHref(new Uri("/networks")); boolean networkEnabled = false; for (int connector = 0; connector < connectorsSize; connector++) { HierarchicalConfiguration subConfig = connectorsConfig .configurationAt("knx-ets.connector(" + connector + ")"); // String connectorName = subConfig.getString("name"); String routerIP = subConfig.getString("router.ip"); int routerPort = subConfig.getInteger("router.port", 3671); String localIP = subConfig.getString("localIP"); Boolean enabled = subConfig.getBoolean("enabled", false); Boolean forceRefresh = subConfig.getBoolean("forceRefresh", false); String knxProj = subConfig.getString("knx-proj"); Boolean enableGroupComm = subConfig.getBoolean("groupCommEnabled", false); Boolean enableHistories = subConfig.getBoolean("historyEnabled", false); if (enabled) { if (!networkEnabled) { objectBroker.addObj(networks, true); networkEnabled = true; } File file = new File(knxProj); if (!file.exists() || file.isDirectory() || !file.getName().endsWith(".knxproj") || file.getName().length() < 8) { log.warning("KNX project file " + knxProj + " is not a valid KNX project file."); continue; } String projDirName = knxProj.substring(0, knxProj.length() - 8); File projDir = new File(projDirName); if (!projDir.exists() || forceRefresh) { log.info("Expanding " + knxProj + " into directory " + projDirName); unZip(knxProj, projDirName); } String directory = "./" + knxProj.substring(knxProj.indexOf("/") + 1).replaceFirst(".knxproj", ""); // now the unpacked ETS project should be available in the directory String transformFileName = knxProj.replaceFirst(".knxproj", "") + "/" + file.getName().replaceFirst(".knxproj", "") + ".xml"; File transformFile = new File(transformFileName); if (!transformFile.exists() || forceRefresh) { log.info("Transforming ETS configuration."); // System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); // Create a transform factory instance. TransformerFactory tfactory = TransformerFactory.newInstance(); // Create a transformer for the stylesheet. Transformer transformer; try { transformer = tfactory.newTransformer(new StreamSource("knx-config/stylesheet_knx.xsl")); Collection<File> listFiles = FileUtils.listFiles(projDir, FileFilterUtils.nameFileFilter("0.xml"), new IOFileFilter() { @Override public boolean accept(File file) { return true; } @Override public boolean accept(File dir, String name) { return true; } }); if (listFiles.size() != 1) { log.severe("Found no or more than one 0.xml file in " + projDirName); continue; } log.info("Transforming with directory parameter set to " + directory); transformer.setParameter("directory", directory); transformer.transform(new StreamSource(listFiles.iterator().next().getAbsoluteFile()), new StreamResult(transformFileName)); log.info("Transformation completed and result written to: " + transformFileName); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } } try { devicesConfig = new XMLConfiguration(transformFileName); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); } KNXConnector knxConnector = new KNXConnector(routerIP, routerPort, localIP); connect(knxConnector); initNetworks(knxConnector, objectBroker, networks, enableGroupComm, enableHistories); connectors.add(knxConnector); } } return connectors; }
From source file:com.igormaznitsa.jute.JuteMojo.java
private static List<String> collectAllPotentialTestClassPaths(final Log log, final boolean verbose, final File rootFolder, final String[] includes, final String[] excludes) { final List<String> result = new ArrayList<String>(); final Iterator<File> iterator = FileUtils.iterateFiles(rootFolder, new IOFileFilter() { private final AntPathMatcher matcher = new AntPathMatcher(); @Override// w w w .ja v a 2 s . c o m public boolean accept(final File file) { if (file.isDirectory()) { return false; } final String path = file.getAbsolutePath(); boolean include = false; if (path.endsWith(".class")) { if (includes.length != 0) { for (final String patteen : includes) { if (matcher.match(patteen, path)) { include = true; break; } } } else { include = true; } if (include && excludes.length != 0) { for (final String pattern : excludes) { if (matcher.match(pattern, path)) { include = false; break; } } } } if (!include && verbose) { log.info("File " + path + " excluded"); } return include; } @Override public boolean accept(final File dir, final String name) { final String path = name; boolean include = false; if (includes.length != 0) { for (final String pattern : includes) { if (matcher.match(pattern, path)) { include = true; break; } } } else { include = true; } if (include && excludes.length != 0) { for (final String pattern : excludes) { if (matcher.match(pattern, path)) { include = false; break; } } } if (!include && verbose) { log.info("Folder " + name + " excluded"); } return include; } }, DirectoryFileFilter.DIRECTORY); while (iterator.hasNext()) { final String detectedFile = iterator.next().getAbsolutePath(); if (verbose) { log.info("Found potential test class : " + detectedFile); } result.add(detectedFile); } if (result.isEmpty()) { log.warn("No test files found in " + rootFolder.getAbsolutePath()); } return result; }
From source file:com.websqrd.catbot.setting.CatbotSettings.java
public static Map<String, CategoryConfig> getSiteCategoryConfigList(String site, boolean reload) { Map<String, CategoryConfig> categoryMap = siteCategoryConfigMap.get(site); if (reload || categoryMap == null || categoryMap.isEmpty()) { categoryMap = new Hashtable<String, CategoryConfig>(); String siteHome = getSiteHome(site); File dir = new File(siteHome); if (!dir.isDirectory()) { logger.error("? {} .", siteHome); return null; }//from w w w. j av a 2 s. com Collection list = FileUtils.listFiles(dir, new IOFileFilter() { public boolean accept(File dir, String name) { if (name.startsWith(categoryPrefix)) { return true; } return false; } public boolean accept(File file) { if (file.getName().startsWith(categoryPrefix)) { return true; } return false; } }, null); Iterator iter = list.iterator(); while (iter.hasNext()) { File file = (File) iter.next(); String fileName = file.getName(); if (fileName.toLowerCase().endsWith(".xml") == false) continue; int s = fileName.indexOf('_'); int e = fileName.indexOf('.'); String categoryName = fileName.substring(s + 1, e); try { categoryMap.put(categoryName, getCategoryConfig(site, categoryName, true)); } catch (Exception e1) { e1.printStackTrace(); logger.error(" ?? ? ??. {} >> {}", site, categoryName); } } } siteCategoryConfigMap.put(site, categoryMap); return categoryMap; }
From source file:mx.itesm.imb.EcoreImbEditor.java
@SuppressWarnings("unchecked") private static void writeSelectionAspect(final File ecoreProject, final String typesPackage, final List<String> types) { Writer writer;/*from www . j a v a 2s . c o m*/ String packageName; VelocityContext context; StringBuilder validTypes; Collection<File> contributorFiles; try { validTypes = new StringBuilder(); for (String type : types) { if (!type.toLowerCase().equals("system")) { validTypes.append("validTypes.add(\"" + type + "\");\n"); } } contributorFiles = FileUtils.listFiles( new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor"), new IOFileFilter() { @Override public boolean accept(File dir, String file) { return file.endsWith("Contributor.java"); } @Override public boolean accept(File file) { return file.getName().endsWith("Contributor.java"); } }, TrueFileFilter.INSTANCE); for (File contributor : contributorFiles) { context = new VelocityContext(); packageName = contributor.getPath() .substring(contributor.getPath().indexOf("src") + "src".length() + 1, contributor.getPath().indexOf(contributor.getName().replace(".java", "")) - 1) .replace('/', '.'); context.put("validTypes", validTypes); context.put("packageName", packageName); context.put("typesPackage", typesPackage); context.put("contributor", contributor.getName().replace(".java", "")); writer = new FileWriter(new File(contributor.getParentFile(), "SelectionAspect.aj")); EcoreImbEditor.selectionTemplate.merge(context, writer); writer.close(); break; } } catch (Exception e) { e.printStackTrace(); System.out.println("Unable to update selection service: " + e.getMessage()); } }