mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8173393: Module system implementation refresh (2/2017)
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com> Reviewed-by: lfoltan, acorn, mchung
This commit is contained in:
parent
27dc8df66b
commit
9db79d57c8
59 changed files with 1070 additions and 1069 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -35,15 +35,15 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// Java System Class Loader --> defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
// Java System Class Loader --> defines m3x --> packages p3
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m1 and m3
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m1x and m3x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access allowed since m1 can read m2 and package p2 is exported to m1.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access allowed since m1x can read m2x and package p2 is exported to m1x.
|
||||
//
|
||||
public class ModuleNonBuiltinCLMain {
|
||||
|
||||
|
@ -52,62 +52,62 @@ public class ModuleNonBuiltinCLMain {
|
|||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported to unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Can read: java.base, m3
|
||||
// Define module: m2x
|
||||
// Can read: java.base, m3x
|
||||
// Packages: p2
|
||||
// Packages exported: package p2 is exported to m1 and m3
|
||||
// Packages exported: package p2 is exported to m1x and m3x
|
||||
Set<String> targets = new HashSet<>();
|
||||
targets.add("m1");
|
||||
targets.add("m3");
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
targets.add("m1x");
|
||||
targets.add("m3x");
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.requires("m3")
|
||||
.requires("m3x")
|
||||
.exports("p2", targets)
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Define module: m3x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing user defined class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
Loader1 cl1 = new Loader1();
|
||||
Loader2 cl2 = new Loader2();
|
||||
ClassLoader cl3 = ClassLoader.getSystemClassLoader();
|
||||
map.put("m1", cl1);
|
||||
map.put("m2", cl2);
|
||||
map.put("m3", cl3);
|
||||
map.put("m1x", cl1);
|
||||
map.put("m2x", cl2);
|
||||
map.put("m3x", cl3);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
assertTrue(layer.findLoader("m1") == cl1);
|
||||
assertTrue(layer.findLoader("m2") == cl2);
|
||||
assertTrue(layer.findLoader("m3") == cl3);
|
||||
assertTrue(layer.findLoader("m1x") == cl1);
|
||||
assertTrue(layer.findLoader("m2x") == cl2);
|
||||
assertTrue(layer.findLoader("m3x") == cl3);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
|
@ -115,7 +115,7 @@ public class ModuleNonBuiltinCLMain {
|
|||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue