bodewig 02/04/02 07:48:53
Modified: docs/manual/CoreTasks pathconvert.html
src/main/org/apache/tools/ant/taskdefs PathConvert.java
Log:
Simplify pathconvert, support OS/2 as well, fix some indentation.
Revision Changes Path
1.8 +2 -1 jakarta-ant/docs/manual/CoreTasks/pathconvert.html
Index: pathconvert.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/pathconvert.html,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- pathconvert.html 1 Apr 2002 08:14:33 -0000 1.7
+++ pathconvert.html 2 Apr 2002 15:48:53 -0000 1.8
@@ -30,7 +30,8 @@
<tr>
<td valign="top">targetos</td>
<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
<code>pathsep</code> and <code>dirsep</code>
according to the specified target architecture.
1.14 +33 -37
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
Index: PathConvert.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PathConvert.java 1 Apr 2002 08:14:33 -0000 1.13
+++ PathConvert.java 2 Apr 2002 15:48:53 -0000 1.14
@@ -57,11 +57,13 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
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.EnumeratedAttribute;
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.Vector;
@@ -137,6 +139,12 @@
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
*/
@@ -165,23 +173,18 @@
/**
* Set the value of the targetos attribute
*/
- public void setTargetos( String target ) {
-
- targetOS = target.toLowerCase();
+ public void setTargetos( TargetOs target ) {
- 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
// 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 @@
// And Unix is everything that is not Windows
// (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 ? "\\" : "/";
@@ -287,25 +284,23 @@
// Now convert the path and file separator characters from the
// current os to the target os.
-// elem = elem.replace( fromDirSep, toDirSep );
-
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;
while ( stDirectory.hasMoreTokens() ) {
- token = stDirectory.nextToken();
+ token = stDirectory.nextToken();
- if (fromDirSep.equals(token)) {
- rslt.append( dirSep );
- }
- else {
- rslt.append( token );
- }
+ if (fromDirSep.equals(token)) {
+ rslt.append( dirSep );
+ }
+ else {
+ rslt.append( token );
+ }
}
}
@@ -412,4 +407,5 @@
private Vector prefixMap = new Vector(); // Path prefix map
private String pathSep = null; // User override on path sep char
private String dirSep = null; // User override on directory
sep char
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>