ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util FileUtils.java PathTokenizer.java
Date Sun, 13 Jan 2002 05:10:58 GMT
donaldp     02/01/12 21:10:58

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jdepend
                        JDependTask.java
               proposal/myrmidon/src/main/org/apache/tools/ant/types
                        Path.java
               proposal/myrmidon/src/main/org/apache/tools/ant/util
                        FileUtils.java PathTokenizer.java
  Log:
  Made PathTokenizer package access and exposed path parsing through FileUtils.
  
  Revision  Changes    Path
  1.17      +7 -7      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
  
  Index: JDependTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JDependTask.java	12 Jan 2002 23:35:23 -0000	1.16
  +++ JDependTask.java	13 Jan 2002 05:10:57 -0000	1.17
  @@ -17,7 +17,7 @@
   import org.apache.tools.ant.types.Argument;
   import org.apache.tools.ant.types.CommandlineJava;
   import org.apache.tools.ant.types.Path;
  -import org.apache.tools.ant.util.PathTokenizer;
  +import org.apache.tools.ant.util.FileUtils;
   
   /**
    * Ant task to run JDepend tests. <p>
  @@ -233,10 +233,10 @@
               // we have to find a cleaner way to put this output
           }
   
  -        PathTokenizer sourcesPath = new PathTokenizer( m_sourcesPath.toString() );
  -        while( sourcesPath.hasMoreTokens() )
  +        final String[] elements = FileUtils.parsePath( m_sourcesPath.toString() );
  +        for( int i = 0; i < elements.length; i++ )
           {
  -            File f = new File( sourcesPath.nextToken() );
  +            File f = new File( elements[ i ] );
   
               // not necessary as JDepend would fail, but why loose some time?
               if( !f.exists() || !f.isDirectory() )
  @@ -312,10 +312,10 @@
               getLogger().info( "Output to be stored in " + m_outputFile.getPath() );
           }
   
  -        PathTokenizer sourcesPath = new PathTokenizer( m_sourcesPath.toString() );
  -        while( sourcesPath.hasMoreTokens() )
  +        final String[] elements = FileUtils.parsePath( m_sourcesPath.toString() );
  +        for( int i = 0; i < elements.length; i++ )
           {
  -            File f = new File( sourcesPath.nextToken() );
  +            File f = new File( elements[ i ] );
   
               // not necessary as JDepend would fail, but why loose some time?
               if( !f.exists() || !f.isDirectory() )
  
  
  
  1.16      +12 -12    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Path.java	12 Jan 2002 23:56:10 -0000	1.15
  +++ Path.java	13 Jan 2002 05:10:57 -0000	1.16
  @@ -14,8 +14,8 @@
   import java.util.Locale;
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.tools.ant.util.PathTokenizer;
   import org.apache.tools.ant.ProjectComponent;
  +import org.apache.tools.ant.util.FileUtils;
   
   /**
    * This object represents a path as used by CLASSPATH or PATH environment
  @@ -88,7 +88,7 @@
        * Returns its argument with all file separator characters replaced so that
        * they match the local OS conventions.
        */
  -    private static String translateFile( final String source )
  +    protected static String translateFile( final String source )
       {
           if( source == null )
               return "";
  @@ -105,18 +105,18 @@
       /**
        * Splits a PATH (with : or ; as separators) into its parts.
        */
  -    private String[] translatePath( final File baseDirectory, String source )
  +    protected String[] translatePath( final File baseDirectory, String source )
       {
           final ArrayList result = new ArrayList();
           if( source == null )
               return new String[ 0 ];
   
  -        PathTokenizer tok = new PathTokenizer( source );
  +        final String[] elements = FileUtils.parsePath( source );
           StringBuffer element = new StringBuffer();
  -        while( tok.hasMoreTokens() )
  +        for( int i = 0; i < elements.length; i++ )
           {
               element.setLength( 0 );
  -            final String pathElement = tok.nextToken();
  +            final String pathElement = elements[ i ];
               try
               {
                   element.append( resolveFile( baseDirectory, pathElement ) );
  @@ -128,9 +128,9 @@
                   getLogger().debug( message );
               }
   
  -            for( int i = 0; i < element.length(); i++ )
  +            for( int j = 0; j < element.length(); j++ )
               {
  -                translateFileSep( element, i );
  +                translateFileSep( element, j );
               }
               result.add( element.toString() );
           }
  @@ -557,21 +557,21 @@
        */
       public class PathElement
       {
  -        private String[] parts;
  +        private String[] m_parts;
   
           public void setLocation( File loc )
           {
  -            parts = new String[]{translateFile( loc.getAbsolutePath() )};
  +            m_parts = new String[]{translateFile( loc.getAbsolutePath() )};
           }
   
           public void setPath( String path )
           {
  -            parts = translatePath( getProject().getBaseDir(), path );
  +            m_parts = translatePath( getProject().getBaseDir(), path );
           }
   
           public String[] getParts()
           {
  -            return parts;
  +            return m_parts;
           }
       }
   }
  
  
  
  1.13      +17 -2     jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FileUtils.java	12 Jan 2002 23:43:32 -0000	1.12
  +++ FileUtils.java	13 Jan 2002 05:10:57 -0000	1.13
  @@ -29,11 +29,26 @@
    * @author duncan@x180.com
    * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  - * @version $Revision: 1.12 $
  + * @version $Revision: 1.13 $
    */
  -
   public class FileUtils
   {
  +    /**
  +     * Parse out a path as appropriate for current OS.
  +     */
  +    public static String[] parsePath( final String path )
  +    {
  +        final PathTokenizer elements = new PathTokenizer( path );
  +
  +        final ArrayList result = new ArrayList();
  +        while( elements.hasNext() )
  +        {
  +            result.add( elements.next() );
  +        }
  +
  +        return (String[])result.toArray( new String[ result.size() ] );
  +    }
  +
       /**
        * Convienence method to copy a file from a source to a destination
        * specifying if token filtering must be used, if source files may overwrite
  
  
  
  1.2       +18 -18    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/PathTokenizer.java
  
  Index: PathTokenizer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/PathTokenizer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PathTokenizer.java	12 Jan 2002 23:48:59 -0000	1.1
  +++ PathTokenizer.java	13 Jan 2002 05:10:57 -0000	1.2
  @@ -18,60 +18,60 @@
    *
    * @author Conor MacNeill (conor@ieee.org)
    */
  -public class PathTokenizer
  +class PathTokenizer
   {
       /**
        * A String which stores any path components which have been read ahead.
        */
  -    private String lookahead;
  +    private String m_lookahead;
   
       /**
        * Flag to indicate whether we are running on a platform with a DOS style
        * filesystem
        */
  -    private boolean dosStyleFilesystem;
  +    private boolean m_dosStyleFilesystem;
       /**
        * A tokenizer to break the string up based on the ':' or ';' separators.
        */
  -    private StringTokenizer tokenizer;
  +    private StringTokenizer m_tokenizer;
   
       public PathTokenizer( String path )
       {
  -        tokenizer = new StringTokenizer( path, ":;", false );
  -        dosStyleFilesystem = File.pathSeparatorChar == ';';
  +        m_tokenizer = new StringTokenizer( path, ":;", false );
  +        m_dosStyleFilesystem = File.pathSeparatorChar == ';';
       }
   
  -    public boolean hasMoreTokens()
  +    public boolean hasNext()
       {
  -        if( lookahead != null )
  +        if( m_lookahead != null )
           {
               return true;
           }
   
  -        return tokenizer.hasMoreTokens();
  +        return m_tokenizer.hasMoreTokens();
       }
   
  -    public String nextToken()
  +    public String next()
           throws NoSuchElementException
       {
           String token = null;
  -        if( lookahead != null )
  +        if( m_lookahead != null )
           {
  -            token = lookahead;
  -            lookahead = null;
  +            token = m_lookahead;
  +            m_lookahead = null;
           }
           else
           {
  -            token = tokenizer.nextToken().trim();
  +            token = m_tokenizer.nextToken().trim();
           }
   
           if( token.length() == 1 && Character.isLetter( token.charAt( 0 ) )
  -            && dosStyleFilesystem
  -            && tokenizer.hasMoreTokens() )
  +            && m_dosStyleFilesystem
  +            && m_tokenizer.hasMoreTokens() )
           {
               // we are on a dos style system so this path could be a drive
               // spec. We look at the next token
  -            String nextToken = tokenizer.nextToken().trim();
  +            String nextToken = m_tokenizer.nextToken().trim();
               if( nextToken.startsWith( "\\" ) || nextToken.startsWith( "/" ) )
               {
                   // we know we are on a DOS style platform and the next path starts with
a
  @@ -81,7 +81,7 @@
               else
               {
                   // store the token just read for next time
  -                lookahead = nextToken;
  +                m_lookahead = nextToken;
               }
           }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message