1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javadoc/6942366/T6942366.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,134 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6942366 1.30 + * @summary javadoc no longer inherits doc from sourcepath 1.31 + * @build p.Base Test 1.32 + * @run main T6942366 1.33 + */ 1.34 + 1.35 +import java.io.*; 1.36 +import java.util.*; 1.37 + 1.38 +public class T6942366 { 1.39 + public static void main(String... args) throws Exception { 1.40 + new T6942366().run(); 1.41 + } 1.42 + 1.43 + File testSrc; 1.44 + File testClasses; 1.45 + int count; 1.46 + int errors; 1.47 + 1.48 + void run() throws Exception { 1.49 + testSrc = new File(System.getProperty("test.src")); 1.50 + testClasses = new File(System.getProperty("test.classes")); 1.51 + 1.52 + test(true, false); 1.53 + test(false, true); 1.54 + test(true, true); 1.55 + 1.56 + if (errors > 0) 1.57 + throw new Exception(errors + " errors found"); 1.58 + } 1.59 + 1.60 + void test(boolean useSourcePath, boolean useClassPath) throws Exception { 1.61 + System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath); 1.62 + File testDir = new File("test" + count); 1.63 + testDir.mkdirs(); 1.64 + 1.65 + List<String> args = new ArrayList<String>(); 1.66 + //args.add("-verbose"); 1.67 + args.add("-d"); 1.68 + args.add(testDir.getPath()); 1.69 + if (useSourcePath) { 1.70 + args.add("-sourcepath"); 1.71 + args.add(testSrc.getPath()); 1.72 + } 1.73 + if (useClassPath) { 1.74 + args.add("-classpath"); 1.75 + args.add(testClasses.getPath()); 1.76 + } else { 1.77 + // override classpath to avoid stuff jtreg might have put on papth 1.78 + args.add("-classpath"); 1.79 + args.add("."); 1.80 + } 1.81 + 1.82 + // use a very simple bootclasspath to avoid stuff jtreg might have put on path 1.83 + File javaHome = new File(System.getProperty("java.home")); 1.84 + File rt_jar = new File(javaHome, "lib/rt.jar"); 1.85 + if (!rt_jar.exists()) 1.86 + throw new Exception("rt.jar not found"); 1.87 + args.add("-bootclasspath"); 1.88 + args.add(rt_jar.getPath()); 1.89 + 1.90 + args.add(new File(testSrc, "Test.java").getPath()); 1.91 + System.out.println("javadoc: " + args); 1.92 + 1.93 + int rc = com.sun.tools.javadoc.Main.execute(args.toArray(new String[args.size()])); 1.94 + if (rc != 0) 1.95 + throw new Exception("unexpected exit from javadoc, rc=" + rc); 1.96 + 1.97 + if (useSourcePath && useClassPath) { 1.98 + long srcLastMod = new File(testSrc, "Test.java").lastModified(); 1.99 + long classLastMod = new File(testClasses, "Test.class").lastModified(); 1.100 + System.out.println("Test.java last modified: " + new Date(srcLastMod)); 1.101 + System.out.println("Test.class last modified: " + new Date(classLastMod)); 1.102 + System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer"); 1.103 + } 1.104 + 1.105 + String s = "javadoc-for-Base.m"; 1.106 + boolean expect = useSourcePath; 1.107 + boolean found = contains(new File(testDir, "Test.html"), s); 1.108 + if (found) { 1.109 + if (expect) 1.110 + System.out.println("javadoc content \"" + s + "\" found, as expected"); 1.111 + else 1.112 + error("javadoc content \"" + s + "\" found unexpectedly"); 1.113 + } else { 1.114 + if (expect) 1.115 + error("javadoc content \"" + s + "\" not found"); 1.116 + else 1.117 + System.out.println("javadoc content \"" + s + "\" not found, as expected"); 1.118 + } 1.119 + 1.120 + System.out.println(); 1.121 + } 1.122 + 1.123 + boolean contains(File f, String s) throws Exception { 1.124 + byte[] buf = new byte[(int) f.length()]; 1.125 + try (DataInputStream in = new DataInputStream(new FileInputStream(f))) { 1.126 + in.readFully(buf); 1.127 + } 1.128 + return new String(buf).contains(s); 1.129 + } 1.130 + 1.131 + void error(String msg) { 1.132 + System.out.println("Error: " + msg); 1.133 + errors++; 1.134 + } 1.135 + 1.136 +} 1.137 +