jjg@377: import java.io.*; jjg@377: import java.util.*; jjg@377: jjg@377: import sun.misc.*; jjg@377: jjg@377: /* jjg@377: * @test /nodynamiccopyright/ jjg@377: * @bug 6873845 jjg@377: * @summary refine access to symbol file jjg@377: */ jjg@377: jjg@377: public class T6873845 { jjg@377: public static void main(String... args) throws Exception { jjg@377: new T6873845().run(); jjg@377: } jjg@377: jjg@377: public void run() throws Exception { jjg@377: String out = compile(Arrays.asList("-XDrawDiagnostics", "-X")); jjg@377: if (out.contains("sunapi")) jjg@377: throw new Exception("unexpected output for -X"); jjg@377: jjg@1521: String warn1 = "T6873845.java:73:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline; jjg@1521: String warn2 = "T6873845.java:78:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline; jjg@377: String note1 = "- compiler.note.sunapi.filename: T6873845.java" + newline; jjg@377: String note2 = "- compiler.note.sunapi.recompile" + newline; jjg@377: jjg@377: test(opts(), jjg@377: warn1 + warn2 + "2 warnings" + newline); jjg@377: test(opts("-XDenableSunApiLintControl"), jjg@377: note1 + note2); jjg@377: test(opts("-XDenableSunApiLintControl", "-XDsuppressNotes"), jjg@377: ""); jjg@377: test(opts("-XDenableSunApiLintControl", "-Xlint:sunapi"), jjg@377: warn1 + "1 warning" + newline); jjg@377: test(opts("-XDenableSunApiLintControl", "-Xlint:all"), jjg@377: warn1 + "1 warning" + newline); jjg@377: test(opts("-XDenableSunApiLintControl", "-Xlint:all,-sunapi"), jjg@377: note1 + note2); jjg@377: } jjg@377: jjg@377: List opts(String... opts) { jjg@377: return Arrays.asList(opts); jjg@377: } jjg@377: jjg@377: void test(List opts, String expect) throws Exception { jjg@377: List args = new ArrayList(); jjg@377: args.addAll(opts); jjg@377: args.add("-d"); jjg@377: args.add(testClasses.getPath()); jjg@377: args.add(new File(testSrc, "T6873845.java").getPath()); jjg@377: compile(args); // to verify resource strings exist jjg@377: args.add(0, "-XDrawDiagnostics"); jjg@377: String out = compile(args); jjg@377: if (!out.equals(expect)) jjg@1521: throw new Exception("unexpected output from compiler; expected: " + expect + jjg@1521: "\n found: " + out); jjg@377: } jjg@377: jjg@377: String compile(List args) throws Exception{ jjg@377: StringWriter sw = new StringWriter(); jjg@377: PrintWriter pw = new PrintWriter(sw); jjg@377: System.out.println("compile: " + args); jjg@377: int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); jjg@377: pw.close(); jjg@377: String out = sw.toString(); jjg@377: System.out.println(out); jjg@377: if (rc != 0) jjg@377: throw new Exception("compilation failed unexpectedly"); jjg@377: return out; jjg@377: } jjg@377: jjg@377: void m1() { jjg@377: Unsafe.getUnsafe(); jjg@377: } jjg@377: jjg@377: @SuppressWarnings("sunapi") jjg@377: void m2() { jjg@377: Unsafe.getUnsafe(); jjg@377: } jjg@377: jjg@377: private File testSrc = new File(System.getProperty("test.src", ".")); jjg@377: private File testClasses = new File(System.getProperty("test.classes", ".")); jjg@377: private String newline = System.getProperty("line.separator"); jjg@377: } jjg@377: