* Removed Path.isEmpty(). * Changed Path.list() -> listFiles( TaskContext ). * Extracted FileList interface from Path. This interface has a single listFile( TaskContext ) method. * Split PathElement into two FileList implementations, ParsedPathElement and ArrayFileList. Removed the special handling of nested PathElement and Path objects from Path.listFiles(). * Added FileList -> String converter. * Temporarily disabled Argument.setPath() and EnvironmentVariable.setPath(). git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271926 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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 ) | |||
{ | |||
@@ -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 | |||
@@ -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 ) | |||
{ | |||
@@ -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 ); | |||
} | |||
@@ -4,9 +4,12 @@ | |||
<task name="java" classname="org.apache.tools.todo.taskdefs.Java" /> | |||
<data-type name="path" classname="org.apache.tools.todo.types.Path" /> | |||
<task name="path" classname="org.apache.myrmidon.framework.TypeInstanceTask" /> | |||
<converter classname="org.apache.tools.ant.types.converters.StringToPathConverter" | |||
<converter classname="org.apache.tools.todo.types.converters.StringToPathConverter" | |||
source="java.lang.String" | |||
destination="org.apache.tools.ant.types.Path" /> | |||
destination="org.apache.tools.todo.types.Path" /> | |||
<converter classname="org.apache.tools.todo.types.converters.FileListToStringConverter" | |||
source="org.apache.tools.todo.types.FileList" | |||
destination="java.lang.String" /> | |||
</types> | |||
</ant-lib> |
@@ -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; | |||
@@ -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 | |||
@@ -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() ); | |||
@@ -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 ); | |||
@@ -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++ ) | |||
{ | |||
@@ -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 | |||
@@ -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 ); | |||
} | |||
@@ -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() ); | |||
} | |||
} | |||
@@ -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 <a href="mailto:tora@debian.org">Takashi Okamoto</a> | |||
* @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 ) | |||
{ | |||
@@ -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!" ); | |||
@@ -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; | |||
* </a> | |||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> | |||
* @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 ) | |||
{ | |||
@@ -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-" ); | |||
@@ -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. | |||
@@ -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 ]; | |||
@@ -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 ] ); | |||
@@ -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!" ); | |||
@@ -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" ); | |||
@@ -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. <p> | |||
@@ -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 ); | |||
@@ -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; | |||
@@ -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 ] ); | |||
@@ -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() ); | |||
@@ -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 ) | |||
@@ -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 | |||
@@ -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." ); | |||
@@ -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 ) | |||
@@ -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 ) }; | |||
} | |||
/** | |||
@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
* @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; | |||
} | |||
} |
@@ -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 ) | |||
@@ -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 <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> | |||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
* @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; | |||
} |
@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
* @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 ); | |||
} | |||
} |
@@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
* | |||
* @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 <pathelement>" ); | |||
} | |||
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 ); | |||
} | |||
} |
@@ -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 <code><></code> 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 ); | |||
} | |||
} |
@@ -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 ] ); | |||
@@ -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 <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> | |||
* @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() ] ); | |||
} | |||
} |
@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
* @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 ); | |||
} | |||
} | |||
} |