langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/remote/RemoteAgent.java
equal
deleted
inserted
replaced
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package jdk.internal.jshell.remote; |
26 package jdk.internal.jshell.remote; |
|
27 import jdk.jshell.spi.SPIResolutionException; |
27 import java.io.File; |
28 import java.io.File; |
28 import java.io.IOException; |
29 import java.io.IOException; |
29 import java.io.ObjectInputStream; |
30 import java.io.ObjectInputStream; |
30 import java.io.ObjectOutputStream; |
31 import java.io.ObjectOutputStream; |
31 import java.io.OutputStream; |
32 import java.io.OutputStream; |
109 out.writeInt(RESULT_FAIL); |
110 out.writeInt(RESULT_FAIL); |
110 out.writeUTF("no such class loaded: " + name); |
111 out.writeUTF("no such class loaded: " + name); |
111 out.flush(); |
112 out.flush(); |
112 break; |
113 break; |
113 } |
114 } |
|
115 String methodName = in.readUTF(); |
114 Method doitMethod; |
116 Method doitMethod; |
115 try { |
117 try { |
116 this.getClass().getModule().addExports(RemoteResolutionException.class.getPackage().getName(), klass.getModule()); |
118 this.getClass().getModule().addExports(SPIResolutionException.class.getPackage().getName(), klass.getModule()); |
117 doitMethod = klass.getDeclaredMethod(DOIT_METHOD_NAME, new Class<?>[0]); |
119 doitMethod = klass.getDeclaredMethod(methodName, new Class<?>[0]); |
118 doitMethod.setAccessible(true); |
120 doitMethod.setAccessible(true); |
119 Object res; |
121 Object res; |
120 try { |
122 try { |
121 clientCodeEnter(); |
123 clientCodeEnter(); |
122 res = doitMethod.invoke(null, new Object[0]); |
124 res = doitMethod.invoke(null, new Object[0]); |
136 out.writeUTF(valueString(res)); |
138 out.writeUTF(valueString(res)); |
137 out.flush(); |
139 out.flush(); |
138 } catch (InvocationTargetException ex) { |
140 } catch (InvocationTargetException ex) { |
139 Throwable cause = ex.getCause(); |
141 Throwable cause = ex.getCause(); |
140 StackTraceElement[] elems = cause.getStackTrace(); |
142 StackTraceElement[] elems = cause.getStackTrace(); |
141 if (cause instanceof RemoteResolutionException) { |
143 if (cause instanceof SPIResolutionException) { |
142 out.writeInt(RESULT_CORRALLED); |
144 out.writeInt(RESULT_CORRALLED); |
143 out.writeInt(((RemoteResolutionException) cause).id); |
145 out.writeInt(((SPIResolutionException) cause).id()); |
144 } else { |
146 } else { |
145 out.writeInt(RESULT_EXCEPTION); |
147 out.writeInt(RESULT_EXCEPTION); |
146 out.writeUTF(cause.getClass().getName()); |
148 out.writeUTF(cause.getClass().getName()); |
147 out.writeUTF(cause.getMessage() == null ? "<none>" : cause.getMessage()); |
149 out.writeUTF(cause.getMessage() == null ? "<none>" : cause.getMessage()); |
148 } |
150 } |
252 |
254 |
253 static String valueString(Object value) { |
255 static String valueString(Object value) { |
254 if (value == null) { |
256 if (value == null) { |
255 return "null"; |
257 return "null"; |
256 } else if (value instanceof String) { |
258 } else if (value instanceof String) { |
257 return "\"" + expunge((String)value) + "\""; |
259 return "\"" + (String)value + "\""; |
258 } else if (value instanceof Character) { |
260 } else if (value instanceof Character) { |
259 return "'" + value + "'"; |
261 return "'" + value + "'"; |
260 } else { |
262 } else { |
261 return expunge(value.toString()); |
263 return value.toString(); |
262 } |
264 } |
263 } |
|
264 |
|
265 /** |
|
266 * Expunge internal info from string |
|
267 * @param s string to process |
|
268 * @return string the display, JShell package and wrapper class names removed |
|
269 */ |
|
270 static String expunge(String s) { |
|
271 StringBuilder sb = new StringBuilder(); |
|
272 for (String comp : PREFIX_PATTERN.split(s)) { |
|
273 sb.append(comp); |
|
274 } |
|
275 return sb.toString(); |
|
276 } |
265 } |
277 |
266 |
278 private static final class MultiplexingOutputStream extends OutputStream { |
267 private static final class MultiplexingOutputStream extends OutputStream { |
279 |
268 |
280 private static final int PACKET_SIZE = 127; |
269 private static final int PACKET_SIZE = 127; |