Browse Source

More LOC bumming

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

+ 10
- 45
src/main/org/apache/tools/ant/taskdefs/PathConvert.java View File

@@ -156,7 +156,7 @@ public class PathConvert extends Task {
*/ */
public static class TargetOs extends EnumeratedAttribute { public static class TargetOs extends EnumeratedAttribute {
/** /**
* @return the list of values for this enumerated attribute
* @return the list of values for this enumerated attribute.
*/ */
public String[] getValues() { public String[] getValues() {
return new String[]{"windows", "unix", "netware", "os/2", "tandem"}; return new String[]{"windows", "unix", "netware", "os/2", "tandem"};
@@ -291,31 +291,21 @@ public class PathConvert extends Task {
// If we are a reference, create a Path from the reference // If we are a reference, create a Path from the reference
if (isReference()) { if (isReference()) {
path = new Path(getProject()).createPath(); path = new Path(getProject()).createPath();

Object obj = refid.getReferencedObject(getProject()); Object obj = refid.getReferencedObject(getProject());


if (obj instanceof Path) { if (obj instanceof Path) {
path.setRefid(refid); path.setRefid(refid);
} else if (obj instanceof FileSet) { } else if (obj instanceof FileSet) {
FileSet fs = (FileSet) obj;

path.addFileset(fs);
path.addFileset((FileSet) obj);
} else if (obj instanceof DirSet) { } else if (obj instanceof DirSet) {
DirSet ds = (DirSet) obj;

path.addDirset(ds);
path.addDirset((DirSet) obj);
} else if (obj instanceof FileList) { } else if (obj instanceof FileList) {
FileList fl = (FileList) obj;

path.addFilelist(fl);

path.addFilelist((FileList) obj);
} else { } else {
throw new BuildException("'refid' does not refer to a " throw new BuildException("'refid' does not refer to a "
+ "path, fileset, dirset, or "
+ "filelist.");
+ "path, fileset, dirset, or filelist.");
} }
} }

validateSetup(); // validate our setup validateSetup(); // validate our setup


// Currently, we deal with only two path formats: Unix and Windows // Currently, we deal with only two path formats: Unix and Windows
@@ -344,11 +334,8 @@ public class PathConvert extends Task {
} }
elems = (String[]) ret.toArray(new String[] {}); elems = (String[]) ret.toArray(new String[] {});
} }

for (int i = 0; i < elems.length; i++) { for (int i = 0; i < elems.length; i++) {
String elem = elems[i];

elem = mapElement(elem); // Apply the path prefix map
String elem = mapElement(elems[i]); // Apply the path prefix map


// Now convert the path and file separator characters from the // Now convert the path and file separator characters from the
// current os to the target os. // current os to the target os.
@@ -356,35 +343,21 @@ public class PathConvert extends Task {
if (i != 0) { if (i != 0) {
rslt.append(pathSep); rslt.append(pathSep);
} }

StringTokenizer stDirectory = StringTokenizer stDirectory =
new StringTokenizer(elem, fromDirSep, true); new StringTokenizer(elem, fromDirSep, true);
String token = null;


while (stDirectory.hasMoreTokens()) { while (stDirectory.hasMoreTokens()) {
token = stDirectory.nextToken();

if (fromDirSep.equals(token)) {
rslt.append(dirSep);
} else {
rslt.append(token);
}
String token = stDirectory.nextToken();
rslt.append(fromDirSep.equals(token) ? dirSep : token);
} }
} }

// Place the result into the specified property, // Place the result into the specified property,
// unless setonempty == false // unless setonempty == false
String value = rslt.toString();
if (setonempty) {
if (setonempty || rslt.length() > 0) {
String value = rslt.toString();
log("Set property " + property + " = " + value, log("Set property " + property + " = " + value,
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
getProject().setNewProperty(property, value); getProject().setNewProperty(property, value);
} else {
if (rslt.length() > 0) {
log("Set property " + property + " = " + value,
Project.MSG_VERBOSE);
getProject().setNewProperty(property, value);
}
} }
} finally { } finally {
path = savedPath; path = savedPath;
@@ -393,7 +366,6 @@ public class PathConvert extends Task {
} }
} }



/** /**
* Apply the configured map to a path element. The map is used to convert * Apply the configured map to a path element. The map is used to convert
* between Windows drive letters and Unix paths. If no map is configured, * between Windows drive letters and Unix paths. If no map is configured,
@@ -424,7 +396,6 @@ public class PathConvert extends Task {
} }
} }
} }

return elem; return elem;
} }


@@ -463,18 +434,15 @@ public class PathConvert extends Task {
if (path == null) { if (path == null) {
throw new BuildException("You must specify a path to convert"); throw new BuildException("You must specify a path to convert");
} }

if (property == null) { if (property == null) {
throw new BuildException("You must specify a property"); throw new BuildException("You must specify a property");
} }

// Must either have a target OS or both a dirSep and pathSep // Must either have a target OS or both a dirSep and pathSep


if (targetOS == null && pathSep == null && dirSep == null) { if (targetOS == null && pathSep == null && dirSep == null) {
throw new BuildException("You must specify at least one of " throw new BuildException("You must specify at least one of "
+ "targetOS, dirSep, or pathSep"); + "targetOS, dirSep, or pathSep");
} }

// Determine the separator strings. The dirsep and pathsep attributes // Determine the separator strings. The dirsep and pathsep attributes
// override the targetOS settings. // override the targetOS settings.
String dsep = File.separator; String dsep = File.separator;
@@ -484,17 +452,14 @@ public class PathConvert extends Task {
psep = targetWindows ? ";" : ":"; psep = targetWindows ? ";" : ":";
dsep = targetWindows ? "\\" : "/"; dsep = targetWindows ? "\\" : "/";
} }

if (pathSep != null) { if (pathSep != null) {
// override with pathsep= // override with pathsep=
psep = pathSep; psep = pathSep;
} }

if (dirSep != null) { if (dirSep != null) {
// override with dirsep= // override with dirsep=
dsep = dirSep; dsep = dirSep;
} }

pathSep = psep; pathSep = psep;
dirSep = dsep; dirSep = dsep;
} }


Loading…
Cancel
Save