Tue, 17 Sep 2013 14:17:13 -0700
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
Reviewed-by: darcy
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.File; |
mchung@1472 | 28 | import java.io.IOException; |
mchung@1472 | 29 | import java.nio.file.FileVisitResult; |
mchung@1472 | 30 | import java.nio.file.Files; |
mchung@1472 | 31 | import java.nio.file.Path; |
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@1472 | 41 | static List<Archive> getArchives() { |
mchung@1472 | 42 | return javaHomeArchives; |
mchung@1472 | 43 | } |
mchung@1472 | 44 | |
mchung@1472 | 45 | static boolean contains(Archive archive) { |
mchung@1472 | 46 | return javaHomeArchives.contains(archive); |
mchung@1472 | 47 | } |
mchung@1472 | 48 | |
mchung@1472 | 49 | private static List<Archive> init() { |
mchung@1472 | 50 | List<Archive> result = new ArrayList<Archive>(); |
mchung@1472 | 51 | String javaHome = System.getProperty("java.home"); |
mchung@1472 | 52 | File jre = new File(javaHome, "jre"); |
mchung@1472 | 53 | File lib = new File(javaHome, "lib"); |
mchung@1472 | 54 | |
mchung@1472 | 55 | try { |
mchung@1472 | 56 | if (jre.exists() && jre.isDirectory()) { |
mchung@1472 | 57 | result.addAll(addJarFiles(new File(jre, "lib"))); |
mchung@1472 | 58 | result.addAll(addJarFiles(lib)); |
mchung@1472 | 59 | } else if (lib.exists() && lib.isDirectory()) { |
mchung@1472 | 60 | // either a JRE or a jdk build image |
mchung@1472 | 61 | File classes = new File(javaHome, "classes"); |
mchung@1472 | 62 | if (classes.exists() && classes.isDirectory()) { |
mchung@1472 | 63 | // jdk build outputdir |
mchung@1472 | 64 | result.add(new Archive(classes, ClassFileReader.newInstance(classes))); |
mchung@1472 | 65 | } |
mchung@1472 | 66 | // add other JAR files |
mchung@1472 | 67 | result.addAll(addJarFiles(lib)); |
mchung@1472 | 68 | } else { |
mchung@1472 | 69 | throw new RuntimeException("\"" + javaHome + "\" not a JDK home"); |
mchung@1472 | 70 | } |
mchung@1472 | 71 | } catch (IOException e) { |
mchung@1472 | 72 | throw new RuntimeException(e); |
mchung@1472 | 73 | } |
mchung@1472 | 74 | return result; |
mchung@1472 | 75 | } |
mchung@1472 | 76 | |
mchung@1472 | 77 | private static List<Archive> addJarFiles(File f) throws IOException { |
mchung@1472 | 78 | final List<Archive> result = new ArrayList<Archive>(); |
mchung@1472 | 79 | final Path root = f.toPath(); |
mchung@1472 | 80 | final Path ext = root.resolve("ext"); |
mchung@1472 | 81 | Files.walkFileTree(root, new SimpleFileVisitor<Path>() { |
mchung@1472 | 82 | @Override |
mchung@1472 | 83 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) |
mchung@1472 | 84 | throws IOException |
mchung@1472 | 85 | { |
mchung@1472 | 86 | if (dir.equals(root) || dir.equals(ext)) { |
mchung@1472 | 87 | return FileVisitResult.CONTINUE; |
mchung@1472 | 88 | } else { |
mchung@1472 | 89 | // skip other cobundled JAR files |
mchung@1472 | 90 | return FileVisitResult.SKIP_SUBTREE; |
mchung@1472 | 91 | } |
mchung@1472 | 92 | } |
mchung@1472 | 93 | @Override |
mchung@1472 | 94 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) |
mchung@1472 | 95 | throws IOException |
mchung@1472 | 96 | { |
mchung@1472 | 97 | File f = file.toFile(); |
mchung@1472 | 98 | String fn = f.getName(); |
mchung@1472 | 99 | if (fn.endsWith(".jar") && !fn.equals("alt-rt.jar")) { |
mchung@1472 | 100 | result.add(new Archive(f, ClassFileReader.newInstance(f))); |
mchung@1472 | 101 | } |
mchung@1472 | 102 | return FileVisitResult.CONTINUE; |
mchung@1472 | 103 | } |
mchung@1472 | 104 | }); |
mchung@1472 | 105 | return result; |
mchung@1472 | 106 | } |
mchung@1472 | 107 | } |