Path: blob/master/test/langtools/jdk/javadoc/tool/6964914/TestStdDoclet.java
40971 views
/*1* Copyright (c) 2011, 2021, 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 696491426* @summary javadoc does not output number of warnings using user written doclet27*/2829import java.io.*;30import java.util.*;3132/**33* Dummy javadoc comment.34* @author jjg35* @see DoesNotExist36*/37public class TestStdDoclet {38public static void main(String... args) throws Exception {39new TestStdDoclet().run();40}4142/**43* More dummy comments.44* @throws DoesNotExist oops, javadoc does not see this45* @see DoesNotExist46*/47void run() throws Exception {48File javaHome = new File(System.getProperty("java.home"));49File javadoc = new File(new File(javaHome, "bin"), "javadoc");50File testSrc = new File(System.getProperty("test.src"));5152// run javadoc in separate process to ensure doclet executed under53// normal user conditions w.r.t. classloader54String thisClassName = TestStdDoclet.class.getName();55List<String> cmdArgs = new ArrayList<>();56cmdArgs.add(javadoc.getPath());57cmdArgs.addAll(Arrays.asList(58"-classpath", ".", // insulates us from ambient classpath59"-Xdoclint:none",60"-package",61new File(testSrc, thisClassName + ".java").getPath()62));63Process p = new ProcessBuilder()64.command(cmdArgs)65.redirectErrorStream(true)66.start();6768int actualDocletWarnCount = 0;69int reportedDocletWarnCount = 0;70BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));71try {72String line;73while ((line = in.readLine()) != null) {74System.err.println(line);75if (line.contains("TestStdDoclet.java") && line.contains("DoesNotExist")) {76actualDocletWarnCount++;77}78if (line.matches("[0-9]+ warning(s)?")) {79reportedDocletWarnCount =80Integer.valueOf(line.substring(0, line.indexOf(" ")));81}82}83} finally {84in.close();85}86int rc = p.waitFor();87if (rc != 0)88System.err.println("javadoc failed, rc:" + rc);8990int expectedDocletWarnCount = 2;91checkEqual("actual", actualDocletWarnCount, "expected", expectedDocletWarnCount);92checkEqual("actual", actualDocletWarnCount, "reported", reportedDocletWarnCount);93}9495/**96* Private method should not cause a warning.97* @see DoesNotExist98*/99private void checkEqual(String l1, int i1, String l2, int i2) throws Exception {100if (i1 != i2)101throw new Exception(l1 + " warn count, " + i1 + ", does not match "102+ l2 + " warn count, " + i2);103}104105}106107108