Browse Source

Allow 'dirsep' and 'pathsep' to contain multi-character values.

(Submitted by M. Kerkhoff, PR 6543)
PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272149 13f79535-47bb-0310-9956-ffa450edef68
master
Diane Holt 23 years ago
parent
commit
e2ca50cce1
2 changed files with 26 additions and 6 deletions
  1. +4
    -2
      docs/manual/CoreTasks/pathconvert.html
  2. +22
    -4
      src/main/org/apache/tools/ant/taskdefs/PathConvert.java

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

@@ -43,14 +43,16 @@ drive letters to Unix paths, and vice-versa.</p>
<tr> <tr>
<td valign="top">dirsep</td> <td valign="top">dirsep</td>
<td valign="top"> <td valign="top">
The character to use as the directory separator in the generated paths.
The character(s) to use as the directory separator in the
generated paths.
</td> </td>
<td valign="top" align="center">No, defaults to current JVM <tt>File.separator</tt></td> <td valign="top" align="center">No, defaults to current JVM <tt>File.separator</tt></td>
</tr> </tr>
<tr> <tr>
<td valign="top">pathsep</td> <td valign="top">pathsep</td>
<td valign="top"> <td valign="top">
The character to use as the path element separator in the generated paths.
The character(s) to use as the path-element separator in the
generated paths.
</td> </td>
<td valign="top" align="center">No, defaults to current JVM <tt>File.pathSeparator</tt></td> <td valign="top" align="center">No, defaults to current JVM <tt>File.pathSeparator</tt></td>
</tr> </tr>


+ 22
- 4
src/main/org/apache/tools/ant/taskdefs/PathConvert.java View File

@@ -63,6 +63,7 @@ import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.DirSet; import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.FileList; import org.apache.tools.ant.types.FileList;


import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
import java.io.File; import java.io.File;


@@ -267,8 +268,10 @@ public class PathConvert extends Task {
(osname.indexOf("netware") >= 0) ); (osname.indexOf("netware") >= 0) );


// Determine the from/to char mappings for dir sep // Determine the from/to char mappings for dir sep
char fromDirSep = onWindows ? '\\' : '/';
char toDirSep = dirSep.charAt(0);
// char fromDirSep = onWindows ? '\\' : '/';
// char toDirSep = dirSep.charAt(0);

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


StringBuffer rslt = new StringBuffer( 100 ); StringBuffer rslt = new StringBuffer( 100 );


@@ -280,15 +283,30 @@ public class PathConvert extends Task {


elem = mapElement( elem ); // Apply the path prefix map elem = mapElement( elem ); // 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.


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


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

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

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

if (fromDirSep.equals(token)) {
rslt.append( dirSep );
}
else {
rslt.append( token );
}
}
} }


// Place the result into the specified property // Place the result into the specified property


Loading…
Cancel
Save