@@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.native2ascii;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
@@ -46,7 +47,7 @@ public class Native2AsciiAdapterFactory {
}
}
/**
/**
* Creates the Native2AsciiAdapter based on the user choice and *
* Creates the Native2AsciiAdapter based on the user choice and
* potentially the VM vendor.
* potentially the VM vendor.
*
*
* @param choice the user choice (if any).
* @param choice the user choice (if any).
@@ -58,13 +59,35 @@ public class Native2AsciiAdapterFactory {
public static Native2AsciiAdapter getAdapter(String choice,
public static Native2AsciiAdapter getAdapter(String choice,
ProjectComponent log)
ProjectComponent log)
throws BuildException {
throws BuildException {
return getAdapter(choice, log, null);
}
/**
* Creates the Native2AsciiAdapter based on the user choice and
* potentially the VM vendor.
*
* @param choice the user choice (if any).
* @param log a ProjectComponent instance used to access Ant's
* logging system.
* @param classpath the classpath to use when looking up an
* adapter class
* @return The adapter to use.
* @throws BuildException if there was a problem.
* @since Ant 1.8.0
*/
public static Native2AsciiAdapter getAdapter(String choice,
ProjectComponent log,
Path classpath)
throws BuildException {
if ((JavaEnvUtils.isKaffe() && choice == null)
if ((JavaEnvUtils.isKaffe() && choice == null)
|| KaffeNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
|| KaffeNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
return new KaffeNative2Ascii();
return new KaffeNative2Ascii();
} else if (SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
} else if (SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
return new SunNative2Ascii();
return new SunNative2Ascii();
} else if (choice != null) {
} else if (choice != null) {
return resolveClassName(choice);
return resolveClassName(choice,
log.getProject()
.createClassLoader(classpath));
}
}
// This default has been good enough until Ant 1.6.3, so stick
// This default has been good enough until Ant 1.6.3, so stick
@@ -77,12 +100,15 @@ public class Native2AsciiAdapterFactory {
* Throws a fit if it can't.
* Throws a fit if it can't.
*
*
* @param className The fully qualified classname to be created.
* @param className The fully qualified classname to be created.
* @param loader the classloader to use
* @throws BuildException This is the fit that is thrown if className
* @throws BuildException This is the fit that is thrown if className
* isn't an instance of Native2AsciiAdapter.
* isn't an instance of Native2AsciiAdapter.
*/
*/
private static Native2AsciiAdapter resolveClassName(String className)
private static Native2AsciiAdapter resolveClassName(String className,
ClassLoader loader)
throws BuildException {
throws BuildException {
return (Native2AsciiAdapter) ClasspathUtils.newInstance(className,
return (Native2AsciiAdapter) ClasspathUtils.newInstance(className,
loader != null ? loader :
Native2AsciiAdapterFactory.class.getClassLoader(),
Native2AsciiAdapterFactory.class.getClassLoader(),
Native2AsciiAdapter.class);
Native2AsciiAdapter.class);
}
}