You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ki...@apache.org on 2003/04/16 23:50:48 UTC
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler Compiler.java SmapStratum.java SmapUtil.java
kinman 2003/04/16 14:50:48
Modified: jasper2/src/share/org/apache/jasper/compiler Compiler.java
SmapStratum.java SmapUtil.java
Log:
- Suppress smap if there is no line info.
- Generate smap in memory, avoid I/O operatons.
Revision Changes Path
1.64 +13 -7 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.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- Compiler.java 11 Apr 2003 22:41:57 -0000 1.63
+++ Compiler.java 16 Apr 2003 21:50:48 -0000 1.64
@@ -191,10 +191,14 @@
/**
* Compile the jsp file from the current engine context
+ * @return a smap for the current JSP page, if one is generated,
+ * null otherwise
*/
- private void generateJava()
+ private String generateJava()
throws Exception
{
+ String smapStr = null;
+
long t1=System.currentTimeMillis();
// Setup page info area
@@ -249,7 +253,7 @@
// generate prototype .java file for the tag file
Generator.generate(writer, this, pageNodes);
writer.close();
- return;
+ return null;
}
// Generate FunctionMapper (used for validation of EL expressions and
@@ -299,7 +303,7 @@
//JSR45 Support - note this needs to be checked by a JSR45 guru
if (! options.suppressSmap()) {
- SmapUtil.generateSmap(ctxt, pageNodes, true);
+ smapStr = SmapUtil.generateSmap(ctxt, pageNodes);
}
// If any proto type .java and .class files was generated,
@@ -309,12 +313,14 @@
// generate .class again from the new .java file just generated.
tfp.removeProtoTypeFiles(ctxt.getClassFileName());
+
+ return smapStr;
}
/**
* Compile the jsp file from the current engine context
*/
- private void generateClass()
+ private void generateClass(String smap)
throws FileNotFoundException, JasperException, Exception {
long t1=System.currentTimeMillis();
@@ -425,7 +431,7 @@
//JSR45 Support - note this needs to be checked by a JSR45 guru
if (! options.suppressSmap()) {
- SmapUtil.installSmap(ctxt);
+ SmapUtil.installSmap(ctxt.getClassFileName(), smap);
}
}
@@ -449,9 +455,9 @@
}
try {
- generateJava();
+ String smap = generateJava();
if (compileClass) {
- generateClass();
+ generateClass(smap);
}
} finally {
if (tfp != null) {
1.3 +2 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapStratum.java
Index: SmapStratum.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapStratum.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SmapStratum.java 16 Apr 2003 18:59:29 -0000 1.2
+++ SmapStratum.java 16 Apr 2003 21:50:48 -0000 1.3
@@ -269,7 +269,8 @@
public synchronized String getString() {
// check state and initialize buffer
if (fileNameList.size() == 0 || lineData.size() == 0)
- throw new IllegalStateException();
+ return null;
+
StringBuffer out = new StringBuffer();
// print StratumSection
1.10 +37 -36 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java
Index: SmapUtil.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SmapUtil.java 16 Apr 2003 18:59:29 -0000 1.9
+++ SmapUtil.java 16 Apr 2003 21:50:48 -0000 1.10
@@ -86,16 +86,14 @@
/**
* Generates an appropriate SMAP representing the current compilation
- * context and optionally installs in the target .class file. (JSR-045.)
- * If the keepGenerated flag is set in the compilation context, the
- * generated .smap file will remain. Otherwise, it will be deleted.
+ * context. (JSR-045.)
*
- * @param install True if the SourceDebugExtension is to be installed
- * in the generated .class file, or false if not.
+ * @param ctxt Current compilation context
+ * @param pageNodes The current JSP page
+ * @return a SMAP for the page
*/
- public static void generateSmap(JspCompilationContext ctxt,
- Node.Nodes pageNodes,
- boolean install )
+ public static String generateSmap(JspCompilationContext ctxt,
+ Node.Nodes pageNodes)
throws IOException
{
// set up our SMAP generator
@@ -121,34 +119,22 @@
SmapStratum s = new SmapStratum("JSP");
g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
- // recursively map out Node.Nodes, it seems ugly..but its the only way??
+ // Map out Node.Nodes
evaluateNodes(pageNodes, s);
g.addStratum(s, true);
- /*
- * Save the output to a temporary file (just so as to use
- * Robert's interface -- so that I don't have to keep changing
- * this code if he updates it). TODO: We could do this more
- * gracefully later. But writing out the SMAP to a known
- * filename (servlet.class.smap) will also make troubleshooting
- * easier.
- */
-
- File outSmap = new File(ctxt.getClassFileName() + ".smap");
- PrintWriter so = new PrintWriter(
- new OutputStreamWriter(new FileOutputStream(outSmap),
- SMAP_ENCODING));
- so.print(g.getString());
- so.close();
+// System.out.println(g.getString());
+ return g.getString();
}
- public static void installSmap(JspCompilationContext ctxt) throws IOException {
- File outSmap = new File(ctxt.getClassFileName() + ".smap");
- File outServlet = new File(ctxt.getClassFileName());
- SDEInstaller.install(outServlet, outSmap);
-// if( !ctxt.keepGenerated() ) {
- outSmap.delete();
-// }
+ public static void installSmap(String classFileName, String smap)
+ throws IOException {
+ if (smap == null) {
+ return;
+ }
+
+ File outServlet = new File(classFileName);
+ SDEInstaller.install(outServlet, smap.getBytes());
}
@@ -215,18 +201,28 @@
}
}
- SDEInstaller(File inClassFile, File attrFile, File outClassFile)
+ static void install(File classFile, byte[] smap)
+ throws IOException {
+ File tmpFile = new File(classFile.getPath() + "tmp");
+ new SDEInstaller(classFile, smap, tmpFile);
+ if (!classFile.delete()) {
+ throw new IOException("classFile.delete() failed");
+ }
+ if (!tmpFile.renameTo(classFile)) {
+ throw new IOException("tmpFile.renameTo(classFile) failed")
+;
+ }
+ }
+
+ SDEInstaller(File inClassFile, byte[] sdeAttr, File outClassFile)
throws IOException {
if (!inClassFile.exists()) {
throw new FileNotFoundException("no such file: " + inClassFile);
}
- if (!attrFile.exists()) {
- throw new FileNotFoundException("no such file: " + attrFile);
- }
+ this.sdeAttr = sdeAttr;
// get the bytes
orig = readWhole(inClassFile);
- sdeAttr = readWhole(attrFile);
gen = new byte[orig.length + sdeAttr.length + 100];
// do it
@@ -237,6 +233,11 @@
outStream.write(gen, 0, genPos);
outStream.close();
}
+
+ SDEInstaller(File inClassFile, File attrFile, File outClassFile)
+ throws IOException {
+ this(inClassFile, readWhole(attrFile), outClassFile);
+ }
static byte[] readWhole(File input) throws IOException {
FileInputStream inStream = new FileInputStream(input);
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org