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:com.gitblit.utils.JGitUtils.java
/** * Creates a bare, shared repository.//from w w w .ja v a2s . c o m * * @param repositoriesFolder * @param name * @param shared * the setting for the --shared option of "git init". * @return Repository */ public static Repository createRepository(File repositoriesFolder, String name, String shared) { try { Repository repo = null; try { Git git = Git.init().setDirectory(new File(repositoriesFolder, name)).setBare(true).call(); repo = git.getRepository(); } catch (GitAPIException e) { throw new RuntimeException(e); } GitConfigSharedRepository sharedRepository = new GitConfigSharedRepository(shared); if (sharedRepository.isShared()) { StoredConfig config = repo.getConfig(); config.setString("core", null, "sharedRepository", sharedRepository.getValue()); config.setBoolean("receive", null, "denyNonFastforwards", true); config.save(); if (!JnaUtils.isWindows()) { Iterator<File> iter = org.apache.commons.io.FileUtils.iterateFilesAndDirs(repo.getDirectory(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); // Adjust permissions on file/directory while (iter.hasNext()) { adjustSharedPerm(iter.next(), sharedRepository); } } } return repo; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:betullam.xmlmodifier.XMLmodifier.java
private Set<File> getFilesToModify(String mdDirectory, String fileName, String condStructureType, String condMdName, String condMdValue) { Set<File> setFilesToModify = new HashSet<File>(); // Iterate over all files in the given directory and it's subdirectories. Works with "FileUtils" in Apache "commons-io" library. //for (File mdFile : FileUtils.listFiles(new File(mdDirectory), new WildcardFileFilter(new String[]{"meta.xml", "meta_anchor.xml"}, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE)) { if (fileName.equals("meta") || fileName.equals("meta_anchor")) { for (File mdFile : FileUtils.listFiles(new File(mdDirectory), new WildcardFileFilter(fileName + ".xml", IOCase.INSENSITIVE), TrueFileFilter.INSTANCE)) { // DOM Parser: String filePath = mdFile.getAbsolutePath(); DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; Document xmlDoc = null; try { documentBuilder = documentFactory.newDocumentBuilder(); xmlDoc = documentBuilder.parse(filePath); // Only get files that match a certain condition (e. g. "AccessLicense" of a "Monograph" is "OpenAccess"). Only they should be modified. boolean isFileToModify = checkCondition(condStructureType, condMdName, condMdValue, xmlDoc); if (isFileToModify) { setFilesToModify.add(mdFile); }/* www . j av a 2 s . c om*/ } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } } } else { System.err.println("Name of meta files can only be \"meta\" or \"meta_anchor\"."); } return setFilesToModify; }
From source file:com.silverpeas.util.FileUtil.java
public static Collection<File> listFiles(File directory, String[] extensions, boolean caseSensitive, boolean recursive) { if (caseSensitive) { return listFiles(directory, extensions, recursive); }//from www . java 2 s . c om IOFileFilter filter; if (extensions == null) { filter = TrueFileFilter.INSTANCE; } else { String[] suffixes = new String[extensions.length]; for (int i = 0; i < extensions.length; i++) { suffixes[i] = "." + extensions[i]; } filter = new SuffixFileFilter(suffixes, IOCase.INSENSITIVE); } return FileUtils.listFiles(directory, filter, (recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE)); }
From source file:bioLockJ.Module.java
protected void initInputFiles(final File dir) throws Exception { setModuleInput(dir, TrueFileFilter.INSTANCE, null); }
From source file:com.taobao.android.builder.tools.bundleinfo.ApkFileListUtils.java
/** * ?apk?/* w w w . j a v a2 s .c o m*/ * * @return */ protected static void prepareApkFileList(File folder, String prefixName) { if (!folder.exists()) { return; } // ?bundle? Collection<File> files = FileUtils.listFiles(folder, new PureFileFilter(), TrueFileFilter.INSTANCE); for (File file : files) { if (file.isFile()) { String relativePath = prefixName + File.separator + PathUtil.toRelative(folder, file.getAbsolutePath()); String md5 = MD5Util.getFileMD5(file); if (isImageFile(relativePath)) { AtlasBuildContext.apkFileList.put(relativePath, md5); } AtlasBuildContext.finalApkFileList.put(relativePath, md5); } } }
From source file:net.flamefeed.ftb.modpackupdater.FileOperator.java
/** * Recursively search for a directory and locate any files which aren't accounted * for on the hash-file. Add these files to the deleteQueue. * // w w w .j a va2s. c o m * @param path * The relative path to search for unaccounted files. * * @throws IOException */ private void findUnaccountedFiles(String path) throws IOException { File pathToSearch = new File(pathMinecraft + "/" + path); if (pathToSearch.exists() && pathToSearch.isDirectory()) { /* * This iterator is provided by Apache commons.io and will recurse * over all files in given directory and also its subdirectories. */ Iterator<File> fileList = iterateFiles(pathToSearch, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); while (fileList.hasNext()) { File currentFile = fileList.next(); // Get the relative path of the file String relativePath = currentFile.getAbsolutePath(); // Replace all \\ which might occur in Windows paths with / to make // it uniform. Sadly this requires a regex of \\, which as a string is \\\\. // Dear god. relativePath = relativePath.replaceAll("\\\\", "/"); relativePath = relativePath.replaceFirst(pathMinecraft + "/", ""); boolean fileAccountedFor = false; for (String[] remoteHash : remoteHashes) { if (remoteHash[FILENAME].equals(relativePath)) { fileAccountedFor = true; break; } } if (!fileAccountedFor) { deleteQueue.add(relativePath); } } } }
From source file:de.peran.dependency.ChangedTestClassesHandler.java
/** * Returns all changed classes with the corresponding changed methods. If the set of a class is empty, the whole class was changed and all tests using any method of the class need to be * re-evaluated.//ww w . j a v a 2 s.c o m * * @return */ public Map<String, Set<String>> getChangedClassesCleaned() { final Map<String, Set<String>> changedClassesMethods = new TreeMap<>(); final Set<String> changedClasses = getChangedClasses(); LOG.debug("Vor dem Bereinigen: {}", changedClasses); if (lastSourcesFolder.exists()) { for (final Iterator<String> clazzIterator = changedClasses.iterator(); clazzIterator.hasNext();) { final String clazz = clazzIterator.next(); final String onlyClassName = clazz.substring(clazz.lastIndexOf(".") + 1); try { final File src = new File(projectFolder, "src"); LOG.debug("Suche nach {} in {}", clazz, src); final File newFile = FileUtils .listFiles(src, new WildcardFileFilter(onlyClassName + "*"), TrueFileFilter.INSTANCE) .iterator().next(); final File oldFile = FileUtils.listFiles(lastSourcesFolder, new WildcardFileFilter(onlyClassName + "*"), TrueFileFilter.INSTANCE).iterator().next(); LOG.info("Vergleiche {}", newFile, oldFile); final ClazzChangeData changeData = FileComparisonUtil.getChangedMethods(newFile, oldFile); if (!changeData.isChange()) { clazzIterator.remove(); LOG.debug("Dateien gleich: {}", clazz); } else { if (changeData.isOnlyMethodChange()) { changedClassesMethods.put(clazz, changeData.getChangedMethods()); } else { changedClassesMethods.put(clazz, new HashSet<>()); } } } catch (final NoSuchElementException nse) { LOG.info("Class did not exist before: {}", clazz); changedClassesMethods.put(clazz, new HashSet<>()); } catch (final ParseException pe) { LOG.info( "Class is unparsable for java parser, so to be sure it is added to the changed classes: {}", clazz); changedClassesMethods.put(clazz, new HashSet<>()); pe.printStackTrace(); } catch (final IOException e) { LOG.info( "Class is unparsable for java parser, so to be sure it is added to the changed classes: {}", clazz); changedClassesMethods.put(clazz, new HashSet<>()); e.printStackTrace(); } } } else { LOG.info("Kein Ordner fr alte Dateien vorhanden"); } LOG.debug("Nach dem Bereinigen: {}", changedClassesMethods); return changedClassesMethods; }
From source file:de.icongmbh.oss.maven.plugin.javassist.JavassistTransformerExecutor.java
/** * Search for class files (file extension: {@code .class}) on the passed {@code directory}. * <p>/*from w ww. j a v a2s. c o m*/ * Note: The passed directory name must exist and readable. * </p> * * @param directory must nor be {@code null} * @return iterator of full qualified class names and never {@code null} * * @throws NullPointerException if passed {@code directory} is {@code null}. * * @see SuffixFileFilter * @see TrueFileFilter * @see FileUtils#iterateFiles(File, IOFileFilter, IOFileFilter) * @see ClassnameExtractor#iterateClassnames(File, Iterator) */ protected Iterator<String> iterateClassnames(final String directory) { final File dir = new File(directory); final String[] extensions = { ".class" }; final IOFileFilter fileFilter = new SuffixFileFilter(extensions); final IOFileFilter dirFilter = TrueFileFilter.INSTANCE; return ClassnameExtractor.iterateClassnames(dir, FileUtils.iterateFiles(dir, fileFilter, dirFilter)); }
From source file:com.taobao.android.builder.tools.bundleinfo.ApkFileListUtils.java
protected static void prepareApkFileList(File folder, String prefixName, String awbName) { if (!folder.exists()) { return;//from w w w.j a v a2 s .co m } // ?bundle? Collection<File> files = FileUtils.listFiles(folder, new PureFileFilter(), TrueFileFilter.INSTANCE); for (File file : files) { if (file.isFile()) { String relativePath = prefixName + File.separator + PathUtil.toRelative(folder, file.getAbsolutePath()); String md5 = MD5Util.getFileMD5(file); if (isImageFile(relativePath)) { if (null == AtlasBuildContext.apkFileList.getAwbs().get(awbName)) { AtlasBuildContext.apkFileList.getAwbs().put(awbName, new HashMap<String, String>()); } AtlasBuildContext.apkFileList.getAwbs().get(awbName).put(relativePath, md5); } if (null == AtlasBuildContext.finalApkFileList.getAwbs().get(awbName)) { AtlasBuildContext.finalApkFileList.getAwbs().put(awbName, new HashMap<String, String>()); } AtlasBuildContext.finalApkFileList.getAwbs().get(awbName).put(relativePath, md5); } } }
From source file:com.github.os72.protocjar.maven.ProtocJarMojo.java
private void processTarget(OutputTarget target) throws MojoExecutionException { boolean shaded = false; String targetType = target.type; if (targetType.equals("java-shaded") || targetType.equals("java_shaded")) { targetType = "java"; shaded = true;/*w w w . j a v a2s . c om*/ } FileFilter fileFilter = new FileFilter(extension); for (File input : inputDirectories) { if (input == null) continue; if (input.exists() && input.isDirectory()) { Collection<File> protoFiles = FileUtils.listFiles(input, fileFilter, TrueFileFilter.INSTANCE); for (File protoFile : protoFiles) { if (target.cleanOutputFolder || buildContext.hasDelta(protoFile.getPath())) { processFile(protoFile, protocVersion, targetType, target.pluginPath, target.outputDirectory, target.outputOptions); } else { getLog().info("Not changed " + protoFile); } } } else { if (input.exists()) getLog().warn(input + " is not a directory"); else getLog().warn(input + " does not exist"); } } if (shaded) { try { getLog().info(" Shading (version " + protocVersion + "): " + target.outputDirectory); Protoc.doShading(target.outputDirectory, protocVersion.replace(".", "")); } catch (IOException e) { throw new MojoExecutionException("Error occurred during shading", e); } } boolean mainAddSources = "main".endsWith(target.addSources); boolean testAddSources = "test".endsWith(target.addSources); if (mainAddSources) { getLog().info("Adding generated classes to classpath"); project.addCompileSourceRoot(target.outputDirectory.getAbsolutePath()); } if (testAddSources) { getLog().info("Adding generated classes to test classpath"); project.addTestCompileSourceRoot(target.outputDirectory.getAbsolutePath()); } if (mainAddSources || testAddSources) { buildContext.refresh(target.outputDirectory); } }