1355 throw new UnsupportedOperationException();
1356 }
1357 };
1358
1359 final ModuleFinder finder = new ModuleFinder() {
1360 @Override
1361 public Optional<ModuleReference> find(final String name) {
1362 if (name.equals(mn)) {
1363 return Optional.of(mref);
1364 } else {
1365 return Optional.empty();
1366 }
1367 }
1368 @Override
1369 public Set<ModuleReference> findAll() {
1370 return Set.of(mref);
1371 }
1372 };
1373
1374 final Configuration cf = parent.configuration()
1375 .resolveRequires(finder, ModuleFinder.of(), Set.of(mn));
1376
1377 final PrivilegedAction<Layer> pa = () -> parent.defineModules(cf, name -> loader);
1378 final Layer layer = AccessController.doPrivileged(pa, GET_LOADER_ACC_CTXT);
1379
1380 final Module m = layer.findModule(mn).get();
1381 assert m.getLayer() == layer;
1382
1383 return m;
1384 }
1385
1386 static Context getContextTrustedOrNull() {
1387 final Global global = Context.getGlobal();
1388 return global == null ? null : getContext(global);
1389 }
1390
1391 private static Context getContext(final Global global) {
1392 // We can't invoke Global.getContext() directly, as it's a protected override, and Global isn't in our package.
1393 // In order to access the method, we must cast it to ScriptObject first (which is in our package) and then let
1394 // virtual invocation do its thing.
1395 return ((ScriptObject)global).getContext();
1781 toArray(sz -> new Path[sz]);
1782 final ModuleFinder mf = ModuleFinder.of(paths);
1783 final Set<ModuleReference> mrefs = mf.findAll();
1784 if (mrefs.isEmpty()) {
1785 throw new RuntimeException("No modules in script --module-path: " + modulePath);
1786 }
1787
1788 final Set<String> rootMods;
1789 if (addModules.equals("ALL-MODULE-PATH")) {
1790 rootMods = mrefs.stream().
1791 map(mr->mr.descriptor().name()).
1792 collect(Collectors.toSet());
1793 } else {
1794 rootMods = Stream.of(addModules.split(",")).
1795 map(String::trim).
1796 collect(Collectors.toSet());
1797 }
1798
1799 final Layer boot = Layer.boot();
1800 final Configuration conf = boot.configuration().
1801 resolveRequires(mf, ModuleFinder.of(), rootMods);
1802 final String firstMod = rootMods.iterator().next();
1803 return boot.defineModulesWithOneLoader(conf, cl).findLoader(firstMod);
1804 }
1805 }
|
1355 throw new UnsupportedOperationException();
1356 }
1357 };
1358
1359 final ModuleFinder finder = new ModuleFinder() {
1360 @Override
1361 public Optional<ModuleReference> find(final String name) {
1362 if (name.equals(mn)) {
1363 return Optional.of(mref);
1364 } else {
1365 return Optional.empty();
1366 }
1367 }
1368 @Override
1369 public Set<ModuleReference> findAll() {
1370 return Set.of(mref);
1371 }
1372 };
1373
1374 final Configuration cf = parent.configuration()
1375 .resolve(finder, ModuleFinder.of(), Set.of(mn));
1376
1377 final PrivilegedAction<Layer> pa = () -> parent.defineModules(cf, name -> loader);
1378 final Layer layer = AccessController.doPrivileged(pa, GET_LOADER_ACC_CTXT);
1379
1380 final Module m = layer.findModule(mn).get();
1381 assert m.getLayer() == layer;
1382
1383 return m;
1384 }
1385
1386 static Context getContextTrustedOrNull() {
1387 final Global global = Context.getGlobal();
1388 return global == null ? null : getContext(global);
1389 }
1390
1391 private static Context getContext(final Global global) {
1392 // We can't invoke Global.getContext() directly, as it's a protected override, and Global isn't in our package.
1393 // In order to access the method, we must cast it to ScriptObject first (which is in our package) and then let
1394 // virtual invocation do its thing.
1395 return ((ScriptObject)global).getContext();
1781 toArray(sz -> new Path[sz]);
1782 final ModuleFinder mf = ModuleFinder.of(paths);
1783 final Set<ModuleReference> mrefs = mf.findAll();
1784 if (mrefs.isEmpty()) {
1785 throw new RuntimeException("No modules in script --module-path: " + modulePath);
1786 }
1787
1788 final Set<String> rootMods;
1789 if (addModules.equals("ALL-MODULE-PATH")) {
1790 rootMods = mrefs.stream().
1791 map(mr->mr.descriptor().name()).
1792 collect(Collectors.toSet());
1793 } else {
1794 rootMods = Stream.of(addModules.split(",")).
1795 map(String::trim).
1796 collect(Collectors.toSet());
1797 }
1798
1799 final Layer boot = Layer.boot();
1800 final Configuration conf = boot.configuration().
1801 resolve(mf, ModuleFinder.of(), rootMods);
1802 final String firstMod = rootMods.iterator().next();
1803 return boot.defineModulesWithOneLoader(conf, cl).findLoader(firstMod);
1804 }
1805 }
|