Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/6964914/TestStdDoclet.java
38813 views
/*1* Copyright (c) 2011, 2013, 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.*;3031/**32* Dummy javadoc comment.33* @author jjg34* @see DoesNotExist35*/36public class TestStdDoclet {37public static void main(String... args) throws Exception {38new TestStdDoclet().run();39}4041/**42* More dummy comments.43* @throws DoesNotExist oops, javadoc does not see this44* @see DoesNotExist45*/46void run() throws Exception {47File javaHome = new File(System.getProperty("java.home"));48if (javaHome.getName().equals("jre"))49javaHome = javaHome.getParentFile();50File javadoc = new File(new File(javaHome, "bin"), "javadoc");51File testSrc = new File(System.getProperty("test.src"));5253// run javadoc in separate process to ensure doclet executed under54// normal user conditions w.r.t. classloader55String thisClassName = TestStdDoclet.class.getName();56Process p = new ProcessBuilder()57.command(javadoc.getPath(),58"-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"),59"-Xdoclint:none",60"-package",61new File(testSrc, thisClassName + ".java").getPath())62.redirectErrorStream(true)63.start();6465int actualDocletWarnCount = 0;66int reportedDocletWarnCount = 0;67BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));68try {69String line;70while ((line = in.readLine()) != null) {71System.err.println(line);72if (line.contains("DoesNotExist"))73actualDocletWarnCount++;74if (line.matches("[0-9]+ warning(s)?"))75reportedDocletWarnCount =76Integer.valueOf(line.substring(0, line.indexOf(" ")));77}78} finally {79in.close();80}81int rc = p.waitFor();82if (rc != 0)83System.err.println("javadoc failed, rc:" + rc);8485int expectedDocletWarnCount = 2;86checkEqual("actual", actualDocletWarnCount, "expected", expectedDocletWarnCount);87checkEqual("actual", actualDocletWarnCount, "reported", reportedDocletWarnCount);88}8990/**91* Private method should not cause a warning.92* @see DoesNotExist93*/94private void checkEqual(String l1, int i1, String l2, int i2) throws Exception {95if (i1 != i2)96throw new Exception(l1 + " warn count, " + i1 + ", does not match "97+ l2 + " warn count, " + i2);98}99100}101102103