author | mbaesken |
Wed, 10 Apr 2019 08:51:38 +0200 | |
changeset 54485 | ddc19ea5059c |
parent 52804 | 28094715ae71 |
permissions | -rw-r--r-- |
42338 | 1 |
/* |
52804
28094715ae71
8214718: Update missing copyright year in build system
ihse
parents:
51499
diff
changeset
|
2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
42338 | 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 |
||
26 |
package build.tools.module; |
|
27 |
||
28 |
import java.io.BufferedWriter; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.PrintWriter; |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
31 |
import java.io.UncheckedIOException; |
42338 | 32 |
import java.nio.file.Files; |
33 |
import java.nio.file.Path; |
|
34 |
import java.nio.file.Paths; |
|
35 |
import java.util.Arrays; |
|
36 |
import java.util.Collections; |
|
37 |
import java.util.HashSet; |
|
38 |
import java.util.List; |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
39 |
import java.util.Map; |
42338 | 40 |
import java.util.Set; |
41 |
import build.tools.module.GenModuleInfoSource.Statement; |
|
42 |
||
43 |
/** |
|
44 |
* Sanity test for GenModuleInfoSource tool |
|
45 |
*/ |
|
46 |
public class ModuleInfoExtraTest { |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
47 |
private static final Path DIR = Paths.get("gen-module-info-test"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
48 |
private static boolean verbose = false; |
42338 | 49 |
public static void main(String... args) throws Exception { |
50 |
if (args.length != 0) |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
51 |
verbose = true; |
42338 | 52 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
53 |
GenModuleInfoSource.verbose = verbose; |
42338 | 54 |
ModuleInfoExtraTest test = new ModuleInfoExtraTest("m", "m1", "m2", "m3"); |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
55 |
test.testModuleInfo(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
56 |
test.errorCases(); |
42338 | 57 |
} |
58 |
||
59 |
String[] moduleInfo = new String[] { |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
60 |
"module m {", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
61 |
" requires m1;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
62 |
" requires transitive m2;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
63 |
" exports p", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
64 |
" to", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
65 |
" // comment ... ", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
66 |
" /* comment */ m1", |
42338 | 67 |
",", |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
68 |
" m2,m3", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
69 |
" ;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
70 |
" exports q to m1;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
71 |
" provides s with /* ", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
72 |
" comment */ impl ; // comment", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
73 |
" provides s1", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
74 |
" with ", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
75 |
" impl1, impl2;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
76 |
"}" |
42338 | 77 |
}; |
78 |
||
79 |
String[] moduleInfoExtra = new String[] { |
|
80 |
"exports q", |
|
81 |
"to", |
|
82 |
" m2 // comment", |
|
83 |
" /* comment */;", |
|
84 |
" ;", |
|
85 |
"opens p.q ", |
|
86 |
" to /* comment */ m3", |
|
87 |
" , // m1", |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
88 |
" /* comment */ m4; uses p.I", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
89 |
"; provides s1 with impl3;" |
42338 | 90 |
}; |
91 |
||
92 |
final Builder builder; |
|
93 |
ModuleInfoExtraTest(String name, String... modules) { |
|
94 |
this.builder = new Builder(name).modules(modules); |
|
95 |
} |
|
96 |
||
97 |
||
98 |
void testModuleInfo() throws IOException { |
|
99 |
GenModuleInfoSource source = builder.sourceFile(moduleInfo).build(); |
|
100 |
Set<String> targetsP = new HashSet<>(); |
|
101 |
targetsP.add("m1"); |
|
102 |
targetsP.add("m2"); |
|
103 |
targetsP.add("m3"); |
|
104 |
||
105 |
Set<String> targetsQ = new HashSet<>(); |
|
106 |
targetsQ.add("m1"); |
|
107 |
||
108 |
Set<String> providerS = new HashSet<>(); |
|
109 |
providerS.add("impl"); |
|
110 |
||
111 |
Set<String> providerS1 = new HashSet<>(); |
|
112 |
providerS1.add("impl1"); |
|
113 |
providerS1.add("impl2"); |
|
114 |
||
115 |
Set<String> opensPQ = new HashSet<>(); |
|
116 |
||
117 |
check(source, targetsP, targetsQ, opensPQ, providerS, providerS1); |
|
118 |
||
119 |
// augment with extra |
|
120 |
Path file = DIR.resolve("extra"); |
|
121 |
Files.write(file, Arrays.asList(moduleInfoExtra)); |
|
122 |
source = builder.build(file); |
|
123 |
||
124 |
targetsQ.add("m2"); |
|
125 |
providerS1.add("impl3"); |
|
126 |
||
127 |
opensPQ.add("m3"); |
|
128 |
check(source, targetsP, targetsQ, opensPQ, providerS, providerS1); |
|
129 |
} |
|
130 |
||
131 |
void check(GenModuleInfoSource source, |
|
132 |
Set<String> targetsP, |
|
133 |
Set<String> targetsQ, |
|
134 |
Set<String> opensPQ, |
|
135 |
Set<String> providerS, |
|
136 |
Set<String> providerS1) { |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
137 |
if (verbose) |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
138 |
source.moduleInfo.print(new PrintWriter(System.out, true)); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
139 |
|
42338 | 140 |
Statement export = source.moduleInfo.exports.get("p"); |
141 |
if (!export.targets.equals(targetsP)) { |
|
142 |
throw new Error("unexpected: " + export); |
|
143 |
} |
|
144 |
||
145 |
export = source.moduleInfo.exports.get("q"); |
|
146 |
if (!export.targets.equals(targetsQ)) { |
|
147 |
throw new Error("unexpected: " + export); |
|
148 |
} |
|
149 |
||
150 |
Statement provides = source.moduleInfo.provides.get("s"); |
|
151 |
if (!provides.targets.equals(providerS)) { |
|
152 |
throw new Error("unexpected: " + provides); |
|
153 |
} |
|
154 |
||
155 |
provides = source.moduleInfo.provides.get("s1"); |
|
156 |
if (!provides.targets.equals(providerS1)) { |
|
157 |
throw new Error("unexpected: " + provides); |
|
158 |
} |
|
159 |
} |
|
160 |
||
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
161 |
final Map<String[], String> badModuleInfos = Map.of( |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
162 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
163 |
"module x {", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
164 |
" exports p1 to ", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
165 |
" m1", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
166 |
"}" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
167 |
}, ".*, line .*, missing semicolon.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
168 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
169 |
"module x ", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
170 |
" exports p1;" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
171 |
}, ".*, line .*, missing \\{.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
172 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
173 |
"module x {", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
174 |
" requires m1;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
175 |
" requires", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
176 |
"}" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
177 |
}, ".*, line .*, <identifier> missing.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
178 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
179 |
"module x {", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
180 |
" requires transitive m1", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
181 |
"}" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
182 |
}, ".*, line .*, missing semicolon.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
183 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
184 |
"module x {", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
185 |
" exports p1 to m1;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
186 |
" exports p1 to m2;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
187 |
"}" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
188 |
}, ".*, line .*, multiple exports p1.*" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
189 |
); |
42338 | 190 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
191 |
final Map<String[], String> badExtraFiles = Map.of( |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
192 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
193 |
"requires m2;" // not allowed |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
194 |
}, ".*, line .*, cannot declare requires .*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
195 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
196 |
"exports p1 to m1;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
197 |
"exports p2" // missing semicolon |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
198 |
}, ".*, line .*, reach end of file.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
199 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
200 |
"exports to m1;" // missing <identifier> |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
201 |
}, ".*, line .*, <identifier> missing.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
202 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
203 |
"exports p3 to m1;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
204 |
" m2, m3;" // missing keyword |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
205 |
}, ".*, line .*, missing keyword.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
206 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
207 |
"provides s with impl1;", // typo ; should be , |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
208 |
" impl2, impl3;" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
209 |
}, ".*, line .*, missing keyword.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
210 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
211 |
"uses s3", // missing semicolon |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
212 |
"provides s3 with impl1,", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
213 |
" impl2, impl3;" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
214 |
}, ".*, line .*, missing semicolon.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
215 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
216 |
"opens p1 to m1,, m2;" // missing identifier |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
217 |
}, ".*, line .*, <identifier> missing.*" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
218 |
); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
219 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
220 |
final Map<String[], String> duplicates = Map.of( |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
221 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
222 |
" exports p1 to m1, m2;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
223 |
" exports p1 to m3;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
224 |
}, ".*, line .*, multiple exports p1.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
225 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
226 |
" opens p1 to m1, m2;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
227 |
" exports p1 to m3;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
228 |
" opens p1 to m3;" |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
229 |
}, ".*, line .*, multiple opens p1.*", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
230 |
new String[] { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
231 |
" uses s;", |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
232 |
" uses s;" |
51499
fdd768b9865e
8167314: Enable the check to detect duplicate provides in in GenModuleInfoSource
mchung
parents:
51339
diff
changeset
|
233 |
}, ".*, line .*, multiple uses s.*", |
fdd768b9865e
8167314: Enable the check to detect duplicate provides in in GenModuleInfoSource
mchung
parents:
51339
diff
changeset
|
234 |
new String[] { |
fdd768b9865e
8167314: Enable the check to detect duplicate provides in in GenModuleInfoSource
mchung
parents:
51339
diff
changeset
|
235 |
" provides s with impl1;", |
fdd768b9865e
8167314: Enable the check to detect duplicate provides in in GenModuleInfoSource
mchung
parents:
51339
diff
changeset
|
236 |
" provides s with impl2, impl3;" |
fdd768b9865e
8167314: Enable the check to detect duplicate provides in in GenModuleInfoSource
mchung
parents:
51339
diff
changeset
|
237 |
}, ".*, line .*, multiple provides s.*" |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
238 |
); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
239 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
240 |
void errorCases() { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
241 |
badModuleInfos.entrySet().stream().forEach(e -> badModuleInfoFile(e.getKey(), e.getValue())); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
242 |
badExtraFiles.entrySet().stream().forEach(e -> badExtraFile(e.getKey(), e.getValue())); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
243 |
duplicates.entrySet().stream().forEach(e -> badExtraFile(e.getKey(), e.getValue())); |
42338 | 244 |
} |
245 |
||
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
246 |
void badModuleInfoFile(String[] lines, String regex) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
247 |
Builder builder = new Builder("x").modules("m1", "m2", "m3"); |
42338 | 248 |
try { |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
249 |
GenModuleInfoSource source = builder.sourceFile(lines).build(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
250 |
throw new RuntimeException("Expected error: " + Arrays.toString(lines)); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
251 |
} catch (IOException e) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
252 |
throw new UncheckedIOException(e); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
253 |
} catch (Error e) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
254 |
if (!e.getMessage().matches(regex)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
255 |
throw e; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
256 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
257 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
258 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
259 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
260 |
void badExtraFile(String[] extras, String regex) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
261 |
Path file = DIR.resolve("test1"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
262 |
try { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
263 |
Files.write(file, Arrays.asList(extras)); |
42338 | 264 |
builder.build(file); |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
265 |
Files.deleteIfExists(file); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
266 |
throw new RuntimeException("Expected error: " + Arrays.toString(extras)); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
267 |
} catch (IOException e) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
268 |
throw new UncheckedIOException(e); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
269 |
} catch (Error e) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
270 |
if (!e.getMessage().matches(regex)) { |
42338 | 271 |
throw e; |
272 |
} |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
static class Builder { |
|
277 |
final String moduleName; |
|
278 |
final Path sourceFile; |
|
279 |
final Set<String> modules = new HashSet<>(); |
|
280 |
public Builder(String name) { |
|
281 |
this.moduleName = name; |
|
282 |
this.sourceFile = DIR.resolve(name).resolve("module-info.java"); |
|
283 |
} |
|
284 |
||
285 |
public Builder modules(String... names) { |
|
286 |
Arrays.stream(names).forEach(modules::add); |
|
287 |
return this; |
|
288 |
} |
|
289 |
||
290 |
public Builder sourceFile(String... lines) throws IOException { |
|
291 |
Files.createDirectories(sourceFile.getParent()); |
|
292 |
try (BufferedWriter bw = Files.newBufferedWriter(sourceFile); |
|
293 |
PrintWriter writer = new PrintWriter(bw)) { |
|
294 |
for (String l : lines) { |
|
295 |
writer.println(l); |
|
296 |
} |
|
297 |
} |
|
298 |
return this; |
|
299 |
} |
|
300 |
||
301 |
public GenModuleInfoSource build() throws IOException { |
|
302 |
return build(Collections.emptyList()); |
|
303 |
} |
|
304 |
||
305 |
public GenModuleInfoSource build(Path extraFile) throws IOException { |
|
306 |
return build(Collections.singletonList(extraFile)); |
|
307 |
} |
|
308 |
||
309 |
public GenModuleInfoSource build(List<Path> extraFiles) throws IOException { |
|
310 |
return new GenModuleInfoSource(sourceFile, extraFiles, modules); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
} |