Browse Source

Removing some (IMO) unnecessary blank lines; a couple of string cat merges;

replaced an if block with ?: notation.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277644 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
0cff5aacff
1 changed files with 11 additions and 34 deletions
  1. +11
    -34
      src/main/org/apache/tools/ant/taskdefs/Copy.java

+ 11
- 34
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -225,11 +225,7 @@ public class Copy extends Task {
* Default is false. * Default is false.
*/ */
public void setVerbose(boolean verbose) { public void setVerbose(boolean verbose) {
if (verbose) {
this.verbosity = Project.MSG_INFO;
} else {
this.verbosity = Project.MSG_VERBOSE;
}
this.verbosity = verbose ? Project.MSG_INFO : Project.MSG_VERBOSE;
} }


/** /**
@@ -371,19 +367,16 @@ public class Copy extends Task {
// will be removed in validateAttributes // will be removed in validateAttributes
savedFileSet = (FileSet) filesets.elementAt(0); savedFileSet = (FileSet) filesets.elementAt(0);
} }

// make sure we don't have an illegal set of options // make sure we don't have an illegal set of options
validateAttributes(); validateAttributes();


try { try {

// deal with the single file // deal with the single file
if (file != null) { if (file != null) {
if (file.exists()) { if (file.exists()) {
if (destFile == null) { if (destFile == null) {
destFile = new File(destDir, file.getName()); destFile = new File(destDir, file.getName());
} }

if (forceOverwrite || !destFile.exists() if (forceOverwrite || !destFile.exists()
|| (file.lastModified() - granularity || (file.lastModified() - granularity
> destFile.lastModified())) { > destFile.lastModified())) {
@@ -403,7 +396,6 @@ public class Copy extends Task {
} }
} }
} }

// deal with the filesets // deal with the filesets
for (int i = 0; i < filesets.size(); i++) { for (int i = 0; i < filesets.size(); i++) {
FileSet fs = (FileSet) filesets.elementAt(i); FileSet fs = (FileSet) filesets.elementAt(i);
@@ -419,7 +411,6 @@ public class Copy extends Task {
continue; continue;
} }
} }

File fromDir = fs.getDir(getProject()); File fromDir = fs.getDir(getProject());


String[] srcFiles = ds.getIncludedFiles(); String[] srcFiles = ds.getIncludedFiles();
@@ -432,7 +423,6 @@ public class Copy extends Task {
} }
scan(fromDir, destDir, srcFiles, srcDirs); scan(fromDir, destDir, srcFiles, srcDirs);
} }

// do all the copy operations now... // do all the copy operations now...
try { try {
doFileOperations(); doFileOperations();
@@ -452,7 +442,6 @@ public class Copy extends Task {
if (savedFileSet != null) { if (savedFileSet != null) {
filesets.insertElementAt(savedFileSet, 0); filesets.insertElementAt(savedFileSet, 0);
} }

fileCopyMap.clear(); fileCopyMap.clear();
dirCopyMap.clear(); dirCopyMap.clear();
completeDirMap.clear(); completeDirMap.clear();
@@ -471,27 +460,23 @@ public class Copy extends Task {
*/ */
protected void validateAttributes() throws BuildException { protected void validateAttributes() throws BuildException {
if (file == null && filesets.size() == 0) { if (file == null && filesets.size() == 0) {
throw new BuildException("Specify at least one source "
+ "- a file or a fileset.");
throw new BuildException(
"Specify at least one source--a file or a fileset.");
} }

if (destFile != null && destDir != null) { if (destFile != null && destDir != null) {
throw new BuildException("Only one of tofile and todir "
+ "may be set.");
throw new BuildException(
"Only one of tofile and todir may be set.");
} }

if (destFile == null && destDir == null) { if (destFile == null && destDir == null) {
throw new BuildException("One of tofile or todir must be set."); throw new BuildException("One of tofile or todir must be set.");
} }

if (file != null && file.isDirectory()) { if (file != null && file.isDirectory()) {
throw new BuildException("Use a fileset to copy directories."); throw new BuildException("Use a fileset to copy directories.");
} }

if (destFile != null && filesets.size() > 0) { if (destFile != null && filesets.size() > 0) {
if (filesets.size() > 1) { if (filesets.size() > 1) {
throw new BuildException( throw new BuildException(
"Cannot concatenate multiple files into a single file.");
"Cannot concatenate multiple files into a single file.");
} else { } else {
FileSet fs = (FileSet) filesets.elementAt(0); FileSet fs = (FileSet) filesets.elementAt(0);
DirectoryScanner ds = fs.getDirectoryScanner(getProject()); DirectoryScanner ds = fs.getDirectoryScanner(getProject());
@@ -499,26 +484,24 @@ public class Copy extends Task {


if (srcFiles.length == 0) { if (srcFiles.length == 0) {
throw new BuildException( throw new BuildException(
"Cannot perform operation from directory to file.");
"Cannot perform operation from directory to file.");
} else if (srcFiles.length == 1) { } else if (srcFiles.length == 1) {
if (file == null) { if (file == null) {
file = new File(ds.getBasedir(), srcFiles[0]); file = new File(ds.getBasedir(), srcFiles[0]);
filesets.removeElementAt(0); filesets.removeElementAt(0);
} else { } else {
throw new BuildException("Cannot concatenate multiple "
+ "files into a single file.");
throw new BuildException(
"Cannot concatenate multiple files into a single file.");
} }
} else { } else {
throw new BuildException("Cannot concatenate multiple "
+ "files into a single file.");
throw new BuildException(
"Cannot concatenate multiple files into a single file.");
} }
} }
} }

if (destFile != null) { if (destFile != null) {
destDir = destFile.getParentFile(); destDir = destFile.getParentFile();
} }

} }


/** /**
@@ -540,7 +523,6 @@ public class Copy extends Task {
} else { } else {
mapper = new IdentityMapper(); mapper = new IdentityMapper();
} }

buildMap(fromDir, toDir, files, mapper, fileCopyMap); buildMap(fromDir, toDir, files, mapper, fileCopyMap);


if (includeEmpty) { if (includeEmpty) {
@@ -559,7 +541,6 @@ public class Copy extends Task {
*/ */
protected void buildMap(File fromDir, File toDir, String[] names, protected void buildMap(File fromDir, File toDir, String[] names,
FileNameMapper mapper, Hashtable map) { FileNameMapper mapper, Hashtable map) {

String[] toCopy = null; String[] toCopy = null;
if (forceOverwrite) { if (forceOverwrite) {
Vector v = new Vector(); Vector v = new Vector();
@@ -574,7 +555,6 @@ public class Copy extends Task {
SourceFileScanner ds = new SourceFileScanner(this); SourceFileScanner ds = new SourceFileScanner(this);
toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity); toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity);
} }

for (int i = 0; i < toCopy.length; i++) { for (int i = 0; i < toCopy.length; i++) {
File src = new File(fromDir, toCopy[i]); File src = new File(fromDir, toCopy[i]);


@@ -588,7 +568,6 @@ public class Copy extends Task {
for (int k = 0; k < mappedFiles.length; k++) { for (int k = 0; k < mappedFiles.length; k++) {
mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath(); mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
} }

map.put(src.getAbsolutePath(), mappedFiles); map.put(src.getAbsolutePath(), mappedFiles);
} }
} }
@@ -616,7 +595,6 @@ public class Copy extends Task {
log("Skipping self-copy of " + fromFile, verbosity); log("Skipping self-copy of " + fromFile, verbosity);
continue; continue;
} }

try { try {
log("Copying " + fromFile + " to " + toFile, verbosity); log("Copying " + fromFile + " to " + toFile, verbosity);


@@ -647,7 +625,6 @@ public class Copy extends Task {
} }
} }
} }

if (includeEmpty) { if (includeEmpty) {
Enumeration e = dirCopyMap.elements(); Enumeration e = dirCopyMap.elements();
int createCount = 0; int createCount = 0;


Loading…
Cancel
Save