org.apache.tools.ant.util
Class ClasspathUtils
java.lang.Object
org.apache.tools.ant.util.ClasspathUtils
public class ClasspathUtils
extends java.lang.Object
Offers some helper methods on the Path structure in ant.
Basic idea behind this utility class is to use it from inside the
different ant objects (and user defined objects) that need classLoading
for their operation.
Normally those would have a setClasspathRef() {for the @classpathref}
and/or a createClasspath() {for the nested <classpath>}
Typically one would have in your Ant Task or DataType
ClasspathUtils.Delegate cpDelegate;
public void init() {
this.cpDelegate = ClasspathUtils.getDelegate(this);
super.init();
}
public void setClasspathRef(Reference r) {
this.cpDelegate.setClasspathRef(r);
}
public Path createClasspath() {
return this.cpDelegate.createClasspath();
}
public void setClassname(String fqcn) {
this.cpDelegate.setClassname(fqcn);
}
At execution time, when you actually need the classloading
you can just:
Object o = this.cpDelegate.newInstance();
static class | ClasspathUtils.Delegate - Delegate that helps out any specific ProjectComponent that needs
dynamic classloading.
|
static String | REUSE_LOADER_REF - Name of the magic property that controls classloader reuse in Ant 1.4.
|
static ClassLoader | getClassLoaderForPath(Project p, Path path, String loaderId) - Convenience overloaded version of
getClassLoaderForPath(Project,Path,String,boolean) .
|
static ClassLoader | getClassLoaderForPath(Project p, Path path, String loaderId, boolean reverseLoader) - Convenience overloaded version of
getClassLoaderForPath(Project,Path,String,boolean,boolean) .
|
static ClassLoader | getClassLoaderForPath(Project p, Path path, String loaderId, boolean reverseLoader, boolean reuseLoader) - Gets a classloader that loads classes from the classpath
defined in the path argument.
|
static ClassLoader | getClassLoaderForPath(Project p, Reference ref) - Convenience overloaded version of
getClassLoaderForPath(Project,Reference,boolean) .
|
static ClassLoader | getClassLoaderForPath(Project p, Reference ref, boolean reverseLoader) - Convenience overloaded version of
getClassLoaderForPath(Project,Path,String,boolean) .
|
static ClasspathUtils.Delegate | getDelegate(ProjectComponent component) - Obtains a delegate that helps out with classic classpath configuration.
|
static ClassLoader | getUniqueClassLoaderForPath(Project p, Path path, boolean reverseLoader) - Gets a fresh, different, not used before classloader that uses the
passed path as it's classpath.
|
static Object | newInstance(String className, ClassLoader userDefinedLoader) - Creates a fresh object instance of the specified classname.
|
REUSE_LOADER_REF
public static final String REUSE_LOADER_REF
Name of the magic property that controls classloader reuse in Ant 1.4.
getClassLoaderForPath
public static ClassLoader getClassLoaderForPath(Project p,
Path path,
String loaderId)
p
- current ant projectpath
- the pathloaderId
- the loader id string
getClassLoaderForPath
public static ClassLoader getClassLoaderForPath(Project p,
Path path,
String loaderId,
boolean reverseLoader)
p
- the projectpath
- the pathloaderId
- the loader id stringreverseLoader
- if set to true this new loader will take
precedence over it's parent (which is contra the regular
classloader behaviour)
getClassLoaderForPath
public static ClassLoader getClassLoaderForPath(Project p,
Path path,
String loaderId,
boolean reverseLoader,
boolean reuseLoader)
Gets a classloader that loads classes from the classpath
defined in the path argument.
Based on the setting of the magic property
'ant.reuse.loader' this will try to reuse the perviously
created loader with that id, and of course store it there upon
creation.
p
- Ant Project where the handled components are living in.path
- Path object to be used as classpath for this classloaderloaderId
- identification for this Loader,reverseLoader
- if set to true this new loader will take
precedence over it's parent (which is contra the regular
classloader behaviour)reuseLoader
- if true reuse the loader if it is found
- ClassLoader that uses the Path as its classpath.
getClassLoaderForPath
public static ClassLoader getClassLoaderForPath(Project p,
Reference ref)
p
- the projectref
- the reference
getClassLoaderForPath
public static ClassLoader getClassLoaderForPath(Project p,
Reference ref,
boolean reverseLoader)
p
- current ant projectref
- Reference to Path structurereverseLoader
- if set to true this new loader will take
precedence over it's parent (which is contra the regular
classloader behaviour)
getDelegate
public static ClasspathUtils.Delegate getDelegate(ProjectComponent component)
Obtains a delegate that helps out with classic classpath configuration.
component
- your projectComponent that needs the assistence
getUniqueClassLoaderForPath
public static ClassLoader getUniqueClassLoaderForPath(Project p,
Path path,
boolean reverseLoader)
Gets a fresh, different, not used before classloader that uses the
passed path as it's classpath.
This method completely ignores the ant.reuse.loader magic
property and should be used with caution.
p
- Ant Project where the handled components are living in.path
- the classpath for this loaderreverseLoader
- if set to true this new loader will take
precedence over it's parent (which is contra the regular
classloader behaviour)
- The fresh, different, not used before class loader.
newInstance
public static Object newInstance(String className,
ClassLoader userDefinedLoader)
Creates a fresh object instance of the specified classname.
This uses the userDefinedLoader to load the specified class,
and then makes an instance using the default no-argument constructor
className
- the full qualified class name to load.userDefinedLoader
- the classloader to use.
- The fresh object instance
Copyright B) 2000-2008 Apache Software Foundation. All Rights Reserved.