911N/A/*
911N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
911N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
911N/A *
911N/A * This code is free software; you can redistribute it and/or modify it
911N/A * under the terms of the GNU General Public License version 2 only, as
911N/A * published by the Free Software Foundation.
911N/A *
911N/A * This code is distributed in the hope that it will be useful, but WITHOUT
911N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
911N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
911N/A * version 2 for more details (a copy is included in the LICENSE file that
911N/A * accompanied this code).
911N/A *
911N/A * You should have received a copy of the GNU General Public License version
911N/A * 2 along with this work; if not, write to the Free Software Foundation,
911N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
911N/A *
911N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
911N/A * or visit www.oracle.com if you need additional information or have any
911N/A * questions.
911N/A */
911N/A
911N/A/*
911N/A * @test
911N/A * @bug 6964914
911N/A * @summary javadoc does not output number of warnings using user written doclet
911N/A */
911N/A
911N/Aimport java.io.*;
911N/Aimport com.sun.javadoc.Doclet;
911N/Aimport com.sun.javadoc.RootDoc;
911N/A
911N/Apublic class TestUserDoclet extends Doclet {
911N/A public static void main(String... args) throws Exception {
911N/A new TestUserDoclet().run();
911N/A }
911N/A
911N/A static final String docletWarning = "warning from test doclet";
911N/A
911N/A /** Main doclet method. */
911N/A public static boolean start(RootDoc root) {
911N/A root.printWarning(null, docletWarning);
911N/A return true;
911N/A }
911N/A
911N/A /** Main test method. */
911N/A void run() throws Exception {
911N/A File javaHome = new File(System.getProperty("java.home"));
911N/A if (javaHome.getName().equals("jre"))
911N/A javaHome = javaHome.getParentFile();
911N/A File javadoc = new File(new File(javaHome, "bin"), "javadoc");
911N/A File testSrc = new File(System.getProperty("test.src"));
911N/A File testClasses = new File(System.getProperty("test.classes"));
911N/A
911N/A // run javadoc in separate process to ensure doclet executed under
911N/A // normal user conditions w.r.t. classloader
911N/A String thisClassName = TestUserDoclet.class.getName();
911N/A Process p = new ProcessBuilder()
911N/A .command(javadoc.getPath(),
911N/A "-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"),
911N/A "-doclet", thisClassName,
911N/A "-docletpath", testClasses.getPath(),
911N/A new File(testSrc, thisClassName + ".java").getPath())
911N/A .redirectErrorStream(true)
911N/A .start();
911N/A
911N/A int actualDocletWarnCount = 0;
911N/A int reportedDocletWarnCount = 0;
911N/A BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
911N/A try {
911N/A String line;
911N/A while ((line = in.readLine()) != null) {
911N/A System.err.println(line);
911N/A if (line.contains(docletWarning))
911N/A actualDocletWarnCount++;
911N/A if (line.matches("[0-9]+ warning(s)?"))
911N/A reportedDocletWarnCount =
911N/A Integer.valueOf(line.substring(0, line.indexOf(" ")));
911N/A }
911N/A } finally {
911N/A in.close();
911N/A }
911N/A int rc = p.waitFor();
911N/A if (rc != 0)
911N/A System.err.println("javadoc failed, rc:" + rc);
911N/A
911N/A int expectedDocletWarnCount = 1;
911N/A checkEqual("actual", actualDocletWarnCount, "expected", expectedDocletWarnCount);
911N/A checkEqual("actual", actualDocletWarnCount, "reported", reportedDocletWarnCount);
911N/A }
911N/A
911N/A void checkEqual(String l1, int i1, String l2, int i2) throws Exception {
911N/A if (i1 != i2)
911N/A throw new Exception(l1 + " warn count, " + i1 + ", does not match "
911N/A + l2 + " warn count, " + i2);
911N/A }
911N/A
911N/A}