Example usage for org.apache.commons.io FileUtils iterateFiles

List of usage examples for org.apache.commons.io FileUtils iterateFiles

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils iterateFiles.

Prototype

public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Allows iteration over the files in a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:org.gradle.api.internal.tasks.compile.incremental.graph.ClassDependencyInfoExtractor.java

public ClassDependencyInfo extractInfo(String packagePrefix) {
    Map<String, ClassDependents> dependents = new HashMap<String, ClassDependents>();
    Iterator output = FileUtils.iterateFiles(classesDir, new String[] { "class" }, true);
    ClassNameProvider nameProvider = new ClassNameProvider(classesDir);
    while (output.hasNext()) {
        File classFile = (File) output.next();
        String className = nameProvider.provideName(classFile);
        if (!className.startsWith(packagePrefix)) {
            continue;
        }/*from  w ww . ja va2  s .  co m*/
        try {
            ClassAnalysis analysis = new ClassDependenciesAnalyzer().getClassAnalysis(className, classFile);
            for (String dependency : analysis.getClassDependencies()) {
                if (!dependency.equals(className) && dependency.startsWith(packagePrefix)) {
                    getOrCreateDependentMapping(dependents, dependency).addClass(className);
                }
            }
            if (analysis.isDependentToAll()) {
                getOrCreateDependentMapping(dependents, className).setDependentToAll();
            }
        } catch (IOException e) {
            throw new RuntimeException("Problems extracting class dependency from " + classFile, e);
        }
    }
    return new ClassDependencyInfo(dependents);
}

From source file:org.jenkins.plugins.leroy.NewProject.java

private void readWorkflowsFromDisk(String workflowsDir) {
    File wfDir = new File(workflowsDir);
    workflow = new ArrayList<String>();
    if (wfDir.exists() && wfDir.canRead()) {
        //get file names
        IOFileFilter workflowFileFilter = new AbstractFileFilter() {
            @Override/*from  www  .  j  av a2 s.  c o m*/
            public boolean accept(File file) {
                try {
                    if (LeroyUtils.isWorkflow(file)) {
                        return true;
                    }
                } catch (Throwable t) {
                    t.printStackTrace();
                }
                return false;
            }
        };
        Iterator<File> fileIterator = FileUtils.iterateFiles(new File(workflowsDir), workflowFileFilter,
                TrueFileFilter.INSTANCE);
        if (fileIterator != null) {
            URI workFlowsBase = new File(workflowsDir).toURI();
            while (fileIterator.hasNext()) {
                // get relative path using workflow folder as a base and remove extension
                File wf = fileIterator.next();
                String relative = workFlowsBase.relativize(wf.toURI()).getPath();
                String wfName = relative.substring(0, relative.lastIndexOf('.'));
                workflow.add(wfName);
            }
        }
    }
}

From source file:org.jenkinsci.plugins.django.DjangoProjectSettingsFinder.java

@Override
public final String invoke(final File dir, final VirtualChannel channel)
        throws IOException, InterruptedException {
    File found = null;//w  w w. j  a v  a2 s  . c  om
    DjangoJenkinsBuilder.LOGGER.info("Finding settings modules in " + dir.getPath());
    String foundCandidate = null;
    final NotFileFilter excldeJenkins = new NotFileFilter(
            new NameFileFilter(PythonVirtualenv.DJANGO_JENKINS_MODULE));

    searchCandidate: for (final String candidate : MODULE_CANDIDATES) {
        DjangoJenkinsBuilder.LOGGER.info("Trying to find some " + candidate);
        DjangoJenkinsBuilder.LOGGER.info("Probing " + candidate);
        final Iterator<File> iter = FileUtils.iterateFiles(dir, new NameFileFilter(candidate + ".py"),
                excldeJenkins);
        while (iter.hasNext()) {
            found = iter.next();
            foundCandidate = candidate;
            DjangoJenkinsBuilder.LOGGER.info("Found settings in " + found.getPath());
            break searchCandidate;
        }
    }

    if (found == null) {
        DjangoJenkinsBuilder.LOGGER.info("No settings modules found!!!");
        DjangoJenkinsBuilder.LOGGER.info("No settings module!");
        throw (new IOException("No settings module found"));
    }
    final String pkgPath = dir.toURI().relativize(found.getParentFile().toURI()).toString();
    DjangoJenkinsBuilder.LOGGER.info("Pakage found: " + pkgPath);
    final String module = pkgPath.replace(File.separatorChar, '.') + foundCandidate;
    DjangoJenkinsBuilder.LOGGER.info("Settings module is: " + module);
    return module;
}

From source file:org.jenkinsci.plugins.django.ProjectApplicationsFinder.java

@Override
public final String invoke(final File dir, final VirtualChannel channel)
        throws IOException, InterruptedException {
    DjangoJenkinsBuilder.LOGGER.info("Finding project apps in: " + dir.getPath());
    String apps = null;//from   www  .  j  a v  a2s  . com
    final NotFileFilter excludeJenkins = new NotFileFilter(
            new NameFileFilter(PythonVirtualenv.DJANGO_JENKINS_MODULE));

    final String[] appFiles = { "views.py", "models.py", "urls.py", "tests.py" };
    final NameFileFilter filterApps = new NameFileFilter(appFiles);

    final Iterator<File> iter = FileUtils.iterateFiles(dir, filterApps, excludeJenkins);
    final Set<String> foundApps = new HashSet<String>();
    while (iter.hasNext()) {
        final File found = iter.next();
        final String app = found.getParentFile().getName();
        DjangoJenkinsBuilder.LOGGER.info("Found app: " + app);
        foundApps.add(app);
    }
    if (foundApps.size() > 0) {
        apps = StringUtils.join(foundApps, ",");
    }
    DjangoJenkinsBuilder.LOGGER.info("Found apps: " + apps);
    return apps;
}

From source file:org.jenkinsci.plugins.django.ProjectRequirementsFinder.java

@Override
public final String invoke(final File dir, final VirtualChannel channel)
        throws IOException, InterruptedException {
    File found = null;/*  w w w.  j  av  a2  s. c om*/
    DjangoJenkinsBuilder.LOGGER.info("Finding requirement files in " + dir.getPath());
    String foundCandidate = null;
    final NotFileFilter excludeJenkins = new NotFileFilter(
            new NameFileFilter(PythonVirtualenv.DJANGO_JENKINS_MODULE));

    searchCandidate: for (final String candidate : REQUIREMENTS_CANDIDATE) {
        DjangoJenkinsBuilder.LOGGER.info("Trying to find some " + candidate);
        DjangoJenkinsBuilder.LOGGER.info("Probing " + candidate);
        final Iterator<File> iter = FileUtils.iterateFiles(dir, new NameFileFilter(candidate), excludeJenkins);
        while (iter.hasNext()) {
            found = iter.next();
            foundCandidate = candidate;
            DjangoJenkinsBuilder.LOGGER.info("Found settings in " + found.getPath());
            break searchCandidate;
        }
    }

    if (found == null) {
        DjangoJenkinsBuilder.LOGGER.info("No requirements modules found!!!");
        DjangoJenkinsBuilder.LOGGER.info("No settings module!");
        throw (new IOException("No settings module found"));
    }
    final String pkgPath = dir.toURI().relativize(found.getParentFile().toURI()).toString();
    DjangoJenkinsBuilder.LOGGER.info("Pakage found: " + pkgPath);
    final String module = pkgPath + foundCandidate;
    DjangoJenkinsBuilder.LOGGER.info("Settings module is: " + module);
    return module;
}

From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.TimeseriesImporter.java

public void copyTimeseries(final IProgressMonitor monitor) {
    final String name = Messages.getString("TimeseriesImporter_2", m_sourceDir.getName()); //$NON-NLS-1$
    monitor.beginTask(name, IProgressMonitor.UNKNOWN);

    final File sourceTimeseriesDir = m_sourceDir;

    /* Return, if directory does not exist */
    if (!sourceTimeseriesDir.isDirectory())
        return;/*from www .  j ava  2 s  .c o m*/

    final IStatusCollector stati = new StatusCollector(KalypsoUIRRMPlugin.getID());

    /* Find all .zml */
    final Iterator<File> zmlIterator = FileUtils.iterateFiles(sourceTimeseriesDir, new String[] { "zml" }, //$NON-NLS-1$
            true);
    for (final Iterator<File> iterator = zmlIterator; iterator.hasNext();) {
        final File zmlFile = iterator.next();
        monitor.subTask(zmlFile.getName());

        try {
            stati.add(importZml(sourceTimeseriesDir, zmlFile));
        } catch (final CoreException e) {
            stati.add(e.getStatus());
        } catch (final Exception e) {
            final String relativePath = FileUtilities.getRelativePathTo(sourceTimeseriesDir, zmlFile);

            final String message = String.format(Messages.getString("TimeseriesImporter_4"), relativePath); //$NON-NLS-1$
            final IStatus status = new Status(IStatus.WARNING, KalypsoUIRRMPlugin.getID(), message, e);
            stati.add(status);
        }

        monitor.worked(1);
    }

    /* Log it */
    final String message = Messages.getString("TimeseriesImporter_5", m_sourceDir.getName()); //$NON-NLS-1$
    final IStatus status = stati.asMultiStatusOrOK(message, message);
    m_log.add(status);

    monitor.done();
}

From source file:org.limy.eclipse.qalab.task.Java2HtmlTask.java

/**
 * srcdirwR}h?s?B/*from  ww w.j a  va 2  s . c om*/
 * @param cmd java->htmlR}h
 * @throws IOException I/OO
 */
private void execWithSrcDir(JavaToHtml cmd) throws IOException {
    if (srcDir == null) {
        throw new BuildException("srcDir  fileset vfK?{?B");
    }

    Collection<String> classNames = new ArrayList<String>();

    Iterator<Object> fileIt = FileUtils.iterateFiles(srcDir, new String[] { "java" }, true);
    while (fileIt.hasNext()) {
        File file = (File) fileIt.next();
        writeFile(cmd, file, srcDir);
        classNames.add(file.getAbsolutePath().substring(srcDir.getAbsolutePath().length() + 1));
    }
    createIndexHtml(classNames);
}

From source file:org.limy.eclipse.qalab.task.TodoReportTask.java

/**
 * srcdirwR}h?s?B// ww  w.  j  a v a2 s .co  m
 * @param cmd TODO?oR}h
 * @throws IOException I/OO
 */
private void execWithSrcDir(TodoReport cmd) throws IOException {
    if (srcDir == null) {
        throw new BuildException("srcDir  fileset vfK?{?B");
    }
    Iterator<File> fileIt = FileUtils.iterateFiles(srcDir, new String[] { "java" }, true);
    while (fileIt.hasNext()) {
        parseFile(cmd, fileIt.next(), srcDir);
    }
    cmd.writeXml(outputFile, "UTF-8");
}

From source file:org.lpe.common.util.system.LpeSystemUtils.java

/**
 * Extracts files from a directory in the classpath to a temp directory and
 * returns the File instance of the destination directory.
 * /*from  w w  w.  j a  v a2s  .c  om*/
 * @param srcDirName
 *            a directory name in the classpath
 * @param destName
 *            the name of the destination folder in the temp folder
 * @param fileType
 *            a string describing the file types, if a log message is needed
 * @param timeStamp
 *            if <code>true</code>, it will add a time stamp to the name of
 *            the target directory (recommended)
 * @param classloader
 *            classloader to use
 * 
 * @return the name of the target directory
 * 
 * @throws IOException
 *             ...
 * @throws URISyntaxException
 *             ...
 */
public static String extractFilesFromClasspath(String srcDirName, String destName, String fileType,
        ClassLoader classloader, boolean timeStamp) throws IOException, URISyntaxException {

    if (timeStamp) {
        // remove dots and colons from timestamp as they are not allowed for
        // windows directory names
        String clearedTimeStamp = (LpeStringUtils.getTimeStamp() + "-" + Thread.currentThread().getId())
                .replace('.', '_');

        clearedTimeStamp = clearedTimeStamp.replace(':', '_');
        clearedTimeStamp = clearedTimeStamp.replace(' ', '_');

        destName = destName + "_" + clearedTimeStamp;
    }
    final String targetDirName = LpeFileUtils.concatFileName(getSystemTempDir(), destName);

    // create a temp lib directory
    File targetDirFile = new File(targetDirName);
    if (!targetDirFile.exists()) {
        boolean ok = targetDirFile.mkdir();
        if (!ok) {
            logger.warn("Could not create directory {}", targetDirFile.getAbsolutePath());
        }
    }

    logger.debug("Copying {} to {}.", fileType, targetDirName);

    Enumeration<URL> urls = classloader.getResources(srcDirName); // getSystemResources(srcDirName);

    if (urls.hasMoreElements()) {
        logger.debug("There are some urls for resource '{}' provided by the classloader.", srcDirName);
    } else {
        logger.debug("There are no urls for resource '{}' provided by the classloader.", srcDirName);
    }

    while (urls.hasMoreElements()) {

        final URL url = urls.nextElement();

        if (fileType != null && fileType.trim().length() > 0) {
            logger.debug("Loading {} from {}...", fileType, url);
        }

        Iterator<File> libs = null;
        String unpackedJarDir = null;
        if (url.getProtocol().equals("bundleresource")) {
            continue;
        } else if (url.getProtocol().equals("jar")) {
            try {
                unpackedJarDir = LpeFileUtils.concatFileName(targetDirName, "temp");

                extractJARtoTemp(url, srcDirName, unpackedJarDir);

                final String unpackedNativeDir = LpeFileUtils.concatFileName(unpackedJarDir, srcDirName);
                final File unpackedNativeDirFile = new File(unpackedNativeDir);
                libs = FileUtils.iterateFiles(unpackedNativeDirFile, null, false);
            } catch (IllegalArgumentException iae) {
                // ignore
                LOGGER.warn("Jar not found, could not extract jar. {}", iae);

            }
        } else {
            // File nativeLibDir = new
            // File(url.toString().replaceAll("\\\\", "/"));
            File nativeLibDir = new File(url.toURI());
            libs = FileUtils.iterateFiles(nativeLibDir, null, false);
        }

        while (libs != null && libs.hasNext()) {
            final File libFile = libs.next();
            logger.debug("Copying resouce file {}...", libFile.getName());
            FileUtils.copyFileToDirectory(libFile, targetDirFile);
        }

        // clean up temp dir
        if (unpackedJarDir != null) {
            File dirToRemove = new File(unpackedJarDir);
            if (dirToRemove.isDirectory() && dirToRemove.exists()) {
                LpeFileUtils.removeDir(unpackedJarDir);
            }
        }

    }

    return targetDirName;
}

From source file:org.mili.ant.FileHeaderCheckerImpl.java

/**
 * Start./*from ww  w  .  ja v  a  2s.  c o m*/
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void start() throws IOException {
    Iterator<File> i = FileUtils.iterateFiles(this.dir, new String[] { "java" }, true);
    String temp = FileUtils.readFileToString(this.template);
    while (i.hasNext()) {
        File f = i.next();
        try {
            this.proceed(f, temp);
        } catch (IOException e) {
            System.out.println("ERROR: " + f + " -> " + e.getMessage());
        }
    }
}