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

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

Introduction

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

Prototype

public static Collection listFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Finds files within a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:com.sonar.sslr.test.minic.integration.MiniCOwnExamplesTest.java

@Test
public void test() throws Exception {
    Collection<File> files = FileUtils.listFiles(new File("src/test/resources/MiniCIntegration"), null, true);
    assertThat(files).isNotEmpty();/*from   w  w w . ja  v a 2 s. c om*/
    for (File file : files) {
        try {
            parser.parse(file);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }
}

From source file:com.bancvue.mongomigrate.MigrationFileRepositoryTests.java

@After
public void tearDown() {
    // Delete all js files in that the test may have created.
    File directory = new File(".");
    Collection<File> files = FileUtils.listFiles(directory, new WildcardFileFilter("*.js"), null);
    for (File file : files) {
        FileUtils.deleteQuietly(file);//w w w .  j  a va  2  s .c o  m
    }
}

From source file:com.wavemaker.tools.project.ProjectUtils.java

/**
 * Gets a temporary classloader for this project. The project should already be built; classes and libraries should
 * be present in WEB-INF/classes & WEB-INF/lib, respectively.
 * //from   ww  w  . j av  a  2s  .  c o  m
 * @param project The project to get a ClassLoader for.
 * @return A temporary ClassLoader for the given project.
 */
@SuppressWarnings("unchecked")
public static ClassLoader getClassLoaderForProject(Project project) {

    // TODO - This may get ripped out entirely later, so for now we just
    // need to ensure it does not get used in Cloud Foundry
    Assert.isTrue(!WMAppContext.getInstance().isCloudFoundry(),
            "This class should not get used in CloudFoundry");

    try {
        List<File> classpath = new ArrayList<File>();
        if (project.getWebInfClasses() != null) {
            classpath.add(project.getWebInfClasses().getFile());
        }

        if (project.getWebInfLib() != null && project.getWebInfLib().exists()) {
            if (!project.getWebInfLib().getFile().isDirectory()) {
                throw new WMRuntimeException(MessageResource.LIB_DIR_NOT_DIR, project.getWebInfLib());
            }

            classpath.addAll(
                    FileUtils.listFiles(project.getWebInfLib().getFile(), new String[] { "jar" }, false));
        }

        return ClassLoaderUtils.getTempClassLoaderForFile(classpath.toArray(new File[] {}));
    } catch (IOException ex) {
        throw new WMRuntimeException(ex);
    }
}

From source file:cc.recommenders.utils.Zips.java

public static void zip(File directory, File out) throws IOException {
    ZipOutputStream zos = null;//from ww w .  j a va 2s . c  o m
    try {
        OutputSupplier<FileOutputStream> s = Files.newOutputStreamSupplier(out);
        zos = new ZipOutputStream(s.getOutput());
        Collection<File> files = FileUtils.listFiles(directory, FILE, DIRECTORY);
        for (File f : files) {
            String path = removeStart(f.getPath(), directory.getAbsolutePath() + "/");
            ZipEntry e = new ZipEntry(path);
            zos.putNextEntry(e);
            byte[] data = Files.toByteArray(f);
            zos.write(data);
            zos.closeEntry();
        }
    } finally {
        Closeables.close(zos, false);
    }
}

From source file:com.joanju.proparse.unittest.TestNewSyntax.java

public void test01() throws Exception {
    File directory = new File("data/newsyntax/11.7");
    String[] extensions = { "p", "w", "cls" };
    Collection files = FileUtils.listFiles(directory, extensions, true);
    for (Iterator it = files.iterator(); it.hasNext();) {
        File file = (File) it.next();
        System.out.println("Parse: " + file.getAbsolutePath());

        DoParse pu = new DoParse(file.getAbsolutePath());
        pu.doParse();/*from  w  ww .  j  a  v a  2 s .com*/

        // pu.treeParser01();
        // TreeParser03 tp3 = new TreeParser03();
        // tp3.setSupport(new TP03Support());
        // pu.treeParser(tp3);
    }
}

From source file:net.chris54721.infinitycubed.workers.AccountLoader.java

@Override
public void run() {
    try {/*ww  w. j  av  a2  s  . c om*/
        LogHelper.info("Loading saved accounts");
        Collection<File> accountJsons = FileUtils.listFiles(Resources.getFolder(Reference.ACCOUNTS_FOLDER),
                new String[] { "json" }, false);
        Type stringMap = new TypeToken<LinkedHashMap<String, String>>() {
        }.getType();
        for (File accountJson : accountJsons) {
            Map<String, String> data = Reference.DEFAULT_GSON
                    .fromJson(Files.toString(accountJson, Charsets.UTF_8), stringMap);
            if (data == null)
                throw new NullPointerException(
                        "Content of file " + accountJson.getName() + " deserializes to null");
            Account account = new Account(data.get("uuid"), data.get("username"), data.get("nickname"),
                    data.get("accessToken"), data.get("clientToken"));
            boolean selected = Launcher.getSettings().getProperty("selectedAccount")
                    .equalsIgnoreCase(data.get("uuid"));
            account.fetchSkin(selected);
            Launcher.accounts.add(account);
            if (selected)
                selectAccount(account);
        }
    } catch (Exception e) {
        LogHelper.fatal("Failed loading accounts", e);
    }
}

From source file:com.espirit.moddev.basicworkflowsTestIT.java

/**
 * Check if FSM is valid// www.  j  a  v  a2 s. co m
 */
@Test
public void testisFSMValid() {
    try {
        File directory = new File("target");
        Collection files = FileUtils.listFiles(directory, new WildcardFileFilter("*.fsm"), null);
        assertTrue("FSM doesn't contain any files", files.iterator().hasNext());
        if (files.iterator().hasNext()) {
            ZipFile _fsmZip = new ZipFile((File) files.iterator().next());
            ZipEntry fsmEntry = _fsmZip.getEntry(MODULE_DESCRIPTOR);
            assertNotNull("Couldn't find module descriptor (module.xml) in fsm file", fsmEntry);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.joanju.proparse.unittest.TestIncludeRef.java

public void test01() throws Exception {
    File directory = new File("data/newsyntax/Consultingwerk");
    String[] extensions = { "p", "w", "cls" };
    Environment.instance().configSet("propath",
            "/Users/marian/Work/acorn/projects/proparse-mike/data/newsyntax");

    Collection files = FileUtils.listFiles(directory, extensions, true);
    for (Iterator it = files.iterator(); it.hasNext();) {
        File file = (File) it.next();
        System.out.println("Parse: " + file.getAbsolutePath());

        DoParse du = new DoParse(file.getAbsolutePath());
        du.doParse();/*from   w  w  w.ja  v a2s. c o m*/

        ParseUnit pu = new ParseUnit(file);
        pu.treeParser01();
    }
}

From source file:com.exxeta.iss.sonar.esql.test.CheckListTest.java

/**
 * Enforces that each check declared in list.
 *//*from   www.  java2s .  com*/
@Test
public void count() {
    int count = 0;
    List<File> files = (List<File>) FileUtils.listFiles(
            new File("src/main/java/com/exxeta/iss/sonar/esql/check/"), new String[] { "java" }, false);
    for (File file : files) {
        if (file.getName().endsWith("Check.java") && !file.getName().startsWith("Abstract")) {
            count++;
        }
    }
    assertThat(CheckList.getChecks().size()).isEqualTo(count);
}

From source file:biz.gabrys.maven.plugin.util.io.RegexFileScanner.java

/**
 * {@inheritDoc} You must use '/' as path separator in include/exclude patterns.
 *///  w  w w  .  jav a  2s.  co  m
public Collection<File> getFiles(final File directory, final String[] includes, final String[] excludes) {
    final IOFileFilter filter = createFileFilter(directory, includes, excludes);
    return FileUtils.listFiles(directory, filter, TrueFileFilter.INSTANCE);
}