1 /* 2 * Copyright (c) 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 */ 23 24 /** 25 * @test 26 * @bug 8180744 27 * @summary Verify unsupported modules and module options handling. 28 * @library /tools/lib 29 * @modules jdk.compiler/com.sun.tools.javac.api 30 * jdk.compiler/com.sun.tools.javac.main 31 * jdk.compiler/com.sun.tools.javac.jvm 32 * jdk.jdeps/com.sun.tools.classfile 33 * jdk.jdeps/com.sun.tools.javap 34 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner 35 * @run main ReleaseOption9 36 */ 37 38 import java.io.IOException; 39 import java.nio.file.Path; 40 import java.nio.file.Paths; 41 import java.util.Arrays; 42 import java.util.List; 43 44 import toolbox.JavacTask; 45 import toolbox.Task; 46 import toolbox.Task.Expect; 47 import toolbox.TestRunner; 48 import toolbox.ToolBox; 49 50 public class ReleaseOption9 extends TestRunner { 51 52 private final ToolBox tb = new ToolBox(); 53 ReleaseOption9()54 public ReleaseOption9() { 55 super(System.err); 56 } 57 main(String... args)58 public static void main(String... args) throws Exception { 59 new ReleaseOption9().runTests(); 60 } 61 62 @Test testUnsafe(Path base)63 public void testUnsafe(Path base) throws IOException { 64 Path src = base.resolve("src"); 65 tb.writeJavaFiles(src, 66 "module m { requires jdk.unsupported; }", 67 "package test; public class Test { sun.misc.Unsafe unsafe; } "); 68 Path classes = base.resolve("classes"); 69 tb.createDirectories(classes); 70 71 List<String> log; 72 List<String> expected = Arrays.asList( 73 "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe", 74 "1 warning" 75 ); 76 77 log = new JavacTask(tb) 78 .options("-XDrawDiagnostics") 79 .outdir(classes) 80 .files(tb.findJavaFiles(src)) 81 .run(Expect.SUCCESS) 82 .writeAll() 83 .getOutputLines(Task.OutputKind.DIRECT); 84 85 if (!expected.equals(log)) { 86 throw new AssertionError("Unexpected output: " + log); 87 } 88 89 log = new JavacTask(tb) 90 .options("-XDrawDiagnostics", 91 "--release", "9") 92 .outdir(classes) 93 .files(tb.findJavaFiles(src)) 94 .run(Expect.SUCCESS) 95 .writeAll() 96 .getOutputLines(Task.OutputKind.DIRECT); 97 98 if (!expected.equals(log)) { 99 throw new AssertionError("Unexpected output: " + log); 100 } 101 } 102 103 @Test testUnsafeUnnamed(Path base)104 public void testUnsafeUnnamed(Path base) throws IOException { 105 Path src = base.resolve("src"); 106 tb.writeJavaFiles(src, 107 "package test; public class Test { sun.misc.Unsafe unsafe; } "); 108 Path classes = base.resolve("classes"); 109 tb.createDirectories(classes); 110 111 List<String> log; 112 List<String> expected = Arrays.asList( 113 "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe", 114 "1 warning" 115 ); 116 117 log = new JavacTask(tb) 118 .options("-XDrawDiagnostics") 119 .outdir(classes) 120 .files(tb.findJavaFiles(src)) 121 .run(Expect.SUCCESS) 122 .writeAll() 123 .getOutputLines(Task.OutputKind.DIRECT); 124 125 if (!expected.equals(log)) { 126 throw new AssertionError("Unexpected output: " + log); 127 } 128 129 log = new JavacTask(tb) 130 .options("-XDrawDiagnostics", 131 "--release", "9") 132 .outdir(classes) 133 .files(tb.findJavaFiles(src)) 134 .run(Expect.SUCCESS) 135 .writeAll() 136 .getOutputLines(Task.OutputKind.DIRECT); 137 138 if (!expected.equals(log)) { 139 throw new AssertionError("Unexpected output: " + log); 140 } 141 } 142 143 @Test testIncubatorHttpClient(Path base)144 public void testIncubatorHttpClient(Path base) throws IOException { 145 Path src = base.resolve("src"); 146 tb.writeJavaFiles(src, 147 "module m { requires jdk.incubator.httpclient; }", 148 "package test;\n" + 149 "public class Test {\n" + 150 " jdk.incubator.http.HttpRequest v;\n" + 151 "}\n"); 152 Path classes = base.resolve("classes"); 153 tb.createDirectories(classes); 154 155 List<String> log; 156 List<String> expected = Arrays.asList( 157 "- compiler.warn.incubating.modules: jdk.incubator.httpclient", 158 "1 warning" 159 ); 160 161 log = new JavacTask(tb) 162 .options("-XDrawDiagnostics", 163 "--release", "9") 164 .outdir(classes) 165 .files(tb.findJavaFiles(src)) 166 .run(Expect.SUCCESS) 167 .writeAll() 168 .getOutputLines(Task.OutputKind.DIRECT); 169 170 if (!expected.equals(log)) { 171 throw new AssertionError("Unexpected output: " + log); 172 } 173 } 174 runTests()175 protected void runTests() throws Exception { 176 runTests(m -> new Object[] { Paths.get(m.getName()) }); 177 } 178 } 179