Example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Prototype

IOFileFilter INSTANCE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:mase.stat.MasterTournament.java

public void makeIndsTournaments(String indName) throws Exception {
    List<PersistentSolution> inds = new ArrayList<PersistentSolution>();
    for (File folder : sampleFolders) {
        Collection<File> files = FileUtils.listFiles(folder, new SuffixFileFilter(indName),
                TrueFileFilter.INSTANCE);
        for (File f : files) {
            FileInputStream fis = new FileInputStream(f);
            inds.add(SolutionPersistence.readSolution(fis));
            fis.close();/* w  w  w  . ja  v a2  s  . c  o  m*/
        }
    }

    List<AgentController>[] samples = new List[2];
    samples[0] = new ArrayList<AgentController>(inds.size());
    samples[1] = new ArrayList<AgentController>(inds.size());
    for (PersistentSolution sol : inds) {
        AgentController[] controllers = sol.getController().getAgentControllers(2);
        samples[0].add(controllers[1]);
        samples[1].add(controllers[0]);
    }

    List<File>[] tars = findTars(testFolders);
    // Make tournaments
    for (int job = 0; job < tars[0].size(); job++) {
        // Make evaluations -- test every best from every generation against the samples
        List<EvaluationResult[]>[] subpopEvals = new List[2];
        List<PersistentSolution>[] solutions = new List[2];
        for (int s = 0; s < 2; s++) {
            File tar = tars[s].get(job);
            System.out.println(tar.getAbsolutePath());
            solutions[s] = SolutionPersistence.readSolutionsFromTar(tar);
            List<AgentController> all = loadControllers(solutions[s], s, 1);
            System.out.println(tar.getAbsolutePath() + " " + all.size() + " vs " + samples[s].size());
            subpopEvals[s] = tournament(all, samples[s], s);
        }

        logResults(solutions, subpopEvals, tars[0].get(job).getAbsolutePath().replace("bests.0.tar.gz", ""));
    }
}

From source file:com.fiveamsolutions.nci.commons.mojo.copywebfiles.CopyWebFilesMojo.java

/**
 * @param latestDeployDirectory/*from   ww w  .j  a v a 2  s . c  om*/
 * @param fileFilter
 * @throws MojoExecutionException
 */
@SuppressWarnings("rawtypes")
private void copyFiles(File latestDeployDirectory, IOFileFilter fileFilter) throws MojoExecutionException {
    try {
        for (File srcDir : srcDirectories) {
            Collection filesToCopy = FileUtils.listFiles(srcDir, fileFilter, TrueFileFilter.INSTANCE);
            int count = 0;
            for (Object o : filesToCopy) {
                File src = (File) o;
                String relativePath = StringUtils.removeStart(src.getAbsolutePath(), srcDir.getAbsolutePath());
                File dest = new File(latestDeployDirectory.getAbsoluteFile() + relativePath);
                if (src.lastModified() > dest.lastModified()) {
                    getLog().debug("Copying " + src.getAbsolutePath() + " to " + dest.getAbsolutePath());
                    FileUtils.copyFile(src, dest);
                    count++;
                }
            }
            getLog().info("Copied " + count + " files from " + srcDir.getAbsolutePath() + " to "
                    + latestDeployDirectory.getAbsolutePath());
            FileUtils.copyDirectory(srcDir, latestDeployDirectory, fileFilter);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to copy web files", e);
    }
}

From source file:bioLockJ.module.agent.MailAgent.java

private List<BodyPart> getQsubLogs() throws Exception {
    final List<BodyPart> attachments = new ArrayList<>();
    final List<String> qsubDirs = Config.getList(Config.QSUBS);
    for (final String qsub : qsubDirs) {
        final Collection<File> files = FileUtils.listFiles(new File(qsub), TrueFileFilter.INSTANCE, null);
        for (final File f : files) {
            final BodyPart qsubAttachment = getAttachment(f.getAbsolutePath());
            if (qsubAttachment != null) {
                attachments.add(qsubAttachment);
            } else {
                Log.out.warn("Unable to attache Qsub output: " + f.getAbsolutePath());
            }// w w w.  j a va  2  s  .com
        }
    }

    return attachments;
}

From source file:de.uzk.hki.da.cb.RetrievePackagesHelper.java

/**
 * Unpacks one archive container and moves its content to targetPath.
 * When unpacked, all files below [containerFirstLevelEntry]/data/ are content in this sense.
 * <pre>Example:/*w w  w  .jav  a 2 s. c om*/
 * a/data/rep/abc.tif (from a.tar) -\> [targetPath]/rep/abc.tif</pre>
 *  
 * @param container
 * @param targetPath
 * @throws IOException
 */
private List<DAFile> unpackArchiveAndMoveContents(File container, String targetPath) throws IOException {

    List<DAFile> results = new ArrayList<DAFile>();

    File tempFolder = new File(targetPath + "Temp");
    tempFolder.mkdir();

    try {
        ArchiveBuilder builder = ArchiveBuilderFactory.getArchiveBuilderForFile(container);
        builder.unarchiveFolder(container, tempFolder);
    } catch (Exception e) {
        throw new IOException("Existing AIP \"" + container + "\" couldn't be unpacked to folder " + tempFolder,
                e);
    }

    String containerFirstLevelEntry[] = (tempFolder).list();
    File tempDataFolder = new File(tempFolder.getPath() + "/" + containerFirstLevelEntry[0] + "/data");
    if (!tempDataFolder.exists())
        throw new RuntimeException("unpacked package in Temp doesn't contain a data folder!");

    logger.debug("Listing representations inside temporary folder: ");
    File[] repFolders = tempDataFolder.listFiles();
    for (File rep : repFolders) {

        String repPartialPath = (rep.getPath()).replace(tempDataFolder.getPath() + "/", "");
        if (!rep.isDirectory())
            continue;

        for (File f : FileUtils.listFiles(rep, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
            results.add(new DAFile(repPartialPath,
                    f.getPath().replace((tempDataFolder.getPath() + "/" + repPartialPath + "/"), "")));
        }

        FileUtils.moveDirectoryToDirectory(rep, new File(targetPath), true);
    }

    FolderUtils.deleteDirectorySafe(tempFolder);

    return results;
}

From source file:io.github.jeremgamer.editor.panels.Actions.java

protected void updateList() {
    data.clear();//  w w w.j a v  a  2  s.co m
    File dir = new File("projects/" + Editor.getProjectName() + "/actions");
    if (!dir.exists()) {
        dir.mkdirs();
    }
    for (File file : FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
        data.addElement(file.getName().replace(".rbd", ""));
    }
    actionList.setModel(data);
}

From source file:com.tasktop.c2c.server.internal.profile.service.template.GitServiceCloner.java

/**
 * @param directory// w ww .j ava 2  s.  c  o m
 * @param context
 * @throws IOException
 */
private void maybeRewriteRepo(File directory, CloneContext context) throws IOException {
    if (context.getProjectTemplateMetadata() == null
            || context.getProjectTemplateMetadata().getFileReplacements() == null) {
        return;
    }
    for (GitFileReplacement fileReplacement : context.getProjectTemplateMetadata().getFileReplacements()) {

        ProjectTemplateProperty property = context.getProperty(fileReplacement.getPropertyId());

        if (property == null || property.getValue() == null) {
            throw new IllegalStateException("Missing property: " + fileReplacement.getPropertyId());
        }

        IOFileFilter fileFilter;

        if (fileReplacement.getFileName() != null) {
            fileFilter = new NameFileFilter(fileReplacement.getFileName());
        } else if (fileReplacement.getFilePattern() != null) {
            fileFilter = new RegexFileFilter(fileReplacement.getFilePattern());
        } else {
            fileFilter = TrueFileFilter.INSTANCE;
        }

        IOFileFilter dirFilter = new NotFileFilter(new NameFileFilter(".git"));
        for (File file : FileUtils.listFiles(directory, fileFilter, dirFilter)) {
            // REVIEW, this rewrites the content, by streaming the entire process into memory.
            String content = FileUtils.readFileToString(file);
            String rewrittenContent = content.replace(fileReplacement.getPatternToReplace(),
                    property.getValue());
            FileUtils.write(file, rewrittenContent);
        }
    }

}

From source file:com.github.blindpirate.gogradle.crossplatform.DefaultGoBinaryManager.java

private void addXPermissionToAllDescendant(Path path) {
    listFiles(path.toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).stream().map(File::toPath)
            .forEach(IOUtils::chmodAddX);
}

From source file:com.ibm.soatf.component.jms.JmsComponent.java

/**
 *
 * @param objectName/*  w w w  . ja v  a 2s  . c  o m*/
 * @return
 */
public Iterator<File> getGeneratedFilesIterator(String objectName) {
    String pattern = "*";
    if (objectName != null) {
        pattern = objectName;
    }
    String filemask = new StringBuilder(jmsInterfaceConfig.getQueue().getName()).append(NAME_DELIMITER)
            .append(pattern).append(MESSAGE_SUFFIX).toString();
    Iterator it = FileUtils.iterateFiles(workingDir, new WildcardFileFilter(filemask), TrueFileFilter.INSTANCE);
    return it;
}

From source file:io.github.jeremgamer.maintenance.Maintenance.java

public void backupProcess(CommandSender sender) {

    Calendar cal = Calendar.getInstance();
    DateFormat dateFormat = new SimpleDateFormat("yyyy MM dd - HH mm ss");
    String zipFile = new File("").getAbsolutePath() + "/backups/" + dateFormat.format(cal.getTime()) + ".zip";
    File zip = new File(zipFile);
    String srcDir = new File("").getAbsolutePath();

    try {//from  w  ww  .ja  v  a 2s . c  o  m

        try {
            zip.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        File dir = new File(srcDir);

        List<File> filesList = (List<File>) FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
                TrueFileFilter.INSTANCE);
        File[] files = filesList.toArray(new File[filesList.size()]);

        OutputStream out = new FileOutputStream(zip);
        ArchiveOutputStream zipOutput = new ZipArchiveOutputStream(out);
        String filePath;

        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {

            } else if (files[i].getAbsolutePath().contains(new File("").getAbsolutePath() + "\\backups\\")) {

            } else {

                filePath = files[i].getAbsolutePath().substring(srcDir.length() + 1);

                try {
                    ZipArchiveEntry entry = new ZipArchiveEntry(filePath);
                    entry.setSize(new File(files[i].getAbsolutePath()).length());
                    zipOutput.putArchiveEntry(entry);
                    IOUtils.copy(new FileInputStream(files[i].getAbsolutePath()), zipOutput);
                    zipOutput.closeArchiveEntry();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        zipOutput.finish();
        zipOutput.close();
        out.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
    }

    sender.sendMessage(getConfig().getString("backupSuccess").replaceAll("&", ""));
    getLogger().info("Backup success!");
}

From source file:de.peran.dependency.ChangedTestClassesHandler.java

/**
 * Updates the dependencies of the current version by running each testclass once. The testcases, that have been added in this version, are returned (since they can not be determined from the old
 * dependency information or the svn diff directly).
 * //from  ww  w. j av  a  2  s.c  o  m
 * @param testsToUpdate
 * @return
 * @throws IOException
 * @throws InterruptedException
 */
public Map<String, Set<String>> updateDependencies(final Map<String, List<String>> testsToUpdate)
        throws InterruptedException {
    final Map<String, Map<String, Set<String>>> oldDepdendencies = dependencies.getCopiedDependencies();

    truncateKiekerResults();

    LOG.debug("Fhre Tests neu aus fr Abhngigkeiten-Aktuallisierung, Ergebnisordner: {}", resultsFolder);
    try {
        final TestSet tests = new TestSet();
        for (final String clazzname : testsToUpdate.keySet()) {
            tests.addTest(clazzname, "");
        }
        executeKoPeMeKiekerRun(tests);
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    LOG.debug("Beginne Abhngigkeiten-Aktuallisierung fr {} Klassen", testsToUpdate.keySet().size());

    // Remove all old dependencies, because they may have been deleted
    for (final Entry<String, List<String>> className : testsToUpdate.entrySet()) {
        for (final String method : className.getValue()) {
            dependencies.getDependencyMap().remove(className + "." + method);
        }
    }

    for (final Entry<String, List<String>> entry : testsToUpdate.entrySet()) {
        final File testclazzFolder = new File(xmlFileFolder, entry.getKey());
        LOG.debug("Suche in {} Existiert: {} Ordner: {}", testclazzFolder, testclazzFolder.exists(),
                testclazzFolder.isDirectory());
        if (testclazzFolder.exists() && entry.getValue().size() > 0) {
            for (final File testResultFile : testclazzFolder
                    .listFiles((FileFilter) new WildcardFileFilter("*.xml"))) {
                if (testResultFile.exists()) {
                    final String testClassName = testResultFile.getParentFile().getName();
                    final File parent = testResultFile.getParentFile();
                    final String methodName = testResultFile.getName().substring(0,
                            testResultFile.getName().length() - 4);
                    updateDependenciesOnce(testClassName, methodName, parent);
                }
            }
        } else {
            LOG.debug("Suche in {} Existiert: {} Ordner: {}", testclazzFolder, testclazzFolder.exists(),
                    testclazzFolder.isDirectory());
            if (testclazzFolder.exists()) {
                for (final File testResultFile : FileUtils.listFiles(testclazzFolder,
                        new WildcardFileFilter("*.xml"), TrueFileFilter.INSTANCE)) {
                    final String testClassName = testResultFile.getParentFile().getName();
                    final String testName = testResultFile.getName().substring(0,
                            testResultFile.getName().length() - 4); // .xml entfernen
                    final File parent = testResultFile.getParentFile();
                    updateDependenciesOnce(testClassName, testName, parent);
                }
            } else {
                LOG.error(
                        "Testklasse {} existiert nicht mehr bzw. liefert keine Ergebnisse mehr (JUnit 4 statt 3?).",
                        entry.getKey());
            }
        }
    }

    final Map<String, Set<String>> newTestCases = new TreeMap<>(); // Map from changedclass to a set of testcases that may have changed
    for (final Map.Entry<String, Map<String, Set<String>>> entry : dependencies.getDependencyMap().entrySet()) {
        final String testcase = entry.getKey();
        if (!oldDepdendencies.containsKey(testcase)) {
            for (final Map.Entry<String, Set<String>> changedClass : entry.getValue().entrySet()) {
                Set<String> testcaseSet = newTestCases.get(changedClass.getKey());
                if (testcaseSet == null) {
                    testcaseSet = new TreeSet<>();
                    newTestCases.put(changedClass.getKey(), testcaseSet);
                }
                testcaseSet.add(testcase);
            }
        }
    }
    return newTestCases;
}