test/tools/javac/diags/CheckResourceKeys.java

changeset 605
0e1fab5cffc8
parent 597
d2b7ecf33b35
child 916
cb9493a80341
     1.1 --- a/test/tools/javac/diags/CheckResourceKeys.java	Tue Jul 13 19:14:09 2010 -0700
     1.2 +++ b/test/tools/javac/diags/CheckResourceKeys.java	Tue Jul 13 19:17:55 2010 -0700
     1.3 @@ -294,6 +294,7 @@
     1.4          Set<String> results = new TreeSet<String>();
     1.5          JavaCompiler c = ToolProvider.getSystemJavaCompiler();
     1.6          JavaFileManager fm = c.getStandardFileManager(null, null, null);
     1.7 +        JavaFileManager.Location javacLoc = findJavacLocation(fm);
     1.8          String[] pkgs = {
     1.9              "javax.annotation.processing",
    1.10              "javax.lang.model",
    1.11 @@ -302,7 +303,7 @@
    1.12              "com.sun.tools.javac"
    1.13          };
    1.14          for (String pkg: pkgs) {
    1.15 -            for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
    1.16 +            for (JavaFileObject fo: fm.list(javacLoc,
    1.17                      pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
    1.18                  String name = fo.getName();
    1.19                  // ignore resource files, and files which are not really part of javac
    1.20 @@ -316,6 +317,23 @@
    1.21          return results;
    1.22      }
    1.23  
    1.24 +    // depending on how the test is run, javac may be on bootclasspath or classpath
    1.25 +    JavaFileManager.Location findJavacLocation(JavaFileManager fm) {
    1.26 +        JavaFileManager.Location[] locns =
    1.27 +            { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH };
    1.28 +        try {
    1.29 +            for (JavaFileManager.Location l: locns) {
    1.30 +                JavaFileObject fo = fm.getJavaFileForInput(l,
    1.31 +                    "com.sun.tools.javac.Main", JavaFileObject.Kind.CLASS);
    1.32 +                if (fo != null)
    1.33 +                    return l;
    1.34 +            }
    1.35 +        } catch (IOException e) {
    1.36 +            throw new Error(e);
    1.37 +        }
    1.38 +        throw new IllegalStateException("Cannot find javac");
    1.39 +    }
    1.40 +
    1.41      /**
    1.42       * Get the set of strings from a class file.
    1.43       * Only strings that look like they might be a resource key are returned.

mercurial