ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant PathTokenizer.java Project.java
Date Sun, 09 Jul 2000 03:48:11 GMT
conor       00/07/08 20:48:11

  Modified:    src/main/org/apache/tools/ant PathTokenizer.java
                        Project.java
  Log:
  Change Project.translatePath to use PathTokenizer
  
  I have changed the Project.translatePath method to use the PathTokenizer. This
  adds support for paths of the format C:/blah. These used to translate to C;\blah
  but this will now be C:\blah.
  
  Revision  Changes    Path
  1.3       +8 -1      jakarta-ant/src/main/org/apache/tools/ant/PathTokenizer.java
  
  Index: PathTokenizer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/PathTokenizer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PathTokenizer.java	2000/06/30 11:33:03	1.2
  +++ PathTokenizer.java	2000/07/09 03:48:11	1.3
  @@ -77,8 +77,15 @@
        */
       private String lookahead = null;
   
  +    /**
  +     * Flag to indicate whether we are running on a platform with a DOS style
  +     * filesystem
  +     */
  +    private boolean dosStyleFilesystem;
  +
       public PathTokenizer(String path) {
          tokenizer = new StringTokenizer(path, ":;", false);
  +       dosStyleFilesystem = File.pathSeparatorChar == ';'; 
       }
   
       public boolean hasMoreTokens() {
  @@ -100,7 +107,7 @@
           }            
               
           if (token.length() == 1 && Character.isLetter(token.charAt(0))
  -                                && File.pathSeparator.equals(";") 
  +                                && dosStyleFilesystem
                                   && tokenizer.hasMoreTokens()) {
               // we are on a dos style system so this path could be a drive
               // spec. We look at the next token
  
  
  
  1.28      +26 -33    jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- Project.java	2000/07/08 17:18:50	1.27
  +++ Project.java	2000/07/09 03:48:11	1.28
  @@ -499,43 +499,36 @@
       }
   
       /**
  -        Translate a path into its native (platform specific)
  -        path. This should be extremely fast, code is
  -        borrowed from ECS project.
  -        <p>
  -        All it does is translate the : into ; and / into \
  -        if needed. In other words, it isn't perfect.
  -
  -        @returns translated string or empty string if to_process is null or empty
  -        @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
  -    */
  +     * Translate a path into its native (platform specific) format. 
  +     * <p>
  +     * This method uses the PathTokenizer class to separate the input path
  +     * into its components. This handles DOS style paths in a relatively
  +     * sensible way. The file separators are then converted to their platform
  +     * specific versions.
  +     *
  +     * @param to_process the path to be converted   
  +     *
  +     * @return the native version of to_process or 
  +     *         an empty string if to_process is null or empty
  +     */
       static public String translatePath(String to_process) {
  -        if ( to_process == null || to_process.length() == 0 ) return "";
  -
  -        StringBuffer bs = new StringBuffer(to_process.length() + 50);
  -        StringCharacterIterator sci = new StringCharacterIterator(to_process);
  -        String path = System.getProperty("path.separator");
  -        String file = System.getProperty("file.separator");
  -        String tmp = null;
  -        for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next()) {
  -            tmp = String.valueOf(c);
  +        if ( to_process == null || to_process.length() == 0 ) {
  +            return "";
  +        }
   
  -            if (tmp.equals(":")) {
  -                // could be a DOS drive or a Unix path separator...
  -                // if followed by a backslash, assume it is a drive
  -                c = sci.next();
  -                tmp = String.valueOf(c);
  -                bs.append( tmp.equals("\\") ? ":" : path );
  -                if (c == CharacterIterator.DONE) break;
  +        StringBuffer path = new StringBuffer(to_process.length() + 50);
  +        PathTokenizer tokenizer = new PathTokenizer(to_process);
  +        while (tokenizer.hasMoreTokens()) {
  +            String pathComponent = tokenizer.nextToken();
  +            pathComponent = pathComponent.replace('/', File.separatorChar);
  +            pathComponent = pathComponent.replace('\\', File.separatorChar);
  +            if (path.length() != 0) {
  +                path.append(File.pathSeparatorChar);
               }
  -
  -            if (tmp.equals(":") || tmp.equals(";"))
  -                tmp = path;
  -            else if (tmp.equals("/") || tmp.equals ("\\"))
  -                tmp = file;
  -            bs.append(tmp);
  +            path.append(pathComponent);
           }
  -        return(bs.toString());
  +        
  +        return path.toString();
       }
   
       /**
  
  
  

Mime
View raw message