From cc141e87cde0563beefdbb2a7c3ea5eb7e172a64 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 28 Jun 2004 08:49:46 +0000 Subject: [PATCH] try to support Tomcat 5.x git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276647 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 5 ++ docs/manual/OptionalTasks/jspc.html | 7 +++ .../optional/jsp/compilers/JasperC.java | 56 +++++++++++++++---- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index f0fddba3d..ba0d5d748 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -259,6 +259,11 @@ Other changes: * now also works with Xalan XSLTC and/or JDK 1.5. Bugzilla Report 27541. +* doesn't work properly with Tomcat 5.x. We've implemented a + work-around but don't intend to support future changes in Tomcat + 5.x. Please use the jspc task that ships with Tomcat instead of + Ant's. + Changes from Ant 1.6.0 to Ant 1.6.1 ============================================= diff --git a/docs/manual/OptionalTasks/jspc.html b/docs/manual/OptionalTasks/jspc.html index 97624b11e..3c5d73e5b 100644 --- a/docs/manual/OptionalTasks/jspc.html +++ b/docs/manual/OptionalTasks/jspc.html @@ -11,6 +11,13 @@

Description

Ant task to run the JSP compiler and turn JSP pages into Java source. + +

Deprecated if you use this task with Tomcat's Jasper JSP +compiler, you should seriously consider using the task shipping with +Tomcat instead. This task is only tested against Tomcat 4.x. There +are known problems with Tomcat 5.x that won't get fixed in Ant, please +use Tomcat's jspc task instead.

+

It can be used to precompile JSP pages for fast initial invocation diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java index 7a46d9bb8..ad1f0a85e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.taskdefs.optional.jsp.compilers; import java.io.File; +import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Java; @@ -52,23 +53,19 @@ public class JasperC extends DefaultJspCompilerAdapter { getJspc().log("Using jasper compiler", Project.MSG_VERBOSE); CommandlineJava cmd = setupJasperCommand(); - try { // Create an instance of the compiler, redirecting output to // the project log Java java = (Java) (getProject().createTask("java")); + Path p = getClasspath(); if (getJspc().getClasspath() != null) { - getProject().log("using user supplied classpath: " - + getJspc().getClasspath(), Project.MSG_DEBUG); - java.setClasspath(getJspc().getClasspath() - .concatSystemClasspath("ignore")); + getProject().log("using user supplied classpath: " + p, + Project.MSG_DEBUG); } else { - Path classpath = new Path(getProject()); - classpath = classpath.concatSystemClasspath("only"); - getProject().log("using system classpath: " + classpath, + getProject().log("using system classpath: " + p, Project.MSG_DEBUG); - java.setClasspath(classpath); } + java.setClasspath(p); java.setDir(getProject().getBaseDir()); java.setClassname("org.apache.jasper.JspC"); //this is really irritating; we need a way to set stuff @@ -106,7 +103,15 @@ public class JasperC extends DefaultJspCompilerAdapter { JspC jspc = getJspc(); addArg(cmd, "-d", jspc.getDestdir()); addArg(cmd, "-p", jspc.getPackage()); - addArg(cmd, "-v" + jspc.getVerbose()); + + if (!isTomcat5x()) { + addArg(cmd, "-v" + jspc.getVerbose()); + } else { + getProject().log("this task doesn't support Tomcat 5.x properly, " + + "please use the Tomcat provided jspc task " + + "instead"); + } + addArg(cmd, "-uriroot", jspc.getUriroot()); addArg(cmd, "-uribase", jspc.getUribase()); addArg(cmd, "-ieplugin", jspc.getIeplugin()); @@ -132,4 +137,35 @@ public class JasperC extends DefaultJspCompilerAdapter { public JspMangler createMangler() { return mangler; } + + /** + * @since Ant 1.6.2 + */ + private Path getClasspath() { + Path p = getJspc().getClasspath(); + if (p == null) { + p = new Path(getProject()); + return p.concatSystemClasspath("only"); + } else { + return p.concatSystemClasspath("ignore"); + } + } + + /** + * @since Ant 1.6.2 + */ + private boolean isTomcat5x() { + AntClassLoader l = null; + try { + l = getProject().createClassLoader(getClasspath()); + l.loadClass("org.apache.jasper.tagplugins.jstl.If"); + return true; + } catch (ClassNotFoundException e) { + return false; + } finally { + if (l != null) { + l.cleanup(); + } + } + } }