diff -r 7193f6ef25db -r 868af3718a21 langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java Wed Feb 08 09:12:45 2017 -0800 +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java Wed Feb 08 10:43:16 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,8 +44,10 @@ import java.util.function.BiFunction; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Stream; +import javax.tools.StandardJavaFileManager; import jdk.internal.jshell.debug.InternalDebugControl; import jdk.jshell.Snippet.Status; import jdk.jshell.spi.ExecutionControl.EngineTerminationException; @@ -92,6 +94,7 @@ final BiFunction idGenerator; final List extraRemoteVMOptions; final List extraCompilerOptions; + final Function fileManagerMapping; private int nextKeyIndex = 1; @@ -115,6 +118,7 @@ this.idGenerator = b.idGenerator; this.extraRemoteVMOptions = b.extraRemoteVMOptions; this.extraCompilerOptions = b.extraCompilerOptions; + this.fileManagerMapping = b.fileManagerMapping; try { if (b.executionControlProvider != null) { executionControl = b.executionControlProvider.generate(new ExecutionEnvImpl(), @@ -171,6 +175,7 @@ ExecutionControlProvider executionControlProvider; Map executionControlParameters; String executionControlSpec; + Function fileManagerMapping; Builder() { } @@ -365,6 +370,28 @@ } /** + * Configure the {@code FileManager} to be used by compilation and + * source analysis. + * If not set or passed null, the compiler's standard file manager will + * be used (identity mapping). + * For use in special applications where the compiler's normal file + * handling needs to be overridden. See the file manager APIs for more + * information. + * The file manager input enables forwarding file managers, if this + * is not needed, the incoming file manager can be ignored (constant + * function). + * + * @param mapping a function that given the compiler's standard file + * manager, returns a file manager to use + * @return the {@code Builder} instance (for use in chained + * initialization) + */ + public Builder fileManager(Function mapping) { + this.fileManagerMapping = mapping; + return this; + } + + /** * Builds a JShell state engine. This is the entry-point to all JShell * functionality. This creates a remote process for execution. It is * thus important to close the returned instance. @@ -501,6 +528,7 @@ * @throws IllegalStateException if this {@code JShell} instance is closed. */ public void addToClasspath(String path) { + checkIfAlive(); // Compiler taskFactory.addToClasspath(path); // Runtime