langtools/test/tools/sjavac/IgnoreSymbolFile.java
author sogoel
Wed, 24 Dec 2014 11:17:51 -0800
changeset 28276 ec66954fa850
parent 26271 97603426a4ce
child 30730 d3ce7619db2c
permissions -rw-r--r--
8054689: Split large SJavac.java test source into multiple files Reviewed-by: jjg, jfranck
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25290
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     1
/*
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     4
 *
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    10
 *
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    15
 * accompanied this code).
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    16
 *
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    20
 *
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    23
 * questions.
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    24
 */
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    25
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    26
/*
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    27
 * @test
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    28
 * @bug 8047183
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    29
 * @summary JDK build fails with sjavac enabled
25603
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 25290
diff changeset
    30
 *
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 25290
diff changeset
    31
 * @build Wrapper
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 25290
diff changeset
    32
 * @run main Wrapper IgnoreSymbolFile
25290
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    33
 */
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    34
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    35
import java.io.File;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    36
import java.io.FileWriter;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    37
import java.io.IOException;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    38
import java.io.PrintStream;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    39
import java.lang.reflect.Method;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    40
import java.util.Arrays;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    41
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    42
public class IgnoreSymbolFile {
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    43
    public static void main(String... args) throws Exception {
25603
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 25290
diff changeset
    44
        IgnoreSymbolFile test = new IgnoreSymbolFile();
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 25290
diff changeset
    45
        test.run();
25290
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    46
    }
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    47
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    48
    void run() throws Exception {
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    49
        String body =
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    50
                "package p;\n"
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    51
                + "import sun.reflect.annotation.*;\n"
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    52
                + "class X {\n"
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    53
                + "    ExceptionProxy proxy;"
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    54
                + "}";
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    55
        writeFile("src/p/X.java", body);
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    56
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    57
        new File("classes").mkdirs();
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    58
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    59
        String server = "--server:portfile=testserver,background=false";
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    60
        int rc1 = compile(server, "-d", "classes", "-Werror", "src");
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    61
        if (rc1 == 0)
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    62
            error("compilation succeeded unexpectedly");
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    63
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    64
        int rc2 = compile(server, "-d", "classes", "-Werror", "-XDignore.symbol.file=true", "src");
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    65
        if (rc2 != 0)
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    66
            error("compilation failed unexpectedly: rc=" + rc2);
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    67
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    68
        if (errors > 0)
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    69
            throw new Exception(errors + " errors occurred");
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    70
    }
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    71
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    72
    int compile(String... args) throws ReflectiveOperationException {
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    73
        // Use reflection to avoid a compile-time dependency on sjavac Main
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    74
        System.err.println("compile: " + Arrays.toString(args));
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    75
        Class<?> c = Class.forName("com.sun.tools.sjavac.Main");
26271
97603426a4ce 8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents: 25603
diff changeset
    76
        Method m = c.getDeclaredMethod("go", String[].class);
97603426a4ce 8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents: 25603
diff changeset
    77
        int rc = (Integer) m.invoke(null, (Object) args);
25290
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    78
        System.err.println("rc=" + rc);
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    79
        return rc;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    80
    }
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    81
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    82
    void writeFile(String path, String body) throws IOException {
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    83
        File f = new File(path);
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    84
        if (f.getParentFile() != null)
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    85
            f.getParentFile().mkdirs();
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    86
        try (FileWriter w = new FileWriter(f)) {
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    87
            w.write(body);
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    88
        }
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    89
    }
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    90
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    91
    void error(String msg) {
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    92
        System.err.println("Error: " + msg);
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    93
        errors++;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    94
    }
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    95
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    96
    int errors;
72f49068d56c 8047183: JDK build fails with sjavac enabled
jjg
parents:
diff changeset
    97
}