Search in sources :

Example 1 with Copy

use of org.apache.tools.ant.taskdefs.Copy in project gate-core by GateNLP.

the class PackageGappTask method copyDirectories.

/**
 * Copy directories as specified by the given map.
 *
 * @param copyMap map specifying the directories to copy and the
 *          target locations to which they should be copied.
 * @param minimalPlugin if true, treat the directory as a GATE plugin
 *          and copy just the minimal files needed for the plugin to
 *          work (creole.xml and any referenced jars).
 */
private void copyDirectories(Map<URL, URL> copyMap, boolean minimalPlugin) {
    for (Map.Entry<URL, URL> copyEntry : copyMap.entrySet()) {
        File source = Files.fileFromURL(copyEntry.getKey());
        if (!source.exists()) {
            return;
        }
        File dest = Files.fileFromURL(copyEntry.getValue());
        // set up a copy task to do the copying
        Copy copyTask = new Copy();
        copyTask.setProject(getProject());
        copyTask.setLocation(getLocation());
        copyTask.setTaskName(getTaskName());
        copyTask.setTodir(dest);
        // ensure the target directory exists
        dest.mkdirs();
        FileSet fileSet = new FileSet();
        copyTask.addFileset(fileSet);
        fileSet.setDir(source);
        if (minimalPlugin) {
            // just copy creole.xml and JARs
            NameEntry include = fileSet.createInclude();
            include.setName("creole.xml");
            URL creoleXml;
            try {
                creoleXml = new URL(copyEntry.getKey().toExternalForm() + "/creole.xml");
            } catch (MalformedURLException e) {
                throw new BuildException("Error creating URL for creole.xml in plugin " + copyEntry.getKey());
            }
            for (String jarString : getJars(creoleXml)) {
                NameEntry jarInclude = fileSet.createInclude();
                jarInclude.setName(jarString);
            }
        }
        // do the copying
        copyTask.init();
        copyTask.perform();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) FileSet(org.apache.tools.ant.types.FileSet) Copy(org.apache.tools.ant.taskdefs.Copy) NameEntry(org.apache.tools.ant.types.PatternSet.NameEntry) BuildException(org.apache.tools.ant.BuildException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) File(java.io.File) URL(java.net.URL)

Example 2 with Copy

use of org.apache.tools.ant.taskdefs.Copy 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)

Example 3 with Copy

use of org.apache.tools.ant.taskdefs.Copy in project hudson-2.x by hudson.

the class Util method copyFile.

/**
 * Copies a single file by using Ant.
 */
public static void copyFile(File src, File dst) throws BuildException {
    Copy cp = new Copy();
    cp.setProject(new org.apache.tools.ant.Project());
    cp.setTofile(dst);
    cp.setFile(src);
    cp.setOverwrite(true);
    cp.execute();
}
Also used : Copy(org.apache.tools.ant.taskdefs.Copy) Project(org.apache.tools.ant.Project)

Example 4 with Copy

use of org.apache.tools.ant.taskdefs.Copy in project hudson-2.x by hudson.

the class AbstractItem method renameTo.

/**
 * Renames this item.
 * Not all the Items need to support this operation, but if you decide to do so,
 * you can use this method.
 */
protected void renameTo(String newName) throws IOException {
    // always synchronize from bigger objects first
    final ItemGroup parent = getParent();
    synchronized (parent) {
        synchronized (this) {
            // sanity check
            if (newName == null)
                throw new IllegalArgumentException("New name is not given");
            // noop?
            if (this.name.equals(newName))
                return;
            Item existing = parent.getItem(newName);
            if (existing != null && existing != this)
                // see http://www.nabble.com/error-on-renaming-project-tt18061629.html
                throw new IllegalArgumentException("Job " + newName + " already exists");
            String oldName = this.name;
            performBeforeItemRenaming(oldName, newName);
            File oldRoot = this.getRootDir();
            doSetName(newName);
            File newRoot = this.getRootDir();
            boolean success = false;
            try {
                // rename data files
                boolean interrupted = false;
                boolean renamed = false;
                // so retry few times before we fall back to copy.
                for (int retry = 0; retry < 5; retry++) {
                    if (oldRoot.renameTo(newRoot)) {
                        renamed = true;
                        // succeeded
                        break;
                    }
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        // process the interruption later
                        interrupted = true;
                    }
                }
                if (interrupted)
                    Thread.currentThread().interrupt();
                if (!renamed) {
                    // failed to rename. it must be that some lengthy
                    // process is going on
                    // to prevent a rename operation. So do a copy. Ideally
                    // we'd like to
                    // later delete the old copy, but we can't reliably do
                    // so, as before the VM
                    // shuts down there might be a new job created under the
                    // old name.
                    Copy cp = new Copy();
                    cp.setProject(new org.apache.tools.ant.Project());
                    cp.setTodir(newRoot);
                    FileSet src = new FileSet();
                    src.setDir(getRootDir());
                    cp.addFileset(src);
                    cp.setOverwrite(true);
                    cp.setPreserveLastModified(true);
                    // keep going even if
                    cp.setFailOnError(false);
                    // there's an error
                    cp.execute();
                    // try to delete as much as possible
                    try {
                        Util.deleteRecursive(oldRoot);
                    } catch (IOException e) {
                        // but ignore the error, since we expect that
                        e.printStackTrace();
                    }
                }
                success = true;
            } finally {
                // if failed, back out the rename.
                if (!success)
                    doSetName(oldName);
            }
            callOnRenamed(newName, parent, oldName);
            for (ItemListener l : ItemListener.all()) l.onRenamed(this, oldName, newName);
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) IOException(java.io.IOException) Copy(org.apache.tools.ant.taskdefs.Copy) ItemListener(hudson.model.listeners.ItemListener) XmlFile(hudson.XmlFile) File(java.io.File)

Example 5 with Copy

use of org.apache.tools.ant.taskdefs.Copy in project intellij-community by JetBrains.

the class RootContainer method copySet.

private void copySet(LayoutFileSet set) {
    Copy task = new Copy();
    task.setTaskName("copy");
    task.setProject(getProject());
    String prefix = set.getPrefix(getProject());
    File target = prefix.length() > 0 ? new File(destDirectory, prefix + "/") : destDirectory;
    target.mkdirs();
    task.setTodir(target);
    LayoutFileSet unprefixed = (LayoutFileSet) set.clone();
    unprefixed.setPrefix("");
    task.addFileset(unprefixed);
    task.perform();
}
Also used : Copy(org.apache.tools.ant.taskdefs.Copy) LayoutFileSet(jetbrains.antlayout.util.LayoutFileSet) File(java.io.File)

Aggregations

Copy (org.apache.tools.ant.taskdefs.Copy)5 File (java.io.File)3 FileSet (org.apache.tools.ant.types.FileSet)3 XmlFile (hudson.XmlFile)1 ItemListener (hudson.model.listeners.ItemListener)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 LayoutFileSet (jetbrains.antlayout.util.LayoutFileSet)1 BuildException (org.apache.tools.ant.BuildException)1 Project (org.apache.tools.ant.Project)1 NameEntry (org.apache.tools.ant.types.PatternSet.NameEntry)1 ZipFileSet (org.apache.tools.ant.types.ZipFileSet)1