292 */ |
292 */ |
293 Set<String> getCodeStrings() throws IOException { |
293 Set<String> getCodeStrings() throws IOException { |
294 Set<String> results = new TreeSet<String>(); |
294 Set<String> results = new TreeSet<String>(); |
295 JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
295 JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
296 JavaFileManager fm = c.getStandardFileManager(null, null, null); |
296 JavaFileManager fm = c.getStandardFileManager(null, null, null); |
|
297 JavaFileManager.Location javacLoc = findJavacLocation(fm); |
297 String[] pkgs = { |
298 String[] pkgs = { |
298 "javax.annotation.processing", |
299 "javax.annotation.processing", |
299 "javax.lang.model", |
300 "javax.lang.model", |
300 "javax.tools", |
301 "javax.tools", |
301 "com.sun.source", |
302 "com.sun.source", |
302 "com.sun.tools.javac" |
303 "com.sun.tools.javac" |
303 }; |
304 }; |
304 for (String pkg: pkgs) { |
305 for (String pkg: pkgs) { |
305 for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH, |
306 for (JavaFileObject fo: fm.list(javacLoc, |
306 pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) { |
307 pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) { |
307 String name = fo.getName(); |
308 String name = fo.getName(); |
308 // ignore resource files, and files which are not really part of javac |
309 // ignore resource files, and files which are not really part of javac |
309 if (name.contains("resources") |
310 if (name.contains("resources") |
310 || name.contains("Launcher.class") |
311 || name.contains("Launcher.class") |
312 continue; |
313 continue; |
313 scan(fo, results); |
314 scan(fo, results); |
314 } |
315 } |
315 } |
316 } |
316 return results; |
317 return results; |
|
318 } |
|
319 |
|
320 // depending on how the test is run, javac may be on bootclasspath or classpath |
|
321 JavaFileManager.Location findJavacLocation(JavaFileManager fm) { |
|
322 JavaFileManager.Location[] locns = |
|
323 { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH }; |
|
324 try { |
|
325 for (JavaFileManager.Location l: locns) { |
|
326 JavaFileObject fo = fm.getJavaFileForInput(l, |
|
327 "com.sun.tools.javac.Main", JavaFileObject.Kind.CLASS); |
|
328 if (fo != null) |
|
329 return l; |
|
330 } |
|
331 } catch (IOException e) { |
|
332 throw new Error(e); |
|
333 } |
|
334 throw new IllegalStateException("Cannot find javac"); |
317 } |
335 } |
318 |
336 |
319 /** |
337 /** |
320 * Get the set of strings from a class file. |
338 * Get the set of strings from a class file. |
321 * Only strings that look like they might be a resource key are returned. |
339 * Only strings that look like they might be a resource key are returned. |