langtools/test/tools/javac/T6873845.java
author ssides
Wed, 09 Jul 2014 15:14:06 +0400
changeset 25760 7955db32d6b0
parent 15385 ee1eebe7e210
child 27579 d1a63c99cdd5
permissions -rw-r--r--
8046597: fix doclint issues in swing classes, part 4 of 4 Reviewed-by: pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     1
import java.io.*;
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     2
import java.util.*;
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     3
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     4
import sun.misc.*;
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     5
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     6
/*
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     7
 * @test /nodynamiccopyright/
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     8
 * @bug 6873845
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
     9
 * @summary refine access to symbol file
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    10
 */
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    11
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    12
public class T6873845 {
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    13
    public static void main(String... args) throws Exception {
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    14
        new T6873845().run();
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    15
    }
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    16
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    17
    public void run() throws Exception {
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    18
        String out = compile(Arrays.asList("-XDrawDiagnostics", "-X"));
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    19
        if (out.contains("sunapi"))
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    20
            throw new Exception("unexpected output for -X");
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    21
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 3661
diff changeset
    22
        String warn1 = "T6873845.java:73:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 3661
diff changeset
    23
        String warn2 = "T6873845.java:78:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    24
        String note1 = "- compiler.note.sunapi.filename: T6873845.java" + newline;
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    25
        String note2 = "- compiler.note.sunapi.recompile" + newline;
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    26
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    27
        test(opts(),
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    28
                warn1 + warn2 + "2 warnings" + newline);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    29
        test(opts("-XDenableSunApiLintControl"),
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    30
                note1 + note2);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    31
        test(opts("-XDenableSunApiLintControl", "-XDsuppressNotes"),
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    32
                "");
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    33
        test(opts("-XDenableSunApiLintControl", "-Xlint:sunapi"),
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    34
                warn1 + "1 warning" + newline);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    35
        test(opts("-XDenableSunApiLintControl", "-Xlint:all"),
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    36
                warn1 + "1 warning" + newline);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    37
        test(opts("-XDenableSunApiLintControl", "-Xlint:all,-sunapi"),
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    38
                note1 + note2);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    39
    }
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    40
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    41
    List<String> opts(String... opts) {
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    42
        return Arrays.asList(opts);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    43
    }
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    44
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    45
    void test(List<String> opts, String expect) throws Exception {
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    46
        List<String> args = new ArrayList<String>();
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    47
        args.addAll(opts);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    48
        args.add("-d");
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    49
        args.add(testClasses.getPath());
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    50
        args.add(new File(testSrc, "T6873845.java").getPath());
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    51
        compile(args); // to verify resource strings exist
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    52
        args.add(0, "-XDrawDiagnostics");
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    53
        String out = compile(args);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    54
        if (!out.equals(expect))
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 3661
diff changeset
    55
            throw new Exception("unexpected output from compiler; expected: " + expect +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 3661
diff changeset
    56
                    "\n  found: " + out);
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    57
    }
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    58
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    59
    String compile(List<String> args) throws Exception{
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    60
        StringWriter sw = new StringWriter();
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    61
        PrintWriter pw = new PrintWriter(sw);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    62
        System.out.println("compile: " + args);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    63
        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    64
        pw.close();
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    65
        String out = sw.toString();
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    66
        System.out.println(out);
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    67
        if (rc != 0)
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    68
            throw new Exception("compilation failed unexpectedly");
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    69
        return out;
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    70
    }
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    71
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    72
    void m1() {
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    73
        Unsafe.getUnsafe();
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    74
    }
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    75
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    76
    @SuppressWarnings("sunapi")
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    77
    void m2() {
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    78
        Unsafe.getUnsafe();
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    79
    }
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    80
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    81
    private File testSrc = new File(System.getProperty("test.src", "."));
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    82
    private File testClasses = new File(System.getProperty("test.classes", "."));
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    83
    private String newline = System.getProperty("line.separator");
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    84
}
104c425e96aa 6873845: refine access to symbol file
jjg
parents:
diff changeset
    85