stevel 2003/01/30 23:10:28 Modified: src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers JasperC.java JspCompilerAdapterFactory.java src/main/org/apache/tools/ant/taskdefs/optional/jsp JspC.java JspNameMangler.java src/etc/testcases/taskdefs/optional jspc.xml src/testcases/org/apache/tools/ant/taskdefs/optional JspcTest.java Log: jasper4.1 name mangling support via new name mangler, a new compiler in the factory (jasper41), and various new tests. Revision Changes Path 1.14 +12 -18 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java Index: JasperC.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- JasperC.java 13 Jan 2003 15:52:12 -0000 1.13 +++ JasperC.java 31 Jan 2003 07:10:27 -0000 1.14 @@ -73,6 +73,17 @@ * @since ant1.5 */ public class JasperC extends DefaultJspCompilerAdapter { + + + /** + * what produces java classes from .jsp files + */ + JspMangler mangler; + + public JasperC(JspMangler mangler) { + this.mangler = mangler; + } + /** * our execute method */ @@ -80,28 +91,11 @@ throws BuildException { getJspc().log("Using jasper compiler", Project.MSG_VERBOSE); CommandlineJava cmd = setupJasperCommand(); - /* - Path classpath=cmd.createClasspath(getProject()); - if (getJspc().getClasspath() != null) { - classpath=getJspc().getClasspath(); - } else { - classpath.concatSystemClasspath(); - } - ExecuteJava exec=new ExecuteJava(); - exec.execute(getProject()); - if ((err = executeJava()) != 0) { - if (failOnError) { - throw new BuildException("Java returned: " + err, location); - } else { - log("Java Result: " + err, Project.MSG_ERR); - } - */ try { // Create an instance of the compiler, redirecting output to // the project log - // REVISIT. ugly. Java java = (Java) (getProject().createTask("java")); if (getJspc().getClasspath() != null) { getProject().log("using user supplied classpath: "+getJspc().getClasspath(), @@ -175,6 +169,6 @@ */ public JspMangler createMangler() { - return new JspNameMangler(); + return mangler; } } 1.5 +10 -4 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JspCompilerAdapterFactory.java Index: JspCompilerAdapterFactory.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JspCompilerAdapterFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JspCompilerAdapterFactory.java 24 Jan 2003 14:18:23 -0000 1.4 +++ JspCompilerAdapterFactory.java 31 Jan 2003 07:10:27 -0000 1.5 @@ -56,6 +56,8 @@ import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler; +import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler; /** @@ -63,6 +65,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">J D Glanville</a> * @author Matthew Watson <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Steve Loughran */ public class JspCompilerAdapterFactory { @@ -112,11 +115,14 @@ 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 - * conditional statements required. - */ + if (compilerType.equalsIgnoreCase("jasper")) { - return new JasperC(); + //tomcat4.0 gets the old mangler + return new JasperC(new JspNameMangler()); + } + if (compilerType.equalsIgnoreCase("jasper41")) { + //tomcat4.1 gets the new one + return new JasperC(new Jasper41Mangler()); } return resolveClassName(compilerType, loader); } 1.28 +14 -17 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java Index: JspC.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- JspC.java 24 Jan 2003 14:34:49 -0000 1.27 +++ JspC.java 31 Jan 2003 07:10:27 -0000 1.28 @@ -106,7 +106,6 @@ * @since 1.5 */ public class JspC extends MatchingTask { - /* ------------------------------------------------------------ */ private Path classpath; private Path compilerClasspath; private Path src; @@ -155,11 +154,11 @@ private static final String FAIL_MSG = "Compile failed, messages should have been provided."; - /* ------------------------------------------------------------ */ + /** - * Path for source JSP files. + * Set the path for source JSP files. */ - public void setSrcdir(Path srcDir) { + public void setSrcDir(Path srcDir) { if (src == null) { src = srcDir; } else { @@ -169,7 +168,7 @@ public Path getSrcDir(){ return src; } - /* ------------------------------------------------------------ */ + /** * Set the destination directory into which the JSP source * files should be compiled. @@ -180,7 +179,6 @@ public File getDestdir(){ return destDir; } - /* ------------------------------------------------------------ */ /** * Set the name of the package the compiled jsp files should be in. @@ -193,7 +191,6 @@ return packageName; } - /* ------------------------------------------------------------ */ /** * Set the verbose level of the compiler */ @@ -204,7 +201,6 @@ return verbose; } - /* ------------------------------------------------------------ */ /** * Whether or not the build should halt if compilation fails. * Defaults to <code>true</code>. @@ -218,15 +214,15 @@ public boolean getFailonerror() { return failOnError; } - /* ------------------------------------------------------------ */ + public String getIeplugin() { return iepluginid; } /** * Java Plugin CLASSID for Internet Explorer */ - public void setIeplugin(String iepluginid_) { - iepluginid = iepluginid_; + public void setIeplugin(String iepluginid) { + this.iepluginid = iepluginid; } /** @@ -237,12 +233,13 @@ public boolean isMapped() { return mapped; } + /** * If true, generate separate write() calls for each HTML line * in the JSP. */ - public void setMapped(boolean mapped_) { - mapped = mapped_; + public void setMapped(boolean mapped) { + this.mapped = mapped; } /** @@ -426,12 +423,12 @@ // make sure that we've got a srcdir if (src == null) { throw new BuildException("srcdir attribute must be set!", - location); - } + getLocation()); + } String [] list = src.list(); if (list.length == 0) { throw new BuildException("srcdir attribute must be set!", - location); + getLocation()); } @@ -449,7 +446,7 @@ resetFileLists(); int filecount = 0; for (int i = 0; i < list.length; i++) { - File srcDir = (File) getProject().resolveFile(list[i]); + File srcDir = getProject().resolveFile(list[i]); if (!srcDir.exists()) { throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", getLocation()); 1.8 +3 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java Index: JspNameMangler.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- JspNameMangler.java 15 Apr 2002 14:56:33 -0000 1.7 +++ JspNameMangler.java 31 Jan 2003 07:10:27 -0000 1.8 @@ -55,7 +55,7 @@ import java.io.File; /** - * This is a class derived from the Jasper code + * This is a class derived from the Jasper code * (org.apache.jasper.compiler.CommandLineCompiler) to map from a JSP filename * to a valid Java classname. * @@ -159,7 +159,7 @@ * definition of the char escaping algorithm * * @param ch char to mangle - * @return mangled string; 5 digit hex value + * @return mangled string; 5 digit hex value */ private static final String mangleChar(char ch) { @@ -183,7 +183,7 @@ /** * taking in the substring representing the path relative to the source dir * return a new string representing the destination path - * @todo + * not supported, as jasper in tomcat4.0 doesnt either */ public String mapPath(String path) { return null; 1.5 +9 -0 jakarta-ant/src/etc/testcases/taskdefs/optional/jspc.xml Index: jspc.xml =================================================================== RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/optional/jspc.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- jspc.xml 10 Aug 2002 05:18:16 -0000 1.4 +++ jspc.xml 31 Jan 2003 07:10:28 -0000 1.5 @@ -9,6 +9,7 @@ <property name="jsp.dir" location="jsp"/> <property name="jsp.output.dir" location="${jsp.dir}/java"/> <property name="jsp.verbosity" value="3"/> + <property name="jsp.compiler" value="jasper41"/> <mkdir dir="${jsp.output.dir}"/> </target> @@ -23,6 +24,7 @@ <jspc destdir="${jsp.output.dir}" srcdir="${jsp.dir}" + compiler="${jsp.compiler}" verbose="${jsp.verbosity}"> <include name="missing_tld.jsp"/> @@ -30,6 +32,7 @@ </target> <!-- this should compile to simple.java --> + <!-- also, stick to the default compiler here to ensure it still works--> <target name="testSimple" depends="init"> <jspc destdir="${jsp.output.dir}" @@ -46,6 +49,7 @@ destdir="${jsp.output.dir}" uriroot="${jsp.dir}" srcdir="${jsp.dir}" + compiler="${jsp.compiler}" verbose="${jsp.verbosity}"> <include name="uriroot.jsp"/> @@ -58,6 +62,7 @@ destdir="${jsp.output.dir}" uriroot="${jsp.dir}" srcdir="${jsp.dir}" + compiler="${jsp.compiler}" verbose="${jsp.verbosity}"> <include name="xml.jsp"/> </jspc> @@ -68,6 +73,7 @@ <jspc destdir="${jsp.output.dir}" srcdir="${jsp.dir}" + compiler="${jsp.compiler}" verbose="${jsp.verbosity}"> <include name="default.jsp"/> @@ -79,6 +85,7 @@ <jspc destdir="${jsp.output.dir}" srcdir="${jsp.dir}" + compiler="${jsp.compiler}" verbose="${jsp.verbosity}"> <include name="1nvalid-classname.jsp"/> @@ -90,6 +97,7 @@ <jspc destdir="${jsp.output.dir}" srcdir="${jsp.dir}" + compiler="${jsp.compiler}" verbose="${jsp.verbosity}"> <include name="wrong_type.txt"/> @@ -100,6 +108,7 @@ <target name="testWebapp" depends="init"> <jspc destdir="${jsp.output.dir}" + compiler="${jsp.compiler}" verbose="${jsp.verbosity}"> <webapp basedir="${jsp.dir}" /> </jspc> 1.4 +64 -1 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/JspcTest.java Index: JspcTest.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/JspcTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JspcTest.java 30 Dec 2002 06:11:14 -0000 1.3 +++ JspcTest.java 31 Jan 2003 07:10:28 -0000 1.4 @@ -57,6 +57,12 @@ import java.util.Properties; import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler; +import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler; +import org.apache.tools.ant.taskdefs.optional.jsp.JspC; +import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler; +import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapterFactory; +import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapter; /** * Tests the Jspc task. @@ -163,8 +169,23 @@ } + /** + * A unit test for JUnit + */ + public void testNotAJspFile() throws Exception { + executeTarget("testNotAJspFile"); + } /** + * webapp test is currently broken, because it picks up + * on the missing_tld file, and bails. + */ +/* + public void testWebapp() throws Exception { + executeTarget("testWebapp"); + } +*/ + /** * run a target then verify the named file gets created * * @param target Description of Parameter @@ -191,7 +212,6 @@ assertTrue("file " + filename + " is empty", file.length() > 0); } - /** * Gets the OutputFile attribute of the JspcTest object * @@ -201,5 +221,48 @@ protected File getOutputFile(String subpath) { return new File(outDir, subpath); } + + /** + * verify that we select the appropriate mangler + */ + public void testJasperNameManglerSelection() { + JspCompilerAdapter adapter= + JspCompilerAdapterFactory.getCompiler("jasper", null,null); + JspMangler mangler=adapter.createMangler(); + assertTrue(mangler instanceof JspNameMangler); + adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null); + mangler = adapter.createMangler(); + assertTrue(mangler instanceof Jasper41Mangler); + } + + public void testJasper41() { + JspMangler mangler = new Jasper41Mangler(); + //java keywords are not special + assertMapped(mangler, "for.jsp", "for_jsp"); + //underscores go in front of invalid start chars + assertMapped(mangler, "0.jsp", "_0_jsp"); + //underscores at the front get an underscore too + assertMapped(mangler, "_.jsp", "___jsp"); + //non java char at start => underscore then the the _hex value + assertMapped(mangler, "-.jsp", "__0002d_jsp"); + //and paths are stripped + char s = File.separatorChar; + assertMapped(mangler, "" + s + s + "somewhere" + s + "file" + s + "index.jsp", "index_jsp"); + } + + /** + * assert our mapping rules + * @param mangler + * @param filename + * @param classname + */ + protected void assertMapped(JspMangler mangler, String filename, String classname) { + String mappedname = mangler.mapJspToJavaName(new File(filename)); + assertTrue(filename+" should have mapped to "+classname + +" but instead mapped to "+mappedname, + classname.equals(mappedname)); + } + + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]