kinman 2003/02/27 14:51:38
Modified: jasper2/src/share/org/apache/jasper JspC.java
JspCompilationContext.java
jasper2/src/share/org/apache/jasper/compiler Compiler.java
jasper2/src/share/org/apache/jasper/servlet
JasperLoader.java
Log:
- Fixes to make Jspc work:
* Make sure the correct classloader is used.
* Mangle package names if they contain Java keywords.
Revision Changes Path
1.35 +46 -15
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java
Index: JspC.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- JspC.java 26 Feb 2003 16:36:13 -0000 1.34
+++ JspC.java 27 Feb 2003 22:51:38 -0000 1.35
@@ -573,17 +573,12 @@
Compiler clc = clctxt.createCompiler();
this.setOutputDir( baseDir );
- if( compile ) {
- // Generate both .class and .java
- if( clc.isOutDated() ) {
- clc.compile();
- }
- } else {
- // Only generate .java, compilation is separated
- // Don't compile if the .class file is newer than the .jsp file
- if( clc.isOutDated(false) ) {
- clc.generateJava();
- }
+ // If compile is set, generate both .java and .class, if
+ // .jsp file is newer than .class file;
+ // Otherwise only generate .java, if .jsp file is newer than
+ // the .java file
+ if( clc.isOutDated(compile) ) {
+ clc.compile(compile);
}
// Generate mapping
@@ -983,17 +978,25 @@
StringBuffer modifiedPackageName = new StringBuffer();
int iSep = jspUri.lastIndexOf('/');
// Start after the first slash
+ int nameStart = 1;
for (int i = 1; i < iSep; i++) {
char ch = jspUri.charAt(i);
if (Character.isJavaIdentifierPart(ch)) {
modifiedPackageName.append(ch);
}
else if (ch == '/') {
+ if (isJavaKeyword(jspUri.substring(nameStart, i))) {
+ modifiedPackageName.append('_');
+ }
+ nameStart = i+1;
modifiedPackageName.append('.');
} else {
modifiedPackageName.append(mangleChar(ch));
}
}
+ if (nameStart < iSep && isJavaKeyword(jspUri.substring(nameStart, iSep))) {
+ modifiedPackageName.append('_');
+ }
return modifiedPackageName.toString();
}
@@ -1018,6 +1021,34 @@
return new String(result);
}
-
+ static final String javaKeywords[] = {
+ "abstract", "boolean", "break", "byte", "case",
+ "catch", "char", "class", "const", "continue",
+ "default", "do", "double", "else", "extends",
+ "final", "finally", "float", "for", "goto",
+ "if", "implements", "import", "instanceof", "int",
+ "interface", "long", "native", "new", "package",
+ "private", "protected", "public", "return", "short",
+ "static", "strictfp", "super", "switch", "synchronized",
+ "this", "throws", "transient", "try", "void",
+ "volatile", "while" };
+
+ static private boolean isJavaKeyword(String key) {
+ int i = 0;
+ int j = javaKeywords.length;
+ while (i < j) {
+ int k = (i+j)/2;
+ int result = javaKeywords[k].compareTo(key);
+ if (result == 0) {
+ return true;
+ }
+ if (result < 0) {
+ i = k+1;
+ } else {
+ j = k;
+ }
+ }
+ return false;
+ }
}
1.35 +4 -4
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspCompilationContext.java
Index: JspCompilationContext.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspCompilationContext.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- JspCompilationContext.java 21 Feb 2003 18:23:14 -0000 1.34
+++ JspCompilationContext.java 27 Feb 2003 22:51:38 -0000 1.35
@@ -589,7 +589,7 @@
jspLoader = new JasperLoader
(outUrls,
getServletPackageName() + "." + getServletClassName(),
- rctxt.getParentClassLoader(),
+ getClassLoader(),
rctxt.getPermissionCollection(),
rctxt.getCodeSource());
1.58 +15 -4
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- Compiler.java 26 Feb 2003 22:58:15 -0000 1.57
+++ Compiler.java 27 Feb 2003 22:51:38 -0000 1.58
@@ -152,7 +152,7 @@
logger.setErrorPrintStream(System.err);
logger.setMessageOutputLevel(Project.MSG_INFO);
project.addBuildListener( logger);
- if (System.getProperty("catalina.home") != null) {
+ if (System.getProperty("catalina.home") != null) {
project.setBasedir( System.getProperty("catalina.home"));
}
@@ -192,7 +192,7 @@
/**
* Compile the jsp file from the current engine context
*/
- public void generateJava()
+ private void generateJava()
throws Exception
{
long t1=System.currentTimeMillis();
@@ -310,7 +310,7 @@
/**
* Compile the jsp file from the current engine context
*/
- public void generateClass()
+ private void generateClass()
throws FileNotFoundException, JasperException, Exception {
long t1=System.currentTimeMillis();
@@ -431,13 +431,24 @@
public void compile()
throws FileNotFoundException, JasperException, Exception
{
+ compile(true);
+ }
+
+ /**
+ * Compile the jsp file from the current engine context
+ */
+ public void compile(boolean compileClass)
+ throws FileNotFoundException, JasperException, Exception
+ {
if (errDispatcher == null) {
this.errDispatcher = new ErrorDispatcher();
}
try {
generateJava();
- generateClass();
+ if (compileClass) {
+ generateClass();
+ }
} finally {
if (tfp != null) {
tfp.removeProtoTypeFiles(null);
1.8 +3 -3
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JasperLoader.java
Index: JasperLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JasperLoader.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JasperLoader.java 28 Nov 2002 04:18:08 -0000 1.7
+++ JasperLoader.java 27 Feb 2003 22:51:38 -0000 1.8
@@ -188,9 +188,9 @@
ex.getException().printStackTrace();
}
- } else {
- clazz =
Thread.currentThread().getContextClassLoader().loadClass(name);
- }
+ } else {
+ clazz = parent.loadClass(name);
+ }
if( resolve )
resolveClass(clazz);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]