1 /*
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
160 .options("--module-path", modulePath.toString(),
161 "--should-stop:ifNoError=FLOW",
162 "--limit-modules", "m3x")
163 .outdir(modulePath)
164 .files(findJavaFiles(m1))
165 .run(Task.Expect.FAIL)
166 .writeAll();
167
168 new JavacTask(tb)
169 .options("--module-path", modulePath.toString(),
170 "--should-stop:ifNoError=FLOW",
171 "--limit-modules", "m3x",
172 "--add-modules", "m2x")
173 .outdir(modulePath)
174 .files(findJavaFiles(m1))
175 .run()
176 .writeAll();
177 }
178
179 @Test
180 public void testObservableForUnnamed(Path base) throws Exception {
181 Path src = base.resolve("src");
182
183 tb.writeJavaFiles(src,
184 "package test;\n" +
185 "@javax.annotation.Generated(\"test\")\n" +
186 "public class Test {\n" +
187 " com.sun.tools.javac.Main m;\n" +
188 " javax.xml.bind.JAXBException e;\n" +
189 "}\n");
190
191 Path out = base.resolve("out");
192
193 Files.createDirectories(out);
194
195 for (Entry<String[], String> variant : variants) {
196 System.err.println("running variant: options=" + Arrays.asList(variant.getKey()) + ", expected log: " + variant.getValue());
197
198 List<String> options = new ArrayList<>();
199 options.add("-XDrawDiagnostics");
200 options.addAll(Arrays.asList(variant.getKey()));
201
202 String log = new JavacTask(tb)
203 .options(options.toArray(new String[0]))
204 .outdir(out)
205 .files(findJavaFiles(src))
206 .run(variant.getValue() == null ? Task.Expect.SUCCESS : Task.Expect.FAIL)
207 .writeAll()
208 .getOutput(Task.OutputKind.DIRECT);
209
210 log = log.replace(System.getProperty("line.separator"), "\n");
211
212 if (variant.getValue() != null && !log.equals(variant.getValue())) {
213 throw new AssertionError();
214 }
215 }
216 }
217
218 private static final List<Entry<String[], String>> variants = Arrays.asList(
219 new SimpleEntry<String[], String>(new String[] {},
220 "Test.java:2:7: compiler.err.package.not.visible: javax.annotation, (compiler.misc.not.def.access.does.not.read.from.unnamed: javax.annotation, java.xml.ws.annotation)\n"
221 + "Test.java:5:14: compiler.err.package.not.visible: javax.xml.bind, (compiler.misc.not.def.access.does.not.read.from.unnamed: javax.xml.bind, java.xml.bind)\n"
222 + "2 errors\n"),
223 new SimpleEntry<String[], String>(new String[] {"--add-modules", "java.xml.ws.annotation,java.xml.bind"},
224 null),
225 new SimpleEntry<String[], String>(new String[] {"--limit-modules", "java.xml.ws,jdk.compiler"},
226 null),
227 new SimpleEntry<String[], String>(new String[] {"--add-modules", "ALL-SYSTEM"},
228 null)
229 );
230
231 @Test
232 public void testAllModulePath(Path base) throws Exception {
233 if (Files.isDirectory(base))
234 tb.cleanDirectory(base);
235
236 Path moduleSrc = base.resolve("module-src");
237 Path m1 = moduleSrc.resolve("m1x");
238
239 tb.writeJavaFiles(m1,
240 "module m1x { exports api; }",
241 "package api; public class Api { }");
242
243 Path modulePath = base.resolve("module-path");
244
245 Files.createDirectories(modulePath);
246
247 new JavacTask(tb)
248 .options("--module-source-path", moduleSrc.toString())
249 .outdir(modulePath)
250 .files(findJavaFiles(moduleSrc))
251 .run()
|
1 /*
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
160 .options("--module-path", modulePath.toString(),
161 "--should-stop:ifNoError=FLOW",
162 "--limit-modules", "m3x")
163 .outdir(modulePath)
164 .files(findJavaFiles(m1))
165 .run(Task.Expect.FAIL)
166 .writeAll();
167
168 new JavacTask(tb)
169 .options("--module-path", modulePath.toString(),
170 "--should-stop:ifNoError=FLOW",
171 "--limit-modules", "m3x",
172 "--add-modules", "m2x")
173 .outdir(modulePath)
174 .files(findJavaFiles(m1))
175 .run()
176 .writeAll();
177 }
178
179 @Test
180 public void testAllModulePath(Path base) throws Exception {
181 if (Files.isDirectory(base))
182 tb.cleanDirectory(base);
183
184 Path moduleSrc = base.resolve("module-src");
185 Path m1 = moduleSrc.resolve("m1x");
186
187 tb.writeJavaFiles(m1,
188 "module m1x { exports api; }",
189 "package api; public class Api { }");
190
191 Path modulePath = base.resolve("module-path");
192
193 Files.createDirectories(modulePath);
194
195 new JavacTask(tb)
196 .options("--module-source-path", moduleSrc.toString())
197 .outdir(modulePath)
198 .files(findJavaFiles(moduleSrc))
199 .run()
|