What do you think about adding a cp property to find
the adaptor, like this?
Keith
| -----Original Message-----
| From: Steve Loughran [mailto:[EMAIL PROTECTED]
| Sent: Friday, May 17, 2002 3:39 PM
| To: Ant Developers List
| Subject: Re: classloader for factories
|
| Fixing classloader defects is usually viewed as an ant2.0 feature, cos the
| probability of breaking so much is high. but if you could come up with a
| good solution that doesnt introduce issues, that would be great.
Index: docs/manual/OptionalTasks/jspc.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTasks/jspc.html,v
retrieving revision 1.6
diff -u -r1.6 jspc.html
--- docs/manual/OptionalTasks/jspc.html 3 Feb 2002 22:09:09 -0000 1.6
+++ docs/manual/OptionalTasks/jspc.html 17 May 2002 23:42:06 -0000
@@ -107,6 +107,20 @@
</td>
<td valign="top" align="center">No</td>
</tr>
+ <tr>
+ <td valign="top">compiler</td>
+ <td valign="top">
+ Class name of jsp compiler adapter to use. Defaults to
+ the standard adapter for Jasper.
+ </td>
+ <td valign="top" align="center">No</td>
+ </tr>
+ <tr>
+ <td valign="top">compilerclasspath</td>
+ <td valign="top">The classpath used to find the compiler adapter specified
+ by the <code>compiler</code> attribute.</td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<P>The <tt>mapped</tt> option will, if set to true, split the JSP text content
into a
@@ -155,6 +169,10 @@
<h4>classpathref</h4>
a reference to an existing classpath
+<h4>compilerclasspath</h4>
+
+The classpath used to locate an optional compiler adapter specified by
+<code>compiler</code>
<h3>Example</h3>
<pre>
<jspc srcdir="${basedir}/src/war"
Index: src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java,v
retrieving revision 1.16
diff -u -r1.16 JspC.java
--- src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java 15 Apr
2002 14:56:33 -0000 1.16
+++ src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java 17 May
2002 23:42:22 -0000
@@ -113,6 +113,7 @@
public class JspC extends MatchingTask {
/* ------------------------------------------------------------ */
private Path classpath;
+ private Path compilerClasspath;
private Path src;
private File destDir;
private String packageName ;
@@ -297,6 +297,35 @@
return classpath;
}
+ /* ------------------------------------------------------------ */
+ /**
+ * Set the classpath to be used to find this compiler adapter
+ */
+ public void setCompilerclasspath(Path cp) {
+ if (compilerClasspath == null) {
+ compilerClasspath = cp;
+ } else {
+ compilerClasspath.append(cp);
+ }
+ }
+
+ /**
+ * get the classpath used to find the compiler adapter
+ */
+ public Path getCompilerclasspath(){
+ return compilerClasspath;
+ }
+
+ /**
+ * Support nested compiler classpath, used to locate compiler adapter
+ */
+ public Path createCompilerclasspath() {
+ if (compilerClasspath == null) {
+ compilerClasspath = new Path(project);
+ }
+ return compilerClasspath.createPath();
+ }
+
/**
* -webxml <file>Creates a complete web.xml when using the -webapp option.
*
@@ -384,7 +413,8 @@
//bind to a compiler
JspCompilerAdapter compiler =
- JspCompilerAdapterFactory.getCompiler(compilerName, this);
+ JspCompilerAdapterFactory.getCompiler(compilerName, this,
+ compilerClasspath);
// if the compiler does its own dependency stuff, we just call it
right now
if (compiler.implementsOwnDependencyChecking()) {
Index:
src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JspCompilerAdapterFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JspCompilerAdapterFactory.java,v
retrieving revision 1.2
diff -u -r1.2 JspCompilerAdapterFactory.java
---
src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JspCompilerAdapterFactory.java
15 Apr 2002 12:11:48 -0000 1.2
+++
src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JspCompilerAdapterFactory.java
17 May 2002 23:42:22 -0000
@@ -53,9 +53,11 @@
*/
package org.apache.tools.ant.taskdefs.optional.jsp.compilers;
+import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
/**
* Creates the necessary compiler adapter, given basic criteria.
@@ -87,13 +89,37 @@
*/
public static JspCompilerAdapter getCompiler(String compilerType, Task
task)
throws BuildException {
+ return getCompiler(compilerType, task, null);
+ }
+
+ /**
+ * Based on the parameter passed in, this method creates the necessary
+ * factory desired.
+ *
+ * The current mapping for compiler names are as follows:
+ * <ul><li>jasper = jasper compiler (the default)
+ * <li><i>a fully quallified classname</i> = the name of a jsp compiler
+ * adapter
+ * </ul>
+ *
+ * @param compilerType either the name of the desired compiler, or the
+ * full classname of the compiler's adapter.
+ * @param task a task to log through.
+ * @param compilerClasspath classpath used to locate non-default compiler
+ * @throws BuildException if the compiler type could not be resolved into
+ * a compiler adapter.
+ */
+ public static JspCompilerAdapter getCompiler(String compilerType, Task
task,
+ Path compilerClasspath)
+ throws BuildException {
/* If I've done things right, this should be the extent of the
* conditional statements required.
*/
if (compilerType.equalsIgnoreCase("jasper")) {
return new JasperC();
}
- return resolveClassName(compilerType);
+ return resolveClassName(compilerType,
+ new AntClassLoader(task.getProject(), compilerClasspath));
}
/**
@@ -104,10 +130,11 @@
* @throws BuildException This is the fit that is thrown if className
* isn't an instance of JspCompilerAdapter.
*/
- private static JspCompilerAdapter resolveClassName(String className)
+ private static JspCompilerAdapter resolveClassName(String className,
+ AntClassLoader classloader)
throws BuildException {
try {
- Class c = Class.forName(className);
+ Class c = classloader.findClass(className);
Object o = c.newInstance();
return (JspCompilerAdapter) o;
} catch (ClassNotFoundException cnfe) {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>