Search in sources :

Example 21 with FileSet

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

the class FTP method transferFiles.

/**
 * Sends all files specified by the configured filesets to the remote
 * server.
 *
 * @param ftp the FTPClient instance used to perform FTP actions
 *
 * @throws IOException if there is a problem reading a file
 * @throws BuildException if there is a problem in the configuration.
 */
protected void transferFiles(FTPClient ftp) throws IOException, BuildException {
    transferred = 0;
    skipped = 0;
    if (filesets.isEmpty()) {
        throw new BuildException("at least one fileset must be specified.");
    }
    for (FileSet fs : filesets) {
        if (fs != null) {
            transferFiles(ftp, fs);
        }
    }
    log(transferred + " " + ACTION_TARGET_STRS[action] + " " + COMPLETED_ACTION_STRS[action]);
    if (skipped != 0) {
        log(skipped + " " + ACTION_TARGET_STRS[action] + " were not successfully " + COMPLETED_ACTION_STRS[action]);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) BuildException(org.apache.tools.ant.BuildException)

Example 22 with FileSet

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

the class FTPTaskMirrorImpl method transferFiles.

/**
 * Sends all files specified by the configured filesets to the remote
 * server.
 *
 * @param ftp the FTPClient instance used to perform FTP actions
 *
 * @throws IOException if there is a problem reading a file
 * @throws BuildException if there is a problem in the configuration.
 */
protected void transferFiles(FTPClient ftp) throws IOException, BuildException {
    transferred = 0;
    skipped = 0;
    if (task.getFilesets().isEmpty()) {
        throw new BuildException("at least one fileset must be specified.");
    }
    // get files from filesets
    for (FileSet fs : task.getFilesets()) {
        if (fs != null) {
            transferFiles(ftp, fs);
        }
    }
    task.log(transferred + " " + FTPTask.ACTION_TARGET_STRS[task.getAction()] + " " + FTPTask.COMPLETED_ACTION_STRS[task.getAction()]);
    if (skipped != 0) {
        task.log(skipped + " " + FTPTask.ACTION_TARGET_STRS[task.getAction()] + " were not successfully " + FTPTask.COMPLETED_ACTION_STRS[task.getAction()]);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) BuildException(org.apache.tools.ant.BuildException)

Example 23 with FileSet

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

the class Scp method upload.

private void upload(final List<ResourceCollection> rcs, final String toSshUri) throws IOException, JSchException {
    final String file = parseUri(toSshUri);
    Session session = null;
    try {
        final List<Directory> list = new ArrayList<>(rcs.size());
        for (ResourceCollection rc : rcs) {
            if (rc instanceof FileSet && rc.isFilesystemOnly()) {
                FileSet fs = (FileSet) rc;
                final Directory d = createDirectory(fs);
                if (d != null) {
                    list.add(d);
                }
            } else {
                List<Directory> ds = createDirectoryCollection(rc);
                if (ds != null) {
                    list.addAll(ds);
                }
            }
        }
        if (!list.isEmpty()) {
            session = openSession();
            ScpToMessage message;
            if (!isSftp) {
                message = new ScpToMessage(getVerbose(), compressed, session, list, file, preserveLastModified);
            } else {
                message = new ScpToMessageBySftp(getVerbose(), session, list, file, preserveLastModified);
            }
            message.setLogListener(this);
            if (fileMode != null) {
                message.setFileMode(fileMode);
            }
            if (dirMode != null) {
                message.setDirMode(dirMode);
            }
            message.execute();
        }
    } finally {
        if (session != null) {
            session.disconnect();
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArrayList(java.util.ArrayList) Session(com.jcraft.jsch.Session) ResourceCollection(org.apache.tools.ant.types.ResourceCollection)

Example 24 with FileSet

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

the class AbstractAccessTask method setFile.

/**
 * Set the file which should have its access attributes modified.
 * @param src the file to modify
 */
public void setFile(File src) {
    FileSet fs = new FileSet();
    fs.setFile(src);
    addFileset(fs);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet)

Example 25 with FileSet

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

the class Symlink method loadLinks.

/**
 * Load links from properties files included in one or more FileSets.
 *
 * <p>This method is only invoked when the action attribute is set to
 * &quot;recreate&quot;. The filesets passed in are assumed to specify the
 * names of the property files with the link information and the
 * subdirectories in which to look for them.</p>
 *
 * @param fileSets    The <code>FileSet</code>s for this task.
 * @return            The links to be made.
 */
private Properties loadLinks(List<FileSet> fileSets) {
    Properties finalList = new Properties();
    // loop through the supplied file sets:
    for (FileSet fs : fileSets) {
        DirectoryScanner ds = new DirectoryScanner();
        fs.setupDirectoryScanner(ds, getProject());
        ds.setFollowSymlinks(false);
        ds.scan();
        File dir = fs.getDir(getProject());
        // load included files as properties files:
        for (String name : ds.getIncludedFiles()) {
            File inc = new File(dir, name);
            File pf = inc.getParentFile();
            Properties lnks = new Properties();
            try (InputStream is = new BufferedInputStream(Files.newInputStream(inc.toPath()))) {
                lnks.load(is);
                pf = pf.getCanonicalFile();
            } catch (FileNotFoundException fnfe) {
                handleError("Unable to find " + name + "; skipping it.");
                continue;
            } catch (IOException ioe) {
                handleError("Unable to open " + name + " or its parent dir; skipping it.");
                continue;
            }
            try {
                lnks.store(new PrintStream(new LogOutputStream(this, Project.MSG_INFO)), "listing properties");
            } catch (IOException ex) {
                log("failed to log unshortened properties");
                lnks.list(new PrintStream(new LogOutputStream(this, Project.MSG_INFO)));
            }
            // working directory:
            for (String key : lnks.stringPropertyNames()) {
                finalList.put(new File(pf, key).getAbsolutePath(), lnks.getProperty(key));
            }
        }
    }
    return finalList;
}
Also used : PrintStream(java.io.PrintStream) FileSet(org.apache.tools.ant.types.FileSet) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) LogOutputStream(org.apache.tools.ant.taskdefs.LogOutputStream)

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