Java Code Examples for org.apache.tools.ant.DirectoryScanner#getIncludedFiles()

The following examples show how to use org.apache.tools.ant.DirectoryScanner#getIncludedFiles() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSummaryCreatorTask.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of input files ({@link java.io.File} objects) to process.
 * Note that this does not check that the file is a valid and useful XML file.
 * 
 * @return The input files
 */
private List getInputFiles()
{
	ArrayList result = new ArrayList();

    for (Iterator it = _fileSets.iterator(); it.hasNext();)
    {
        FileSet          fileSet    = (FileSet)it.next();
        File             fileSetDir = fileSet.getDir(getProject());
        DirectoryScanner scanner    = fileSet.getDirectoryScanner(getProject());
        String[]         files      = scanner.getIncludedFiles();

        for (int idx = 0; (files != null) && (idx < files.length); idx++)
        {
        	File file = new File(fileSetDir, files[idx]);

            if (file.isFile() && file.canRead())
            {
            	result.add(file);
            }
        }
    }
    return result;
}
 
Example 2
Source File: RccTask.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Invoke the Hadoop record compiler on each record definition file
 */
@Override
public void execute() throws BuildException {
  if (src == null && filesets.size()==0) {
    throw new BuildException("There must be a file attribute or a fileset child element");
  }
  if (src != null) {
    doCompile(src);
  }
  Project myProject = getProject();
  for (int i = 0; i < filesets.size(); i++) {
    FileSet fs = filesets.get(i);
    DirectoryScanner ds = fs.getDirectoryScanner(myProject);
    File dir = fs.getDir(myProject);
    String[] srcs = ds.getIncludedFiles();
    for (int j = 0; j < srcs.length; j++) {
      doCompile(new File(dir, srcs[j]));
    }
  }
}
 
Example 3
Source File: ApexCli.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static String[] expandFileNames(String fileName) throws IOException
{
  // TODO: need to work with other users
  if (fileName.matches("^[a-zA-Z]+:.*")) {
    // it's a URL
    return new String[]{fileName};
  }
  if (fileName.startsWith("~" + File.separator)) {
    fileName = System.getProperty("user.home") + fileName.substring(1);
  }
  fileName = new File(fileName).getCanonicalPath();
  LOG.debug("Canonical path: {}", fileName);
  DirectoryScanner scanner = new DirectoryScanner();
  scanner.setIncludes(new String[]{fileName});
  scanner.scan();
  return scanner.getIncludedFiles();
}
 
Example 4
Source File: MapRenderer.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ants execute method.
 */
@Override
public void execute() {
	try {
		for (final FileSet fileset : filesets) {
			final DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
			final String[] includedFiles = ds.getIncludedFiles();
			for (final String filename : includedFiles) {
				System.out.println(ds.getBasedir().getAbsolutePath() + File.separator + filename);
				convert(ds.getBasedir().getAbsolutePath() + File.separator + filename);
			}
		}
	} catch (final Exception e) {
		throw new BuildException(e);
	}
}
 
Example 5
Source File: BasicInstrumentationTask.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void execute() throws BuildException {
	if ( isExtended() ) {
		collectClassNames();
	}
	logger.info( "starting instrumentation" );
	Project project = getProject();
	Iterator filesets = filesets();
	while ( filesets.hasNext() ) {
		FileSet fs = ( FileSet ) filesets.next();
		DirectoryScanner ds = fs.getDirectoryScanner( project );
		String[] includedFiles = ds.getIncludedFiles();
		File d = fs.getDir( project );
		for ( int i = 0; i < includedFiles.length; ++i ) {
			File file = new File( d, includedFiles[i] );
			try {
				processFile( file );
			}
			catch ( Exception e ) {
				throw new BuildException( e );
			}
		}
	}
}
 
Example 6
Source File: MXJC2Task.java    From mxjc with MIT License 5 votes vote down vote up
/**
 * Extracts {@link File} objects that the given {@link FileSet}
 * represents and adds them all to the given {@link List}.
 */
private void addIndividualFilesTo( FileSet fs, List<File> lst ) {
    DirectoryScanner ds = fs.getDirectoryScanner(getProject());
    String[] includedFiles = ds.getIncludedFiles();
    File baseDir = ds.getBasedir();

    for (String value : includedFiles) {
        lst.add(new File(baseDir, value));
    }
}
 
Example 7
Source File: AbstractCajaAntTask.java    From caja with Apache License 2.0 5 votes vote down vote up
public void addConfiguredFileSet(FileSet fs) {
  DirectoryScanner scanner = fs.getDirectoryScanner(getProject());
  File baseDir = scanner.getBasedir();
  scanner.scan();
  String[] includedFiles = scanner.getIncludedFiles();
  Arrays.sort(includedFiles);
  for (String localPath : includedFiles) {
    files.add(new File(baseDir, localPath));
  }
}
 
Example 8
Source File: VerifyJNLP.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void execute() throws BuildException {
    Map<String,String> results = new LinkedHashMap<>();
    for (FileSet fs : filesets) {
        DirectoryScanner s = fs.getDirectoryScanner(getProject());
        File basedir = s.getBasedir();
        for (String incl : s.getIncludedFiles()) {
            validate(new File(basedir, incl), results);
        }
    }
    JUnitReportWriter.writeReport(this, null, failOnError ? null : report, results);
}
 
Example 9
Source File: Helper.java    From bootstraped-multi-test-results-report with MIT License 5 votes vote down vote up
public static String[] findFiles(File targetDirectory, String fileIncludePattern, String fileExcludePattern,
    final String DEFAULT_FILE_INCLUDE_PATTERN) {
    DirectoryScanner scanner = new DirectoryScanner();
    if (fileIncludePattern == null || fileIncludePattern.isEmpty()) {
        scanner.setIncludes(new String[] {DEFAULT_FILE_INCLUDE_PATTERN});
    } else {
        scanner.setIncludes(new String[] {fileIncludePattern});
    }
    if (fileExcludePattern != null) {
        scanner.setExcludes(new String[] {fileExcludePattern});
    }
    scanner.setBasedir(targetDirectory);
    scanner.scan();
    return scanner.getIncludedFiles();
}
 
Example 10
Source File: ApexCli.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private static String expandFileName(String fileName, boolean expandWildCard) throws IOException
{
  if (fileName.matches("^[a-zA-Z]+:.*")) {
    // it's a URL
    return fileName;
  }

  // TODO: need to work with other users' home directory
  if (fileName.startsWith("~" + File.separator)) {
    fileName = System.getProperty("user.home") + fileName.substring(1);
  }
  fileName = new File(fileName).getCanonicalPath();
  //LOG.debug("Canonical path: {}", fileName);
  if (expandWildCard) {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setIncludes(new String[]{fileName});
    scanner.scan();
    String[] files = scanner.getIncludedFiles();

    if (files.length == 0) {
      throw new CliException(fileName + " does not match any file");
    } else if (files.length > 1) {
      throw new CliException(fileName + " matches more than one file");
    }
    return files[0];
  } else {
    return fileName;
  }
}
 
Example 11
Source File: AbstractProcessTask.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected Collection getFiles() {
    Map fileMap = new HashMap();
    Project p = getProject();
    for (int i = 0; i < filesets.size(); i++) {
        FileSet fs = (FileSet)filesets.elementAt(i);
        DirectoryScanner ds = fs.getDirectoryScanner(p);
        String[] srcFiles = ds.getIncludedFiles();
        File dir = fs.getDir(p);
        for (int j = 0; j < srcFiles.length; j++) {
             File src = new File(dir, srcFiles[j]);
             fileMap.put(src.getAbsolutePath(), src);
        }
    }
    return fileMap.values();
}
 
Example 12
Source File: MXJC2Task.java    From mxjc with MIT License 5 votes vote down vote up
/**
 * Extracts files in the given {@link FileSet}.
 */
private InputSource[] toInputSources( FileSet fs ) {
    DirectoryScanner ds = fs.getDirectoryScanner(getProject());
    String[] includedFiles = ds.getIncludedFiles();
    File baseDir = ds.getBasedir();
    
    ArrayList<InputSource> lst = new ArrayList<InputSource>();

    for (String value : includedFiles) {
        lst.add(getInputSource(new File(baseDir, value)));
    }
    
    return lst.toArray(new InputSource[lst.size()]);
}
 
Example 13
Source File: Test.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
protected Resource[][] grabResources(FileSet[] filesets) {
    Resource[][] result = new Resource[filesets.length][];
    for (int i = 0; i < filesets.length; i++) {
        boolean skipEmptyNames = true;
        if (filesets[i] instanceof ZipFileSet) {
            ZipFileSet zfs = (ZipFileSet) filesets[i];
            skipEmptyNames = zfs.getPrefix(getProject()).equals("")
                    && zfs.getFullpath(getProject()).equals("");
        }
        DirectoryScanner rs =
                filesets[i].getDirectoryScanner(getProject());
        if (rs instanceof ZipScanner) {
            ((ZipScanner) rs).setEncoding(encoding);
        }
        Vector<Resource> resources = new Vector<Resource>();
        if (!doFilesonly) {
            String[] directories = rs.getIncludedDirectories();
            for (int j = 0; j < directories.length; j++) {
                if (!"".equals(directories[j]) || !skipEmptyNames) {
                    resources.addElement(rs.getResource(directories[j]));
                }
            }
        }
        String[] files = rs.getIncludedFiles();
        for (int j = 0; j < files.length; j++) {
            if (!"".equals(files[j]) || !skipEmptyNames) {
                resources.addElement(rs.getResource(files[j]));
            }
        }

        result[i] = new Resource[resources.size()];
        resources.copyInto(result[i]);
    }
    return result;
}
 
Example 14
Source File: ApexCli.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static String expandFileName(String fileName, boolean expandWildCard) throws IOException
{
  if (fileName.matches("^[a-zA-Z]+:.*")) {
    // it's a URL
    return fileName;
  }

  // TODO: need to work with other users' home directory
  if (fileName.startsWith("~" + File.separator)) {
    fileName = System.getProperty("user.home") + fileName.substring(1);
  }
  fileName = new File(fileName).getCanonicalPath();
  //LOG.debug("Canonical path: {}", fileName);
  if (expandWildCard) {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setIncludes(new String[]{fileName});
    scanner.scan();
    String[] files = scanner.getIncludedFiles();

    if (files.length == 0) {
      throw new CliException(fileName + " does not match any file");
    } else if (files.length > 1) {
      throw new CliException(fileName + " matches more than one file");
    }
    return files[0];
  } else {
    return fileName;
  }
}
 
Example 15
Source File: StramAppLauncher.java    From Bats with Apache License 2.0 5 votes vote down vote up
private void processLibJars(String libjars, Set<URL> clUrls) throws Exception
{
  for (String libjar : libjars.split(",")) {
    // if hadoop file system, copy from hadoop file system to local
    URI uri = new URI(libjar);
    String scheme = uri.getScheme();
    if (scheme == null) {
      // expand wildcards
      DirectoryScanner scanner = new DirectoryScanner();
      scanner.setIncludes(new String[]{libjar});
      scanner.scan();
      String[] files = scanner.getIncludedFiles();
      for (String file : files) {
        clUrls.add(new URL("file:" + file));
      }
    } else if (scheme.equals("file")) {
      clUrls.add(new URL(libjar));
    } else {
      if (fs != null) {
        Path path = new Path(libjar);
        File dependencyJarsDir = new File(StramClientUtils.getUserDTDirectory(), "dependencyJars");
        dependencyJarsDir.mkdirs();
        File localJarFile = new File(dependencyJarsDir, path.getName());
        fs.copyToLocalFile(path, new Path(localJarFile.getAbsolutePath()));
        clUrls.add(new URL("file:" + localJarFile.getAbsolutePath()));
      } else {
        throw new NotImplementedException("Jar file needs to be from Hadoop File System also in order for the dependency jars to be in Hadoop File System");
      }
    }
  }
}
 
Example 16
Source File: AbstractProcessTask.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected Collection getFiles() {
    Map fileMap = new HashMap();
    Project p = getProject();
    for (int i = 0; i < filesets.size(); i++) {
        FileSet fs = (FileSet)filesets.elementAt(i);
        DirectoryScanner ds = fs.getDirectoryScanner(p);
        String[] srcFiles = ds.getIncludedFiles();
        File dir = fs.getDir(p);
        for (int j = 0; j < srcFiles.length; j++) {
             File src = new File(dir, srcFiles[j]);
             fileMap.put(src.getAbsolutePath(), src);
        }
    }
    return fileMap.values();
}
 
Example 17
Source File: CompleterHelper.java    From yiistorm with MIT License 5 votes vote down vote up
public static String[] searchFiles(String searchPath, String searchString) {

        DirectoryScanner scanner = new DirectoryScanner();
        scanner.setIncludes(new String[]{searchString + "*.php"});

        scanner.setBasedir(searchPath);
        scanner.setCaseSensitive(false);
        scanner.scan();
        return scanner.getIncludedFiles();

    }
 
Example 18
Source File: Branding.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void packBrandingJar(File srcDir, File destJarBase, String locale) throws IOException {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(srcDir);
    String localeToken = "";
    if(locale != null) {
        String [] includes = {"**/*_" + locale.toString() + ".*"};
        scanner.setIncludes(includes);
        localeToken = "_" + locale.toString();
    } else {
        String [] excludes = {"**/*_??_??.*", "**/*_??.*"};
        scanner.setExcludes(excludes);
    }
    scanner.addDefaultExcludes(); // #68929
    scanner.scan();
    String[] files = scanner.getIncludedFiles();
    if(files.length > 0) {
        Jar zip = (Jar) getProject().createTask("jar");
        String name = destJarBase.getName();
        String nameBase = name.substring(0, name.length() - ".jar".length());
        File destFolder = new File(destJarBase.getParentFile(), "locale");
        if (!destFolder.isDirectory() && !destFolder.mkdirs()) {
            throw new IOException("Could not create directory " + destFolder);
        }
        File destJar = new File(destFolder, nameBase + "_" + token + localeToken + ".jar");
        zip.setDestFile(destJar);
        zip.setCompress(true);
        for (int i = 0; i < files.length; i++) {
            ZipFileSet entry = new ZipFileSet();
            entry.setFile(new File(srcDir, files[i]));
            String basePath = files[i].replace(File.separatorChar, '/');
            int slash = basePath.lastIndexOf('/');
            int dot = basePath.lastIndexOf('.');
            String infix = "_" + token + localeToken;
            String brandedPath;
            if (dot == -1 || dot < slash) {
                brandedPath = basePath + infix;
            } else {
                brandedPath = basePath.substring(0, dot - localeToken.length()) + infix + basePath.substring(dot);
            }
            entry.setFullpath(brandedPath);
            zip.addZipfileset(entry);
        }
        zip.setLocation(getLocation());
        zip.init();
        zip.execute();
    }
}
 
Example 19
Source File: AntRewriteTask.java    From tascalate-javaflow with Apache License 2.0 4 votes vote down vote up
public void execute() throws BuildException {
    DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
    String[] fileNames = ds.getIncludedFiles();
    try {
        createClasspath();

        List<URL> classPath = new ArrayList<URL>();
        for (Iterator<Resource> i = compileClasspath.iterator(); i.hasNext();) {
            FileResource resource = (FileResource)i.next();
            classPath.add( resource.getFile().toURI().toURL() );
        }

        List<URL> classPathByDir = new ArrayList<URL>(classPath);
        classPathByDir.add(srcDir.toURI().toURL());

        ResourceTransformer dirTransformer = RewritingUtils.createTransformer(
            classPathByDir.toArray(new URL[]{}),
            transformerType
        );
        try {
            for (String fileName : fileNames) {
                File source = new File(srcDir, fileName);
                File destination = new File(dstDir, fileName);
                
                if (!destination.getParentFile().exists()) {
                    log("Creating dir: " + destination.getParentFile(), Project.MSG_VERBOSE);
                    destination.getParentFile().mkdirs();
                }

                if (source.lastModified() < destination.lastModified()) {
                    log("Omitting " + source + " as " + destination + " is up to date", Project.MSG_VERBOSE);
                    continue;
                }
                
                if (fileName.endsWith(".class")) {
                    log("Rewriting " + source + " to " + destination, Project.MSG_VERBOSE);
                    // System.out.println("Rewriting " + source);

                    RewritingUtils.rewriteClassFile( source, dirTransformer, destination );
                }

                if (fileName.endsWith(".jar") || 
                    fileName.endsWith(".ear") || 
                    fileName.endsWith(".zip") || 
                    fileName.endsWith(".war")) {

                    log("Rewriting " + source + " to " + destination, Project.MSG_VERBOSE);

                    List<URL> classPathByJar = new ArrayList<URL>(classPath);
                    classPathByJar.add(source.toURI().toURL());
                    
                    ResourceTransformer jarTransformer = RewritingUtils.createTransformer(
                       classPathByJar.toArray(new URL[]{}), 
                       transformerType
                    );
                    try {
                        RewritingUtils.rewriteJar(
                            new JarInputStream(new FileInputStream(source)),
                            jarTransformer,
                            new JarOutputStream(new FileOutputStream(destination))
                        );
                    } finally {
                        jarTransformer.release();
                    }
                    
                }
            }
        } finally {
            dirTransformer.release();
        }
    } catch (IOException e) {
        throw new BuildException(e);
    }
}
 
Example 20
Source File: TestResult.java    From junit-plugin with MIT License 2 votes vote down vote up
/**
 * Collect reports from the given {@link DirectoryScanner}, while
 * filtering out all files that were created before the given time.
 * @param buildTime Build time.
 * @param results Directory scanner.
 * @param pipelineTestDetails A {@link PipelineTestDetails} instance containing Pipeline-related additional arguments.
 *
 * @throws IOException if an error occurs.
 * @since 1.22
 */
public void parse(long buildTime, DirectoryScanner results, PipelineTestDetails pipelineTestDetails) throws IOException {
    String[] includedFiles = results.getIncludedFiles();
    File baseDir = results.getBasedir();
    parse(buildTime,baseDir, pipelineTestDetails,includedFiles);
}