1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
42 import java.util.Objects; |
42 import java.util.Objects; |
43 import java.util.ResourceBundle; |
43 import java.util.ResourceBundle; |
44 import java.util.function.BiFunction; |
44 import java.util.function.BiFunction; |
45 import java.util.function.Consumer; |
45 import java.util.function.Consumer; |
46 |
46 |
|
47 import java.util.function.Function; |
47 import java.util.function.Supplier; |
48 import java.util.function.Supplier; |
48 import java.util.stream.Stream; |
49 import java.util.stream.Stream; |
|
50 import javax.tools.StandardJavaFileManager; |
49 import jdk.internal.jshell.debug.InternalDebugControl; |
51 import jdk.internal.jshell.debug.InternalDebugControl; |
50 import jdk.jshell.Snippet.Status; |
52 import jdk.jshell.Snippet.Status; |
51 import jdk.jshell.spi.ExecutionControl.EngineTerminationException; |
53 import jdk.jshell.spi.ExecutionControl.EngineTerminationException; |
52 import jdk.jshell.spi.ExecutionControl.ExecutionControlException; |
54 import jdk.jshell.spi.ExecutionControl.ExecutionControlException; |
53 import jdk.jshell.spi.ExecutionControlProvider; |
55 import jdk.jshell.spi.ExecutionControlProvider; |
90 final PrintStream err; |
92 final PrintStream err; |
91 final Supplier<String> tempVariableNameGenerator; |
93 final Supplier<String> tempVariableNameGenerator; |
92 final BiFunction<Snippet, Integer, String> idGenerator; |
94 final BiFunction<Snippet, Integer, String> idGenerator; |
93 final List<String> extraRemoteVMOptions; |
95 final List<String> extraRemoteVMOptions; |
94 final List<String> extraCompilerOptions; |
96 final List<String> extraCompilerOptions; |
|
97 final Function<StandardJavaFileManager, StandardJavaFileManager> fileManagerMapping; |
95 |
98 |
96 private int nextKeyIndex = 1; |
99 private int nextKeyIndex = 1; |
97 |
100 |
98 final Eval eval; |
101 final Eval eval; |
99 final ClassTracker classTracker; |
102 final ClassTracker classTracker; |
113 this.err = b.err; |
116 this.err = b.err; |
114 this.tempVariableNameGenerator = b.tempVariableNameGenerator; |
117 this.tempVariableNameGenerator = b.tempVariableNameGenerator; |
115 this.idGenerator = b.idGenerator; |
118 this.idGenerator = b.idGenerator; |
116 this.extraRemoteVMOptions = b.extraRemoteVMOptions; |
119 this.extraRemoteVMOptions = b.extraRemoteVMOptions; |
117 this.extraCompilerOptions = b.extraCompilerOptions; |
120 this.extraCompilerOptions = b.extraCompilerOptions; |
|
121 this.fileManagerMapping = b.fileManagerMapping; |
118 try { |
122 try { |
119 if (b.executionControlProvider != null) { |
123 if (b.executionControlProvider != null) { |
120 executionControl = b.executionControlProvider.generate(new ExecutionEnvImpl(), |
124 executionControl = b.executionControlProvider.generate(new ExecutionEnvImpl(), |
121 b.executionControlParameters == null |
125 b.executionControlParameters == null |
122 ? b.executionControlProvider.defaultParameters() |
126 ? b.executionControlProvider.defaultParameters() |
169 List<String> extraRemoteVMOptions = new ArrayList<>(); |
173 List<String> extraRemoteVMOptions = new ArrayList<>(); |
170 List<String> extraCompilerOptions = new ArrayList<>(); |
174 List<String> extraCompilerOptions = new ArrayList<>(); |
171 ExecutionControlProvider executionControlProvider; |
175 ExecutionControlProvider executionControlProvider; |
172 Map<String,String> executionControlParameters; |
176 Map<String,String> executionControlParameters; |
173 String executionControlSpec; |
177 String executionControlSpec; |
|
178 Function<StandardJavaFileManager, StandardJavaFileManager> fileManagerMapping; |
174 |
179 |
175 Builder() { } |
180 Builder() { } |
176 |
181 |
177 /** |
182 /** |
178 * Sets the input for the running evaluation (it's {@code System.in}). Note: |
183 * Sets the input for the running evaluation (it's {@code System.in}). Note: |
359 */ |
364 */ |
360 public Builder executionEngine(ExecutionControlProvider executionControlProvider, |
365 public Builder executionEngine(ExecutionControlProvider executionControlProvider, |
361 Map<String,String> executionControlParameters) { |
366 Map<String,String> executionControlParameters) { |
362 this.executionControlProvider = executionControlProvider; |
367 this.executionControlProvider = executionControlProvider; |
363 this.executionControlParameters = executionControlParameters; |
368 this.executionControlParameters = executionControlParameters; |
|
369 return this; |
|
370 } |
|
371 |
|
372 /** |
|
373 * Configure the {@code FileManager} to be used by compilation and |
|
374 * source analysis. |
|
375 * If not set or passed null, the compiler's standard file manager will |
|
376 * be used (identity mapping). |
|
377 * For use in special applications where the compiler's normal file |
|
378 * handling needs to be overridden. See the file manager APIs for more |
|
379 * information. |
|
380 * The file manager input enables forwarding file managers, if this |
|
381 * is not needed, the incoming file manager can be ignored (constant |
|
382 * function). |
|
383 * |
|
384 * @param mapping a function that given the compiler's standard file |
|
385 * manager, returns a file manager to use |
|
386 * @return the {@code Builder} instance (for use in chained |
|
387 * initialization) |
|
388 */ |
|
389 public Builder fileManager(Function<StandardJavaFileManager, StandardJavaFileManager> mapping) { |
|
390 this.fileManagerMapping = mapping; |
364 return this; |
391 return this; |
365 } |
392 } |
366 |
393 |
367 /** |
394 /** |
368 * Builds a JShell state engine. This is the entry-point to all JShell |
395 * Builds a JShell state engine. This is the entry-point to all JShell |
499 * {@link JShell#eval(String)} code is placed. |
526 * {@link JShell#eval(String)} code is placed. |
500 * @param path the path to add to the classpath. |
527 * @param path the path to add to the classpath. |
501 * @throws IllegalStateException if this {@code JShell} instance is closed. |
528 * @throws IllegalStateException if this {@code JShell} instance is closed. |
502 */ |
529 */ |
503 public void addToClasspath(String path) { |
530 public void addToClasspath(String path) { |
|
531 checkIfAlive(); |
504 // Compiler |
532 // Compiler |
505 taskFactory.addToClasspath(path); |
533 taskFactory.addToClasspath(path); |
506 // Runtime |
534 // Runtime |
507 try { |
535 try { |
508 executionControl().addToClasspath(path); |
536 executionControl().addToClasspath(path); |