Path: blob/master/test/langtools/jdk/javadoc/tool/6942366/T6942366.java
40973 views
/*1* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 694236626* @summary javadoc no longer inherits doc from sourcepath27* @modules jdk.javadoc/jdk.javadoc.internal.tool28* @build p.Base Test29* @run main T694236630*/3132import java.io.*;33import java.util.*;3435public class T6942366 {36public static void main(String... args) throws Exception {37new T6942366().run();38}3940File testSrc;41File testClasses;42int count;43int errors;4445void run() throws Exception {46testSrc = new File(System.getProperty("test.src"));47testClasses = new File(System.getProperty("test.classes"));4849test(true, false);50test(false, true);51test(true, true);5253if (errors > 0)54throw new Exception(errors + " errors found");55}5657void test(boolean useSourcePath, boolean useClassPath) throws Exception {58System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath);59File testDir = new File("test" + count);60testDir.mkdirs();6162List<String> args = new ArrayList<String>();63//args.add("-verbose");64args.add("-d");65args.add(testDir.getPath());66if (useSourcePath) {67args.add("-sourcepath");68args.add(testSrc.getPath());69}70if (useClassPath) {71args.add("-classpath");72args.add(testClasses.getPath());73} else {74// override classpath to avoid stuff jtreg might have put on papth75args.add("-classpath");76args.add(".");77}7879args.add(new File(testSrc, "Test.java").getPath());80System.out.println("javadoc: " + args);8182int rc = jdk.javadoc.internal.tool.Main.execute(args.toArray(new String[args.size()]));83if (rc != 0)84throw new Exception("unexpected exit from javadoc, rc=" + rc);8586if (useSourcePath && useClassPath) {87long srcLastMod = new File(testSrc, "Test.java").lastModified();88long classLastMod = new File(testClasses, "Test.class").lastModified();89System.out.println("Test.java last modified: " + new Date(srcLastMod));90System.out.println("Test.class last modified: " + new Date(classLastMod));91System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer");92}9394String s = "javadoc-for-Base.m";95boolean expect = useSourcePath;96boolean found = contains(new File(testDir, "Test.html"), s);97if (found) {98if (expect)99System.out.println("javadoc content \"" + s + "\" found, as expected");100else101error("javadoc content \"" + s + "\" found unexpectedly");102} else {103if (expect)104error("javadoc content \"" + s + "\" not found");105else106System.out.println("javadoc content \"" + s + "\" not found, as expected");107}108109System.out.println();110}111112boolean contains(File f, String s) throws Exception {113byte[] buf = new byte[(int) f.length()];114try (DataInputStream in = new DataInputStream(new FileInputStream(f))) {115in.readFully(buf);116}117return new String(buf).contains(s);118}119120void error(String msg) {121System.out.println("Error: " + msg);122errors++;123}124125}126127128129