Wed, 27 Apr 2016 01:34:52 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test |
aoqi@0 | 26 | * @bug 6942366 |
aoqi@0 | 27 | * @summary javadoc no longer inherits doc from sourcepath |
aoqi@0 | 28 | * @build p.Base Test |
aoqi@0 | 29 | * @run main T6942366 |
aoqi@0 | 30 | */ |
aoqi@0 | 31 | |
aoqi@0 | 32 | import java.io.*; |
aoqi@0 | 33 | import java.util.*; |
aoqi@0 | 34 | |
aoqi@0 | 35 | public class T6942366 { |
aoqi@0 | 36 | public static void main(String... args) throws Exception { |
aoqi@0 | 37 | new T6942366().run(); |
aoqi@0 | 38 | } |
aoqi@0 | 39 | |
aoqi@0 | 40 | File testSrc; |
aoqi@0 | 41 | File testClasses; |
aoqi@0 | 42 | int count; |
aoqi@0 | 43 | int errors; |
aoqi@0 | 44 | |
aoqi@0 | 45 | void run() throws Exception { |
aoqi@0 | 46 | testSrc = new File(System.getProperty("test.src")); |
aoqi@0 | 47 | testClasses = new File(System.getProperty("test.classes")); |
aoqi@0 | 48 | |
aoqi@0 | 49 | test(true, false); |
aoqi@0 | 50 | test(false, true); |
aoqi@0 | 51 | test(true, true); |
aoqi@0 | 52 | |
aoqi@0 | 53 | if (errors > 0) |
aoqi@0 | 54 | throw new Exception(errors + " errors found"); |
aoqi@0 | 55 | } |
aoqi@0 | 56 | |
aoqi@0 | 57 | void test(boolean useSourcePath, boolean useClassPath) throws Exception { |
aoqi@0 | 58 | System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath); |
aoqi@0 | 59 | File testDir = new File("test" + count); |
aoqi@0 | 60 | testDir.mkdirs(); |
aoqi@0 | 61 | |
aoqi@0 | 62 | List<String> args = new ArrayList<String>(); |
aoqi@0 | 63 | //args.add("-verbose"); |
aoqi@0 | 64 | args.add("-d"); |
aoqi@0 | 65 | args.add(testDir.getPath()); |
aoqi@0 | 66 | if (useSourcePath) { |
aoqi@0 | 67 | args.add("-sourcepath"); |
aoqi@0 | 68 | args.add(testSrc.getPath()); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | if (useClassPath) { |
aoqi@0 | 71 | args.add("-classpath"); |
aoqi@0 | 72 | args.add(testClasses.getPath()); |
aoqi@0 | 73 | } else { |
aoqi@0 | 74 | // override classpath to avoid stuff jtreg might have put on papth |
aoqi@0 | 75 | args.add("-classpath"); |
aoqi@0 | 76 | args.add("."); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | // use a very simple bootclasspath to avoid stuff jtreg might have put on path |
aoqi@0 | 80 | File javaHome = new File(System.getProperty("java.home")); |
aoqi@0 | 81 | File rt_jar = new File(javaHome, "lib/rt.jar"); |
aoqi@0 | 82 | if (!rt_jar.exists()) |
aoqi@0 | 83 | throw new Exception("rt.jar not found"); |
aoqi@0 | 84 | args.add("-bootclasspath"); |
aoqi@0 | 85 | args.add(rt_jar.getPath()); |
aoqi@0 | 86 | |
aoqi@0 | 87 | args.add(new File(testSrc, "Test.java").getPath()); |
aoqi@0 | 88 | System.out.println("javadoc: " + args); |
aoqi@0 | 89 | |
aoqi@0 | 90 | int rc = com.sun.tools.javadoc.Main.execute(args.toArray(new String[args.size()])); |
aoqi@0 | 91 | if (rc != 0) |
aoqi@0 | 92 | throw new Exception("unexpected exit from javadoc, rc=" + rc); |
aoqi@0 | 93 | |
aoqi@0 | 94 | if (useSourcePath && useClassPath) { |
aoqi@0 | 95 | long srcLastMod = new File(testSrc, "Test.java").lastModified(); |
aoqi@0 | 96 | long classLastMod = new File(testClasses, "Test.class").lastModified(); |
aoqi@0 | 97 | System.out.println("Test.java last modified: " + new Date(srcLastMod)); |
aoqi@0 | 98 | System.out.println("Test.class last modified: " + new Date(classLastMod)); |
aoqi@0 | 99 | System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer"); |
aoqi@0 | 100 | } |
aoqi@0 | 101 | |
aoqi@0 | 102 | String s = "javadoc-for-Base.m"; |
aoqi@0 | 103 | boolean expect = useSourcePath; |
aoqi@0 | 104 | boolean found = contains(new File(testDir, "Test.html"), s); |
aoqi@0 | 105 | if (found) { |
aoqi@0 | 106 | if (expect) |
aoqi@0 | 107 | System.out.println("javadoc content \"" + s + "\" found, as expected"); |
aoqi@0 | 108 | else |
aoqi@0 | 109 | error("javadoc content \"" + s + "\" found unexpectedly"); |
aoqi@0 | 110 | } else { |
aoqi@0 | 111 | if (expect) |
aoqi@0 | 112 | error("javadoc content \"" + s + "\" not found"); |
aoqi@0 | 113 | else |
aoqi@0 | 114 | System.out.println("javadoc content \"" + s + "\" not found, as expected"); |
aoqi@0 | 115 | } |
aoqi@0 | 116 | |
aoqi@0 | 117 | System.out.println(); |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | boolean contains(File f, String s) throws Exception { |
aoqi@0 | 121 | byte[] buf = new byte[(int) f.length()]; |
aoqi@0 | 122 | try (DataInputStream in = new DataInputStream(new FileInputStream(f))) { |
aoqi@0 | 123 | in.readFully(buf); |
aoqi@0 | 124 | } |
aoqi@0 | 125 | return new String(buf).contains(s); |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | void error(String msg) { |
aoqi@0 | 129 | System.out.println("Error: " + msg); |
aoqi@0 | 130 | errors++; |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | } |
aoqi@0 | 134 |