78 try { |
78 try { |
79 Class<?> layerClass = Layer.layerClass; |
79 Class<?> layerClass = Layer.layerClass; |
80 loadMethod = ServiceLoader.class.getDeclaredMethod("load", layerClass, Class.class); |
80 loadMethod = ServiceLoader.class.getDeclaredMethod("load", layerClass, Class.class); |
81 } catch (NoSuchMethodException | SecurityException ex) { |
81 } catch (NoSuchMethodException | SecurityException ex) { |
82 throw new Abort(ex); |
82 throw new Abort(ex); |
|
83 } |
|
84 } |
|
85 } |
|
86 } |
|
87 |
|
88 /** |
|
89 * Wrapper class for java.lang.module.ModuleDescriptor and ModuleDescriptor.Version. |
|
90 */ |
|
91 public static class ModuleDescriptor { |
|
92 public static class Version { |
|
93 public static final String CLASSNAME = "java.lang.module.ModuleDescriptor$Version"; |
|
94 private final Object theRealVersion; |
|
95 |
|
96 private Version(Object version) { |
|
97 this.theRealVersion = version; |
|
98 } |
|
99 |
|
100 public static Version parse(String v) { |
|
101 try { |
|
102 init(); |
|
103 Object result = parseMethod.invoke(null, v); |
|
104 Version version = new Version(result); |
|
105 return version; |
|
106 } catch (InvocationTargetException ex) { |
|
107 if (ex.getCause() instanceof IllegalArgumentException) { |
|
108 throw (IllegalArgumentException) ex.getCause(); |
|
109 } else { |
|
110 throw new Abort(ex); |
|
111 } |
|
112 } catch (IllegalAccessException | IllegalArgumentException | SecurityException ex) { |
|
113 throw new Abort(ex); |
|
114 } |
|
115 } |
|
116 |
|
117 @Override |
|
118 public String toString() { |
|
119 return theRealVersion.toString(); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------------------- |
|
123 |
|
124 private static Class<?> versionClass = null; |
|
125 private static Method parseMethod = null; |
|
126 |
|
127 private static void init() { |
|
128 if (versionClass == null) { |
|
129 try { |
|
130 versionClass = Class.forName(CLASSNAME, false, null); |
|
131 parseMethod = versionClass.getDeclaredMethod("parse", String.class); |
|
132 } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
|
133 throw new Abort(ex); |
|
134 } |
83 } |
135 } |
84 } |
136 } |
85 } |
137 } |
86 } |
138 } |
87 |
139 |
336 |
388 |
337 /** |
389 /** |
338 * Helper class for new method in jdk.internal.misc.VM. |
390 * Helper class for new method in jdk.internal.misc.VM. |
339 */ |
391 */ |
340 public static final class VMHelper { |
392 public static final class VMHelper { |
341 public static final String VM_CLASSNAME = "jdk.internal.misc.VM"; |
393 public static final String CLASSNAME = "jdk.internal.misc.VM"; |
342 |
394 |
343 @SuppressWarnings("unchecked") |
395 @SuppressWarnings("unchecked") |
344 public static String[] getRuntimeArguments() { |
396 public static String[] getRuntimeArguments() { |
345 try { |
397 try { |
346 init(); |
398 init(); |
358 private static Method getRuntimeArgumentsMethod = null; |
410 private static Method getRuntimeArgumentsMethod = null; |
359 |
411 |
360 private static void init() { |
412 private static void init() { |
361 if (vmClass == null) { |
413 if (vmClass == null) { |
362 try { |
414 try { |
363 vmClass = Class.forName(VM_CLASSNAME, false, null); |
415 vmClass = Class.forName(CLASSNAME, false, null); |
364 getRuntimeArgumentsMethod = vmClass.getDeclaredMethod("getRuntimeArguments"); |
416 getRuntimeArgumentsMethod = vmClass.getDeclaredMethod("getRuntimeArguments"); |
365 } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
417 } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
366 throw new Abort(ex); |
418 throw new Abort(ex); |
367 } |
419 } |
368 } |
420 } |