Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/6942366/T6942366.java
38813 views
/*1* Copyright (c) 2010, 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* @build p.Base Test28* @run main T694236629*/3031import java.io.*;32import java.util.*;3334public class T6942366 {35public static void main(String... args) throws Exception {36new T6942366().run();37}3839File testSrc;40File testClasses;41int count;42int errors;4344void run() throws Exception {45testSrc = new File(System.getProperty("test.src"));46testClasses = new File(System.getProperty("test.classes"));4748test(true, false);49test(false, true);50test(true, true);5152if (errors > 0)53throw new Exception(errors + " errors found");54}5556void test(boolean useSourcePath, boolean useClassPath) throws Exception {57System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath);58File testDir = new File("test" + count);59testDir.mkdirs();6061List<String> args = new ArrayList<String>();62//args.add("-verbose");63args.add("-d");64args.add(testDir.getPath());65if (useSourcePath) {66args.add("-sourcepath");67args.add(testSrc.getPath());68}69if (useClassPath) {70args.add("-classpath");71args.add(testClasses.getPath());72} else {73// override classpath to avoid stuff jtreg might have put on papth74args.add("-classpath");75args.add(".");76}7778// use a very simple bootclasspath to avoid stuff jtreg might have put on path79File javaHome = new File(System.getProperty("java.home"));80File rt_jar = new File(javaHome, "lib/rt.jar");81if (!rt_jar.exists())82throw new Exception("rt.jar not found");83args.add("-bootclasspath");84args.add(rt_jar.getPath());8586args.add(new File(testSrc, "Test.java").getPath());87System.out.println("javadoc: " + args);8889int rc = com.sun.tools.javadoc.Main.execute(args.toArray(new String[args.size()]));90if (rc != 0)91throw new Exception("unexpected exit from javadoc, rc=" + rc);9293if (useSourcePath && useClassPath) {94long srcLastMod = new File(testSrc, "Test.java").lastModified();95long classLastMod = new File(testClasses, "Test.class").lastModified();96System.out.println("Test.java last modified: " + new Date(srcLastMod));97System.out.println("Test.class last modified: " + new Date(classLastMod));98System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer");99}100101String s = "javadoc-for-Base.m";102boolean expect = useSourcePath;103boolean found = contains(new File(testDir, "Test.html"), s);104if (found) {105if (expect)106System.out.println("javadoc content \"" + s + "\" found, as expected");107else108error("javadoc content \"" + s + "\" found unexpectedly");109} else {110if (expect)111error("javadoc content \"" + s + "\" not found");112else113System.out.println("javadoc content \"" + s + "\" not found, as expected");114}115116System.out.println();117}118119boolean contains(File f, String s) throws Exception {120byte[] buf = new byte[(int) f.length()];121try (DataInputStream in = new DataInputStream(new FileInputStream(f))) {122in.readFully(buf);123}124return new String(buf).contains(s);125}126127void error(String msg) {128System.out.println("Error: " + msg);129errors++;130}131132}133134135136