git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270730 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -17,7 +17,7 @@ import org.apache.tools.ant.taskdefs.exec.Execute2; | |||||
| import org.apache.tools.ant.types.Argument; | import org.apache.tools.ant.types.Argument; | ||||
| import org.apache.tools.ant.types.CommandlineJava; | import org.apache.tools.ant.types.CommandlineJava; | ||||
| import org.apache.tools.ant.types.Path; | 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> | * Ant task to run JDepend tests. <p> | ||||
| @@ -233,10 +233,10 @@ public class JDependTask | |||||
| // we have to find a cleaner way to put this output | // 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? | // not necessary as JDepend would fail, but why loose some time? | ||||
| if( !f.exists() || !f.isDirectory() ) | if( !f.exists() || !f.isDirectory() ) | ||||
| @@ -312,10 +312,10 @@ public class JDependTask | |||||
| getLogger().info( "Output to be stored in " + m_outputFile.getPath() ); | 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? | // not necessary as JDepend would fail, but why loose some time? | ||||
| if( !f.exists() || !f.isDirectory() ) | if( !f.exists() || !f.isDirectory() ) | ||||
| @@ -14,8 +14,8 @@ import java.util.ArrayList; | |||||
| import java.util.Locale; | import java.util.Locale; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.util.PathTokenizer; | |||||
| import org.apache.tools.ant.ProjectComponent; | 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 | * This object represents a path as used by CLASSPATH or PATH environment | ||||
| @@ -88,7 +88,7 @@ public class Path | |||||
| * Returns its argument with all file separator characters replaced so that | * Returns its argument with all file separator characters replaced so that | ||||
| * they match the local OS conventions. | * they match the local OS conventions. | ||||
| */ | */ | ||||
| private static String translateFile( final String source ) | |||||
| protected static String translateFile( final String source ) | |||||
| { | { | ||||
| if( source == null ) | if( source == null ) | ||||
| return ""; | return ""; | ||||
| @@ -105,18 +105,18 @@ public class Path | |||||
| /** | /** | ||||
| * Splits a PATH (with : or ; as separators) into its parts. | * 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(); | final ArrayList result = new ArrayList(); | ||||
| if( source == null ) | if( source == null ) | ||||
| return new String[ 0 ]; | return new String[ 0 ]; | ||||
| PathTokenizer tok = new PathTokenizer( source ); | |||||
| final String[] elements = FileUtils.parsePath( source ); | |||||
| StringBuffer element = new StringBuffer(); | StringBuffer element = new StringBuffer(); | ||||
| while( tok.hasMoreTokens() ) | |||||
| for( int i = 0; i < elements.length; i++ ) | |||||
| { | { | ||||
| element.setLength( 0 ); | element.setLength( 0 ); | ||||
| final String pathElement = tok.nextToken(); | |||||
| final String pathElement = elements[ i ]; | |||||
| try | try | ||||
| { | { | ||||
| element.append( resolveFile( baseDirectory, pathElement ) ); | element.append( resolveFile( baseDirectory, pathElement ) ); | ||||
| @@ -128,9 +128,9 @@ public class Path | |||||
| getLogger().debug( message ); | 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() ); | result.add( element.toString() ); | ||||
| } | } | ||||
| @@ -557,21 +557,21 @@ public class Path | |||||
| */ | */ | ||||
| public class PathElement | public class PathElement | ||||
| { | { | ||||
| private String[] parts; | |||||
| private String[] m_parts; | |||||
| public void setLocation( File loc ) | public void setLocation( File loc ) | ||||
| { | { | ||||
| parts = new String[]{translateFile( loc.getAbsolutePath() )}; | |||||
| m_parts = new String[]{translateFile( loc.getAbsolutePath() )}; | |||||
| } | } | ||||
| public void setPath( String path ) | public void setPath( String path ) | ||||
| { | { | ||||
| parts = translatePath( getProject().getBaseDir(), path ); | |||||
| m_parts = translatePath( getProject().getBaseDir(), path ); | |||||
| } | } | ||||
| public String[] getParts() | public String[] getParts() | ||||
| { | { | ||||
| return parts; | |||||
| return m_parts; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -31,9 +31,24 @@ import org.apache.tools.ant.types.FilterSetCollection; | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @version $Revision$ | * @version $Revision$ | ||||
| */ | */ | ||||
| public class FileUtils | 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 | * Convienence method to copy a file from a source to a destination | ||||
| * specifying if token filtering must be used, if source files may overwrite | * specifying if token filtering must be used, if source files may overwrite | ||||
| @@ -18,60 +18,60 @@ import java.util.StringTokenizer; | |||||
| * | * | ||||
| * @author Conor MacNeill (conor@ieee.org) | * @author Conor MacNeill (conor@ieee.org) | ||||
| */ | */ | ||||
| public class PathTokenizer | |||||
| class PathTokenizer | |||||
| { | { | ||||
| /** | /** | ||||
| * A String which stores any path components which have been read ahead. | * 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 | * Flag to indicate whether we are running on a platform with a DOS style | ||||
| * filesystem | * filesystem | ||||
| */ | */ | ||||
| private boolean dosStyleFilesystem; | |||||
| private boolean m_dosStyleFilesystem; | |||||
| /** | /** | ||||
| * A tokenizer to break the string up based on the ':' or ';' separators. | * A tokenizer to break the string up based on the ':' or ';' separators. | ||||
| */ | */ | ||||
| private StringTokenizer tokenizer; | |||||
| private StringTokenizer m_tokenizer; | |||||
| public PathTokenizer( String path ) | 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 true; | ||||
| } | } | ||||
| return tokenizer.hasMoreTokens(); | |||||
| return m_tokenizer.hasMoreTokens(); | |||||
| } | } | ||||
| public String nextToken() | |||||
| public String next() | |||||
| throws NoSuchElementException | throws NoSuchElementException | ||||
| { | { | ||||
| String token = null; | String token = null; | ||||
| if( lookahead != null ) | |||||
| if( m_lookahead != null ) | |||||
| { | { | ||||
| token = lookahead; | |||||
| lookahead = null; | |||||
| token = m_lookahead; | |||||
| m_lookahead = null; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| token = tokenizer.nextToken().trim(); | |||||
| token = m_tokenizer.nextToken().trim(); | |||||
| } | } | ||||
| if( token.length() == 1 && Character.isLetter( token.charAt( 0 ) ) | 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 | // we are on a dos style system so this path could be a drive | ||||
| // spec. We look at the next token | // spec. We look at the next token | ||||
| String nextToken = tokenizer.nextToken().trim(); | |||||
| String nextToken = m_tokenizer.nextToken().trim(); | |||||
| if( nextToken.startsWith( "\\" ) || nextToken.startsWith( "/" ) ) | if( nextToken.startsWith( "\\" ) || nextToken.startsWith( "/" ) ) | ||||
| { | { | ||||
| // we know we are on a DOS style platform and the next path starts with a | // we know we are on a DOS style platform and the next path starts with a | ||||
| @@ -81,7 +81,7 @@ public class PathTokenizer | |||||
| else | else | ||||
| { | { | ||||
| // store the token just read for next time | // store the token just read for next time | ||||
| lookahead = nextToken; | |||||
| m_lookahead = nextToken; | |||||
| } | } | ||||
| } | } | ||||
| @@ -17,7 +17,7 @@ import org.apache.tools.ant.taskdefs.exec.Execute2; | |||||
| import org.apache.tools.ant.types.Argument; | import org.apache.tools.ant.types.Argument; | ||||
| import org.apache.tools.ant.types.CommandlineJava; | import org.apache.tools.ant.types.CommandlineJava; | ||||
| import org.apache.tools.ant.types.Path; | 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> | * Ant task to run JDepend tests. <p> | ||||
| @@ -233,10 +233,10 @@ public class JDependTask | |||||
| // we have to find a cleaner way to put this output | // 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? | // not necessary as JDepend would fail, but why loose some time? | ||||
| if( !f.exists() || !f.isDirectory() ) | if( !f.exists() || !f.isDirectory() ) | ||||
| @@ -312,10 +312,10 @@ public class JDependTask | |||||
| getLogger().info( "Output to be stored in " + m_outputFile.getPath() ); | 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? | // not necessary as JDepend would fail, but why loose some time? | ||||
| if( !f.exists() || !f.isDirectory() ) | if( !f.exists() || !f.isDirectory() ) | ||||
| @@ -14,8 +14,8 @@ import java.util.ArrayList; | |||||
| import java.util.Locale; | import java.util.Locale; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.util.PathTokenizer; | |||||
| import org.apache.tools.ant.ProjectComponent; | 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 | * This object represents a path as used by CLASSPATH or PATH environment | ||||
| @@ -88,7 +88,7 @@ public class Path | |||||
| * Returns its argument with all file separator characters replaced so that | * Returns its argument with all file separator characters replaced so that | ||||
| * they match the local OS conventions. | * they match the local OS conventions. | ||||
| */ | */ | ||||
| private static String translateFile( final String source ) | |||||
| protected static String translateFile( final String source ) | |||||
| { | { | ||||
| if( source == null ) | if( source == null ) | ||||
| return ""; | return ""; | ||||
| @@ -105,18 +105,18 @@ public class Path | |||||
| /** | /** | ||||
| * Splits a PATH (with : or ; as separators) into its parts. | * 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(); | final ArrayList result = new ArrayList(); | ||||
| if( source == null ) | if( source == null ) | ||||
| return new String[ 0 ]; | return new String[ 0 ]; | ||||
| PathTokenizer tok = new PathTokenizer( source ); | |||||
| final String[] elements = FileUtils.parsePath( source ); | |||||
| StringBuffer element = new StringBuffer(); | StringBuffer element = new StringBuffer(); | ||||
| while( tok.hasMoreTokens() ) | |||||
| for( int i = 0; i < elements.length; i++ ) | |||||
| { | { | ||||
| element.setLength( 0 ); | element.setLength( 0 ); | ||||
| final String pathElement = tok.nextToken(); | |||||
| final String pathElement = elements[ i ]; | |||||
| try | try | ||||
| { | { | ||||
| element.append( resolveFile( baseDirectory, pathElement ) ); | element.append( resolveFile( baseDirectory, pathElement ) ); | ||||
| @@ -128,9 +128,9 @@ public class Path | |||||
| getLogger().debug( message ); | 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() ); | result.add( element.toString() ); | ||||
| } | } | ||||
| @@ -557,21 +557,21 @@ public class Path | |||||
| */ | */ | ||||
| public class PathElement | public class PathElement | ||||
| { | { | ||||
| private String[] parts; | |||||
| private String[] m_parts; | |||||
| public void setLocation( File loc ) | public void setLocation( File loc ) | ||||
| { | { | ||||
| parts = new String[]{translateFile( loc.getAbsolutePath() )}; | |||||
| m_parts = new String[]{translateFile( loc.getAbsolutePath() )}; | |||||
| } | } | ||||
| public void setPath( String path ) | public void setPath( String path ) | ||||
| { | { | ||||
| parts = translatePath( getProject().getBaseDir(), path ); | |||||
| m_parts = translatePath( getProject().getBaseDir(), path ); | |||||
| } | } | ||||
| public String[] getParts() | public String[] getParts() | ||||
| { | { | ||||
| return parts; | |||||
| return m_parts; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -31,9 +31,24 @@ import org.apache.tools.ant.types.FilterSetCollection; | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @version $Revision$ | * @version $Revision$ | ||||
| */ | */ | ||||
| public class FileUtils | 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 | * Convienence method to copy a file from a source to a destination | ||||
| * specifying if token filtering must be used, if source files may overwrite | * specifying if token filtering must be used, if source files may overwrite | ||||
| @@ -18,60 +18,60 @@ import java.util.StringTokenizer; | |||||
| * | * | ||||
| * @author Conor MacNeill (conor@ieee.org) | * @author Conor MacNeill (conor@ieee.org) | ||||
| */ | */ | ||||
| public class PathTokenizer | |||||
| class PathTokenizer | |||||
| { | { | ||||
| /** | /** | ||||
| * A String which stores any path components which have been read ahead. | * 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 | * Flag to indicate whether we are running on a platform with a DOS style | ||||
| * filesystem | * filesystem | ||||
| */ | */ | ||||
| private boolean dosStyleFilesystem; | |||||
| private boolean m_dosStyleFilesystem; | |||||
| /** | /** | ||||
| * A tokenizer to break the string up based on the ':' or ';' separators. | * A tokenizer to break the string up based on the ':' or ';' separators. | ||||
| */ | */ | ||||
| private StringTokenizer tokenizer; | |||||
| private StringTokenizer m_tokenizer; | |||||
| public PathTokenizer( String path ) | 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 true; | ||||
| } | } | ||||
| return tokenizer.hasMoreTokens(); | |||||
| return m_tokenizer.hasMoreTokens(); | |||||
| } | } | ||||
| public String nextToken() | |||||
| public String next() | |||||
| throws NoSuchElementException | throws NoSuchElementException | ||||
| { | { | ||||
| String token = null; | String token = null; | ||||
| if( lookahead != null ) | |||||
| if( m_lookahead != null ) | |||||
| { | { | ||||
| token = lookahead; | |||||
| lookahead = null; | |||||
| token = m_lookahead; | |||||
| m_lookahead = null; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| token = tokenizer.nextToken().trim(); | |||||
| token = m_tokenizer.nextToken().trim(); | |||||
| } | } | ||||
| if( token.length() == 1 && Character.isLetter( token.charAt( 0 ) ) | 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 | // we are on a dos style system so this path could be a drive | ||||
| // spec. We look at the next token | // spec. We look at the next token | ||||
| String nextToken = tokenizer.nextToken().trim(); | |||||
| String nextToken = m_tokenizer.nextToken().trim(); | |||||
| if( nextToken.startsWith( "\\" ) || nextToken.startsWith( "/" ) ) | if( nextToken.startsWith( "\\" ) || nextToken.startsWith( "/" ) ) | ||||
| { | { | ||||
| // we know we are on a DOS style platform and the next path starts with a | // we know we are on a DOS style platform and the next path starts with a | ||||
| @@ -81,7 +81,7 @@ public class PathTokenizer | |||||
| else | else | ||||
| { | { | ||||
| // store the token just read for next time | // store the token just read for next time | ||||
| lookahead = nextToken; | |||||
| m_lookahead = nextToken; | |||||
| } | } | ||||
| } | } | ||||