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.github.nullstress.asm.SourceSetScanner.java

public Set<String> analyze(URI uri) {
    Set<String> dependencies = new HashSet<String>();
    try {//  w w  w .j av  a 2s. co  m
        File startDir = new File(uri);
        if (!startDir.isDirectory()) {
            return dependencies;
        }
        Collection<File> files = FileUtils.listFiles(startDir, new String[] { "class" }, true);
        for (File file : files) {
            dependencies.addAll(scanFile(FileUtils.openInputStream(file)));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return dependencies;
}

From source file:com.denimgroup.threadfix.framework.impl.dotNet.DotNetMappings.java

@SuppressWarnings("unchecked")
public DotNetMappings(@Nonnull File rootDirectory) {
    assert rootDirectory.exists() : "Root file did not exist.";
    assert rootDirectory.isDirectory() : "Root file was not a directory.";

    this.rootDirectory = rootDirectory;

    cSharpFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter("cs"),
            TrueFileFilter.INSTANCE);//  ww w.java2  s  .c o  m

    generateMappings();
}

From source file:fr.paris.lutece.plugins.swaggerui.service.SwaggerFileService.java

/**
 * Returns the list of swagger files//  w ww  .j a v a2s.  c om
 * 
 * @param request The HTTP request
 * @return The list of swagger files
 */
public static List<SwaggerFile> getSwaggerFiles(HttpServletRequest request) {
    List<SwaggerFile> listSwaggerFiles = new ArrayList<>();
    List<File> listSwaggerDirectories = new ArrayList<>();
    String[] filesExtension = { EXT_JSON, EXT_YAML };
    File folderWebApp = new File(AppPathService.getWebAppPath() + SWAGGER_DIRECTORY_PATH);
    findDirectory(listSwaggerDirectories, folderWebApp);

    for (File swaggerDirectory : listSwaggerDirectories) {
        Collection<File> filesSwagger = FileUtils.listFiles(swaggerDirectory, filesExtension, true);
        for (File fileSwagger : filesSwagger) {
            String strPluginName = swaggerDirectory.getParentFile().getParentFile().getName();
            if (PluginService.isPluginEnable(strPluginName)) {
                SwaggerFile swaggerFile = new SwaggerFile();
                swaggerFile.setPluginName(strPluginName);
                swaggerFile.setVersion(fileSwagger.getParentFile().getName());

                String relativePath = new File(AppPathService.getWebAppPath()).toURI()
                        .relativize(fileSwagger.toURI()).getPath();
                swaggerFile.setPath(AppPathService.getBaseUrl(request) + SERVLET_PATH + relativePath);

                listSwaggerFiles.add(swaggerFile);
            }
        }
    }
    return listSwaggerFiles;
}

From source file:com.dianping.maven.plugin.tools.misc.file.ServiceLionPropertiesGenerator.java

protected void generate(ServiceLionContext context) throws Exception {

    File projectMetaOutput = new File(context.getOutputBaseDir(), SERVICE_META_FILE);

    if (context.isRefreshProjectMeta()) {
        ProjectMetaGenerator projectMetaGenerator = new ProjectMetaGenerator();
        projectMetaGenerator.generate(projectMetaOutput, context.getProjectMetaContext());
    }//w  ww .j av a 2  s  . c  o m

    Scanner<ProjectPortEntry> projectMetaScanner = new ProjectMetaScanner();
    List<ProjectPortEntry> projectPortsList = projectMetaScanner.scan(projectMetaOutput);
    Map<String, Integer> projectPortMapping = new HashMap<String, Integer>();
    for (ProjectPortEntry entry : projectPortsList) {
        projectPortMapping.put(entry.getProject(), entry.getPort());
    }

    Map<String, String> serviceLionContents = new HashMap<String, String>();

    Scanner<String> serviceScanner = new ServiceScanner();
    for (Map.Entry<String, File> entry : context.getProjectBaseDirMapping().entrySet()) {
        Collection<File> allXmlFiles = FileUtils.listFiles(entry.getValue(), new String[] { "xml" }, true);

        List<String> serviceKeys = new ArrayList<String>();

        for (File xml : allXmlFiles) {
            serviceKeys.addAll(serviceScanner.scan(xml));
        }

        for (String serviceKey : serviceKeys) {
            serviceLionContents.put(serviceKey,
                    context.getServiceHost() + ":" + projectPortMapping.get(entry.getKey()));
        }

    }

    BytemanScriptGenerator bytemanScriptGenerator = new BytemanScriptGenerator();
    bytemanScriptGenerator.generate(new File(context.getOutputBaseDir(), OUTPUT), serviceLionContents);

}

From source file:com.cisco.dbds.utils.git.FileUtilities.java

/**
 * Recurse and get the files...//from  w w  w.ja  va  2 s . c  o  m
 *
 * @param path the path
 * @return the files
 * @throws IOException Signals that an I/O exception has occurred.
 */
public Collection<File> getFiles(String path) throws IOException {
    // path = "src" + "\\" + "it" + "\\" + "resources";

    Collection<File> files = FileUtils.listFiles(new File(path), SUFFIX, true);

    return files;
}

From source file:com.uksf.mf.core.utility.sqm.SqmFixer.java

/**
 * Fixes given sqm file or searches folder for sqm files to fix
 *//*  w w  w.j a  va  2 s  . c o  m*/
private void fixFiles() {
    Core.getInstanceUI().setMessageText("Fixing...");
    CLASS_NAMES = ClassNames.getClassNames();
    if (CLASS_NAMES != null) {
        LogHandler.logNoTime(HASHSPACE);
        LogHandler.logSeverity(INFO, "Found class names: ");
        for (String className : CLASS_NAMES.keySet()) {
            LogHandler.logSeverity(INFO, className + "," + CLASS_NAMES.get(className));
        }
    } else {
        LogHandler.logSeverity(WARNING, "No class names found");
    }
    LogHandler.logNoTime(HASHSPACE);
    FIXEDCOUNT = 0;
    COUNT = 0;
    if (activeFile.isFile()) {
        if (activeFile.getAbsolutePath().toLowerCase().contains(".sqm")) {
            processSqm();
        } else {
            LogHandler.logSeverity(ERROR, "File is not an sqm file at '" + activeFile.getAbsolutePath() + "'");
        }
    } else if (activeFile.isDirectory()) {
        List<File> files = (List<File>) FileUtils.listFiles(activeFile, new String[] { "sqm" }, true);
        if (files.size() > 0) {
            for (File file : files) {
                activeFile = file;
                processSqm();
            }
        } else {
            LogHandler.logSeverity(ERROR,
                    "Could not find any sqm files in '" + activeFile.getAbsolutePath() + "'");
        }
    } else {
        LogHandler.logSeverity(ERROR, "File is not a file or folder? '" + activeFile.getAbsolutePath() + "'");
    }
    LogHandler.logSeverity(INFO, FIXEDCOUNT + " sqm out of " + COUNT + " fixed");
    Core.getInstanceUI().displayCount();
}

From source file:ipLock.ProcessHandle.java

private static String determineJavaExecutablePath() {
    File javaHome = new File(System.getProperty("java.home"));

    Collection<File> files = FileUtils.listFiles(javaHome, new NameFileFilter("java"),
            new NameFileFilter("bin"));

    if (files.isEmpty()) {
        throw new RuntimeException("No java executable found at java home '" + javaHome + "'");
    }//from   ww w .  j av  a  2s .  c  o m
    if (files.size() > 1) {
        throw new RuntimeException("Multiple java executables found at java home '" + javaHome + "': "
                + StringUtils.join(files, "; "));
    }

    return Collections.min(files).getAbsolutePath();
}

From source file:ca.uviccscu.lp.server.main.ShutdownListener.java

@Deprecated
public void releaseLocks() {
    l.trace("Trying to check file locks ");
    try {/*  w w  w  .  ja v a2s.  c  om*/
        Collection c = FileUtils.listFiles(new File(Shared.workingDirectory), null, true);
        Object[] arr = c.toArray();
        for (int i = 0; i < arr.length; i++) {
            l.trace("Trying lock for: " + ((File) arr[i]).getAbsolutePath());
            // Get a file channel for the file
            File file = ((File) arr[i]);
            FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
            // Use the file channel to create a lock on the file.
            // This method blocks until it can retrieve the lock.
            //FileLock lock = channel.lock();
            // Try acquiring the lock without blocking. This method returns
            // null or throws an exception if the file is already locked.
            FileLock lock = null;
            try {
                lock = channel.lock();
            } catch (OverlappingFileLockException ex) {
                l.trace("Lock already exists", ex);
            }
            if (lock == null) {
                l.trace("Lock failed - someone else holds lock");
            } else {
                l.trace("Lock shared: " + lock.isShared() + " Lock valid: " + lock.isValid());
                lock.release();
                l.trace("Lock release OK");
                try {
                    if (!file.delete()) {
                        throw new IOException();
                    }
                } catch (Exception e) {
                    l.trace("Delete failed", e);
                }
            }
        }
        //Thread.sleep(25000);

    } catch (Exception e) {
        // File is already locked in this thread or virtual machine
        l.trace("File lock problem", e);
    }
}

From source file:ch.ivyteam.ivy.maven.TestIarPackagingMojo.java

/**
 * Happy path creation tests/*from w  w w. ja v  a2s.co  m*/
 * @throws Exception
 */
@Test
public void archiveCreationDefault() throws Exception {
    IarPackagingMojo mojo = rule.getMojo();
    File svn = new File(mojo.project.getBasedir(), ".svn/svn.txt");
    FileUtils.write(svn, "svn");
    mojo.execute();
    Collection<File> iarFiles = FileUtils.listFiles(new File(mojo.project.getBasedir(), "target"),
            new String[] { "iar" }, false);
    assertThat(iarFiles).hasSize(1);

    File iarFile = iarFiles.iterator().next();
    assertThat(iarFile.getName()).isEqualTo("base-1.0.0.iar");
    assertThat(mojo.project.getArtifact().getFile())
            .as("Created IAR must be registered as artifact for later repository installation.")
            .isEqualTo(iarFile);

    try (ZipFile archive = new ZipFile(iarFile)) {
        assertThat(archive.getEntry(".classpath")).as(".classpath must be packed for internal binary retrieval")
                .isNotNull();
        assertThat(archive.getEntry("src_hd")).as("Empty directories should be included (by default) "
                + "so that the IAR can be re-imported into the designer").isNotNull();
        assertThat(archive.getEntry("target/sampleOutput.txt")).as("'target' folder should not be packed")
                .isNull();
        assertThat(archive.getEntry("target")).as("'target'folder should not be packed").isNull();
        assertThat(archive.getEntry(".svn/svn.txt")).as("'.svn' folder should not be packed").isNull();
        assertThat(archive.getEntry(".svn")).as("'target'.svn should not be packed").isNull();
        assertThat(archive.getEntry("classes/gugus.txt")).as("classes content should be included by default")
                .isNotNull();
    }
}

From source file:cloudExplorer.SyncToS3.java

public void run() {
    String[] extensions = new String[] { " " };
    List<File> files = (List<File>) FileUtils.listFiles(location, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);/*w w w  .jav a  2s . c  o  m*/
    for (File file_found : files) {
        int found = 0;

        if (mainFrame.jRadioButton1.isSelected()) {

        } else {

            for (int y = 1; y != objectarray.length; y++) {
                if (objectarray[y].contains(makeDirectory(file_found.getAbsolutePath().toString()))) {
                    //mainFrame.jTextArea1.append("\nObject already exists on S3: " + file_found);
                    calibrate();
                    found++;
                }
            }
        }

        if (found == 0) {

            String object = makeDirectory(file_found.getAbsolutePath().toString());
            String[] cut = object.split(file_found.getName());
            String[] cut2 = null;
            object = object.replace(cut[0], "");
            String win = "\\";
            String lin = "/";
            if (cut[0].contains(win)) {
                cut2 = cut[0].split(win);
                object = cut2[cut2.length - 1] + win + object;
            } else {
                cut2 = cut[0].split(lin);
                object = cut2[cut2.length - 1] + lin + object;
            }

            if (SyncToS3.running) {
                int index = mainFrame.jList3.getSelectedIndex(); //get selected index

                try {
                    if (index != -1) {
                        object = mainFrame.jList3.getSelectedValue().toString() + object;
                    }
                } catch (Exception indaex) {

                }
                put = new Put(file_found.getAbsolutePath().toString(), access_key, secret_key, bucket, endpoint,
                        object, rrs, encrypt);
                put.run();
            }
            found = 0;
        }
    }
    mainFrame.reloadBuckets();
    mainFrame.jTextArea1.append(
            "\nSync operation finished running. Please observe this window for any transfers that may still be running.");
    calibrate();
}