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