98 |
98 |
99 File x = writeFile(new File(srcDir, "X.java"), src); |
99 File x = writeFile(new File(srcDir, "X.java"), src); |
100 |
100 |
101 DiagListener dl = new DiagListener(); |
101 DiagListener dl = new DiagListener(); |
102 JavacTool tool = JavacTool.create(); |
102 JavacTool tool = JavacTool.create(); |
103 StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); |
103 try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { |
104 fm.setLocation(StandardLocation.CLASS_PATH, |
104 fm.setLocation(StandardLocation.CLASS_PATH, |
105 Arrays.asList(classesDir, new File(System.getProperty("test.classes")))); |
105 Arrays.asList(classesDir, new File(System.getProperty("test.classes")))); |
106 fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir)); |
106 fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir)); |
107 fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir)); |
107 fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir)); |
108 List<String> args = new ArrayList<String>(); |
108 List<String> args = new ArrayList<String>(); |
109 // args.add("-XprintProcessorInfo"); |
109 // args.add("-XprintProcessorInfo"); |
110 args.add("-XprintRounds"); |
110 args.add("-XprintRounds"); |
111 args.add("-Agen=" + gen); |
111 args.add("-Agen=" + gen); |
112 if (wk == WarningKind.YES) |
112 if (wk == WarningKind.YES) |
113 args.add("-Xlint:serial"); |
113 args.add("-Xlint:serial"); |
114 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x); |
114 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x); |
115 |
115 |
116 StringWriter sw = new StringWriter(); |
116 StringWriter sw = new StringWriter(); |
117 PrintWriter pw = new PrintWriter(sw); |
117 PrintWriter pw = new PrintWriter(sw); |
118 JavacTask task = tool.getTask(pw, fm, dl, args, null, files); |
118 JavacTask task = tool.getTask(pw, fm, dl, args, null, files); |
119 task.setProcessors(Arrays.asList(new AnnoProc())); |
119 task.setProcessors(Arrays.asList(new AnnoProc())); |
120 boolean ok = task.call(); |
120 boolean ok = task.call(); |
121 pw.close(); |
121 pw.close(); |
122 |
122 |
123 System.err.println("ok:" + ok + " diags:" + dl.counts); |
123 System.err.println("ok:" + ok + " diags:" + dl.counts); |
124 if (sw.toString().length() > 0) { |
124 if (sw.toString().length() > 0) { |
125 System.err.println("output:\n" + sw.toString()); |
125 System.err.println("output:\n" + sw.toString()); |
126 } |
126 } |
127 |
127 |
128 for (Diagnostic.Kind dk: Diagnostic.Kind.values()) { |
128 for (Diagnostic.Kind dk: Diagnostic.Kind.values()) { |
129 Integer v = dl.counts.get(dk); |
129 Integer v = dl.counts.get(dk); |
130 int found = (v == null) ? 0 : v; |
130 int found = (v == null) ? 0 : v; |
131 int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0; |
131 int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0; |
132 if (found != expect) { |
132 if (found != expect) { |
133 error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found); |
133 error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found); |
134 } |
134 } |
135 } |
135 } |
136 |
136 |
137 System.err.println(); |
137 System.err.println(); |
|
138 } |
138 } |
139 } |
139 |
140 |
140 File createDir(File parent, String name) { |
141 File createDir(File parent, String name) { |
141 File dir = new File(parent, name); |
142 File dir = new File(parent, name); |
142 dir.mkdirs(); |
143 dir.mkdirs(); |