src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java

changeset 2139
defadd528513
parent 1648
a03c4a86ea2b
child 2525
2eb010b6cb22
child 2538
1e39ae45d8ac
     1.1 --- a/src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java	Thu Oct 17 13:50:00 2013 +0200
     1.2 +++ b/src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java	Thu Oct 17 13:19:48 2013 -0700
     1.3 @@ -24,11 +24,11 @@
     1.4   */
     1.5  package com.sun.tools.jdeps;
     1.6  
     1.7 -import java.io.File;
     1.8  import java.io.IOException;
     1.9  import java.nio.file.FileVisitResult;
    1.10  import java.nio.file.Files;
    1.11  import java.nio.file.Path;
    1.12 +import java.nio.file.Paths;
    1.13  import java.nio.file.SimpleFileVisitor;
    1.14  import java.nio.file.attribute.BasicFileAttributes;
    1.15  import java.util.*;
    1.16 @@ -38,45 +38,38 @@
    1.17   */
    1.18  class PlatformClassPath {
    1.19      private final static List<Archive> javaHomeArchives = init();
    1.20 +
    1.21      static List<Archive> getArchives() {
    1.22          return javaHomeArchives;
    1.23      }
    1.24  
    1.25 -    static boolean contains(Archive archive) {
    1.26 -        return javaHomeArchives.contains(archive);
    1.27 +    private static List<Archive> init() {
    1.28 +        List<Archive> result = new ArrayList<>();
    1.29 +        Path home = Paths.get(System.getProperty("java.home"));
    1.30 +        try {
    1.31 +            if (home.endsWith("jre")) {
    1.32 +                // jar files in <javahome>/jre/lib
    1.33 +                result.addAll(addJarFiles(home.resolve("lib")));
    1.34 +            } else if (Files.exists(home.resolve("lib"))) {
    1.35 +                // either a JRE or a jdk build image
    1.36 +                Path classes = home.resolve("classes");
    1.37 +                if (Files.isDirectory(classes)) {
    1.38 +                    // jdk build outputdir
    1.39 +                    result.add(new JDKArchive(classes, ClassFileReader.newInstance(classes)));
    1.40 +                }
    1.41 +                // add other JAR files
    1.42 +                result.addAll(addJarFiles(home.resolve("lib")));
    1.43 +            } else {
    1.44 +                throw new RuntimeException("\"" + home + "\" not a JDK home");
    1.45 +            }
    1.46 +            return result;
    1.47 +        } catch (IOException e) {
    1.48 +            throw new Error(e);
    1.49 +        }
    1.50      }
    1.51  
    1.52 -    private static List<Archive> init() {
    1.53 -        List<Archive> result = new ArrayList<Archive>();
    1.54 -        String javaHome = System.getProperty("java.home");
    1.55 -        File jre = new File(javaHome, "jre");
    1.56 -        File lib = new File(javaHome, "lib");
    1.57 -
    1.58 -        try {
    1.59 -            if (jre.exists() && jre.isDirectory()) {
    1.60 -                result.addAll(addJarFiles(new File(jre, "lib")));
    1.61 -                result.addAll(addJarFiles(lib));
    1.62 -            } else if (lib.exists() && lib.isDirectory()) {
    1.63 -                // either a JRE or a jdk build image
    1.64 -                File classes = new File(javaHome, "classes");
    1.65 -                if (classes.exists() && classes.isDirectory()) {
    1.66 -                    // jdk build outputdir
    1.67 -                    result.add(new Archive(classes, ClassFileReader.newInstance(classes)));
    1.68 -                }
    1.69 -                // add other JAR files
    1.70 -                result.addAll(addJarFiles(lib));
    1.71 -            } else {
    1.72 -                throw new RuntimeException("\"" + javaHome + "\" not a JDK home");
    1.73 -            }
    1.74 -        } catch (IOException e) {
    1.75 -            throw new RuntimeException(e);
    1.76 -        }
    1.77 -        return result;
    1.78 -    }
    1.79 -
    1.80 -    private static List<Archive> addJarFiles(File f) throws IOException {
    1.81 -        final List<Archive> result = new ArrayList<Archive>();
    1.82 -        final Path root = f.toPath();
    1.83 +    private static List<Archive> addJarFiles(final Path root) throws IOException {
    1.84 +        final List<Archive> result = new ArrayList<>();
    1.85          final Path ext = root.resolve("ext");
    1.86          Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
    1.87              @Override
    1.88 @@ -91,17 +84,30 @@
    1.89                  }
    1.90              }
    1.91              @Override
    1.92 -            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
    1.93 +            public FileVisitResult visitFile(Path p, BasicFileAttributes attrs)
    1.94                  throws IOException
    1.95              {
    1.96 -                File f = file.toFile();
    1.97 -                String fn = f.getName();
    1.98 -                if (fn.endsWith(".jar") && !fn.equals("alt-rt.jar")) {
    1.99 -                    result.add(new Archive(f, ClassFileReader.newInstance(f)));
   1.100 +                String fn = p.getFileName().toString();
   1.101 +                if (fn.endsWith(".jar")) {
   1.102 +                    // JDK may cobundle with JavaFX that doesn't belong to any profile
   1.103 +                    // Treat jfxrt.jar as regular Archive
   1.104 +                    result.add(fn.equals("jfxrt.jar")
   1.105 +                        ? new Archive(p, ClassFileReader.newInstance(p))
   1.106 +                        : new JDKArchive(p, ClassFileReader.newInstance(p)));
   1.107                  }
   1.108                  return FileVisitResult.CONTINUE;
   1.109              }
   1.110          });
   1.111          return result;
   1.112      }
   1.113 +
   1.114 +    /**
   1.115 +     * A JDK archive is part of the JDK containing the Java SE API
   1.116 +     * or implementation classes (i.e. JDK internal API)
   1.117 +     */
   1.118 +    static class JDKArchive extends Archive {
   1.119 +        JDKArchive(Path p, ClassFileReader reader) {
   1.120 +            super(p, reader);
   1.121 +        }
   1.122 +    }
   1.123  }

mercurial