All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.joestelmach.util.FileSearcher Maven / Gradle / Ivy

Go to download

Zipper is a full-featured asset packaging plugin for Maven that provides JavaScript lint lint checking, Closure Compiler and YUI Compressor support, CSS and JavaScript concatenation, and up-front gzipping.

There is a newer version: 0.2.3
Show newest version
package com.joestelmach.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.codehaus.plexus.util.DirectoryScanner;

/**
 * Locates files using standard ant patterns
 * http://ant.apache.org/manual/dirtasks.html#patterns
 * 
 * @author Joe Stelmach
 */
public class FileSearcher {
  
  /**
   * Searches for files with the given pattern, starting in the given base directory,
   * and returns a list of absolute paths to matching files.
   *  
   * @param pattern
   * @param basePath
   * @return
   */
  public List search(String pattern, String basePath) {
    File baseDir = new File(basePath);
    
    if(pattern.startsWith("/")) pattern = pattern.substring(1);
    
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(baseDir);
    scanner.setIncludes(new String[]{pattern});
    scanner.addDefaultExcludes();
    scanner.scan();
    
    List fileNames = new ArrayList();
    for(String fileName:scanner.getIncludedFiles() ) {
      fileNames.add(baseDir + "/" + fileName);
    }
    return fileNames;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy