langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ExternalEditor.java
equal
deleted
inserted
replaced
31 import java.nio.file.FileSystems; |
31 import java.nio.file.FileSystems; |
32 import java.nio.file.Files; |
32 import java.nio.file.Files; |
33 import java.nio.file.Path; |
33 import java.nio.file.Path; |
34 import java.nio.file.WatchKey; |
34 import java.nio.file.WatchKey; |
35 import java.nio.file.WatchService; |
35 import java.nio.file.WatchService; |
|
36 import java.util.Arrays; |
36 import java.util.function.Consumer; |
37 import java.util.function.Consumer; |
37 import java.util.stream.Collectors; |
38 import java.util.stream.Collectors; |
38 import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; |
39 import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; |
39 import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; |
40 import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; |
40 import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; |
41 import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; |
56 this.errorHandler = errorHandler; |
57 this.errorHandler = errorHandler; |
57 this.saveHandler = saveHandler; |
58 this.saveHandler = saveHandler; |
58 this.input = input; |
59 this.input = input; |
59 } |
60 } |
60 |
61 |
61 private void edit(String cmd, String initialText) { |
62 private void edit(String[] cmd, String initialText) { |
62 try { |
63 try { |
63 setupWatch(initialText); |
64 setupWatch(initialText); |
64 launch(cmd); |
65 launch(cmd); |
65 } catch (IOException ex) { |
66 } catch (IOException ex) { |
66 errorHandler.accept(ex.getMessage()); |
67 errorHandler.accept(ex.getMessage()); |
104 } |
105 } |
105 }); |
106 }); |
106 watchedThread.start(); |
107 watchedThread.start(); |
107 } |
108 } |
108 |
109 |
109 private void launch(String cmd) throws IOException { |
110 private void launch(String[] cmd) throws IOException { |
110 ProcessBuilder pb = new ProcessBuilder(cmd, tmpfile.toString()); |
111 String[] params = Arrays.copyOf(cmd, cmd.length + 1); |
|
112 params[cmd.length] = tmpfile.toString(); |
|
113 ProcessBuilder pb = new ProcessBuilder(params); |
111 pb = pb.inheritIO(); |
114 pb = pb.inheritIO(); |
112 |
115 |
113 try { |
116 try { |
114 input.suspend(); |
117 input.suspend(); |
115 Process process = pb.start(); |
118 Process process = pb.start(); |
137 } catch (IOException ex) { |
140 } catch (IOException ex) { |
138 errorHandler.accept("Failure in read edit file: " + ex.getMessage()); |
141 errorHandler.accept("Failure in read edit file: " + ex.getMessage()); |
139 } |
142 } |
140 } |
143 } |
141 |
144 |
142 static void edit(String cmd, Consumer<String> errorHandler, String initialText, |
145 static void edit(String[] cmd, Consumer<String> errorHandler, String initialText, |
143 Consumer<String> saveHandler, IOContext input) { |
146 Consumer<String> saveHandler, IOContext input) { |
144 ExternalEditor ed = new ExternalEditor(errorHandler, saveHandler, input); |
147 ExternalEditor ed = new ExternalEditor(errorHandler, saveHandler, input); |
145 ed.edit(cmd, initialText); |
148 ed.edit(cmd, initialText); |
146 } |
149 } |
147 } |
150 } |