author | alanb |
Fri, 10 Feb 2017 09:06:10 +0000 | |
changeset 43767 | 9cff98a149cb |
parent 42822 | a84956e7ee4d |
child 44573 | 245bb4e6f983 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
41440 | 28 |
import java.io.IOException; |
36526 | 29 |
import java.lang.reflect.InvocationTargetException; |
30 |
import java.lang.reflect.Method; |
|
31 |
import java.nio.file.Path; |
|
32 |
import java.util.Collection; |
|
33 |
import java.util.ServiceLoader; |
|
34 |
||
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
35 |
/** |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
36 |
* This class provides wrappers for classes and methods that are new in JDK 9, and which are not |
36526 | 37 |
* available on older versions of the platform on which javac may be compiled and run. |
38 |
* In future releases, when javac is always compiled on JDK 9 or later, the use of these wrappers |
|
39 |
* can be replaced by use of the real underlying classes. |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
40 |
* |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
41 |
* <p>Wrapper classes provide a subset of the API of the wrapped classes, as needed for use |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
42 |
* in javac. Wrapper objects contain an {@code Object} reference to the underlying runtime object, |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
43 |
* and {@code Class} and {@code Method} objects for obtaining or using such instances via |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
44 |
* runtime reflection. The {@code Class} and {@code Method} objects are set up on a per-class |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
45 |
* basis, by an {@code init} method, which is called from static methods on the wrapper class, |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
46 |
* or in the constructor, when instances are created. |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
47 |
* <p> |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
48 |
* |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
49 |
* <p><b>This is NOT part of any supported API. |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
50 |
* If you write code that depends on this, you do so at your own risk. |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
51 |
* This code and its internal interfaces are subject to change or |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
52 |
* deletion without notice.</b> |
36526 | 53 |
*/ |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
54 |
public class JDK9Wrappers { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
55 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
56 |
/** |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
57 |
* Helper class for new method in java.util.ServiceLoader. |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
58 |
*/ |
36526 | 59 |
public static final class ServiceLoaderHelper { |
60 |
@SuppressWarnings("unchecked") |
|
61 |
public static <S> ServiceLoader<S> load(Layer layer, Class<S> service) { |
|
62 |
try { |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
63 |
init(); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
64 |
Object result = loadMethod.invoke(null, layer.theRealLayer, service); |
36526 | 65 |
return (ServiceLoader<S>)result; |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
66 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
67 |
| SecurityException ex) { |
36526 | 68 |
throw new Abort(ex); |
69 |
} |
|
70 |
} |
|
71 |
||
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
72 |
// ----------------------------------------------------------------------------------------- |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
73 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
74 |
private static Method loadMethod = null; |
36526 | 75 |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
76 |
private static void init() { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
77 |
if (loadMethod == null) { |
36526 | 78 |
try { |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
79 |
Class<?> layerClass = Layer.layerClass; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
80 |
loadMethod = ServiceLoader.class.getDeclaredMethod("load", layerClass, Class.class); |
36526 | 81 |
} catch (NoSuchMethodException | SecurityException ex) { |
82 |
throw new Abort(ex); |
|
83 |
} |
|
84 |
} |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
85 |
} |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
86 |
} |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
87 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
88 |
/** |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
89 |
* Wrapper class for java.lang.module.ModuleDescriptor and ModuleDescriptor.Version. |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
90 |
*/ |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
91 |
public static class ModuleDescriptor { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
92 |
public static class Version { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
93 |
public static final String CLASSNAME = "java.lang.module.ModuleDescriptor$Version"; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
94 |
private final Object theRealVersion; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
95 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
96 |
private Version(Object version) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
97 |
this.theRealVersion = version; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
98 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
99 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
100 |
public static Version parse(String v) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
101 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
102 |
init(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
103 |
Object result = parseMethod.invoke(null, v); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
104 |
Version version = new Version(result); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
105 |
return version; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
106 |
} catch (InvocationTargetException ex) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
107 |
if (ex.getCause() instanceof IllegalArgumentException) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
108 |
throw (IllegalArgumentException) ex.getCause(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
109 |
} else { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
110 |
throw new Abort(ex); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
111 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
112 |
} catch (IllegalAccessException | IllegalArgumentException | SecurityException ex) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
113 |
throw new Abort(ex); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
114 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
115 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
116 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
117 |
@Override |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
118 |
public String toString() { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
119 |
return theRealVersion.toString(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
120 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
121 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
122 |
// ----------------------------------------------------------------------------------------- |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
123 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
124 |
private static Class<?> versionClass = null; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
125 |
private static Method parseMethod = null; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
126 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
127 |
private static void init() { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
128 |
if (versionClass == null) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
129 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
130 |
versionClass = Class.forName(CLASSNAME, false, null); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
131 |
parseMethod = versionClass.getDeclaredMethod("parse", String.class); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
132 |
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
133 |
throw new Abort(ex); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
134 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
135 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
136 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
137 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
138 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
139 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
140 |
/** |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
141 |
* Wrapper class for java.lang.module.ModuleFinder. |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
142 |
*/ |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
143 |
public static class ModuleFinder { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
144 |
private final Object theRealModuleFinder; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
145 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
146 |
private ModuleFinder(Object moduleFinder) { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
147 |
this.theRealModuleFinder = moduleFinder; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
148 |
init(); |
36526 | 149 |
} |
150 |
||
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
151 |
public static ModuleFinder of(Path... dirs) { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
152 |
try { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
153 |
init(); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
154 |
Object result = ofMethod.invoke(null, (Object)dirs); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
155 |
ModuleFinder mFinder = new ModuleFinder(result); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
156 |
return mFinder; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
157 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
158 |
| SecurityException ex) { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
159 |
throw new Abort(ex); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
160 |
} |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
161 |
} |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
162 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
163 |
// ----------------------------------------------------------------------------------------- |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
164 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
165 |
private static Class<?> moduleFinderClass = null; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
166 |
private static Method ofMethod; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
167 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
168 |
static final Class<?> getModuleFinderClass() { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
169 |
init(); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
170 |
return moduleFinderClass; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
171 |
} |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
172 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
173 |
private static void init() { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
174 |
if (moduleFinderClass == null) { |
36526 | 175 |
try { |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
176 |
moduleFinderClass = Class.forName("java.lang.module.ModuleFinder", false, null); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
177 |
ofMethod = moduleFinderClass.getDeclaredMethod("of", Path[].class); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
178 |
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
36526 | 179 |
throw new Abort(ex); |
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
} |
|
184 |
||
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
185 |
/** |
41033
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
186 |
* Wrapper class for java.lang.reflect.Module. To materialize a handle use the static factory |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
187 |
* methods Module#getModule(Class<?>) or Module#getUnnamedModule(ClassLoader). |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
188 |
*/ |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
189 |
public static class Module { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
190 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
191 |
private final Object theRealModule; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
192 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
193 |
private Module(Object module) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
194 |
this.theRealModule = module; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
195 |
init(); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
196 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
197 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
198 |
public static Module getModule(Class<?> clazz) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
199 |
try { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
200 |
init(); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
201 |
Object result = getModuleMethod.invoke(clazz, new Object[0]); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
202 |
return new Module(result); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
203 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
204 |
| SecurityException ex) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
205 |
throw new Abort(ex); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
206 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
207 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
208 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
209 |
public static Module getUnnamedModule(ClassLoader classLoader) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
210 |
try { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
211 |
init(); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
212 |
Object result = getUnnamedModuleMethod.invoke(classLoader, new Object[0]); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
213 |
return new Module(result); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
214 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
215 |
| SecurityException ex) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
216 |
throw new Abort(ex); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
217 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
218 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
219 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
220 |
public Module addExports(String pn, Module other) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
221 |
try { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
222 |
addExportsMethod.invoke(theRealModule, new Object[] { pn, other.theRealModule}); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
223 |
} catch (IllegalAccessException | InvocationTargetException ex) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
224 |
throw new Abort(ex); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
225 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
226 |
return this; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
227 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
228 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
229 |
public Module addUses(Class<?> st) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
230 |
try { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
231 |
addUsesMethod.invoke(theRealModule, new Object[] { st }); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
232 |
} catch (IllegalAccessException | InvocationTargetException ex) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
233 |
throw new Abort(ex); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
234 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
235 |
return this; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
236 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
237 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
238 |
// ----------------------------------------------------------------------------------------- |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
239 |
// on java.lang.reflect.Module |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
240 |
private static Method addExportsMethod = null; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
241 |
// on java.lang.reflect.Module |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
242 |
private static Method addUsesMethod = null; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
243 |
// on java.lang.Class |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
244 |
private static Method getModuleMethod; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
245 |
// on java.lang.ClassLoader |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
246 |
private static Method getUnnamedModuleMethod; |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
247 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
248 |
private static void init() { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
249 |
if (addExportsMethod == null) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
250 |
try { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
251 |
Class<?> moduleClass = Class.forName("java.lang.reflect.Module", false, null); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
252 |
addUsesMethod = moduleClass.getDeclaredMethod("addUses", new Class<?>[] { Class.class }); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
253 |
addExportsMethod = moduleClass.getDeclaredMethod("addExports", |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
254 |
new Class<?>[] { String.class, moduleClass }); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
255 |
getModuleMethod = Class.class.getDeclaredMethod("getModule", new Class<?>[0]); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
256 |
getUnnamedModuleMethod = ClassLoader.class.getDeclaredMethod("getUnnamedModule", new Class<?>[0]); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
257 |
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
258 |
throw new Abort(ex); |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
259 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
260 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
261 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
262 |
} |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
263 |
|
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
264 |
/** |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
265 |
* Wrapper class for java.lang.module.Configuration. |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
266 |
*/ |
36526 | 267 |
public static final class Configuration { |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
268 |
private final Object theRealConfiguration; |
36526 | 269 |
|
270 |
private Configuration(Object configuration) { |
|
271 |
this.theRealConfiguration = configuration; |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
272 |
init(); |
36526 | 273 |
} |
274 |
||
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42822
diff
changeset
|
275 |
public Configuration resolveAndBind( |
36526 | 276 |
ModuleFinder beforeFinder, |
277 |
ModuleFinder afterFinder, |
|
278 |
Collection<String> roots) { |
|
279 |
try { |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42822
diff
changeset
|
280 |
Object result = resolveAndBindMethod.invoke(theRealConfiguration, |
36526 | 281 |
beforeFinder.theRealModuleFinder, |
282 |
afterFinder.theRealModuleFinder, |
|
283 |
roots |
|
284 |
); |
|
285 |
Configuration configuration = new Configuration(result); |
|
286 |
return configuration; |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
287 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
288 |
| SecurityException ex) { |
36526 | 289 |
throw new Abort(ex); |
290 |
} |
|
291 |
} |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
292 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
293 |
// ----------------------------------------------------------------------------------------- |
36526 | 294 |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
295 |
private static Class<?> configurationClass = null; |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42822
diff
changeset
|
296 |
private static Method resolveAndBindMethod; |
36526 | 297 |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
298 |
static final Class<?> getConfigurationClass() { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
299 |
init(); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
300 |
return configurationClass; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
301 |
} |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
302 |
|
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
303 |
private static void init() { |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
304 |
if (configurationClass == null) { |
36526 | 305 |
try { |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
306 |
configurationClass = Class.forName("java.lang.module.Configuration", false, null); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
307 |
Class<?> moduleFinderInterface = ModuleFinder.getModuleFinderClass(); |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42822
diff
changeset
|
308 |
resolveAndBindMethod = configurationClass.getDeclaredMethod("resolveAndBind", |
36526 | 309 |
moduleFinderInterface, |
310 |
moduleFinderInterface, |
|
311 |
Collection.class |
|
312 |
); |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
313 |
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
36526 | 314 |
throw new Abort(ex); |
315 |
} |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
||
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
320 |
/** |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
321 |
* Wrapper class for java.lang.module.Layer. |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
322 |
*/ |
36526 | 323 |
public static final class Layer { |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
324 |
private final Object theRealLayer; |
36526 | 325 |
|
326 |
private Layer(Object layer) { |
|
327 |
this.theRealLayer = layer; |
|
328 |
} |
|
329 |
||
330 |
public static Layer boot() { |
|
331 |
try { |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
332 |
init(); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
333 |
Object result = bootMethod.invoke(null); |
36526 | 334 |
Layer layer = new Layer(result); |
335 |
return layer; |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
336 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
337 |
| SecurityException ex) { |
36526 | 338 |
throw new Abort(ex); |
339 |
} |
|
340 |
} |
|
341 |
||
342 |
public Configuration configuration() { |
|
343 |
try { |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
344 |
Object result = configurationMethod.invoke(theRealLayer); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
345 |
Configuration configuration = new Configuration(result); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
346 |
return configuration; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
347 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
348 |
| SecurityException ex) { |
36526 | 349 |
throw new Abort(ex); |
350 |
} |
|
351 |
} |
|
352 |
||
353 |
public Layer defineModulesWithOneLoader(Configuration configuration, ClassLoader parentClassLoader) { |
|
354 |
try { |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
355 |
Object result = defineModulesWithOneLoaderMethod.invoke( |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
356 |
theRealLayer, configuration.theRealConfiguration, parentClassLoader); |
36526 | 357 |
Layer layer = new Layer(result); |
358 |
return layer; |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
359 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
360 |
| SecurityException ex) { |
36526 | 361 |
throw new Abort(ex); |
362 |
} |
|
363 |
} |
|
364 |
||
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
365 |
// ----------------------------------------------------------------------------------------- |
36526 | 366 |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
367 |
private static Class<?> layerClass = null; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
368 |
private static Method bootMethod; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
369 |
private static Method defineModulesWithOneLoaderMethod; |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
370 |
private static Method configurationMethod; |
36526 | 371 |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
372 |
private static void init() { |
36526 | 373 |
if (layerClass == null) { |
374 |
try { |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
375 |
layerClass = Class.forName("java.lang.reflect.Layer", false, null); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
376 |
bootMethod = layerClass.getDeclaredMethod("boot"); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
377 |
defineModulesWithOneLoaderMethod = layerClass.getDeclaredMethod("defineModulesWithOneLoader", |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
378 |
Configuration.getConfigurationClass(), |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
379 |
ClassLoader.class); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
380 |
configurationMethod = layerClass.getDeclaredMethod("configuration"); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
37848
diff
changeset
|
381 |
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
36526 | 382 |
throw new Abort(ex); |
383 |
} |
|
384 |
} |
|
385 |
} |
|
386 |
} |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
387 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
388 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
389 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
390 |
* Helper class for new method in jdk.internal.misc.VM. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
391 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
392 |
public static final class VMHelper { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
393 |
public static final String CLASSNAME = "jdk.internal.misc.VM"; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
394 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
395 |
@SuppressWarnings("unchecked") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
396 |
public static String[] getRuntimeArguments() { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
397 |
try { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
398 |
init(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
399 |
Object result = getRuntimeArgumentsMethod.invoke(null); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
400 |
return (String[])result; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
401 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
402 |
| SecurityException ex) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
403 |
throw new Abort(ex); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
404 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
405 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
406 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
407 |
// ----------------------------------------------------------------------------------------- |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
408 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
409 |
private static Class<?> vmClass = null; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
410 |
private static Method getRuntimeArgumentsMethod = null; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
411 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
412 |
private static void init() { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
413 |
if (vmClass == null) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
414 |
try { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41440
diff
changeset
|
415 |
vmClass = Class.forName(CLASSNAME, false, null); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
416 |
getRuntimeArgumentsMethod = vmClass.getDeclaredMethod("getRuntimeArguments"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
417 |
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
418 |
throw new Abort(ex); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
419 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
420 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
421 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
422 |
} |
41440 | 423 |
|
424 |
/** |
|
425 |
* Helper class for new method in jdk.internal.jmod.JmodFile |
|
426 |
*/ |
|
427 |
public static final class JmodFile { |
|
428 |
public static final String JMOD_FILE_CLASSNAME = "jdk.internal.jmod.JmodFile"; |
|
429 |
||
430 |
public static void checkMagic(Path file) throws IOException { |
|
431 |
try { |
|
432 |
init(); |
|
433 |
checkMagicMethod.invoke(null, file); |
|
434 |
} catch (InvocationTargetException ex) { |
|
435 |
if (ex.getCause() instanceof IOException) { |
|
436 |
throw IOException.class.cast(ex.getCause()); |
|
437 |
} |
|
438 |
throw new Abort(ex); |
|
439 |
} catch (IllegalAccessException | IllegalArgumentException | SecurityException ex) { |
|
440 |
throw new Abort(ex); |
|
441 |
} |
|
442 |
} |
|
443 |
||
444 |
// ----------------------------------------------------------------------------------------- |
|
445 |
||
446 |
private static Class<?> jmodFileClass = null; |
|
447 |
private static Method checkMagicMethod = null; |
|
448 |
||
449 |
private static void init() { |
|
450 |
if (jmodFileClass == null) { |
|
451 |
try { |
|
452 |
jmodFileClass = Class.forName(JMOD_FILE_CLASSNAME, false, null); |
|
453 |
checkMagicMethod = jmodFileClass.getDeclaredMethod("checkMagic", Path.class); |
|
454 |
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
|
455 |
throw new Abort(ex); |
|
456 |
} |
|
457 |
} |
|
458 |
} |
|
459 |
} |
|
36526 | 460 |
} |