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