Search in sources :

Example 71 with FileSet

use of org.apache.tools.ant.types.FileSet in project openj9 by eclipse.

the class ExecOverFiles method execute.

public void execute() throws BuildException {
    if (exec == null) {
        throw new BuildException("No <exec> nested element supplied.");
    }
    if (command == null || command.length() == 0) {
        throw new BuildException("No non-empty command attribute supplied.");
    }
    for (FileSet fs : fileSets) {
        DirectoryScanner scanner = fs.getDirectoryScanner(getProject());
        String[] files = scanner.getIncludedFiles();
        exec.setDir(scanner.getBasedir());
        for (String filename : files) {
            Commandline cmd = new Commandline(command.replace(FILENAME_REPLACE, filename));
            exec.setCommand(cmd);
            // overwrites file with output
            exec.setOutput(new File(scanner.getBasedir() + "/" + filename));
            exec.execute();
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) Commandline(org.apache.tools.ant.types.Commandline) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 72 with FileSet

use of org.apache.tools.ant.types.FileSet in project tomcat70 by apache.

the class Txt2Html method execute.

/**
 * Perform the conversion
 *
 * @throws BuildException if an error occurs during execution of
 *    this task.
 */
@Override
public void execute() throws BuildException {
    int count = 0;
    // Step through each file and convert.
    Iterator<FileSet> iter = filesets.iterator();
    while (iter.hasNext()) {
        FileSet fs = iter.next();
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        for (int i = 0; i < files.length; i++) {
            File from = new File(basedir, files[i]);
            File to = new File(todir, files[i] + ".html");
            if (!to.exists() || (from.lastModified() > to.lastModified())) {
                log("Converting file '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath(), Project.MSG_VERBOSE);
                try {
                    convert(from, to);
                } catch (IOException e) {
                    throw new BuildException("Could not convert '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath() + "'", e);
                }
                count++;
            }
        }
        if (count > 0) {
            log("Converted " + count + " file" + (count > 1 ? "s" : "") + " to " + todir.getAbsolutePath());
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 73 with FileSet

use of org.apache.tools.ant.types.FileSet in project maven-plugins by apache.

the class DependencyFilesetsTask method execute.

/**
 * {@inheritDoc}
 */
public void execute() {
    if (this.getProject().getReference(mavenProjectId) == null) {
        throw new BuildException("Maven project reference not found: " + mavenProjectId);
    }
    MavenProject mavenProject = (MavenProject) this.getProject().getReference("maven.project");
    // Add filesets for depenedency artifacts
    Set<Artifact> depArtifacts = filterArtifacts(mavenProject.getArtifacts());
    FileSet dependenciesFileSet = new FileSet();
    dependenciesFileSet.setProject(getProject());
    ArtifactRepository localRepository = (ArtifactRepository) getProject().getReference("maven.local.repository");
    dependenciesFileSet.setDir(new File(localRepository.getBasedir()));
    if (depArtifacts.isEmpty()) {
        // For performance reasons in case of huge local repo, tell Ant to include a single thing, otherwise the
        // whole directory is scanned (even though ** is excluded).
        dependenciesFileSet.createInclude().setName(".");
        dependenciesFileSet.createExclude().setName("**");
    }
    for (Artifact artifact : depArtifacts) {
        String relativeArtifactPath = localRepository.pathOf(artifact);
        dependenciesFileSet.createInclude().setName(relativeArtifactPath);
        String fileSetName = getPrefix() + artifact.getDependencyConflictId();
        FileSet singleArtifactFileSet = new FileSet();
        singleArtifactFileSet.setProject(getProject());
        singleArtifactFileSet.setFile(artifact.getFile());
        getProject().addReference(fileSetName, singleArtifactFileSet);
    }
    getProject().addReference((getPrefix() + projectDependenciesId), dependenciesFileSet);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.tools.ant.types.FileSet) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 74 with FileSet

use of org.apache.tools.ant.types.FileSet in project groovy-core by groovy.

the class FileIterator method setNextObject.

// Implementation methods
// -------------------------------------------------------------------------
/*
     * Set nextObject to the next object. If there are no more
     * objects then return false. Otherwise, return true.
     */
private boolean setNextObject() {
    while (true) {
        while (ds == null) {
            if (!fileSetIterator.hasNext()) {
                return false;
            }
            FileSet fs = fileSetIterator.next();
            ds = fs.getDirectoryScanner(project);
            ds.scan();
            if (iterateDirectories) {
                files = ds.getIncludedDirectories();
            } else {
                files = ds.getIncludedFiles();
            }
            if (files.length > 0) {
                fileIndex = -1;
                break;
            } else {
                ds = null;
            }
        }
        if (ds != null && files != null) {
            if (++fileIndex < files.length) {
                nextFile = new File(ds.getBasedir(), files[fileIndex]);
                nextObjectSet = true;
                return true;
            } else {
                ds = null;
            }
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) File(java.io.File)

Example 75 with FileSet

use of org.apache.tools.ant.types.FileSet in project randomizedtesting by randomizedtesting.

the class MergeHints method add.

/**
 * Adds a resource collection with execution hints.
 */
public void add(ResourceCollection rc) {
    if (rc instanceof FileSet) {
        FileSet fs = (FileSet) rc;
        fs.setProject(getProject());
    }
    resources.add(rc);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet)

Aggregations

FileSet (org.apache.tools.ant.types.FileSet)165 File (java.io.File)124 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)83 BuildException (org.apache.tools.ant.BuildException)49 Test (org.junit.Test)41 IOException (java.io.IOException)36 ArrayList (java.util.ArrayList)29 Project (org.apache.tools.ant.Project)22 Resource (org.apache.tools.ant.types.Resource)12 FileResource (org.apache.tools.ant.types.resources.FileResource)10 URL (java.net.URL)6 Hashtable (java.util.Hashtable)6 ArchiveFileSet (org.apache.tools.ant.types.ArchiveFileSet)6 Path (org.apache.tools.ant.types.Path)6 ResourceCollection (org.apache.tools.ant.types.ResourceCollection)6 PrintStream (java.io.PrintStream)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 List (java.util.List)5 ZipFileSet (org.apache.tools.ant.types.ZipFileSet)5