Thu, 17 Oct 2013 13:19:48 -0700
8015912: jdeps support to output in dot file format
8026255: Switch jdeps to follow traditional Java option style
Reviewed-by: alanb
mchung@1472 | 1 | /* |
jjg@1648 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
mchung@1472 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mchung@1472 | 4 | * |
mchung@1472 | 5 | * This code is free software; you can redistribute it and/or modify it |
mchung@1472 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mchung@1472 | 7 | * published by the Free Software Foundation. Oracle designates this |
mchung@1472 | 8 | * particular file as subject to the "Classpath" exception as provided |
mchung@1472 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
mchung@1472 | 10 | * |
mchung@1472 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mchung@1472 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mchung@1472 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mchung@1472 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
mchung@1472 | 15 | * accompanied this code). |
mchung@1472 | 16 | * |
mchung@1472 | 17 | * You should have received a copy of the GNU General Public License version |
mchung@1472 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
mchung@1472 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mchung@1472 | 20 | * |
mchung@1472 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mchung@1472 | 22 | * or visit www.oracle.com if you need additional information or have any |
mchung@1472 | 23 | * questions. |
mchung@1472 | 24 | */ |
mchung@1472 | 25 | package com.sun.tools.jdeps; |
mchung@1472 | 26 | |
mchung@1472 | 27 | import java.io.IOException; |
mchung@1472 | 28 | import java.nio.file.FileVisitResult; |
mchung@1472 | 29 | import java.nio.file.Files; |
mchung@1472 | 30 | import java.nio.file.Path; |
mchung@2139 | 31 | import java.nio.file.Paths; |
mchung@1472 | 32 | import java.nio.file.SimpleFileVisitor; |
mchung@1472 | 33 | import java.nio.file.attribute.BasicFileAttributes; |
mchung@1472 | 34 | import java.util.*; |
mchung@1472 | 35 | |
mchung@1472 | 36 | /** |
mchung@1472 | 37 | * ClassPath for Java SE and JDK |
mchung@1472 | 38 | */ |
mchung@1472 | 39 | class PlatformClassPath { |
mchung@1472 | 40 | private final static List<Archive> javaHomeArchives = init(); |
mchung@2139 | 41 | |
mchung@1472 | 42 | static List<Archive> getArchives() { |
mchung@1472 | 43 | return javaHomeArchives; |
mchung@1472 | 44 | } |
mchung@1472 | 45 | |
mchung@2139 | 46 | private static List<Archive> init() { |
mchung@2139 | 47 | List<Archive> result = new ArrayList<>(); |
mchung@2139 | 48 | Path home = Paths.get(System.getProperty("java.home")); |
mchung@2139 | 49 | try { |
mchung@2139 | 50 | if (home.endsWith("jre")) { |
mchung@2139 | 51 | // jar files in <javahome>/jre/lib |
mchung@2139 | 52 | result.addAll(addJarFiles(home.resolve("lib"))); |
mchung@2139 | 53 | } else if (Files.exists(home.resolve("lib"))) { |
mchung@2139 | 54 | // either a JRE or a jdk build image |
mchung@2139 | 55 | Path classes = home.resolve("classes"); |
mchung@2139 | 56 | if (Files.isDirectory(classes)) { |
mchung@2139 | 57 | // jdk build outputdir |
mchung@2139 | 58 | result.add(new JDKArchive(classes, ClassFileReader.newInstance(classes))); |
mchung@2139 | 59 | } |
mchung@2139 | 60 | // add other JAR files |
mchung@2139 | 61 | result.addAll(addJarFiles(home.resolve("lib"))); |
mchung@2139 | 62 | } else { |
mchung@2139 | 63 | throw new RuntimeException("\"" + home + "\" not a JDK home"); |
mchung@2139 | 64 | } |
mchung@2139 | 65 | return result; |
mchung@2139 | 66 | } catch (IOException e) { |
mchung@2139 | 67 | throw new Error(e); |
mchung@2139 | 68 | } |
mchung@1472 | 69 | } |
mchung@1472 | 70 | |
mchung@2139 | 71 | private static List<Archive> addJarFiles(final Path root) throws IOException { |
mchung@2139 | 72 | final List<Archive> result = new ArrayList<>(); |
mchung@1472 | 73 | final Path ext = root.resolve("ext"); |
mchung@1472 | 74 | Files.walkFileTree(root, new SimpleFileVisitor<Path>() { |
mchung@1472 | 75 | @Override |
mchung@1472 | 76 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) |
mchung@1472 | 77 | throws IOException |
mchung@1472 | 78 | { |
mchung@1472 | 79 | if (dir.equals(root) || dir.equals(ext)) { |
mchung@1472 | 80 | return FileVisitResult.CONTINUE; |
mchung@1472 | 81 | } else { |
mchung@1472 | 82 | // skip other cobundled JAR files |
mchung@1472 | 83 | return FileVisitResult.SKIP_SUBTREE; |
mchung@1472 | 84 | } |
mchung@1472 | 85 | } |
mchung@1472 | 86 | @Override |
mchung@2139 | 87 | public FileVisitResult visitFile(Path p, BasicFileAttributes attrs) |
mchung@1472 | 88 | throws IOException |
mchung@1472 | 89 | { |
mchung@2139 | 90 | String fn = p.getFileName().toString(); |
mchung@2139 | 91 | if (fn.endsWith(".jar")) { |
mchung@2139 | 92 | // JDK may cobundle with JavaFX that doesn't belong to any profile |
mchung@2139 | 93 | // Treat jfxrt.jar as regular Archive |
mchung@2139 | 94 | result.add(fn.equals("jfxrt.jar") |
mchung@2139 | 95 | ? new Archive(p, ClassFileReader.newInstance(p)) |
mchung@2139 | 96 | : new JDKArchive(p, ClassFileReader.newInstance(p))); |
mchung@1472 | 97 | } |
mchung@1472 | 98 | return FileVisitResult.CONTINUE; |
mchung@1472 | 99 | } |
mchung@1472 | 100 | }); |
mchung@1472 | 101 | return result; |
mchung@1472 | 102 | } |
mchung@2139 | 103 | |
mchung@2139 | 104 | /** |
mchung@2139 | 105 | * A JDK archive is part of the JDK containing the Java SE API |
mchung@2139 | 106 | * or implementation classes (i.e. JDK internal API) |
mchung@2139 | 107 | */ |
mchung@2139 | 108 | static class JDKArchive extends Archive { |
mchung@2139 | 109 | JDKArchive(Path p, ClassFileReader reader) { |
mchung@2139 | 110 | super(p, reader); |
mchung@2139 | 111 | } |
mchung@2139 | 112 | } |
mchung@1472 | 113 | } |