git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272843 13f79535-47bb-0310-9956-ffa450edef68master
@@ -107,6 +107,20 @@ The Task has the following attributes:<p> | |||||
</td> | </td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </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> | </table> | ||||
<P>The <tt>mapped</tt> option will, if set to true, split the JSP text content into a | <P>The <tt>mapped</tt> option will, if set to true, split the JSP text content into a | ||||
@@ -155,6 +169,10 @@ classpath. | |||||
<h4>classpathref</h4> | <h4>classpathref</h4> | ||||
a reference to an existing classpath | 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> | <h3>Example</h3> | ||||
<pre> | <pre> | ||||
<jspc srcdir="${basedir}/src/war" | <jspc srcdir="${basedir}/src/war" | ||||
@@ -60,6 +60,7 @@ import java.util.Date; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import org.apache.tools.ant.AntClassLoader; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
@@ -113,6 +114,7 @@ import org.apache.tools.ant.types.Reference; | |||||
public class JspC extends MatchingTask { | public class JspC extends MatchingTask { | ||||
/* ------------------------------------------------------------ */ | /* ------------------------------------------------------------ */ | ||||
private Path classpath; | private Path classpath; | ||||
private Path compilerClasspath; | |||||
private Path src; | private Path src; | ||||
private File destDir; | private File destDir; | ||||
private String packageName ; | private String packageName ; | ||||
@@ -297,6 +299,35 @@ public class JspC extends MatchingTask { | |||||
return classpath; | 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. | * -webxml <file> Creates a complete web.xml when using the -webapp option. | ||||
* | * | ||||
@@ -384,7 +415,8 @@ public class JspC extends MatchingTask { | |||||
//bind to a compiler | //bind to a compiler | ||||
JspCompilerAdapter compiler = | JspCompilerAdapter compiler = | ||||
JspCompilerAdapterFactory.getCompiler(compilerName, this); | |||||
JspCompilerAdapterFactory.getCompiler(compilerName, this, | |||||
new AntClassLoader(getProject(), compilerClasspath)); | |||||
// if the compiler does its own dependency stuff, we just call it right now | // if the compiler does its own dependency stuff, we just call it right now | ||||
if (compiler.implementsOwnDependencyChecking()) { | if (compiler.implementsOwnDependencyChecking()) { | ||||
@@ -53,6 +53,7 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs.optional.jsp.compilers; | 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.BuildException; | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
@@ -87,13 +88,37 @@ public class JspCompilerAdapterFactory { | |||||
*/ | */ | ||||
public static JspCompilerAdapter getCompiler(String compilerType, Task task) | public static JspCompilerAdapter getCompiler(String compilerType, Task task) | ||||
throws BuildException { | throws BuildException { | ||||
return getCompiler(compilerType, task, | |||||
new AntClassLoader(task.getProject(), 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 loader AntClassLoader with which the compiler should be loaded | |||||
* @throws BuildException if the compiler type could not be resolved into | |||||
* a compiler adapter. | |||||
*/ | |||||
public static JspCompilerAdapter getCompiler(String compilerType, Task task, | |||||
AntClassLoader loader) | |||||
throws BuildException { | |||||
/* If I've done things right, this should be the extent of the | /* If I've done things right, this should be the extent of the | ||||
* conditional statements required. | * conditional statements required. | ||||
*/ | */ | ||||
if (compilerType.equalsIgnoreCase("jasper")) { | if (compilerType.equalsIgnoreCase("jasper")) { | ||||
return new JasperC(); | return new JasperC(); | ||||
} | } | ||||
return resolveClassName(compilerType); | |||||
return resolveClassName(compilerType, loader); | |||||
} | } | ||||
/** | /** | ||||
@@ -101,13 +126,15 @@ public class JspCompilerAdapterFactory { | |||||
* 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 classloader Classloader with which to load the class | |||||
* @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 JspCompilerAdapter. | * isn't an instance of JspCompilerAdapter. | ||||
*/ | */ | ||||
private static JspCompilerAdapter resolveClassName(String className) | |||||
private static JspCompilerAdapter resolveClassName(String className, | |||||
AntClassLoader classloader) | |||||
throws BuildException { | throws BuildException { | ||||
try { | try { | ||||
Class c = Class.forName(className); | |||||
Class c = classloader.findClass(className); | |||||
Object o = c.newInstance(); | Object o = c.newInstance(); | ||||
return (JspCompilerAdapter) o; | return (JspCompilerAdapter) o; | ||||
} catch (ClassNotFoundException cnfe) { | } catch (ClassNotFoundException cnfe) { | ||||