author | mchung |
Tue, 06 Nov 2018 10:01:16 -0800 | |
changeset 52427 | 3c6aa484536c |
parent 51327 | a19fda433921 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
51327
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
package jdk.internal.module; |
|
26 |
||
27 |
import java.lang.module.ModuleDescriptor; |
|
28 |
import java.lang.module.ModuleDescriptor.Exports; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
29 |
import java.lang.module.ModuleDescriptor.Opens; |
36511 | 30 |
import java.lang.module.ModuleDescriptor.Provides; |
31 |
import java.lang.module.ModuleDescriptor.Requires; |
|
32 |
import java.lang.module.ModuleDescriptor.Version; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
33 |
import java.util.List; |
36511 | 34 |
import java.util.Set; |
35 |
||
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
51327
diff
changeset
|
36 |
import jdk.internal.access.JavaLangModuleAccess; |
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
51327
diff
changeset
|
37 |
import jdk.internal.access.SharedSecrets; |
36511 | 38 |
|
39 |
/** |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
40 |
* This builder is optimized for reconstituting the {@code ModuleDescriptor}s |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
41 |
* for system modules. The validation should be done at jlink time. |
36511 | 42 |
* |
43 |
* 1. skip name validation |
|
44 |
* 2. ignores dependency hashes. |
|
45 |
* 3. ModuleDescriptor skips the defensive copy and directly uses the |
|
46 |
* sets/maps created in this Builder. |
|
47 |
* |
|
48 |
* SystemModules should contain modules for the boot layer. |
|
49 |
*/ |
|
50 |
final class Builder { |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
51 |
private static final JavaLangModuleAccess JLMA = |
36511 | 52 |
SharedSecrets.getJavaLangModuleAccess(); |
53 |
||
54 |
// Static cache of the most recently seen Version to cheaply deduplicate |
|
55 |
// most Version objects. JDK modules have the same version. |
|
56 |
static Version cachedVersion; |
|
57 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
58 |
/** |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
59 |
* Returns a {@link Requires} for a dependence on a module with the given |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
60 |
* (and possibly empty) set of modifiers, and optionally the version |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
61 |
* recorded at compile time. |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
62 |
*/ |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
63 |
public static Requires newRequires(Set<Requires.Modifier> mods, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
64 |
String mn, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
65 |
String compiledVersion) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
66 |
{ |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
67 |
Version version = null; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
68 |
if (compiledVersion != null) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
69 |
// use the cached version if the same version string |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
70 |
Version ver = cachedVersion; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
71 |
if (ver != null && compiledVersion.equals(ver.toString())) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
72 |
version = ver; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
73 |
} else { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
74 |
version = Version.parse(compiledVersion); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
75 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
76 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
77 |
return JLMA.newRequires(mods, mn, version); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
78 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
79 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
80 |
/** |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
81 |
* Returns a {@link Requires} for a dependence on a module with the given |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
82 |
* (and possibly empty) set of modifiers, and optionally the version |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
83 |
* recorded at compile time. |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
84 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
85 |
public static Requires newRequires(Set<Requires.Modifier> mods, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
86 |
String mn) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
87 |
{ |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
88 |
return newRequires(mods, mn, null); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
89 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
90 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
91 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
92 |
* Returns a {@link Exports} for a qualified export, with |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
93 |
* the given (and possibly empty) set of modifiers, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
94 |
* to a set of target modules. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
95 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
96 |
public static Exports newExports(Set<Exports.Modifier> ms, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
97 |
String pn, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
98 |
Set<String> targets) { |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
99 |
return JLMA.newExports(ms, pn, targets); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
100 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
101 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
102 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
103 |
* Returns an {@link Opens} for an unqualified open with a given set of |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
104 |
* modifiers. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
105 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
106 |
public static Opens newOpens(Set<Opens.Modifier> ms, String pn) { |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
107 |
return JLMA.newOpens(ms, pn); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
108 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
109 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
110 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
111 |
* Returns an {@link Opens} for a qualified opens, with |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
112 |
* the given (and possibly empty) set of modifiers, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
113 |
* to a set of target modules. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
114 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
115 |
public static Opens newOpens(Set<Opens.Modifier> ms, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
116 |
String pn, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
117 |
Set<String> targets) { |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
118 |
return JLMA.newOpens(ms, pn, targets); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
119 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
120 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
121 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
122 |
* Returns a {@link Exports} for an unqualified export with a given set |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
123 |
* of modifiers. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
124 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
125 |
public static Exports newExports(Set<Exports.Modifier> ms, String pn) { |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
126 |
return JLMA.newExports(ms, pn); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
127 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
128 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
129 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
130 |
* Returns a {@link Provides} for a service with a given list of |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
131 |
* implementation classes. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
132 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
133 |
public static Provides newProvides(String st, List<String> pcs) { |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
134 |
return JLMA.newProvides(st, pcs); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
135 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
136 |
|
36511 | 137 |
final String name; |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
138 |
boolean open, synthetic, mandated; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
139 |
Set<Requires> requires; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
140 |
Set<Exports> exports; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
141 |
Set<Opens> opens; |
38888
dd584fbea6a2
8159334: ModuleDescriptor retains overlapping sets for all and concealed packages
redestad
parents:
37779
diff
changeset
|
142 |
Set<String> packages; |
36511 | 143 |
Set<String> uses; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
144 |
Set<Provides> provides; |
36511 | 145 |
Version version; |
146 |
String mainClass; |
|
147 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
148 |
Builder(String name) { |
36511 | 149 |
this.name = name; |
51327
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
47216
diff
changeset
|
150 |
this.requires = Set.of(); |
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
47216
diff
changeset
|
151 |
this.exports = Set.of(); |
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
47216
diff
changeset
|
152 |
this.opens = Set.of(); |
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
47216
diff
changeset
|
153 |
this.provides = Set.of(); |
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
47216
diff
changeset
|
154 |
this.uses = Set.of(); |
36511 | 155 |
} |
156 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
157 |
Builder open(boolean value) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
158 |
this.open = value; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
159 |
return this; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
160 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
161 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
162 |
Builder synthetic(boolean value) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
163 |
this.synthetic = value; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
164 |
return this; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
165 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
166 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
167 |
Builder mandated(boolean value) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
168 |
this.mandated = value; |
36511 | 169 |
return this; |
170 |
} |
|
171 |
||
172 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
173 |
* Sets module exports. |
36511 | 174 |
*/ |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
175 |
public Builder exports(Exports[] exports) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
176 |
this.exports = Set.of(exports); |
36511 | 177 |
return this; |
178 |
} |
|
179 |
||
180 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
181 |
* Sets module opens. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
182 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
183 |
public Builder opens(Opens[] opens) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
184 |
this.opens = Set.of(opens); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
185 |
return this; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
186 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
187 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
188 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
189 |
* Sets module requires. |
36511 | 190 |
*/ |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
191 |
public Builder requires(Requires[] requires) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
192 |
this.requires = Set.of(requires); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
193 |
return this; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
194 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
195 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
196 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
197 |
* Adds a set of (possible empty) packages. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
198 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
199 |
public Builder packages(Set<String> packages) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
200 |
this.packages = packages; |
36511 | 201 |
return this; |
202 |
} |
|
203 |
||
204 |
/** |
|
205 |
* Sets the set of service dependences. |
|
206 |
*/ |
|
207 |
public Builder uses(Set<String> uses) { |
|
208 |
this.uses = uses; |
|
209 |
return this; |
|
210 |
} |
|
211 |
||
212 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
213 |
* Sets module provides. |
36511 | 214 |
*/ |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
215 |
public Builder provides(Provides[] provides) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
216 |
this.provides = Set.of(provides); |
36511 | 217 |
return this; |
218 |
} |
|
219 |
||
220 |
/** |
|
221 |
* Sets the module version. |
|
222 |
* |
|
223 |
* @throws IllegalArgumentException if {@code v} is null or cannot be |
|
224 |
* parsed as a version string |
|
225 |
* |
|
226 |
* @see Version#parse(String) |
|
227 |
*/ |
|
228 |
public Builder version(String v) { |
|
229 |
Version ver = cachedVersion; |
|
230 |
if (ver != null && v.equals(ver.toString())) { |
|
231 |
version = ver; |
|
232 |
} else { |
|
233 |
cachedVersion = version = Version.parse(v); |
|
234 |
} |
|
235 |
return this; |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Sets the module main class. |
|
240 |
*/ |
|
241 |
public Builder mainClass(String mc) { |
|
242 |
mainClass = mc; |
|
243 |
return this; |
|
244 |
} |
|
245 |
||
246 |
/** |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
247 |
* Returns an immutable set of the module modifiers derived from the flags. |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
248 |
*/ |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
249 |
private Set<ModuleDescriptor.Modifier> modifiers() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
250 |
int n = 0; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
251 |
if (open) n++; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
252 |
if (synthetic) n++; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
253 |
if (mandated) n++; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
254 |
if (n == 0) { |
51327
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
47216
diff
changeset
|
255 |
return Set.of(); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
256 |
} else { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
257 |
ModuleDescriptor.Modifier[] mods = new ModuleDescriptor.Modifier[n]; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
258 |
if (open) mods[--n] = ModuleDescriptor.Modifier.OPEN; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
259 |
if (synthetic) mods[--n] = ModuleDescriptor.Modifier.SYNTHETIC; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
260 |
if (mandated) mods[--n] = ModuleDescriptor.Modifier.MANDATED; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
261 |
return Set.of(mods); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
262 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
263 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
264 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
265 |
/** |
36511 | 266 |
* Builds a {@code ModuleDescriptor} from the components. |
267 |
*/ |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
268 |
public ModuleDescriptor build(int hashCode) { |
36511 | 269 |
assert name != null; |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
270 |
return JLMA.newModuleDescriptor(name, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
271 |
version, |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
272 |
modifiers(), |
36511 | 273 |
requires, |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
274 |
exports, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
275 |
opens, |
36511 | 276 |
uses, |
277 |
provides, |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
278 |
packages, |
36511 | 279 |
mainClass, |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38888
diff
changeset
|
280 |
hashCode); |
36511 | 281 |
} |
282 |
} |