Example usage for org.apache.commons.io.filefilter AgeFileFilter AgeFileFilter

List of usage examples for org.apache.commons.io.filefilter AgeFileFilter AgeFileFilter

Introduction

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

Prototype

public AgeFileFilter(File cutoffReference, boolean acceptOlder) 

Source Link

Document

Constructs a new age file filter for files on any one side of a certain File (whose last modification time will be used as reference).

Usage

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

/**
 * @param latestDeployDirectory//w w w  . ja  v  a 2  s . c  o m
 * @return
 */
private IOFileFilter getFilefilter(File latestDeployDirectory) {
    IOFileFilter fileFilter = new SuffixFileFilter(fileTypes);
    fileFilter = FileFilterUtils.andFileFilter(FileFileFilter.FILE, fileFilter);
    fileFilter = FileFilterUtils.andFileFilter(new AgeFileFilter(latestDeployDirectory, false), fileFilter);
    return fileFilter;
}

From source file:org.elasticwarehouse.core.parsers.FileTools.java

public static LinkedList<FileDef> scanFolder(String path, List<String> excluded_extenstions, Date newerthan)
        throws java.security.AccessControlException {
    LinkedList<FileDef> ret = new LinkedList<FileDef>();
    File folder = new File(path);
    LinkedList<File> listOfFiles = new LinkedList<File>();

    if (newerthan != null) {
        Iterator<File> newFiles = FileUtils.iterateFiles(folder, new AgeFileFilter(newerthan, false), null);//org.apache.commons.io.filefilter.TrueFileFilter.TRUE);
        while (newFiles.hasNext()) {
            listOfFiles.add(newFiles.next());
        }//from  ww  w.  j a v  a 2s  .  c o  m
    } else {
        listOfFiles.addAll(Arrays.asList(folder.listFiles()));
    }
    if (listOfFiles.size() == 0)
        return ret;

    //return listOfFiles;
    for (File file : listOfFiles) {
        if (file.isFile()) {
            String fname = file.getName();
            boolean exclude = false;
            for (String excludeext : excluded_extenstions) {
                if (fname.endsWith("." + excludeext)) {
                    exclude = true;
                    break;
                }
            }
            if (!exclude)
                ret.add(new FileDef(file.getName(), file.getParent(), file.lastModified()));
        }
    }

    return ret;
}

From source file:org.jahia.tools.files.FileWatcherJob.java

/**
 * Checks new files and builds the List of files to pass to Observers
 * /*from w  w w. jav  a2  s  .  c o  m*/
 * @param folder
 *            the root folder where to watch files
 * @param fileOnly
 *            if <code>true</code> we consider only files; otherwise we also consider folders
 * @param recursive
 *            should we recurse into sub-folders
 * @param checkDate
 *            do we need to check the last modification date or in case of <code>false</code> value just return all found files
 * @param lastCheckTime
 *            the last check time
 * @return a list of files and folders matching the provided criteria
 */
protected List<File> checkFiles(File folder, boolean fileOnly, boolean recursive, boolean checkDate,
        long lastCheckTime, IOFileFilter ignoreFilter) {
    if (!folder.isDirectory()) {
        return Collections.emptyList();
    }
    List<File> files = null;
    if (fileOnly || !checkDate) {
        IOFileFilter fileFilter;
        IOFileFilter dirFilter;
        if (ignoreFilter != null) {
            fileFilter = checkDate ? new AndFileFilter(new AgeFileFilter(lastCheckTime, false), ignoreFilter)
                    : ignoreFilter;
            dirFilter = recursive ? ignoreFilter : FalseFileFilter.INSTANCE;
        } else {
            fileFilter = checkDate ? new AgeFileFilter(lastCheckTime, false) : TrueFileFilter.INSTANCE;
            dirFilter = recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE;
        }
        Collection<File> foundFiles = fileOnly ? FileUtils.listFiles(folder, fileFilter, dirFilter)
                : FileUtils.listFilesAndDirs(folder, fileFilter, dirFilter);
        files = (foundFiles instanceof List<?>) ? (List<File>) foundFiles : new LinkedList<File>(foundFiles);
    } else {
        if (recursive) {
            try {
                files = new Walker(lastCheckTime).execute(folder);
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
            }
        } else {
            Collection<File> foundFiles = FileUtils.listFilesAndDirs(folder,
                    ignoreFilter != null
                            ? new AndFileFilter(new AgeFileFilter(lastCheckTime, false), ignoreFilter)
                            : null,
                    FalseFileFilter.INSTANCE);
            files = (foundFiles instanceof List<?>) ? (List<File>) foundFiles
                    : new LinkedList<File>(foundFiles);
        }
    }

    return files;
}

From source file:org.sonatype.flexmojos.compiler.AbstractCompilerMojo.java

@SuppressWarnings("unchecked")
private boolean isCompilationRequired() throws MojoExecutionException {
    if (!quick) {
        // not running at quick mode
        return true;
    }//  w ww  .  j  a va 2 s  .c  om

    Artifact artifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(),
            project.getVersion(), null, project.getPackaging());
    try {
        resolver.resolve(artifact, remoteRepositories, localRepository);
    } catch (AbstractArtifactResolutionException e) {
        // Not available at repository
        return true;
    }

    File artifactFile = artifact.getFile();
    if (artifactFile == null || !artifactFile.exists()) {
        // Recompile, file doesn't exists
        getLog().warn("Can't find any older instaled version.");
        return true;
    }
    try {
        FileUtils.copyFile(artifactFile, getOutput());
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to copy instaled version to target folder.", e);
    }
    long lastCompiledArtifact = artifactFile.lastModified();

    Set<Artifact> dependencies = getDependencyArtifacts();
    for (Artifact dependency : dependencies) {
        if (FileUtils.isFileNewer(dependency.getFile(), lastCompiledArtifact)) {
            // a dependency is newer, recompile
            getLog().warn("Found a updated dependency: " + dependency);
            return true;
        }
    }

    List<File> paths = new ArrayList<File>(Arrays.asList(sourcePaths));
    paths.remove(new File(resourceBundlePath));

    addLocalesPath(paths, compiledLocales);
    addLocalesPath(paths, runtimeLocales);

    for (File sourcePath : paths) {
        Collection<File> files = FileUtils.listFiles(sourcePath, new AgeFileFilter(lastCompiledArtifact, false),
                TrueFileFilter.INSTANCE);

        // If has any newer file
        if (files.size() > 0) {
            getLog().warn("Found some updated files.");
            return true;
        }
    }

    // nothing new was found.
    return false;
}

From source file:org.sonatype.flexmojos.plugin.compiler.AbstractFlexCompilerMojo.java

@SuppressWarnings("unchecked")
public boolean isCompilationRequired() {
    if (!quick) {
        // not running at quick mode
        return true;
    }/*from ww w  .  j  a  v  a2  s  . co m*/

    Artifact artifact;
    try {
        artifact = resolve(project.getGroupId(), project.getArtifactId(), project.getVersion(), getClassifier(),
                project.getPackaging());
    } catch (RuntimeMavenResolutionException e) {
        artifact = e.getArtifact();
    }

    if (!artifact.isResolved() || artifact.getFile() == null || !artifact.getFile().exists()) {
        // Recompile, file doesn't exists
        getLog().warn("Can't find any older installed version.");
        return true;
    }

    long lastCompiledArtifact = artifact.getFile().lastModified();

    boolean required = false;
    Set<Artifact> dependencies = getDependencies();
    for (Artifact dependency : dependencies) {
        if (org.apache.commons.io.FileUtils.isFileNewer(dependency.getFile(), lastCompiledArtifact)) {
            // a dependency is newer, recompile
            getLog().warn("Found a updated dependency: " + dependency);
            required = true;
        }
    }

    if (!required) {
        Collection<File> files = org.apache.commons.io.FileUtils.listFiles(
                new File(project.getBuild().getSourceDirectory()),
                new AgeFileFilter(lastCompiledArtifact, false), TrueFileFilter.INSTANCE);

        // If has any newer file
        if (files.size() > 0) {
            getLog().warn("Found some updated files.");
            required = true;
        }
    }

    if (!required) {
        try {
            final File output = new File(getOutput());

            FileUtils.copyFile(artifact.getFile(), output);

            if (!output.setLastModified(artifact.getFile().lastModified())) {
                getLog().warn("Could not set modified on copied artifact. Unnecessary rebuilds will occur.");
            }
        } catch (IOException e) {
            getLog().error("Unable to copy installed version to target folder.", e);
            return true;
        }
    }

    // nothing new was found.
    return required;
}