diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/AbstractAvailableCondition.java b/proposal/myrmidon/src/java/org/apache/antlib/core/AbstractAvailableCondition.java index 7534f668a..a7713a692 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/AbstractAvailableCondition.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/AbstractAvailableCondition.java @@ -7,12 +7,13 @@ */ package org.apache.antlib.core; -import org.apache.myrmidon.framework.conditions.Condition; +import java.net.URL; +import java.net.URLClassLoader; +import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.conditions.Condition; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; -import java.net.URL; -import java.net.URLClassLoader; /** * An abstract condition which checks for the availability of a particular @@ -38,9 +39,9 @@ public abstract class AbstractAvailableCondition /** * Builds the ClassLoader to use to check resources. */ - protected ClassLoader buildClassLoader() throws TaskException + protected ClassLoader buildClassLoader( final TaskContext context ) throws TaskException { - final URL[] urls = PathUtil.toURLs( m_classpath ); + final URL[] urls = PathUtil.toURLs( m_classpath, context ); final ClassLoader classLoader; if( urls.length > 0 ) { diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/ClassAvailableCondition.java b/proposal/myrmidon/src/java/org/apache/antlib/core/ClassAvailableCondition.java index a1875a6c9..fcf4f3d6d 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/ClassAvailableCondition.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/ClassAvailableCondition.java @@ -47,7 +47,7 @@ public class ClassAvailableCondition } // Build the classloader to use to check resources - final ClassLoader classLoader = buildClassLoader(); + final ClassLoader classLoader = buildClassLoader( context ); // Do the check try diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/ResourceAvailableCondition.java b/proposal/myrmidon/src/java/org/apache/antlib/core/ResourceAvailableCondition.java index a0af0ca20..a704c933b 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/ResourceAvailableCondition.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/ResourceAvailableCondition.java @@ -49,7 +49,7 @@ public class ResourceAvailableCondition } // Check whether the resource is available - final ClassLoader classLoader = buildClassLoader(); + final ClassLoader classLoader = buildClassLoader( context ); final InputStream instr = classLoader.getResourceAsStream( m_resource ); if( instr != null ) { diff --git a/proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java b/proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java index 3aba08955..d41ae494c 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java @@ -330,7 +330,7 @@ public class XMLValidateTask Class readerClass = null; if( m_classpath != null ) { - final URL[] urls = PathUtil.toURLs( m_classpath ); + final URL[] urls = PathUtil.toURLs( m_classpath, getContext() ); final ClassLoader classLoader = new URLClassLoader( urls ); readerClass = classLoader.loadClass( m_readerClassName ); } diff --git a/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml b/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml index e5b5a9194..120d447e6 100644 --- a/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml +++ b/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml @@ -4,9 +4,12 @@ - + destination="org.apache.tools.todo.types.Path" /> + \ No newline at end of file diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/DependSet.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/DependSet.java index ee4ef4b01..c17e1a943 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/DependSet.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/DependSet.java @@ -13,12 +13,10 @@ import java.util.Date; import java.util.Iterator; import org.apache.aut.nativelib.Os; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.FileList; import org.apache.tools.todo.types.FileSet; import org.apache.tools.todo.types.ScannerUtil; +import org.apache.tools.todo.types.SimpleFileList; /** * A Task to record explicit dependencies. If any of the target files are out of @@ -84,7 +82,7 @@ public class DependSet extends MatchingTask * * @param fl The feature to be added to the Srcfilelist attribute */ - public void addSrcfilelist( FileList fl ) + public void addSrcfilelist( SimpleFileList fl ) { sourceFileLists.add( fl ); }//-- DependSet @@ -104,7 +102,7 @@ public class DependSet extends MatchingTask * * @param fl The feature to be added to the Targetfilelist attribute */ - public void addTargetfilelist( FileList fl ) + public void addTargetfilelist( SimpleFileList fl ) { targetFileLists.add( fl ); } @@ -181,7 +179,7 @@ public class DependSet extends MatchingTask while( enumTargetLists.hasNext() ) { - FileList targetFL = (FileList)enumTargetLists.next(); + SimpleFileList targetFL = (SimpleFileList)enumTargetLists.next(); String[] targetFiles = targetFL.getFiles(); for( int i = 0; i < targetFiles.length; i++ ) @@ -252,7 +250,7 @@ public class DependSet extends MatchingTask while( upToDate && enumSourceLists.hasNext() ) { - FileList sourceFL = (FileList)enumSourceLists.next(); + SimpleFileList sourceFL = (SimpleFileList)enumSourceLists.next(); String[] sourceFiles = sourceFL.getFiles(); int i = 0; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ExecuteJava.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ExecuteJava.java index 752a468ae..474abd3c6 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ExecuteJava.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ExecuteJava.java @@ -12,16 +12,16 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; +import org.apache.aut.nativelib.Os; import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.framework.Execute; import org.apache.tools.todo.types.Commandline; +import org.apache.tools.todo.types.EnvironmentData; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; -import org.apache.tools.todo.types.EnvironmentData; import org.apache.tools.todo.types.SysProperties; import org.apache.tools.todo.util.FileUtils; -import org.apache.aut.nativelib.Os; /** * A utility class that executes a Java app, either in this JVM, or a forked @@ -160,7 +160,7 @@ public class ExecuteJava final Class target; try { - final URL[] urls = PathUtil.toURLs( m_classPath ); + final URL[] urls = PathUtil.toURLs( m_classPath, context ); if( urls.length == 0 ) { target = Class.forName( m_className ); @@ -241,10 +241,11 @@ public class ExecuteJava command.addArguments( props ); // Classpath - if( ! m_classPath.isEmpty() ) + final String[] classpath = m_classPath.listFiles( context ); + if( classpath.length > 0 ) { command.addArgument( "-classpath" ); - command.addArgument( PathUtil.formatPath( m_classPath ) ); + command.addArgument( PathUtil.formatPath( classpath ) ); } // What to execute diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.java index da4e8acd0..de46dee41 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.java @@ -773,7 +773,8 @@ public class IContract extends MatchingTask } iControlProps.setProperty( "sourceRoot", srcDir.getAbsolutePath() ); iControlProps.setProperty( "classRoot", classDir.getAbsolutePath() ); - iControlProps.setProperty( "classpath", PathUtil.formatPath( afterInstrumentationClasspath ) ); + final String classpath = PathUtil.formatPath( afterInstrumentationClasspath, getContext() ); + iControlProps.setProperty( "classpath", classpath ); iControlProps.setProperty( "controlFile", controlFile.getAbsolutePath() ); iControlProps.setProperty( "targetsFile", targets.getAbsolutePath() ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Javah.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Javah.java index 3073ea9b9..b57bccf8f 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Javah.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Javah.java @@ -14,12 +14,9 @@ import java.util.StringTokenizer; import org.apache.avalon.excalibur.util.StringUtil; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.Commandline; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; -import org.apache.tools.todo.util.FileUtils; -import org.apache.tools.todo.taskdefs.ClassArgument; /** * Task to generate JNI header files using javah. This task can take the @@ -271,7 +268,7 @@ public class Javah if( m_classpath != null ) { cmd.addArgument( "-classpath" ); - cmd.addArgument( PathUtil.formatPath( m_classpath ) ); + cmd.addArgument( PathUtil.formatPath( m_classpath, getContext() ) ); } if( m_verbose ) @@ -299,7 +296,7 @@ public class Javah if( m_bootclasspath != null ) { cmd.addArgument( "-bootclasspath" ); - cmd.addArgument( PathUtil.formatPath( m_bootclasspath ) ); + cmd.addArgument( PathUtil.formatPath( m_bootclasspath, getContext() ) ); } logAndAddFilesToCompile( cmd ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/PathConvert.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/PathConvert.java index 5179f53c9..c19556bff 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/PathConvert.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/PathConvert.java @@ -12,7 +12,6 @@ import java.util.ArrayList; import org.apache.aut.nativelib.Os; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.Path; /** @@ -135,7 +134,7 @@ public class PathConvert extends AbstractTask StringBuffer rslt = new StringBuffer( 100 ); // Get the list of path components in canonical form - String[] elems = m_path.list(); + String[] elems = m_path.listFiles( getContext() ); for( int i = 0; i < elems.length; i++ ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java index 18e408d93..03982ad8a 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java @@ -16,7 +16,6 @@ import java.util.Iterator; import java.util.Properties; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; @@ -134,7 +133,7 @@ public class Property if( m_classpath != null ) { - final URL[] urls = PathUtil.toURLs( m_classpath ); + final URL[] urls = PathUtil.toURLs( m_classpath, getContext() ); classLoader = new URLClassLoader( urls ); } else diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java index 5e6847fcc..7c7118d67 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java @@ -34,7 +34,6 @@ import java.util.Properties; import java.util.StringTokenizer; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.DirectoryScanner; import org.apache.tools.todo.types.EnumeratedAttribute; import org.apache.tools.todo.types.FileSet; @@ -432,7 +431,7 @@ public class SQLExec { getContext().debug( "Loading " + driver + " using AntClassLoader with classpath " + classpath ); - final URL[] urls = PathUtil.toURLs( classpath ); + final URL[] urls = PathUtil.toURLs( classpath, getContext() ); final ClassLoader classLoader = new URLClassLoader( urls ); dc = classLoader.loadClass( driver ); } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java index ff0777d0f..c3f232980 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java @@ -176,10 +176,10 @@ public abstract class DefaultCompilerAdapter } cmd.addArgument( "-classpath" ); - cmd.addArgument( PathUtil.formatPath( classpath ) ); + cmd.addArgument( PathUtil.formatPath( classpath, getTaskContext() ) ); cmd.addArgument( "-sourcepath" ); - cmd.addArgument( PathUtil.formatPath( src ) ); + cmd.addArgument( PathUtil.formatPath( src, getTaskContext() ) ); if( target != null ) { @@ -187,16 +187,17 @@ public abstract class DefaultCompilerAdapter cmd.addArgument( target ); } - if( m_bootclasspath != null ) + final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); + if( bootclasspath.length > 0 ) { cmd.addArgument( "-bootclasspath" ); - cmd.addArgument( PathUtil.formatPath( m_bootclasspath ) ); + cmd.addArgument( PathUtil.formatPath( bootclasspath ) ); } if( m_extdirs != null ) { cmd.addArgument( "-extdirs" ); - cmd.addArgument( PathUtil.formatPath( m_extdirs ) ); + cmd.addArgument( PathUtil.formatPath( m_extdirs, getTaskContext() ) ); } if( m_encoding != null ) @@ -425,7 +426,7 @@ public abstract class DefaultCompilerAdapter } } - PathUtil.addExtdirs( path, m_extdirs ); + PathUtil.addExtdirs( path, m_extdirs, getTaskContext() ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Gcj.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Gcj.java index bee7d90a0..233c30314 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Gcj.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Gcj.java @@ -8,18 +8,16 @@ package org.apache.tools.todo.taskdefs.javac; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.Commandline; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; -import org.apache.tools.todo.util.FileUtils; -import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter; /** * The implementation of the gcj compiler. This is primarily a cut-and-paste * from the jikes. * * @author Takashi Okamoto + * @author tora@debian.org */ public class Gcj extends DefaultCompilerAdapter { @@ -29,7 +27,6 @@ public class Gcj extends DefaultCompilerAdapter * * @return Description of the Returned Value * @exception org.apache.myrmidon.api.TaskException Description of Exception - * @author tora@debian.org */ public boolean execute() throws TaskException @@ -52,20 +49,19 @@ public class Gcj extends DefaultCompilerAdapter // gcj doesn't support bootclasspath dir (-bootclasspath) // so we'll emulate it for compatibility and convenience. - if( m_bootclasspath != null ) - { - classpath.addPath( m_bootclasspath ); - } + final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); + classpath.addPath( bootclasspath ); // gcj doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. addExtdirs( classpath ); - if( ( m_bootclasspath == null ) || m_bootclasspath.isEmpty() ) + if( bootclasspath.length == 0 ) { // no bootclasspath, therefore, get one from the java runtime m_includeJavaRuntime = true; } + addCompileClasspath( classpath ); // Gcj has no option for source-path so we @@ -87,7 +83,7 @@ public class Gcj extends DefaultCompilerAdapter } cmd.addArgument( "-classpath" ); - cmd.addArgument( PathUtil.formatPath( classpath ) ); + cmd.addArgument( PathUtil.formatPath( classpath, getTaskContext() ) ); if( m_encoding != null ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac.java index 4dda69f76..c18f934fc 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac.java @@ -12,13 +12,8 @@ import java.util.ArrayList; import java.util.Iterator; import org.apache.aut.nativelib.Os; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.framework.JavaVersion; import org.apache.tools.todo.taskdefs.MatchingTask; -import org.apache.tools.todo.taskdefs.javac.CompilerAdapter; -import org.apache.tools.todo.taskdefs.javac.CompilerAdapterFactory; -import org.apache.tools.todo.taskdefs.javac.ImplementationSpecificArgument; import org.apache.tools.todo.types.DirectoryScanner; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.SourceFileScanner; @@ -76,7 +71,7 @@ public class Javac private ArrayList m_implementationSpecificArgs = new ArrayList(); protected File[] m_compileList = new File[ 0 ]; - private Path m_bootclasspath; + private Path m_bootclasspath = new Path(); private Path m_compileClasspath; private String m_debugLevel; private File m_destDir; @@ -92,16 +87,9 @@ public class Javac * Adds an element to the bootclasspath that will be used to compile the * classes against. */ - public void addBootclasspath( Path bootclasspath ) + public void addBootclasspath( final Path bootclasspath ) { - if( m_bootclasspath == null ) - { - m_bootclasspath = bootclasspath; - } - else - { - m_bootclasspath.addPath( bootclasspath ); - } + m_bootclasspath.addPath( bootclasspath ); } /** @@ -602,7 +590,7 @@ public class Javac { throw new TaskException( "srcdir attribute must be set!" ); } - String[] list = m_src.list(); + String[] list = m_src.listFiles( getContext() ); if( list.length == 0 ) { throw new TaskException( "srcdir attribute must be set!" ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jikes.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jikes.java index 29401064d..8faea4cb1 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jikes.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jikes.java @@ -8,12 +8,9 @@ package org.apache.tools.todo.taskdefs.javac; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.Commandline; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; -import org.apache.tools.todo.util.FileUtils; -import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter; /** * The implementation of the jikes compiler. This is primarily a cut-and-paste @@ -24,6 +21,7 @@ import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter; * * @author Stefan Bodewig * @author J D Glanville + * @author skanthak@muehlheim.de */ public class Jikes extends DefaultCompilerAdapter @@ -38,7 +36,6 @@ public class Jikes * * @return Description of the Returned Value * @exception org.apache.myrmidon.api.TaskException Description of Exception - * @author skanthak@muehlheim.de */ public boolean execute() throws TaskException @@ -49,27 +46,23 @@ public class Jikes // Jikes doesn't support bootclasspath dir (-bootclasspath) // so we'll emulate it for compatibility and convenience. - if( m_bootclasspath != null ) - { - classpath.addPath( m_bootclasspath ); - } + final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); + classpath.addPath( bootclasspath ); // Jikes doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. addExtdirs( classpath ); - if( ( m_bootclasspath == null ) || m_bootclasspath.isEmpty() ) + if( bootclasspath.length == 0 ) { // no bootclasspath, therefore, get one from the java runtime m_includeJavaRuntime = true; } - else - { - // there is a bootclasspath stated. By default, the - // includeJavaRuntime is false. If the user has stated a - // bootclasspath and said to include the java runtime, it's on - // their head! - } + // Else, there is a bootclasspath stated. By default, the + // includeJavaRuntime is false. If the user has stated a + // bootclasspath and said to include the java runtime, it's on + // their head! + addCompileClasspath( classpath ); // Jikes has no option for source-path so we @@ -98,7 +91,7 @@ public class Jikes } cmd.addArgument( "-classpath" ); - cmd.addArgument( PathUtil.formatPath( classpath ) ); + cmd.addArgument( PathUtil.formatPath( classpath, getTaskContext() ) ); if( m_encoding != null ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jvc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jvc.java index ca78260ab..11ad1d3e2 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jvc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jvc.java @@ -8,12 +8,9 @@ package org.apache.tools.todo.taskdefs.javac; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.types.Commandline; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; -import org.apache.tools.todo.util.FileUtils; -import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter; /** * The implementation of the jvc compiler from microsoft. This is primarily a @@ -37,27 +34,23 @@ public class Jvc extends DefaultCompilerAdapter // jvc doesn't support bootclasspath dir (-bootclasspath) // so we'll emulate it for compatibility and convenience. - if( m_bootclasspath != null ) - { - classpath.addPath( m_bootclasspath ); - } + final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); + classpath.addPath( bootclasspath ); // jvc doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. addExtdirs( classpath ); - if( ( m_bootclasspath == null ) || m_bootclasspath.isEmpty() ) + if( bootclasspath.length == 0 ) { // no bootclasspath, therefore, get one from the java runtime m_includeJavaRuntime = true; } - else - { - // there is a bootclasspath stated. By default, the - // includeJavaRuntime is false. If the user has stated a - // bootclasspath and said to include the java runtime, it's on - // their head! - } + // Else, there is a bootclasspath stated. By default, the + // includeJavaRuntime is false. If the user has stated a + // bootclasspath and said to include the java runtime, it's on + // their head! + addCompileClasspath( classpath ); // jvc has no option for source-path so we @@ -75,7 +68,7 @@ public class Jvc extends DefaultCompilerAdapter // Add the Classpath before the "internal" one. cmd.addArgument( "/cp:p" ); - cmd.addArgument( PathUtil.formatPath( classpath ) ); + cmd.addArgument( PathUtil.formatPath( classpath, getTaskContext() ) ); // Enable MS-Extensions and ... cmd.addArgument( "/x-" ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Kjc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Kjc.java index 6c40929a7..82984b8c3 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Kjc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Kjc.java @@ -89,10 +89,7 @@ public class Kjc extends DefaultCompilerAdapter Path cp = new Path(); // kjc don't have bootclasspath option. - if( m_bootclasspath != null ) - { - cp.addPath( m_bootclasspath ); - } + cp.addPath( m_bootclasspath ); if( m_extdirs != null ) { @@ -102,7 +99,7 @@ public class Kjc extends DefaultCompilerAdapter cp.addPath( classpath ); cp.addPath( src ); - cmd.addArgument( PathUtil.formatPath( cp ) ); + cmd.addArgument( PathUtil.formatPath( cp, getTaskContext() ) ); // kjc-1.5A doesn't support -encoding option now. // but it will be supported near the feature. diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java index 1a709ecea..1aeb6bd55 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java @@ -570,7 +570,7 @@ public class Javadoc classpath.addPath( m_classpath ); } cmd.addArgument( "-classpath" ); - cmd.addArgument( PathUtil.formatPath( classpath ) ); + cmd.addArgument( PathUtil.formatPath( classpath, getContext() ) ); if( m_version && m_doclet == null ) { @@ -607,7 +607,7 @@ public class Javadoc if( m_doclet.getPath() != null ) { cmd.addArgument( "-docletpath" ); - cmd.addArgument( PathUtil.formatPath( m_doclet.getPath() ) ); + cmd.addArgument( PathUtil.formatPath( m_doclet.getPath(), getContext() ) ); } for( Iterator e = m_doclet.getParams(); e.hasNext(); ) { @@ -628,7 +628,7 @@ public class Javadoc if( m_bootclasspath != null ) { cmd.addArgument( "-bootclasspath" ); - cmd.addArgument( PathUtil.formatPath( m_bootclasspath ) ); + cmd.addArgument( PathUtil.formatPath( m_bootclasspath, getContext() ) ); } // add the links arguments @@ -888,7 +888,7 @@ public class Javadoc ArrayList packages, ArrayList excludePackages ) throws TaskException { - getContext().debug( "Source path = " + PathUtil.formatPath( sourcePath ) ); + getContext().debug( "Source path = " + PathUtil.formatPath( sourcePath, getContext() ) ); StringBuffer msg = new StringBuffer( "Packages = " ); for( int i = 0; i < packages.size(); i++ ) { @@ -914,7 +914,7 @@ public class Javadoc ArrayList addedPackages = new ArrayList(); - String[] list = sourcePath.list(); + String[] list = sourcePath.listFiles( getContext() ); if( list == null ) { list = new String[ 0 ]; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java index f16b925b8..ad2f098c3 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java @@ -180,7 +180,7 @@ public class JDependTask getContext().info( "Output to be stored in " + m_outputFile.getPath() ); } - final String[] elements = m_sourcesPath.list(); + final String[] elements = m_sourcesPath.listFiles( getContext() ); for( int i = 0; i < elements.length; i++ ) { File f = new File( elements[ i ] ); @@ -236,7 +236,7 @@ public class JDependTask getContext().info( "Output to be stored in " + m_outputFile.getPath() ); } - final String[] elements = m_sourcesPath.list(); + final String[] elements = m_sourcesPath.listFiles( getContext() ); for( int i = 0; i < elements.length; i++ ) { File f = new File( elements[ i ] ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/JspC.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/JspC.java index dc877ec19..1532c9d25 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/JspC.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/JspC.java @@ -11,8 +11,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Date; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskContext; import org.apache.tools.todo.taskdefs.MatchingTask; import org.apache.tools.todo.taskdefs.jsp.compilers.CompilerAdapter; import org.apache.tools.todo.taskdefs.jsp.compilers.CompilerAdapterFactory; @@ -325,7 +323,7 @@ public class JspC extends MatchingTask { throw new TaskException( "srcdir attribute must be set!" ); } - String[] list = src.list(); + String[] list = src.listFiles( getContext() ); if( list.length == 0 ) { throw new TaskException( "srcdir attribute must be set!" ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java index aafbf5780..952ef4784 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java @@ -175,7 +175,6 @@ public class WLJspc extends MatchingTask File jspFile = null; String parents = ""; - String arg = ""; int j = 0; //XXX this array stuff is a remnant of prev trials.. gotta remove. args[ j++ ] = "-d"; @@ -191,7 +190,7 @@ public class WLJspc extends MatchingTask // Does not take the classpath from the env.... // Am i missing something about the Java task?? args[ j++ ] = "-classpath"; - args[ j++ ] = PathUtil.formatPath( compileClasspath ); + args[ j++ ] = PathUtil.formatPath( compileClasspath, getContext() ); this.scanDir( files ); getContext().info( "Compiling " + filesToDo.size() + " JSP files" ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java index 9d7d394b7..11de5368a 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java @@ -21,13 +21,13 @@ import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; import org.apache.tools.todo.taskdefs.ExecuteJava; import org.apache.tools.todo.types.Argument; +import org.apache.tools.todo.types.Commandline; import org.apache.tools.todo.types.EnumeratedAttribute; +import org.apache.tools.todo.types.EnvironmentData; import org.apache.tools.todo.types.EnvironmentVariable; import org.apache.tools.todo.types.Path; import org.apache.tools.todo.types.PathUtil; import org.apache.tools.todo.types.SysProperties; -import org.apache.tools.todo.types.Commandline; -import org.apache.tools.todo.types.EnvironmentData; /** * Ant task to run JUnit tests.

@@ -642,7 +642,7 @@ public class JUnitTask extends AbstractTask { getContext().debug( "Using System properties " + System.getProperties() ); ClassLoader classLoader = null; - final URL[] urls = PathUtil.toURLs( classPath ); + final URL[] urls = PathUtil.toURLs( classPath, getContext() ); if( urls.length > 0 ) { classLoader = new URLClassLoader( urls ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MAudit.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MAudit.java index 93b246dae..d0ad8981c 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MAudit.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MAudit.java @@ -129,7 +129,7 @@ public class MAudit // don't forget to modify the pattern if you change the options reporting classpath.addPath( getClassPath() ); - final String formattedClasspath = PathUtil.formatPath( classpath ); + final String formattedClasspath = PathUtil.formatPath( classpath, getContext() ); if( formattedClasspath.length() > 0 ) { options.add( "-classpath" ); @@ -162,7 +162,7 @@ public class MAudit if( m_unused ) { options.add( "-unused" ); - options.add( PathUtil.formatPath( m_searchPath ) ); + options.add( PathUtil.formatPath( m_searchPath, getContext() ) ); } addAllArrayList( options, getIncludedFiles().keySet().iterator() ); return options; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MMetrics.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MMetrics.java index 6979e0a6e..2e29ac6fd 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MMetrics.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MMetrics.java @@ -132,7 +132,7 @@ public class MMetrics extends AbstractMetamataTask // don't forget to modify the pattern if you change the options reporting classpath.addPath( getClassPath() ); - final String formattedClasspath = PathUtil.formatPath( classpath ); + final String formattedClasspath = PathUtil.formatPath( classpath, getContext() ); if( formattedClasspath.length() > 0 ) { options.add( "-classpath" ); @@ -157,7 +157,7 @@ public class MMetrics extends AbstractMetamataTask options.add( "/" ); // directories - final String[] dirs = path.list(); + final String[] dirs = path.listFiles( getContext() ); for( int i = 0; i < dirs.length; i++ ) { options.add( dirs[ i ] ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java index 2952d3671..74309ce7b 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java @@ -235,15 +235,17 @@ public class MParse { options.add( "-dp" ); } - if( ! m_classpath.isEmpty() ) + final String[] classpath = m_classpath.listFiles( getContext() ); + if( classpath.length > 0 ) { options.add( "-classpath" ); - options.add( PathUtil.formatPath( m_classpath ) ); + options.add( PathUtil.formatPath( classpath ) ); } - if( ! m_sourcepath.isEmpty() ) + final String[] sourcepath = m_sourcepath.listFiles( getContext() ); + if( sourcepath.length > 0 ) { options.add( "-sourcepath" ); - options.add( PathUtil.formatPath( m_sourcepath ) ); + options.add( PathUtil.formatPath( sourcepath ) ); } options.add( m_target.getAbsolutePath() ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java index ab1fbbb61..95d296022 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java @@ -120,11 +120,11 @@ public abstract class DefaultRmicAdapter if( attributes.getExtdirs() != null ) { cmd.addArgument( "-extdirs" ); - cmd.addArgument( PathUtil.formatPath( attributes.getExtdirs() ) ); + cmd.addArgument( PathUtil.formatPath( attributes.getExtdirs(), getTaskContext() ) ); } cmd.addArgument( "-classpath" ); - cmd.addArgument( PathUtil.formatPath( classpath ) ); + cmd.addArgument( PathUtil.formatPath( classpath, getTaskContext() ) ); String stubVersion = attributes.getStubVersion(); if( null != stubVersion ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java index 46f28cbf5..6cf07b962 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java @@ -15,8 +15,6 @@ import java.rmi.Remote; import java.util.ArrayList; import org.apache.avalon.excalibur.io.FileUtil; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.framework.FileNameMapper; import org.apache.tools.todo.taskdefs.MatchingTask; import org.apache.tools.todo.types.DirectoryScanner; @@ -487,7 +485,7 @@ public class Rmic extends MatchingTask adapter.setRmic( this ); Path classpath = adapter.getClasspath(); - final URL[] urls = PathUtil.toURLs( classpath ); + final URL[] urls = PathUtil.toURLs( classpath, getContext() ); loader = new URLClassLoader( urls ); // scan base dirs to build up compile lists only if a diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java index cf9b8a896..0e2307282 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java @@ -17,10 +17,8 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.apache.aut.nativelib.ExecManager; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.framework.Execute; import org.apache.tools.todo.types.Commandline; import org.apache.tools.todo.types.EnumeratedAttribute; @@ -392,7 +390,7 @@ public class CovReport throw new TaskException( "Need a 'classpath' element." ); } // and a valid one... - String[] paths = classPath.list(); + String[] paths = classPath.listFiles(); if( paths.length == 0 ) { throw new TaskException( "Coverage path is invalid. It does not contain any existing path." ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java index 345a7bf75..15963e1eb 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java @@ -304,10 +304,11 @@ public class Coverage params.addArguments( m_vmArgs ); // classpath - if( ! m_classpath.isEmpty() ) + final String[] classpath = m_classpath.listFiles(); + if( classpath.length > 0 ) { params.addArgument( "-classpath" ); - params.addArgument( PathUtil.formatPath( m_classpath ) ); + params.addArgument( PathUtil.formatPath( classpath ) ); } // classname (runner or standalone) if( m_className != null ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Argument.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Argument.java index f792437bf..05d15e9e5 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Argument.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Argument.java @@ -62,7 +62,8 @@ public class Argument */ public void setPath( final Path value ) throws TaskException { - m_parts = new String[]{ PathUtil.formatPath( value ) }; + throw new TaskException( "Using a path not implemented." ); + //m_parts = new String[]{ PathUtil.formatPath( value ) }; } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ArrayFileList.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ArrayFileList.java new file mode 100644 index 000000000..3e49118d8 --- /dev/null +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ArrayFileList.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.tools.todo.types; + +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.api.TaskException; + +/** + * A PathElement made up of an array of strings. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + */ +class ArrayFileList + implements FileList +{ + private final String[] m_parts; + + public ArrayFileList( final String part ) + { + m_parts = new String[] { part } ; + } + + public ArrayFileList( final String[] parts ) + { + m_parts = parts; + } + + public String[] listFiles( final TaskContext context ) + throws TaskException + { + return m_parts; + } +} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/EnvironmentVariable.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/EnvironmentVariable.java index 1c823372a..2c5fbbccb 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/EnvironmentVariable.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/EnvironmentVariable.java @@ -27,7 +27,8 @@ public class EnvironmentVariable public void setPath( final Path path ) throws TaskException { - m_value = PathUtil.formatPath( path ); + throw new TaskException( "Using a path not implemented." ); + //m_value = PathUtil.formatPath( path ); } public void setValue( final String value ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/FileList.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/FileList.java index 9b762e5ab..880298d84 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/FileList.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/FileList.java @@ -7,67 +7,23 @@ */ package org.apache.tools.todo.types; -import java.io.File; -import java.util.ArrayList; -import java.util.StringTokenizer; +import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; /** - * FileList represents an explicitly named list of files. FileLists are useful - * when you want to capture a list of files regardless of whether they currently - * exist. By contrast, FileSet operates as a filter, only returning the name of - * a matched file if it currently exists in the file system. + * A list of files. * - * @author Craeg Strong + * @author Adam Murdoch * @version $Revision$ $Date$ */ -public class FileList +public interface FileList { - private final ArrayList m_filenames = new ArrayList(); - private File m_dir; - - public FileList() - { - } - - public void setDir( File dir ) - { - m_dir = dir; - } - - public void setFiles( String filenames ) - { - if( filenames != null && filenames.length() > 0 ) - { - StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false ); - while( tok.hasMoreTokens() ) - { - m_filenames.add( tok.nextToken() ); - } - } - } - - public File getDir() - { - return m_dir; - } - /** - * Returns the list of files represented by this FileList. + * Returns the files in this list. + * + * @param context the context to use to evaluate the list. + * @return The names of the files in this list. All names are absolute paths. */ - public String[] getFiles() - throws TaskException - { - if( m_dir == null ) - { - throw new TaskException( "No directory specified for filelist." ); - } - - if( m_filenames.size() == 0 ) - { - throw new TaskException( "No files specified for filelist." ); - } - - return (String[])m_filenames.toArray( new String[ m_filenames.size() ] ); - } + public String[] listFiles( TaskContext context ) + throws TaskException; } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ParsedPathElement.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ParsedPathElement.java new file mode 100644 index 000000000..bc37979fa --- /dev/null +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ParsedPathElement.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.tools.todo.types; + +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.api.TaskException; +import org.apache.tools.todo.util.FileUtils; + +/** + * A PathElement that is parsed from a string. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + */ +class ParsedPathElement + implements FileList +{ + private final String m_path; + + public ParsedPathElement( final String path ) + { + m_path = path; + } + + public String[] listFiles( final TaskContext context ) + throws TaskException + { + return FileUtils.translatePath( context.getBaseDirectory(), m_path ); + } +} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Path.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Path.java index 6c53c641f..eb09c6ba3 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Path.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/Path.java @@ -9,11 +9,10 @@ package org.apache.tools.todo.types; import java.io.File; import java.util.ArrayList; +import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.framework.DataType; import org.apache.tools.todo.util.FileUtils; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.FileSet; /** * This object represents a path as used by CLASSPATH or PATH environment @@ -45,12 +44,13 @@ import org.apache.tools.todo.types.FileSet; * * @author Thomas.Haas@softwired-inc.com * @author Stefan Bodewig + * + * @ant:data-type name="path" */ public class Path - implements DataType + implements DataType, FileList { private final ArrayList m_elements = new ArrayList(); - private File m_baseDirectory; public Path( final String path ) { @@ -72,14 +72,6 @@ public class Path } } - /** - * Sets the base directory for this path. - */ - public void setBaseDirectory( final File baseDir ) - { - m_baseDirectory = baseDir; - } - /** * Adds an element to the path. */ @@ -96,9 +88,8 @@ public class Path */ public void addLocation( final File location ) { - final PathElement pathElement = new PathElement(); + final FileList pathElement = new ArrayFileList( location.getAbsolutePath() ); m_elements.add( pathElement ); - pathElement.setLocation( location ); } /** @@ -122,9 +113,17 @@ public class Path */ public void addPath( final String path ) { - final PathElement pathElement = new PathElement(); + final FileList pathElement = new ParsedPathElement( path ); + m_elements.add( pathElement ); + } + + /** + * Adds a path. + */ + public void addPath( final String[] path ) + { + final FileList pathElement = new ArrayFileList( path ); m_elements.add( pathElement ); - pathElement.setPath( path ); } /** @@ -139,35 +138,17 @@ public class Path * Returns all path elements defined by this and nested path objects. * The paths returned by this method are absolute. */ - public String[] list() + public String[] listFiles( final TaskContext context ) throws TaskException { ArrayList result = new ArrayList( 2 * m_elements.size() ); for( int i = 0; i < m_elements.size(); i++ ) { Object o = m_elements.get( i ); - if( o instanceof String ) - { - // obtained via append - addUnlessPresent( result, (String)o ); - } - else if( o instanceof PathElement ) + if( o instanceof FileList ) { - final PathElement element = (PathElement)o; - final String[] parts = element.getParts( m_baseDirectory ); - if( parts == null ) - { - throw new NullPointerException( "You must either set location or path on " ); - } - for( int j = 0; j < parts.length; j++ ) - { - addUnlessPresent( result, parts[ j ] ); - } - } - else if( o instanceof Path ) - { - Path p = (Path)o; - String[] parts = p.list(); + final FileList element = (FileList)o; + final String[] parts = element.listFiles( context ); for( int j = 0; j < parts.length; j++ ) { addUnlessPresent( result, parts[ j ] ); @@ -189,13 +170,4 @@ public class Path } return (String[])result.toArray( new String[ result.size() ] ); } - - /** - * Determines if this path is empty. - */ - public boolean isEmpty() - throws TaskException - { - return ( list().length == 0 ); - } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathElement.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathElement.java deleted file mode 100644 index a209996bf..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathElement.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.todo.types; - -import java.io.File; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.todo.util.FileUtils; - -/** - * Helper class, holds <> values. - */ -class PathElement -{ - private String m_location; - private String m_path; - - public void setLocation( final File location ) - { - m_location = location.getAbsolutePath(); - } - - public void setPath( final String path ) - { - m_path = path; - } - - protected String[] getParts( final File baseDirectory ) - throws TaskException - { - if( m_location != null ) - { - return new String[]{m_location}; - } - return FileUtils.translatePath( baseDirectory, m_path ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathUtil.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathUtil.java index 87a293568..2495d12cf 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathUtil.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathUtil.java @@ -11,9 +11,8 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Locale; +import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; -import org.apache.tools.todo.types.FileSet; -import org.apache.tools.todo.types.Path; /** * Utilities for operating on Path objects. @@ -26,37 +25,44 @@ public class PathUtil /** * Formats a Path into its native representation. */ - public static String formatPath( final Path path ) - throws TaskException + public static String formatPath( final String[] path ) { - final String[] list = path.list(); - // empty path return empty string - if( list.length == 0 ) + if( path.length == 0 ) { return ""; } // path containing one or more elements - final StringBuffer result = new StringBuffer( list[ 0 ].toString() ); - for( int i = 1; i < list.length; i++ ) + final StringBuffer result = new StringBuffer( path[ 0 ].toString() ); + for( int i = 1; i < path.length; i++ ) { result.append( File.pathSeparatorChar ); - result.append( list[ i ] ); + result.append( path[ i ] ); } return result.toString(); } + /** + * Formats a Path into its native representation. + */ + public static String formatPath( final Path path, final TaskContext context ) + throws TaskException + { + final String[] list = path.listFiles( context ); + return formatPath( list ); + } + /** * Returns an array of URLs - useful for building a ClassLoader. */ - public static URL[] toURLs( final Path path ) + public static URL[] toURLs( final Path path, final TaskContext context ) throws TaskException { try { - final String[] list = path.list(); + final String[] list = path.listFiles( context ); final URL[] result = new URL[ list.length ]; @@ -126,10 +132,10 @@ public class PathUtil /** * Adds the contents of a set of directories to a path. */ - public static void addExtdirs( final Path toPath, final Path extDirs ) + public static void addExtdirs( final Path toPath, final Path extDirs, TaskContext context ) throws TaskException { - final String[] dirs = extDirs.list(); + final String[] dirs = extDirs.listFiles( context ); for( int i = 0; i < dirs.length; i++ ) { final File dir = new File( dirs[ i ] ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SimpleFileList.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SimpleFileList.java new file mode 100644 index 000000000..cf996add3 --- /dev/null +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SimpleFileList.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.tools.todo.types; + +import java.io.File; +import java.util.ArrayList; +import java.util.StringTokenizer; +import org.apache.myrmidon.api.TaskException; + +/** + * FileList represents an explicitly named list of files. FileLists are useful + * when you want to capture a list of files regardless of whether they currently + * exist. By contrast, FileSet operates as a filter, only returning the name of + * a matched file if it currently exists in the file system. + * + * @author Craeg Strong + * @version $Revision$ $Date$ + */ +public class SimpleFileList +{ + private final ArrayList m_filenames = new ArrayList(); + private File m_dir; + + public SimpleFileList() + { + } + + public void setDir( File dir ) + { + m_dir = dir; + } + + public void setFiles( String filenames ) + { + if( filenames != null && filenames.length() > 0 ) + { + StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false ); + while( tok.hasMoreTokens() ) + { + m_filenames.add( tok.nextToken() ); + } + } + } + + public File getDir() + { + return m_dir; + } + + /** + * Returns the list of files represented by this FileList. + */ + public String[] getFiles() + throws TaskException + { + if( m_dir == null ) + { + throw new TaskException( "No directory specified for filelist." ); + } + + if( m_filenames.size() == 0 ) + { + throw new TaskException( "No files specified for filelist." ); + } + + return (String[])m_filenames.toArray( new String[ m_filenames.size() ] ); + } +} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/converters/FileListToStringConverter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/converters/FileListToStringConverter.java new file mode 100644 index 000000000..90642b9cc --- /dev/null +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/converters/FileListToStringConverter.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.tools.todo.types.converters; + +import org.apache.aut.converter.AbstractConverter; +import org.apache.aut.converter.ConverterException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.api.TaskException; +import org.apache.tools.todo.types.FileList; +import org.apache.tools.todo.types.PathUtil; + +/** + * Converters from FileList to String. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + * + * @ant:converter source="org.apache.tools.todo.types.FileList" destination="java.lang.String" + */ +public class FileListToStringConverter + extends AbstractConverter +{ + public FileListToStringConverter() + { + super( FileList.class, String.class ); + } + + protected Object convert( final Object original, final Object context ) + throws ConverterException + { + try + { + final TaskContext taskContext = (TaskContext)context; + final FileList fileList = (FileList)original; + final String[] files = fileList.listFiles( taskContext ); + return PathUtil.formatPath( files ); + } + catch( final TaskException e ) + { + throw new ConverterException( e.getMessage(), e ); + } + } +}