6968434: test CheckResourceKeys fails on control builds
authorjjg
Tue, 13 Jul 2010 19:17:55 -0700
changeset 6144 12fbc9782944
parent 6143 79b7dee406cc
child 6145 e52c4da245c9
6968434: test CheckResourceKeys fails on control builds Reviewed-by: darcy
langtools/test/tools/javac/diags/CheckResourceKeys.java
--- a/langtools/test/tools/javac/diags/CheckResourceKeys.java	Tue Jul 13 19:14:09 2010 -0700
+++ b/langtools/test/tools/javac/diags/CheckResourceKeys.java	Tue Jul 13 19:17:55 2010 -0700
@@ -294,6 +294,7 @@
         Set<String> results = new TreeSet<String>();
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
         JavaFileManager fm = c.getStandardFileManager(null, null, null);
+        JavaFileManager.Location javacLoc = findJavacLocation(fm);
         String[] pkgs = {
             "javax.annotation.processing",
             "javax.lang.model",
@@ -302,7 +303,7 @@
             "com.sun.tools.javac"
         };
         for (String pkg: pkgs) {
-            for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
+            for (JavaFileObject fo: fm.list(javacLoc,
                     pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
                 String name = fo.getName();
                 // ignore resource files, and files which are not really part of javac
@@ -316,6 +317,23 @@
         return results;
     }
 
+    // depending on how the test is run, javac may be on bootclasspath or classpath
+    JavaFileManager.Location findJavacLocation(JavaFileManager fm) {
+        JavaFileManager.Location[] locns =
+            { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH };
+        try {
+            for (JavaFileManager.Location l: locns) {
+                JavaFileObject fo = fm.getJavaFileForInput(l,
+                    "com.sun.tools.javac.Main", JavaFileObject.Kind.CLASS);
+                if (fo != null)
+                    return l;
+            }
+        } catch (IOException e) {
+            throw new Error(e);
+        }
+        throw new IllegalStateException("Cannot find javac");
+    }
+
     /**
      * Get the set of strings from a class file.
      * Only strings that look like they might be a resource key are returned.