126 |
126 |
127 boolean isOpen = descriptor.isOpen(); |
127 boolean isOpen = descriptor.isOpen(); |
128 Version version = descriptor.version().orElse(null); |
128 Version version = descriptor.version().orElse(null); |
129 String vs = Objects.toString(version, null); |
129 String vs = Objects.toString(version, null); |
130 String loc = Objects.toString(uri, null); |
130 String loc = Objects.toString(uri, null); |
131 Set<String> packages = descriptor.packages(); |
131 String[] packages = descriptor.packages().toArray(new String[0]); |
132 int n = packages.size(); |
132 defineModule0(this, isOpen, vs, loc, packages); |
133 String[] array = new String[n]; |
|
134 int i = 0; |
|
135 for (String pn : packages) { |
|
136 array[i++] = pn.replace('.', '/'); |
|
137 } |
|
138 defineModule0(this, isOpen, vs, loc, array); |
|
139 } |
133 } |
140 |
134 |
141 |
135 |
142 /** |
136 /** |
143 * Create the unnamed Module for the given ClassLoader. |
137 * Create the unnamed Module for the given ClassLoader. |
787 + " not in contents"); |
781 + " not in contents"); |
788 } |
782 } |
789 |
783 |
790 // update VM first, just in case it fails |
784 // update VM first, just in case it fails |
791 if (syncVM) { |
785 if (syncVM) { |
792 String pkgInternalForm = pn.replace('.', '/'); |
|
793 if (other == EVERYONE_MODULE) { |
786 if (other == EVERYONE_MODULE) { |
794 addExportsToAll0(this, pkgInternalForm); |
787 addExportsToAll0(this, pn); |
795 } else if (other == ALL_UNNAMED_MODULE) { |
788 } else if (other == ALL_UNNAMED_MODULE) { |
796 addExportsToAllUnnamed0(this, pkgInternalForm); |
789 addExportsToAllUnnamed0(this, pn); |
797 } else { |
790 } else { |
798 addExports0(this, pkgInternalForm, other); |
791 addExports0(this, pn, other); |
799 } |
792 } |
800 } |
793 } |
801 |
794 |
802 // add package name to reflectivelyExports if absent |
795 // add package name to reflectivelyExports if absent |
803 Map<String, Boolean> map = reflectivelyExports |
796 Map<String, Boolean> map = reflectivelyExports |
1178 { |
1171 { |
1179 // The VM doesn't know about open modules so need to export all packages |
1172 // The VM doesn't know about open modules so need to export all packages |
1180 if (descriptor.isOpen()) { |
1173 if (descriptor.isOpen()) { |
1181 assert descriptor.opens().isEmpty(); |
1174 assert descriptor.opens().isEmpty(); |
1182 for (String source : descriptor.packages()) { |
1175 for (String source : descriptor.packages()) { |
1183 String sourceInternalForm = source.replace('.', '/'); |
1176 addExportsToAll0(m, source); |
1184 addExportsToAll0(m, sourceInternalForm); |
|
1185 } |
1177 } |
1186 return; |
1178 return; |
1187 } |
1179 } |
1188 |
1180 |
1189 Map<String, Set<Module>> openPackages = new HashMap<>(); |
1181 Map<String, Set<Module>> openPackages = new HashMap<>(); |
1190 Map<String, Set<Module>> exportedPackages = new HashMap<>(); |
1182 Map<String, Set<Module>> exportedPackages = new HashMap<>(); |
1191 |
1183 |
1192 // process the open packages first |
1184 // process the open packages first |
1193 for (Opens opens : descriptor.opens()) { |
1185 for (Opens opens : descriptor.opens()) { |
1194 String source = opens.source(); |
1186 String source = opens.source(); |
1195 String sourceInternalForm = source.replace('.', '/'); |
|
1196 |
1187 |
1197 if (opens.isQualified()) { |
1188 if (opens.isQualified()) { |
1198 // qualified opens |
1189 // qualified opens |
1199 Set<Module> targets = new HashSet<>(); |
1190 Set<Module> targets = new HashSet<>(); |
1200 for (String target : opens.targets()) { |
1191 for (String target : opens.targets()) { |
1201 // only open to modules that are in this configuration |
1192 // only open to modules that are in this configuration |
1202 Module m2 = nameToModule.get(target); |
1193 Module m2 = nameToModule.get(target); |
1203 if (m2 != null) { |
1194 if (m2 != null) { |
1204 addExports0(m, sourceInternalForm, m2); |
1195 addExports0(m, source, m2); |
1205 targets.add(m2); |
1196 targets.add(m2); |
1206 } |
1197 } |
1207 } |
1198 } |
1208 if (!targets.isEmpty()) { |
1199 if (!targets.isEmpty()) { |
1209 openPackages.put(source, targets); |
1200 openPackages.put(source, targets); |
1210 } |
1201 } |
1211 } else { |
1202 } else { |
1212 // unqualified opens |
1203 // unqualified opens |
1213 addExportsToAll0(m, sourceInternalForm); |
1204 addExportsToAll0(m, source); |
1214 openPackages.put(source, EVERYONE_SET); |
1205 openPackages.put(source, EVERYONE_SET); |
1215 } |
1206 } |
1216 } |
1207 } |
1217 |
1208 |
1218 // next the exports, skipping exports when the package is open |
1209 // next the exports, skipping exports when the package is open |
1219 for (Exports exports : descriptor.exports()) { |
1210 for (Exports exports : descriptor.exports()) { |
1220 String source = exports.source(); |
1211 String source = exports.source(); |
1221 String sourceInternalForm = source.replace('.', '/'); |
|
1222 |
1212 |
1223 // skip export if package is already open to everyone |
1213 // skip export if package is already open to everyone |
1224 Set<Module> openToTargets = openPackages.get(source); |
1214 Set<Module> openToTargets = openPackages.get(source); |
1225 if (openToTargets != null && openToTargets.contains(EVERYONE_MODULE)) |
1215 if (openToTargets != null && openToTargets.contains(EVERYONE_MODULE)) |
1226 continue; |
1216 continue; |
1232 // only export to modules that are in this configuration |
1222 // only export to modules that are in this configuration |
1233 Module m2 = nameToModule.get(target); |
1223 Module m2 = nameToModule.get(target); |
1234 if (m2 != null) { |
1224 if (m2 != null) { |
1235 // skip qualified export if already open to m2 |
1225 // skip qualified export if already open to m2 |
1236 if (openToTargets == null || !openToTargets.contains(m2)) { |
1226 if (openToTargets == null || !openToTargets.contains(m2)) { |
1237 addExports0(m, sourceInternalForm, m2); |
1227 addExports0(m, source, m2); |
1238 targets.add(m2); |
1228 targets.add(m2); |
1239 } |
1229 } |
1240 } |
1230 } |
1241 } |
1231 } |
1242 if (!targets.isEmpty()) { |
1232 if (!targets.isEmpty()) { |
1243 exportedPackages.put(source, targets); |
1233 exportedPackages.put(source, targets); |
1244 } |
1234 } |
1245 |
1235 |
1246 } else { |
1236 } else { |
1247 // unqualified exports |
1237 // unqualified exports |
1248 addExportsToAll0(m, sourceInternalForm); |
1238 addExportsToAll0(m, source); |
1249 exportedPackages.put(source, EVERYONE_SET); |
1239 exportedPackages.put(source, EVERYONE_SET); |
1250 } |
1240 } |
1251 } |
1241 } |
1252 |
1242 |
1253 if (!openPackages.isEmpty()) |
1243 if (!openPackages.isEmpty()) |