IgnoreSymbolFile.java revision 2606:452dd2988607
1/* 2 * Copyright (c) 2014, 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. 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/* 27 * @test 28 * @bug 8047183 29 * @summary JDK build fails with sjavac enabled 30 * 31 * @build Wrapper 32 * @run main Wrapper IgnoreSymbolFile 33 */ 34 35import java.io.File; 36import java.io.FileWriter; 37import java.io.IOException; 38import java.io.PrintStream; 39import java.lang.reflect.Method; 40import java.util.Arrays; 41 42public class IgnoreSymbolFile { 43 public static void main(String... args) throws Exception { 44 IgnoreSymbolFile test = new IgnoreSymbolFile(); 45 test.run(); 46 } 47 48 void run() throws Exception { 49 String body = 50 "package p;\n" 51 + "import sun.reflect.annotation.*;\n" 52 + "class X {\n" 53 + " ExceptionProxy proxy;" 54 + "}"; 55 writeFile("src/p/X.java", body); 56 57 new File("classes").mkdirs(); 58 59 String server = "--server:portfile=testserver,background=false"; 60 int rc1 = compile(server, "-d", "classes", "-Werror", "src"); 61 if (rc1 == 0) 62 error("compilation succeeded unexpectedly"); 63 64 int rc2 = compile(server, "-d", "classes", "-Werror", "-XDignore.symbol.file=true", "src"); 65 if (rc2 != 0) 66 error("compilation failed unexpectedly: rc=" + rc2); 67 68 if (errors > 0) 69 throw new Exception(errors + " errors occurred"); 70 } 71 72 int compile(String... args) throws ReflectiveOperationException { 73 // Use reflection to avoid a compile-time dependency on sjavac Main 74 System.err.println("compile: " + Arrays.toString(args)); 75 Class<?> c = Class.forName("com.sun.tools.sjavac.Main"); 76 Method m = c.getDeclaredMethod("go", String[].class); 77 int rc = (Integer) m.invoke(null, (Object) args); 78 System.err.println("rc=" + rc); 79 return rc; 80 } 81 82 void writeFile(String path, String body) throws IOException { 83 File f = new File(path); 84 if (f.getParentFile() != null) 85 f.getParentFile().mkdirs(); 86 try (FileWriter w = new FileWriter(f)) { 87 w.write(body); 88 } 89 } 90 91 void error(String msg) { 92 System.err.println("Error: " + msg); 93 errors++; 94 } 95 96 int errors; 97} 98