(Map<String,SmapStratum> smaps)
| 48 | private final Log log = LogFactory.getLog(JavaCompiler.class); // must not be static |
| 49 | |
| 50 | @Override |
| 51 | protected void generateClass(Map<String,SmapStratum> smaps) throws JasperException, IOException { |
| 52 | |
| 53 | long t1 = 0; |
| 54 | if (log.isDebugEnabled()) { |
| 55 | t1 = System.currentTimeMillis(); |
| 56 | } |
| 57 | |
| 58 | javax.tools.JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
| 59 | DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); |
| 60 | try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, |
| 61 | Charset.forName(ctxt.getOptions().getJavaEncoding()))) { |
| 62 | |
| 63 | Iterable<? extends JavaFileObject> compilationUnits = |
| 64 | fileManager.getJavaFileObjectsFromFiles(List.of(new File(ctxt.getServletJavaFileName()))); |
| 65 | // Perform Java compilation using the appropriate options |
| 66 | List<String> compilerOptions = List.of("-classpath", ctxt.getClassPath(), "-source", |
| 67 | ctxt.getOptions().getCompilerSourceVM(), "-target", ctxt.getOptions().getCompilerTargetVM()); |
| 68 | Boolean result = |
| 69 | compiler.getTask(null, fileManager, diagnostics, compilerOptions, null, compilationUnits).call(); |
| 70 | |
| 71 | List<JavacErrorDetail> problemList = new ArrayList<>(); |
| 72 | if (!result.booleanValue()) { |
| 73 | for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) { |
| 74 | if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { |
| 75 | try { |
| 76 | problemList.add(ErrorDispatcher.createJavacError(diagnostic.getSource().getName(), pageNodes, |
| 77 | new StringBuilder(diagnostic.getMessage(Locale.getDefault())), |
| 78 | (int) diagnostic.getLineNumber(), ctxt)); |
| 79 | } catch (JasperException e) { |
| 80 | log.error(Localizer.getMessage("jsp.error.compilation.jdtProblemError"), e); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (!ctxt.keepGenerated()) { |
| 87 | File javaFile = new File(ctxt.getServletJavaFileName()); |
| 88 | if (!javaFile.delete()) { |
| 89 | throw new JasperException(Localizer.getMessage("jsp.warning.compiler.javafile.delete.fail", javaFile)); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (!problemList.isEmpty()) { |
| 94 | JavacErrorDetail[] jeds = problemList.toArray(new JavacErrorDetail[0]); |
| 95 | errDispatcher.javacError(jeds); |
| 96 | } |
| 97 | |
| 98 | if (log.isDebugEnabled()) { |
| 99 | long t2 = System.currentTimeMillis(); |
| 100 | log.debug(Localizer.getMessage("jsp.compiled", ctxt.getServletJavaFileName(), Long.valueOf(t2 - t1))); |
| 101 | } |
| 102 | |
| 103 | if (ctxt.isPrototypeMode()) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | // JSR45 Support |
nothing calls this directly
no test coverage detected