(String className, String src, Iterable<String> options)
| 192 | } |
| 193 | |
| 194 | private void doCompile(String className, String src, Iterable<String> options) throws IOException { |
| 195 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
| 196 | if (compiler == null) { |
| 197 | throw new IllegalStateException("JavaShell requires a JDK at runtime; " |
| 198 | + "ToolProvider.getSystemJavaCompiler() returned null (running on a JRE?)."); |
| 199 | } |
| 200 | try (BytesJavaFileManager bjfm = new BytesJavaFileManager(compiler.getStandardFileManager(null, locale, charset))) { |
| 201 | StringBuilderWriter out = new StringBuilderWriter(); |
| 202 | JavaCompiler.CompilationTask task = |
| 203 | compiler.getTask( |
| 204 | out, |
| 205 | bjfm, |
| 206 | null, |
| 207 | options, |
| 208 | Collections.emptyList(), |
| 209 | Collections.singletonList( |
| 210 | new MemJavaFileObject(className, src) |
| 211 | ) |
| 212 | ); |
| 213 | |
| 214 | task.call(); |
| 215 | |
| 216 | if (bjfm.isEmpty()) { |
| 217 | throw new JavaShellCompilationException(out.toString()); |
| 218 | } |
| 219 | |
| 220 | final Map<String, byte[]> classMap = bjfm.getClassMap(); |
| 221 | |
| 222 | jscl.setClassMap(classMap); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Compile {@code src} and write each resulting class file beneath {@code outputDir} |
no test coverage detected