Generates an appropriate SMAP representing the current compilation context. (JSR-045.) @param ctxt Current compilation context @param pageNodes The current JSP page @return a SMAP for the page @throws IOException Error writing SMAP
(JspCompilationContext ctxt, Node.Nodes pageNodes)
| 62 | * @throws IOException Error writing SMAP |
| 63 | */ |
| 64 | public static Map<String,SmapStratum> generateSmap(JspCompilationContext ctxt, Node.Nodes pageNodes) |
| 65 | throws IOException { |
| 66 | |
| 67 | Map<String,SmapStratum> smapInfo = new HashMap<>(); |
| 68 | |
| 69 | // Scan the nodes for presence of Jasper generated inner classes |
| 70 | PreScanVisitor psVisitor = new PreScanVisitor(); |
| 71 | try { |
| 72 | pageNodes.visit(psVisitor); |
| 73 | } catch (JasperException ex) { |
| 74 | // Ignore |
| 75 | } |
| 76 | HashMap<String,SmapStratum> map = psVisitor.getMap(); |
| 77 | |
| 78 | // Assemble info about our own stratum (JSP) using JspLineMap |
| 79 | SmapStratum s = new SmapStratum(); |
| 80 | |
| 81 | // Map out Node.Nodes |
| 82 | evaluateNodes(pageNodes, s, map, ctxt.getOptions().getMappedFile()); |
| 83 | s.optimizeLineSection(); |
| 84 | s.setOutputFileName(unqualify(ctxt.getServletJavaFileName())); |
| 85 | |
| 86 | String classFileName = ctxt.getClassFileName(); |
| 87 | s.setClassFileName(classFileName); |
| 88 | |
| 89 | smapInfo.put(ctxt.getFQCN(), s); |
| 90 | |
| 91 | if (ctxt.getOptions().isSmapDumped()) { |
| 92 | File outSmap = new File(classFileName + ".smap"); |
| 93 | PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING)); |
| 94 | so.print(s.getSmapString()); |
| 95 | so.close(); |
| 96 | } |
| 97 | |
| 98 | for (Map.Entry<String,SmapStratum> entry : map.entrySet()) { |
| 99 | String innerClass = entry.getKey(); |
| 100 | s = entry.getValue(); |
| 101 | s.optimizeLineSection(); |
| 102 | s.setOutputFileName(unqualify(ctxt.getServletJavaFileName())); |
| 103 | String innerClassFileName = |
| 104 | classFileName.substring(0, classFileName.indexOf(".class")) + '$' + innerClass + ".class"; |
| 105 | s.setClassFileName(innerClassFileName); |
| 106 | |
| 107 | smapInfo.put(ctxt.getFQCN() + "." + innerClass, s); |
| 108 | |
| 109 | if (ctxt.getOptions().isSmapDumped()) { |
| 110 | File outSmap = new File(innerClassFileName + ".smap"); |
| 111 | PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING)); |
| 112 | so.print(s.getSmapString()); |
| 113 | so.close(); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return smapInfo; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Installs SMAP data into the compiled class files by writing the SourceDebugExtension |
no test coverage detected