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