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();
}
}
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();
}
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();
}
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);
}
}
}
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();
}
Aggregations