Search in sources :

Example 41 with FileSet

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

the class Tar method check.

/**
 * Checks whether the archive is out-of-date with respect to the resources
 * of the given collection.
 *
 * <p>Also checks that either all collections only contain file
 * resources or this class supports non-file collections.</p>
 *
 * <p>And - in case of file-collections - ensures that the archive won't
 * contain itself.</p>
 *
 * @param rc the resource collection to check
 * @return whether the archive is up-to-date
 * @since Ant 1.7
 */
protected boolean check(final ResourceCollection rc) {
    boolean upToDate = true;
    if (isFileFileSet(rc)) {
        final FileSet fs = (FileSet) rc;
        upToDate = check(fs.getDir(getProject()), getFileNames(fs));
    } else if (!rc.isFilesystemOnly() && !supportsNonFileResources()) {
        throw new BuildException("only filesystem resources are supported");
    } else if (rc.isFilesystemOnly()) {
        final Set<File> basedirs = new HashSet<>();
        final Map<File, List<String>> basedirToFilesMap = new HashMap<>();
        for (final Resource res : rc) {
            final FileResource r = ResourceUtils.asFileResource(res.as(FileProvider.class));
            File base = r.getBaseDir();
            if (base == null) {
                base = Copy.NULL_FILE_PLACEHOLDER;
            }
            basedirs.add(base);
            List<String> files = basedirToFilesMap.get(base);
            if (files == null) {
                files = new Vector<>();
                basedirToFilesMap.put(base, files);
            }
            if (base == Copy.NULL_FILE_PLACEHOLDER) {
                files.add(r.getFile().getAbsolutePath());
            } else {
                files.add(r.getName());
            }
        }
        for (final File base : basedirs) {
            final File tmpBase = base == Copy.NULL_FILE_PLACEHOLDER ? null : base;
            final List<String> files = basedirToFilesMap.get(base);
            upToDate &= check(tmpBase, files);
        }
    } else {
        // non-file resources
        for (Resource r : rc) {
            upToDate = archiveIsUpToDate(r);
        }
    }
    return upToDate;
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArchiveFileSet(org.apache.tools.ant.types.ArchiveFileSet) HashMap(java.util.HashMap) ArchiveResource(org.apache.tools.ant.types.resources.ArchiveResource) FileResource(org.apache.tools.ant.types.resources.FileResource) TarResource(org.apache.tools.ant.types.resources.TarResource) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) FileProvider(org.apache.tools.ant.types.resources.FileProvider) List(java.util.List) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) HashSet(java.util.HashSet)

Example 42 with FileSet

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

the class CCMCheck method execute.

/**
 * Executes the task.
 * <p>
 * Builds a command line to execute ccm and then calls Exec's run method
 * to execute the command line.
 * </p>
 * @throws BuildException on error
 */
@Override
public void execute() throws BuildException {
    if (file == null && filesets.isEmpty()) {
        throw new BuildException("Specify at least one source - a file or a fileset.");
    }
    if (file != null && file.exists() && file.isDirectory()) {
        throw new BuildException("CCMCheck cannot be generated for directories");
    }
    if (file != null && !filesets.isEmpty()) {
        throw new BuildException("Choose between file and fileset !");
    }
    if (getFile() != null) {
        doit();
        return;
    }
    for (FileSet fs : filesets) {
        final File basedir = fs.getDir(getProject());
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        for (String srcFile : ds.getIncludedFiles()) {
            setFile(new File(basedir, srcFile));
            doit();
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 43 with FileSet

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

the class ChangeLogTask method execute.

/**
 * Execute task
 *
 * @exception BuildException if something goes wrong executing the
 *            cvs command
 */
@Override
public void execute() throws BuildException {
    // may be altered in validate
    File savedDir = inputDir;
    try {
        validate();
        final Properties userList = new Properties();
        loadUserlist(userList);
        for (CvsUser user : cvsUsers) {
            user.validate();
            userList.put(user.getUserID(), user.getDisplayname());
        }
        if (!remote) {
            setCommand("log");
            if (getTag() != null) {
                CvsVersion myCvsVersion = new CvsVersion();
                myCvsVersion.setProject(getProject());
                myCvsVersion.setTaskName("cvsversion");
                myCvsVersion.setCvsRoot(getCvsRoot());
                myCvsVersion.setCvsRsh(getCvsRsh());
                myCvsVersion.setPassfile(getPassFile());
                myCvsVersion.setDest(inputDir);
                myCvsVersion.execute();
                if (myCvsVersion.supportsCvsLogWithSOption()) {
                    addCommandArgument("-S");
                }
            }
        } else {
            // supply 'rlog' as argument instead of command
            setCommand("");
            addCommandArgument("rlog");
            // Do not print name/header if no revisions
            // selected. This is quicker: less output to parse.
            addCommandArgument("-S");
            // Do not list tags. This is quicker: less output to
            // parse.
            addCommandArgument("-N");
        }
        if (null != startTag || null != endTag) {
            // man, do I get spoiled by C#'s ?? operator
            String startValue = startTag == null ? "" : startTag;
            String endValue = endTag == null ? "" : endTag;
            addCommandArgument("-r" + startValue + "::" + endValue);
        } else if (null != startDate) {
            final SimpleDateFormat outputDate = new SimpleDateFormat("yyyy-MM-dd");
            // We want something of the form: -d ">=YYYY-MM-dd"
            final String dateRange = ">=" + outputDate.format(startDate);
            // Supply '-d' as a separate argument - Bug# 14397
            addCommandArgument("-d");
            addCommandArgument(dateRange);
        }
        // Check if list of files to check has been specified
        for (FileSet fileSet : filesets) {
            final DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
            for (String file : scanner.getIncludedFiles()) {
                addCommandArgument(file);
            }
        }
        final ChangeLogParser parser = new ChangeLogParser(remote, getPackage(), getModules());
        final RedirectingStreamHandler handler = new RedirectingStreamHandler(parser);
        log(getCommand(), Project.MSG_VERBOSE);
        setDest(inputDir);
        setExecuteStreamHandler(handler);
        try {
            super.execute();
        } finally {
            final String errors = handler.getErrors();
            if (null != errors) {
                log(errors, Project.MSG_ERR);
            }
        }
        final CVSEntry[] entrySet = parser.getEntrySetAsArray();
        final CVSEntry[] filteredEntrySet = filterEntrySet(entrySet);
        replaceAuthorIdWithName(userList, filteredEntrySet);
        writeChangeLog(filteredEntrySet);
    } finally {
        inputDir = savedDir;
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Properties(java.util.Properties) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 44 with FileSet

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

the class Find method execute2.

public void execute2() {
    validate();
    String foundLocation = null;
    for (FileSet fs : filesets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        String[] includedFiles = ds.getIncludedFiles();
        for (String includedFile : includedFiles) {
            String filename = includedFile.replace('\\', '/');
            filename = filename.substring(filename.lastIndexOf("/") + 1);
            if (foundLocation == null && file.equals(filename)) {
                File base = ds.getBasedir();
                File found = new File(base, includedFile);
                foundLocation = found.getAbsolutePath();
            }
        }
    }
    if (foundLocation != null)
        getProject().setNewProperty(location, foundLocation);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 45 with FileSet

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

the class CompileJSPs method copyClassFiles.

private void copyClassFiles(File jspCompileDir) {
    Copy copy = new Copy();
    copy.setProject(getProject());
    copy.setTaskName(getTaskName());
    destdir.mkdirs();
    copy.setTodir(destdir);
    FileSet files = new FileSet();
    files.setDir(jspCompileDir);
    files.setIncludes("**/*.class");
    copy.addFileset(files);
    copy.execute();
}
Also used : ZipFileSet(org.apache.tools.ant.types.ZipFileSet) FileSet(org.apache.tools.ant.types.FileSet) Copy(org.apache.tools.ant.taskdefs.Copy)

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