Browse Source

Simplify pathconvert, support OS/2 as well, fix some indentation.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272168 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
5e93b0b89f
2 changed files with 36 additions and 39 deletions
  1. +2
    -1
      docs/manual/CoreTasks/pathconvert.html
  2. +34
    -38
      src/main/org/apache/tools/ant/taskdefs/PathConvert.java

+ 2
- 1
docs/manual/CoreTasks/pathconvert.html View File

@@ -30,7 +30,8 @@ drive letters to Unix paths, and vice-versa.</p>
<tr> <tr>
<td valign="top">targetos</td> <td valign="top">targetos</td>
<td valign="top"> <td valign="top">
The target architecture. Must be one of 'unix' or 'windows'.
The target architecture. Must be one of 'unix', 'windows',
'netware' or 'os/2'.
This is a shorthand mechanism for specifying both This is a shorthand mechanism for specifying both
<code>pathsep</code> and <code>dirsep</code> <code>pathsep</code> and <code>dirsep</code>
according to the specified target architecture. according to the specified target architecture.


+ 34
- 38
src/main/org/apache/tools/ant/taskdefs/PathConvert.java View File

@@ -57,11 +57,13 @@ package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.DirSet; import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.FileList; import org.apache.tools.ant.types.FileList;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;


import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
@@ -137,6 +139,12 @@ public class PathConvert extends Task {
private String to = null; private String to = null;
} }


public static class TargetOs extends EnumeratedAttribute {
public String[] getValues() {
return new String[] {"windows", "unix", "netware", "os/2"};
}
}

/** /**
* Create a nested PATH element * Create a nested PATH element
*/ */
@@ -165,23 +173,18 @@ public class PathConvert extends Task {
/** /**
* Set the value of the targetos attribute * Set the value of the targetos attribute
*/ */
public void setTargetos( String target ) {
public void setTargetos( TargetOs target ) {


targetOS = target.toLowerCase();

if( ! targetOS.equals( "windows" ) && ! target.equals( "unix" ) &&
! targetOS.equals( "netware" )) {
throw new BuildException( "targetos must be one of 'unix', 'netware', or 'windows'" );
}
targetOS = target.getValue();


// Currently, we deal with only two path formats: Unix and Windows // Currently, we deal with only two path formats: Unix and Windows
// And Unix is everything that is not Windows // And Unix is everything that is not Windows


// for NetWare, piggy-back on Windows, since in the validateSetup code,
// the same assumptions can be made as with windows -
// that ; is the path separator
// for NetWare and os/2, piggy-back on Windows, since in the
// validateSetup code, the same assumptions can be made as
// with windows - that ; is the path separator


targetWindows = (targetOS.equals("windows") || targetOS.equals("netware"));
targetWindows = !targetOS.equals("unix");
} }


/** /**
@@ -259,17 +262,11 @@ public class PathConvert extends Task {
// And Unix is everything that is not Windows // And Unix is everything that is not Windows
// (with the exception for NetWare below) // (with the exception for NetWare below)


String osname = System.getProperty("os.name").toLowerCase();

// for NetWare, piggy-back on Windows, since here and in the
// apply code, the same assumptions can be made as with windows -
// that \\ is an OK separator, and do comparisons case-insensitive.
onWindows = ( (osname.indexOf("windows") >= 0) ||
(osname.indexOf("netware") >= 0) );

// Determine the from/to char mappings for dir sep
// char fromDirSep = onWindows ? '\\' : '/';
// char toDirSep = dirSep.charAt(0);
// for NetWare and OS/2, piggy-back on Windows, since here and
// in the apply code, the same assumptions can be made as with
// windows - that \\ is an OK separator, and do comparisons
// case-insensitive.
onWindows = Os.isFamily("dos");


String fromDirSep = onWindows ? "\\" : "/"; String fromDirSep = onWindows ? "\\" : "/";


@@ -287,25 +284,23 @@ public class PathConvert extends Task {
// 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.


// elem = elem.replace( fromDirSep, toDirSep );

if( i != 0 ) { if( i != 0 ) {
rslt.append( pathSep );
rslt.append( pathSep );
} }
// rslt.append( elem );


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


while ( stDirectory.hasMoreTokens() ) { while ( stDirectory.hasMoreTokens() ) {
token = stDirectory.nextToken();
if (fromDirSep.equals(token)) {
rslt.append( dirSep );
}
else {
rslt.append( token );
}
token = stDirectory.nextToken();
if (fromDirSep.equals(token)) {
rslt.append( dirSep );
}
else {
rslt.append( token );
}
} }
} }


@@ -412,4 +407,5 @@ public class PathConvert extends Task {
private Vector prefixMap = new Vector(); // Path prefix map private Vector prefixMap = new Vector(); // Path prefix map
private String pathSep = null; // User override on path sep char private String pathSep = null; // User override on path sep char
private String dirSep = null; // User override on directory sep char private String dirSep = null; // User override on directory sep char

} }

Loading…
Cancel
Save