59 System.out.println(message.toString());
60 System.out.format("Found problem: %s%n", message.getCode());
61 System.out.flush();
62 }
63 };
64 compiler = ToolProvider.getSystemJavaCompiler();
65 fm = compiler.getStandardFileManager(dl, null, null);
66 files =
67 fm.getJavaFileObjectsFromFiles(Arrays.asList(testFile));
68 createTestFile();
69 }
70 final void createTestFile() throws IOException {
71 List<String> scratch = new ArrayList<>();
72 scratch.add("// @author Peter von der Ah" + (char)0xe9);
73 scratch.add("class Utf8{}");
74 Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"),
75 CREATE, TRUNCATE_EXISTING);
76 }
77 void test(String encoding, boolean good) {
78 error = false;
79 Iterable<String> args = Arrays.asList("-source", "6", "-encoding", encoding, "-d", ".");
80 compiler.getTask(null, fm, dl, args, null, files).call();
81 if (error == good) {
82 if (error) {
83 throw new AssertionError("Error reported");
84 } else {
85 throw new AssertionError("No error reported");
86 }
87 }
88 }
89
90 public static void main(String[] args) throws IOException {
91 T6306137 self = new T6306137();
92 self.test("utf-8", true);
93 self.test("ascii", false);
94 self.test("utf-8", true);
95 }
96 }
|
59 System.out.println(message.toString());
60 System.out.format("Found problem: %s%n", message.getCode());
61 System.out.flush();
62 }
63 };
64 compiler = ToolProvider.getSystemJavaCompiler();
65 fm = compiler.getStandardFileManager(dl, null, null);
66 files =
67 fm.getJavaFileObjectsFromFiles(Arrays.asList(testFile));
68 createTestFile();
69 }
70 final void createTestFile() throws IOException {
71 List<String> scratch = new ArrayList<>();
72 scratch.add("// @author Peter von der Ah" + (char)0xe9);
73 scratch.add("class Utf8{}");
74 Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"),
75 CREATE, TRUNCATE_EXISTING);
76 }
77 void test(String encoding, boolean good) {
78 error = false;
79 Iterable<String> args = Arrays.asList("-encoding", encoding, "-d", ".");
80 compiler.getTask(null, fm, dl, args, null, files).call();
81 if (error == good) {
82 if (error) {
83 throw new AssertionError("Error reported");
84 } else {
85 throw new AssertionError("No error reported");
86 }
87 }
88 }
89
90 public static void main(String[] args) throws IOException {
91 T6306137 self = new T6306137();
92 self.test("utf-8", true);
93 self.test("ascii", false);
94 self.test("utf-8", true);
95 }
96 }
|