Path: blob/master/test/langtools/tools/sjavac/IgnoreSymbolFile.java
41144 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 804718326* @summary JDK build fails with sjavac enabled27* @modules jdk.compiler/com.sun.tools.sjavac28* @build Wrapper29* @run main Wrapper IgnoreSymbolFile30*/3132import java.io.File;33import java.io.FileWriter;34import java.io.IOException;35import java.io.PrintStream;36import java.lang.reflect.Method;37import java.util.Arrays;3839public class IgnoreSymbolFile {40public static void main(String... args) throws Exception {41IgnoreSymbolFile test = new IgnoreSymbolFile();42test.run();43}4445void run() throws Exception {46String body =47"package p;\n"48+ "import sun.reflect.annotation.*;\n"49+ "class X {\n"50+ " ExceptionProxy proxy;"51+ "}";52writeFile("src/p/X.java", body);5354new File("classes").mkdirs();5556int rc1 = compile("-d", "classes",57"--state-dir=classes",58"-Werror",59"src");60if (rc1 == 0)61error("compilation succeeded unexpectedly");6263int rc2 = compile("-d", "classes",64"--state-dir=classes",65"-Werror",66"-XDignore.symbol.file=true",67"src");68if (rc2 != 0)69error("compilation failed unexpectedly: rc=" + rc2);7071if (errors > 0)72throw new Exception(errors + " errors occurred");73}7475int compile(String... args) throws ReflectiveOperationException {76// Use reflection to avoid a compile-time dependency on sjavac Main77System.err.println("compile: " + Arrays.toString(args));78Class<?> c = Class.forName("com.sun.tools.sjavac.Main");79Method m = c.getDeclaredMethod("go", String[].class);80int rc = (Integer) m.invoke(null, (Object) args);81System.err.println("rc=" + rc);82return rc;83}8485void writeFile(String path, String body) throws IOException {86File f = new File(path);87if (f.getParentFile() != null)88f.getParentFile().mkdirs();89try (FileWriter w = new FileWriter(f)) {90w.write(body);91}92}9394void error(String msg) {95System.err.println("Error: " + msg);96errors++;97}9899int errors;100}101102103