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:io.magentys.maven.DonutMojo.java
private void zipDonutReport() throws IOException, ArchiveException { Optional<File> file = FileUtils .listFiles(outputDirectory, new RegexFileFilter("^(.*)donut-report.html$"), TrueFileFilter.INSTANCE) .stream().findFirst();//from w ww . j a va 2s . co m if (!file.isPresent()) throw new FileNotFoundException( String.format("Cannot find a donut report in folder: %s", outputDirectory.getAbsolutePath())); File zipFile = new File(outputDirectory, FilenameUtils.removeExtension(file.get().getName()) + ".zip"); try (OutputStream os = new FileOutputStream(zipFile); ArchiveOutputStream aos = new ArchiveStreamFactory() .createArchiveOutputStream(ArchiveStreamFactory.ZIP, os); BufferedInputStream is = new BufferedInputStream(new FileInputStream(file.get()))) { aos.putArchiveEntry(new ZipArchiveEntry(file.get().getName())); IOUtils.copy(is, aos); aos.closeArchiveEntry(); aos.finish(); } }
From source file:com.thruzero.common.core.fs.HierarchicalFileWalker.java
/** * Constructs a walker for the given {@code rootDirectory} using the given {@code filter} and {@code sortDirection}. If the {@code filter} is an instance of * {@code FileAndDirectoryFilter}, then the {@code fileFilter} component will be used to filter files and the {@code directoryFilter} component will be used * to filter directories. Otherwise, directories are implicitly accepted and files are filtered using the given {@code filter}. If the given {@code filter} is * null, then all files and directories will be processed. * /* w w w . j a va2 s . c o m*/ * @param rootDirectory * starting point. * @param filter * use {@link org.apache.commons.io.filefilter.TrueFileFilter#INSTANCE} to process all files. * @param sortDirection * if present, files will be sorted in the direction indicated; otherwise, no sorting will take place. */ public HierarchicalFileWalker(final File rootDirectory, final FileFilter filter, final SortDirection sortDirection) { this.rootDirectory = rootDirectory; if (filter == null) { // default filter returns everything this.filter = new FileAndDirectoryFilter((FileFilter) DirectoryFileFilter.INSTANCE, TrueFileFilter.INSTANCE); } else if (filter instanceof FileAndDirectoryFilter) { this.filter = (FileAndDirectoryFilter) filter; } else { this.filter = new FileAndDirectoryFilter(DirectoryFileFilter.INSTANCE, filter); } this.fileSortComparator = new FileSortComparator(sortDirection); }
From source file:net.sourceforge.jencrypt.lib.FolderList.java
/** * Retrieve all folders beneath a given folder recursively. * /* w w w .j av a 2s. c o m*/ * @param folder * the folder to recursively list * @param fileTree * an ArrayList object to store the tree of folders */ private void getFoldersRecursively() { Collection<File> files = FileUtils.listFilesAndDirs(topFolder, new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); for (File f : files) { // Don't return "." or "" as a folder (i.e. skip root) if (f.getName().equals(".") || f.getName().equals("")) { continue; } folderTree.add(f); folderStringTree.add(getRelativePathString(f)); } }
From source file:de.peran.dependency.ChangedTestClassesHandler.java
private void updateDependenciesOnce(final String testClassName, final String testMethodName, final File parent) { LOG.debug("Parent: " + parent); final File[] listFiles = parent.listFiles(new FileFilter() { @Override/*from w ww .j a va 2s . c om*/ public boolean accept(final File pathname) { return pathname.getName().matches("[0-9]*"); } }); LOG.debug("Kieker-Dateien: {}", listFiles.length); final File kiekerAllFolder = listFiles[0]; LOG.debug("Analysiere Ordner: {} {}", kiekerAllFolder.getAbsolutePath(), testMethodName); final File kiekerNextFolder = new File(kiekerAllFolder, testMethodName); final File kiekerResultFolder = kiekerNextFolder.listFiles()[0]; LOG.debug("Test: " + testMethodName); final PrintStream out = System.out; final PrintStream err = System.err; final File kiekerOutputFile = new File(projectFolder.getParent(), "ausgabe_kieker.txt"); Map<String, Set<String>> calledClasses = null; try { System.setOut(new PrintStream(kiekerOutputFile)); System.setErr(new PrintStream(kiekerOutputFile)); calledClasses = new CalledMethodLoader(kiekerResultFolder).getCalledMethods(); for (final Iterator<String> iterator = calledClasses.keySet().iterator(); iterator.hasNext();) { final String clazz = iterator.next(); final String onlyClass = clazz.substring(clazz.lastIndexOf(".") + 1); final Collection<File> files = FileUtils.listFiles(projectFolder, new WildcardFileFilter(onlyClass + "*"), TrueFileFilter.INSTANCE); if (files.size() == 0) { iterator.remove(); } } } catch (final FileNotFoundException e) { e.printStackTrace(); } finally { System.setOut(out); System.setErr(err); } LOG.debug("Test: {} {}", testClassName, testMethodName); LOG.debug("Kieker: {} Dependencies: {}", kiekerResultFolder.getAbsolutePath(), calledClasses.size()); final Map<String, Set<String>> dependencies = this.dependencies .getDependenciesForTest(testClassName + "." + testMethodName); dependencies.putAll(calledClasses); }
From source file:de.egore911.versioning.deployer.Main.java
private static void perform(String arg, CommandLine line) throws IOException { URL url;/* w ww . j av a 2 s . c o m*/ try { url = new URL(arg); } catch (MalformedURLException e) { LOG.error("Invalid URI: {}", e.getMessage(), e); System.exit(1); return; } HttpURLConnection connection; try { connection = (HttpURLConnection) url.openConnection(); int response = connection.getResponseCode(); if (response != HttpURLConnection.HTTP_OK) { LOG.error("Could not download {}", url); connection.disconnect(); System.exit(1); return; } } catch (ConnectException e) { LOG.error("Error during download from URI {}: {}", url, e.getMessage()); System.exit(1); return; } XmlHolder xmlHolder = XmlHolder.getInstance(); DocumentBuilder documentBuilder = xmlHolder.documentBuilder; XPath xPath = xmlHolder.xPath; try { XPathExpression serverNameXpath = xPath.compile("/server/name/text()"); XPathExpression serverTargetdirXpath = xPath.compile("/server/targetdir/text()"); XPathExpression serverDeploymentsDeploymentXpath = xPath.compile("/server/deployments/deployment"); Document doc = documentBuilder.parse(connection.getInputStream()); connection.disconnect(); String serverName = (String) serverNameXpath.evaluate(doc, XPathConstants.STRING); LOG.info("Deploying {}", serverName); boolean shouldPerformCopy = !line.hasOption('r'); PerformCopy performCopy = new PerformCopy(xPath); boolean shouldPerformExtraction = !line.hasOption('r'); PerformExtraction performExtraction = new PerformExtraction(xPath); boolean shouldPerformCheckout = !line.hasOption('r'); PerformCheckout performCheckout = new PerformCheckout(xPath); boolean shouldPerformReplacement = true; PerformReplacement performReplacement = new PerformReplacement(xPath); String targetdir = (String) serverTargetdirXpath.evaluate(doc, XPathConstants.STRING); FileUtils.forceMkdir(new File(targetdir)); NodeList serverDeploymentsDeploymentNodes = (NodeList) serverDeploymentsDeploymentXpath.evaluate(doc, XPathConstants.NODESET); int max = serverDeploymentsDeploymentNodes.getLength(); for (int i = 0; i < serverDeploymentsDeploymentNodes.getLength(); i++) { Node serverDeploymentsDeploymentNode = serverDeploymentsDeploymentNodes.item(i); // Copy if (shouldPerformCopy) { performCopy.perform(serverDeploymentsDeploymentNode); } // Extraction if (shouldPerformExtraction) { performExtraction.perform(serverDeploymentsDeploymentNode); } // Checkout if (shouldPerformCheckout) { performCheckout.perform(serverDeploymentsDeploymentNode); } // Replacement if (shouldPerformReplacement) { performReplacement.perform(serverDeploymentsDeploymentNode); } logPercent(i + 1, max); } // validate that "${versioning:" is not present Collection<File> files = FileUtils.listFiles(new File(targetdir), TrueFileFilter.TRUE, TrueFileFilter.INSTANCE); for (File file : files) { String content; try { content = FileUtils.readFileToString(file); } catch (IOException e) { continue; } if (content.contains("${versioning:")) { LOG.error("{} contains placeholders even after applying the replacements", file.getAbsolutePath()); } } LOG.info("Done deploying {}", serverName); } catch (SAXException | IOException | XPathExpressionException e) { LOG.error("Error performing deployment: {}", e.getMessage(), e); } }
From source file:co.uk.randompanda30.sao.modules.util.BackupUtil.java
public void backup() { TEMP.isBackingup = true;//www. j a v a 2 s . com SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy-HH:mm:ss-z"); f.setTimeZone(TimeZone.getTimeZone("Europe/London")); ArrayList<File> fq = new ArrayList<>(); File ff = new File(toStore); FileUtils.listFiles(ff, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).stream() .filter(fff -> fff.getName().endsWith(".zip")).forEach(fq::add); if (!fq.isEmpty() && fq.size() >= 5) { File[] fil = fq.toArray(new File[fq.size()]); Arrays.sort(fil, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); fil[0].delete(); } size = 0; files = 0; p = 0; lp = -1; time = f.format(GregorianCalendar.getInstance().getTime()); logFile = new File(toStoreLogs + time + ".log"); if (!new File(toStore).exists()) { new File(toStore).mkdir(); } if (!logFile.exists()) { try { logFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } Dispatch.sendMessage((String) Messages.MessagesValues.MODULES_BACKUP_STARTED.value, null); Bukkit.getOnlinePlayers().stream().filter(player -> player.hasPermission("backup.notification")) .forEach(player -> Dispatch .sendMessage((String) Messages.MessagesValues.MODULES_BACKUP_STARTED.value, player)); Thread t = new Thread(new Runnable() { boolean nc = false; @Override public void run() { String s = "zip -r " + toStore + time + ".zip " + toBackup; for (String exclusion : (List<String>) Config.ConfigValues.BACKUP_EXCLUSIONPATHS.value) { String nex = exclusion.endsWith("/") ? exclusion : exclusion + "/"; s += " -x " + toBackup + nex + "\\" + "*"; } startBackupTimer(); File file = new File(toBackup); // FileUtils.listFiles(file, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE) listFDIR(file.getAbsolutePath()); try { Process process = Runtime.getRuntime().exec(s); InputStreamReader is = new InputStreamReader(process.getInputStream()); BufferedReader buff = new BufferedReader(is); FileOutputStream fos = new FileOutputStream(logFile); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); String line; while ((line = buff.readLine()) != null) { files++; bw.write(line); bw.newLine(); updatePercentage(); } bw.close(); } catch (IOException e) { e.printStackTrace(); } nc = true; Dispatch.sendMessage((String) Messages.MessagesValues.MODULES_BACKUP_STOPPED.value, null); Bukkit.getOnlinePlayers().stream().filter(player -> player.hasPermission("backup.notification")) .forEach(player -> Dispatch.sendMessage( (String) Messages.MessagesValues.MODULES_BACKUP_STOPPED.value, player)); if (TEMP.pendingRestart) { // Message new ShutdownTask().runTaskTimer(SAO.getPlugin(), 0L, 20L); } } private void updatePercentage() { double d = (files / size) * 100; p = (int) d; } private void startBackupTimer() { new BukkitRunnable() { @Override public void run() { if (!nc) { String m = (String) Messages.MessagesValues.MODULES_BACKUP_PERCENTAGE.value; m = m.replace("%perc", Integer.toString(p)); m = m.replace("%done", Integer.toString((int) files)); m = m.replace("%files", Integer.toString((int) size)); if (p != lp) { lp = p; Dispatch.sendMessage(m, null); for (Player player : Bukkit.getOnlinePlayers()) { if (player.hasPermission("backup.notification")) { Dispatch.sendMessage(m, player); } } } } else { TEMP.isBackingup = false; startTimer(); this.cancel(); } } }.runTaskTimer(SAO.getPlugin(), 0L, 100L); } }); t.start(); }
From source file:com.rhythm.louie.pbcompiler.PBCompilerMojo.java
@Override public void execute() throws MojoExecutionException { if (!cppgen && !pygen && !javagen) { getLog().warn("PB Compiler had nothing to run!"); return;//from w ww . j a v a 2s.c o m } //adjust directories according to basedir, and create if necessary if (javagen) { javadir = basedirectory + "/" + javadir; makeDir(javadir); } if (pygen) { pythondir = basedirectory + "/" + pythondir; makeDir(pythondir); } if (cppgen) { cppdir = basedirectory + "/" + cppdir; makeDir(cppdir); } List<String> args = new ArrayList<>(); args.add(compiler); args.add("--proto_path=" + basedirectory + "/" + protosrc); if (compilerInclude != null && compilerInclude.length > 0) { for (String dir : compilerInclude) { args.add("--proto_path=" + dir); } } else { // Try to find the google include in some known include dirs for (String dir : includeDirs) { File libdir = new File(dir + "/google"); if (libdir.exists()) { args.add("--proto_path=" + dir); } } } String archivePath = builddirectory + "/" + mavenSharedDir; File sharedArchive = new File(archivePath); if (sharedArchive.exists()) { args.add("--proto_path=" + archivePath); } if (javagen) args.add("--java_out=" + javadir); if (pygen) args.add("--python_out=" + pythondir); if (cppgen) args.add("--cpp_out=" + cppdir); //Find the proto files File dir = new File(basedirectory + "/" + protosrc); IOFileFilter filter = new WildcardFileFilter("**.proto"); Iterator<File> files = FileUtils.iterateFiles(dir, filter, TrueFileFilter.INSTANCE); while (files.hasNext()) { args.add(files.next().toString()); } try { execProtoCompile(args); } catch (IOException ex) { throw new MojoExecutionException(ex.toString()); } if (pygen) { //Generate __init__ files throughout tree where necessary Path pybase = Paths.get(pythondir); PlacePyInit pf = new PlacePyInit(); pf.start = pybase; try { Files.walkFileTree(pybase, pf); } catch (IOException ex) { getLog().error(ex.toString()); } } if (javagen) { //Add the gen'ed java dir back into maven resources getLog().debug("Injecting the Java PB dir into the compile time source root"); project.addCompileSourceRoot(javadir); } }
From source file:com.simpligility.maven.provisioner.MavenRepositoryHelper.java
/** * Determine if it is a leaf directory with artifacts in it. Criteria used is that there is no subdirectory. * //from w w w .j a v a 2 s.co m * @param subDirectory * @return */ private boolean isLeafVersionDirectory(File subDirectory) { boolean isLeafVersionDirectory; Collection<File> subDirectories = FileUtils.listFilesAndDirs(subDirectory, (IOFileFilter) DirectoryFileFilter.DIRECTORY, TrueFileFilter.INSTANCE); // it finds at least itself so have to check for > 1 isLeafVersionDirectory = subDirectories.size() > 1 ? false : true; return isLeafVersionDirectory; }
From source file:com.github.seqware.queryengine.impl.TmpFileStorage.java
/** {@inheritDoc} */ @Override/*from w ww .j av a 2 s .c o m*/ public Iterable<SGID> getAllAtoms() { List<SGID> list = new ArrayList<SGID>(); for (File f : FileUtils.listFiles(tempDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { try { Atom suspect = this.handleFileWithoutClass(f); if (suspect != null) { list.add(suspect.getSGID()); } } catch (Exception e) { if (!oldClassesFound) { oldClassesFound = true; //TODO: we'll probably want something cooler, but for now, if we run into an old version, just warn about it Logger.getLogger(TmpFileStorage.class.getName()).info("Obselete classes detected in " + tempDir.getAbsolutePath() + " you may want to clean it"); } } } return list; }
From source file:com.doplgangr.secrecy.UpdateManager.UpdateManager.java
@Background void version32to40() { //walks the whole file tree, find out files that do not have encoded file names //and encode them. Collection files = FileUtils.listFiles(storage.getRoot(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (Object file : files) { File realFile = (File) file; String fileName = FilenameUtils.removeExtension(realFile.getName()); fileName = fileName.replace("_thumb", ""); if (".nomedia".equals(fileName)) continue; try {//from ww w . j a v a2 s . c o m Base64Coder.decodeString(fileName); } catch (IllegalArgumentException e) { String encodedFileName = Base64Coder.encodeString(fileName); fileName = realFile.getAbsolutePath().replace(fileName, encodedFileName); Boolean ignored = realFile.renameTo(new File(fileName)); } } onFinishAllUpgrade(); }