use of org.apache.tools.ant.types.FilterSet in project ant by apache.
the class Copy method doResourceOperations.
/**
* Actually does the resource copies.
* This is a good method for subclasses to override.
* @param map a map of source resource to array of destination files.
* @since Ant 1.7
*/
protected void doResourceOperations(final Map<Resource, String[]> map) {
if (!map.isEmpty()) {
log("Copying " + map.size() + " resource" + (map.size() == 1 ? "" : "s") + " to " + destDir.getAbsolutePath());
for (final Map.Entry<Resource, String[]> e : map.entrySet()) {
final Resource fromResource = e.getKey();
for (final String toFile : e.getValue()) {
try {
log("Copying " + fromResource + " to " + toFile, verbosity);
final FilterSetCollection executionFilters = new FilterSetCollection();
if (filtering) {
executionFilters.addFilterSet(getProject().getGlobalFilterSet());
}
for (final FilterSet filterSet : filterSets) {
executionFilters.addFilterSet(filterSet);
}
ResourceUtils.copyResource(fromResource, new FileResource(destDir, toFile), executionFilters, filterChains, forceOverwrite, preserveLastModified, /* append: */
false, inputEncoding, outputEncoding, getProject(), getForce());
} catch (final IOException ioe) {
String msg = "Failed to copy " + fromResource + " to " + toFile + " due to " + getDueTo(ioe);
final File targetFile = new File(toFile);
if (!(ioe instanceof ResourceUtils.ReadOnlyTargetFileException) && targetFile.exists() && !targetFile.delete()) {
msg += " and I couldn't delete the corrupt " + toFile;
}
if (failonerror) {
throw new BuildException(msg, ioe, getLocation());
}
log(msg, Project.MSG_ERR);
}
}
}
}
}
use of org.apache.tools.ant.types.FilterSet in project ant by apache.
the class Copy method createFilterSet.
/**
* Add a filterset.
* @return a filter set object.
*/
public FilterSet createFilterSet() {
final FilterSet filterSet = new FilterSet();
filterSets.addElement(filterSet);
return filterSet;
}
use of org.apache.tools.ant.types.FilterSet in project ant by apache.
the class Copy method doFileOperations.
/**
* Actually does the file (and possibly empty directory) copies.
* This is a good method for subclasses to override.
*/
protected void doFileOperations() {
if (!fileCopyMap.isEmpty()) {
log("Copying " + fileCopyMap.size() + " file" + (fileCopyMap.size() == 1 ? "" : "s") + " to " + destDir.getAbsolutePath());
for (final Map.Entry<String, String[]> e : fileCopyMap.entrySet()) {
final String fromFile = e.getKey();
for (final String toFile : e.getValue()) {
if (fromFile.equals(toFile)) {
log("Skipping self-copy of " + fromFile, verbosity);
continue;
}
try {
log("Copying " + fromFile + " to " + toFile, verbosity);
final FilterSetCollection executionFilters = new FilterSetCollection();
if (filtering) {
executionFilters.addFilterSet(getProject().getGlobalFilterSet());
}
for (final FilterSet filterSet : filterSets) {
executionFilters.addFilterSet(filterSet);
}
fileUtils.copyFile(new File(fromFile), new File(toFile), executionFilters, filterChains, forceOverwrite, preserveLastModified, /* append: */
false, inputEncoding, outputEncoding, getProject(), getForce());
} catch (final IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + getDueTo(ioe);
final File targetFile = new File(toFile);
if (!(ioe instanceof ResourceUtils.ReadOnlyTargetFileException) && targetFile.exists() && !targetFile.delete()) {
msg += " and I couldn't delete the corrupt " + toFile;
}
if (failonerror) {
throw new BuildException(msg, ioe, getLocation());
}
log(msg, Project.MSG_ERR);
}
}
}
}
if (includeEmpty) {
int createCount = 0;
for (final String[] dirs : dirCopyMap.values()) {
for (String dir : dirs) {
final File d = new File(dir);
if (!d.exists()) {
if (!d.mkdirs() && !d.isDirectory()) {
log("Unable to create directory " + d.getAbsolutePath(), Project.MSG_ERR);
} else {
createCount++;
}
}
}
}
if (createCount > 0) {
log("Copied " + dirCopyMap.size() + " empty director" + (dirCopyMap.size() == 1 ? "y" : "ies") + " to " + createCount + " empty director" + (createCount == 1 ? "y" : "ies") + " under " + destDir.getAbsolutePath());
}
}
}
Aggregations