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