author | alanb |
Tue, 19 Nov 2019 11:35:29 +0000 | |
changeset 59133 | 580fb715b29d |
permissions | -rw-r--r-- |
59133
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
1 |
/* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
4 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
8 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
14 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
18 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
21 |
* questions. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
22 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
23 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
24 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
25 |
* @test |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
26 |
* @bug 8233922 |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
27 |
* @modules java.base/jdk.internal.module |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
28 |
* @library /test/lib |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
29 |
* @build ServiceBinding TestBootLayer |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
30 |
* @run testng ServiceBinding |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
31 |
* @summary Test service binding with incubator modules |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
32 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
33 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
34 |
import java.io.File; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
35 |
import java.io.OutputStream; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
36 |
import java.lang.module.ModuleDescriptor; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
37 |
import java.lang.module.Configuration; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
38 |
import java.lang.module.ModuleFinder; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
39 |
import java.lang.module.ResolvedModule; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
40 |
import java.nio.file.Path; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
41 |
import java.nio.file.Files; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
42 |
import java.util.List; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
43 |
import java.util.Set; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
44 |
import java.util.stream.Collectors; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
45 |
import java.util.stream.Stream; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
46 |
import java.util.stream.Stream; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
47 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
48 |
import static java.lang.module.ModuleDescriptor.newModule; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
49 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
50 |
import jdk.internal.module.ModuleInfoWriter; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
51 |
import jdk.internal.module.ModuleResolution; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
52 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
53 |
import org.testng.annotations.Test; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
54 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
55 |
import jdk.test.lib.process.ProcessTools; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
56 |
import jdk.test.lib.process.OutputAnalyzer; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
57 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
58 |
@Test |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
59 |
public class ServiceBinding { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
60 |
private static final Path HERE = Path.of("."); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
61 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
62 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
63 |
* module m1 uses p.S |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
64 |
* (incubating) module m2 requires m1 provides p.S |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
65 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
66 |
public void test1() throws Exception { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
67 |
Path mlib = Files.createTempDirectory(HERE, "mlib"); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
68 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
69 |
var m1 = newModule("m1").exports("p").uses("p.S").build(); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
70 |
var m2 = newModule("m2").requires("m1").provides("p.S", List.of("impl.S1")).build(); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
71 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
72 |
writeModule(mlib, m1); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
73 |
writeIncubatingModule(mlib, m2); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
74 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
75 |
// boot layer: root=m1, incubator module m2 should not be resolved |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
76 |
testBootLayer(mlib, Set.of("m1"), Set.of("m1"), Set.of("m2")) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
77 |
.shouldNotMatch("WARNING:.*m2"); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
78 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
79 |
// custom configuration: root=m1, incubator module m2 should be resolved |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
80 |
testCustomConfiguration(mlib, Set.of("m1"), Set.of("m2")); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
81 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
82 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
83 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
84 |
* module m1 uses p.S |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
85 |
* (incubating) module m2 requires m1 provides P.S uses q.S |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
86 |
* (incubating) module m3 requires m2 provides q.S |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
87 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
88 |
public void test2() throws Exception { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
89 |
Path mlib = Files.createTempDirectory("mlib"); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
90 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
91 |
var m1 = newModule("m1").exports("p").uses("p.S").build(); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
92 |
var m2 = newModule("m2") |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
93 |
.requires("m1") |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
94 |
.provides("p.S", List.of("impl.S1")) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
95 |
.exports("q") |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
96 |
.uses("q.S") |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
97 |
.build(); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
98 |
var m3 = newModule("m3").requires("m2").provides("q.S", List.of("impl.S1")).build(); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
99 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
100 |
writeModule(mlib, m1); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
101 |
writeIncubatingModule(mlib, m2); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
102 |
writeIncubatingModule(mlib, m3); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
103 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
104 |
// boot layer: root=m1, incubator modules m2 and m3 should not be resolved |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
105 |
testBootLayer(mlib, Set.of("m1"), Set.of("m1"), Set.of("m2", "m3")) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
106 |
.shouldNotMatch("WARNING:.*m2") |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
107 |
.shouldNotMatch("WARNING:.*m3"); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
108 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
109 |
// boot layer: root=m2, incubator module m3 should not be resolved |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
110 |
testBootLayer(mlib, Set.of("m2"), Set.of("m1", "m2"), Set.of("m3")) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
111 |
.shouldMatch("WARNING:.*m2") |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
112 |
.shouldNotMatch("WARNING:.*m3"); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
113 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
114 |
// custom configuration: root=m1, incubator modules m2 and m3 should be resolved |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
115 |
testCustomConfiguration(mlib, Set.of("m1"), Set.of("m1", "m2", "m3")); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
116 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
117 |
// custom configuration: root=m2, incubator module m3 should be resolved |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
118 |
testCustomConfiguration(mlib, Set.of("m2"), Set.of("m1", "m2", "m3")); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
119 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
120 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
121 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
122 |
* Creates an exploded module on the file system. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
123 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
124 |
* @param mlib the top-level module directory |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
125 |
* @param descriptor the module descriptor of the module to write |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
126 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
127 |
void writeModule(Path mlib, ModuleDescriptor descriptor) throws Exception { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
128 |
writeModule(mlib, descriptor, false); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
129 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
130 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
131 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
132 |
* Creates an exploded module on the file system. The module will be an |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
133 |
* incubating module. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
134 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
135 |
* @param mlib the top-level module directory |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
136 |
* @param descriptor the module descriptor of the module to write |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
137 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
138 |
void writeIncubatingModule(Path mlib, ModuleDescriptor descriptor) throws Exception { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
139 |
writeModule(mlib, descriptor, true); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
140 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
141 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
142 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
143 |
* Creates an exploded module on the file system. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
144 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
145 |
* @param mlib the top-level module directory |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
146 |
* @param descriptor the module descriptor of the module to write |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
147 |
* @param incubating to create an incubating module |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
148 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
149 |
void writeModule(Path mlib, ModuleDescriptor descriptor, boolean incubating) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
150 |
throws Exception |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
151 |
{ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
152 |
// create ModuleResolution attribute if incubating module |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
153 |
ModuleResolution mres = (incubating) ? ModuleResolution.empty().withIncubating() : null; |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
154 |
String name = descriptor.name(); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
155 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
156 |
// create directory for module |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
157 |
Path dir = Files.createDirectory(mlib.resolve(name)); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
158 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
159 |
// module-info.class |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
160 |
try (OutputStream out = Files.newOutputStream(dir.resolve("module-info.class"))) { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
161 |
ModuleInfoWriter.write(descriptor, mres, out); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
162 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
163 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
164 |
// create a dummy class file for each package |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
165 |
for (String pn : descriptor.packages()) { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
166 |
Path subdir = dir.resolve(pn.replace('.', File.separatorChar)); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
167 |
Files.createDirectories(subdir); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
168 |
Files.createFile(subdir.resolve("C.class")); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
169 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
170 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
171 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
172 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
173 |
* Run TestBootLayer in a child VM with the given module path and the |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
174 |
* --add-modules option with additional root modules. TestBootLayer checks |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
175 |
* the modules in the boot layer. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
176 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
177 |
* @param mlib the module path |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
178 |
* @param roots the modules to specify to --add-modules |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
179 |
* @param expected the names of modules that should be in the boot layer |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
180 |
* @param notExpected the names of modules that should not be in boot layer |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
181 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
182 |
OutputAnalyzer testBootLayer(Path mlib, |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
183 |
Set<String> roots, |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
184 |
Set<String> expected, |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
185 |
Set<String> notExpected) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
186 |
throws Exception |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
187 |
{ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
188 |
var opts = Stream.of("-p", mlib.toString(), |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
189 |
"--add-modules", commaSeparated(roots), |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
190 |
"TestBootLayer", commaSeparated(expected), commaSeparated(notExpected)); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
191 |
return ProcessTools.executeTestJava(opts.toArray(String[]::new)) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
192 |
.outputTo(System.out) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
193 |
.errorTo(System.out) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
194 |
.shouldHaveExitValue(0); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
195 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
196 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
197 |
/** |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
198 |
* Creates a Configuration by resolving a set of root modules, with service |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
199 |
* binding, then checks that the Configuration includes the expected modules. |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
200 |
* |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
201 |
* @param mlib the module path |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
202 |
* @param roots the names of the root modules |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
203 |
* @param expected the names of modules that should be in the configuration |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
204 |
*/ |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
205 |
void testCustomConfiguration(Path mlib, Set<String> roots, Set<String> expected) { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
206 |
ModuleFinder finder = ModuleFinder.of(mlib); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
207 |
Configuration cf = ModuleLayer.boot() |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
208 |
.configuration() |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
209 |
.resolveAndBind(finder, ModuleFinder.of(), roots); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
210 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
211 |
Set<String> modules = cf.modules().stream() |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
212 |
.map(ResolvedModule::name) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
213 |
.collect(Collectors.toSet()); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
214 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
215 |
expected.stream() |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
216 |
.filter(mn -> !modules.contains(mn)) |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
217 |
.findAny() |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
218 |
.ifPresent(mn -> { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
219 |
throw new RuntimeException(mn + " not in configuration!!!"); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
220 |
}); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
221 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
222 |
|
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
223 |
String commaSeparated(Set<String> s) { |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
224 |
return s.stream().collect(Collectors.joining(",")); |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
225 |
} |
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff
changeset
|
226 |
} |