|
1 /* |
|
2 * Copyright (c) 2016, 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 */ |
|
23 |
|
24 /** |
|
25 * @test |
|
26 * @bug 8153391 |
|
27 * @summary Verify javac behaves properly in absence of zip/jar FileSystemProvider |
|
28 * @library /tools/lib |
|
29 * @modules jdk.compiler/com.sun.tools.javac.api |
|
30 * jdk.compiler/com.sun.tools.javac.main |
|
31 * @run main/othervm -limitmods jdk.compiler LimitedImage |
|
32 */ |
|
33 |
|
34 import java.io.IOException; |
|
35 import java.nio.file.Path; |
|
36 import java.nio.file.Paths; |
|
37 import java.util.Arrays; |
|
38 import java.util.List; |
|
39 |
|
40 import toolbox.JavacTask; |
|
41 import toolbox.JarTask; |
|
42 import toolbox.Task.Expect; |
|
43 import toolbox.Task.Mode; |
|
44 import toolbox.Task.OutputKind; |
|
45 import toolbox.ToolBox; |
|
46 |
|
47 public class LimitedImage { |
|
48 public static void main(String... args) throws IOException { |
|
49 ToolBox tb = new ToolBox(); |
|
50 |
|
51 //showing help should be OK |
|
52 new JavacTask(tb, Mode.CMDLINE) |
|
53 .options("--help") |
|
54 .run().writeAll(); |
|
55 |
|
56 Path testSource = Paths.get("Test.java"); |
|
57 tb.writeFile(testSource, "class Test {}"); |
|
58 |
|
59 //when zip/jar FS is not needed, compilation should succeed |
|
60 new JavacTask(tb, Mode.CMDLINE) |
|
61 .classpath() |
|
62 .files(testSource) |
|
63 .outdir(".") |
|
64 .run() |
|
65 .writeAll(); |
|
66 |
|
67 Path testJar = Paths.get("test.jar").toAbsolutePath(); |
|
68 |
|
69 new JarTask(tb, testJar).run(); |
|
70 |
|
71 List<String> actualOutput; |
|
72 List<String> expectedOutput = Arrays.asList( |
|
73 "- compiler.err.no.zipfs.for.archive: " + testJar.toString() |
|
74 ); |
|
75 |
|
76 //check proper diagnostics when zip/jar FS not present: |
|
77 actualOutput = new JavacTask(tb, Mode.CMDLINE) |
|
78 .classpath(testJar) |
|
79 .options("-XDrawDiagnostics") |
|
80 .files(testSource) |
|
81 .outdir(".") |
|
82 .run(Expect.FAIL) |
|
83 .writeAll() |
|
84 .getOutputLines(OutputKind.DIRECT); |
|
85 |
|
86 if (!expectedOutput.equals(actualOutput)) { |
|
87 throw new AssertionError("Unexpected output: " + actualOutput); |
|
88 } |
|
89 |
|
90 actualOutput = new JavacTask(tb, Mode.CMDLINE) |
|
91 .sourcepath(testJar) |
|
92 .options("-XDrawDiagnostics") |
|
93 .files(testSource) |
|
94 .outdir(".") |
|
95 .run(Expect.FAIL) |
|
96 .writeAll() |
|
97 .getOutputLines(OutputKind.DIRECT); |
|
98 |
|
99 if (!expectedOutput.equals(actualOutput)) { |
|
100 throw new AssertionError("Unexpected output: " + actualOutput); |
|
101 } |
|
102 |
|
103 actualOutput = new JavacTask(tb, Mode.CMDLINE) |
|
104 .options("-XDrawDiagnostics", |
|
105 "--module-path", testJar.toString()) |
|
106 .files(testSource) |
|
107 .outdir(".") |
|
108 .run(Expect.FAIL) |
|
109 .writeAll() |
|
110 .getOutputLines(OutputKind.DIRECT); |
|
111 |
|
112 if (!expectedOutput.equals(actualOutput)) { |
|
113 throw new AssertionError("Unexpected output: " + actualOutput); |
|
114 } |
|
115 |
|
116 expectedOutput = Arrays.asList( |
|
117 "- compiler.err.no.zipfs.for.archive: " + testJar.toString(), |
|
118 "1 error" |
|
119 ); |
|
120 |
|
121 actualOutput = new JavacTask(tb, Mode.CMDLINE) |
|
122 .classpath() |
|
123 .options("-XDrawDiagnostics", |
|
124 "--module-path", testJar.getParent().toString()) |
|
125 .files(testSource) |
|
126 .outdir(".") |
|
127 .run(Expect.FAIL) |
|
128 .writeAll() |
|
129 .getOutputLines(OutputKind.DIRECT); |
|
130 |
|
131 if (!expectedOutput.equals(actualOutput)) { |
|
132 throw new AssertionError("Unexpected output: " + actualOutput); |
|
133 } |
|
134 } |
|
135 |
|
136 } |