test/tools/javadoc/6964914/TestStdDoclet.java

Thu, 25 Aug 2011 17:18:25 -0700

author
schien
date
Thu, 25 Aug 2011 17:18:25 -0700
changeset 1067
f497fac86cf9
parent 912
5e6c661891da
child 1490
fc4cb1577ad6
permissions
-rw-r--r--

Added tag jdk8-b02 for changeset b3c059de2a61

jjg@912 1 /*
jjg@912 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
jjg@912 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@912 4 *
jjg@912 5 * This code is free software; you can redistribute it and/or modify it
jjg@912 6 * under the terms of the GNU General Public License version 2 only, as
jjg@912 7 * published by the Free Software Foundation.
jjg@912 8 *
jjg@912 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@912 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@912 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@912 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@912 13 * accompanied this code).
jjg@912 14 *
jjg@912 15 * You should have received a copy of the GNU General Public License version
jjg@912 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@912 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@912 18 *
jjg@912 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@912 20 * or visit www.oracle.com if you need additional information or have any
jjg@912 21 * questions.
jjg@912 22 */
jjg@912 23
jjg@912 24 /*
jjg@912 25 * @test
jjg@912 26 * @bug 6964914
jjg@912 27 * @summary javadoc does not output number of warnings using user written doclet
jjg@912 28 */
jjg@912 29
jjg@912 30 import java.io.*;
jjg@912 31
jjg@912 32 /**
jjg@912 33 * Dummy javadoc comment.
jjg@912 34 * @author jjg
jjg@912 35 * @see DoesNotExist
jjg@912 36 */
jjg@912 37 public class TestStdDoclet {
jjg@912 38 public static void main(String... args) throws Exception {
jjg@912 39 new TestStdDoclet().run();
jjg@912 40 }
jjg@912 41
jjg@912 42 /**
jjg@912 43 * More dummy comments.
jjg@912 44 * @throws DoesNotExist oops, javadoc does not see this
jjg@912 45 * @see DoesNotExist
jjg@912 46 */
jjg@912 47 void run() throws Exception {
jjg@912 48 File javaHome = new File(System.getProperty("java.home"));
jjg@912 49 if (javaHome.getName().equals("jre"))
jjg@912 50 javaHome = javaHome.getParentFile();
jjg@912 51 File javadoc = new File(new File(javaHome, "bin"), "javadoc");
jjg@912 52 File testSrc = new File(System.getProperty("test.src"));
jjg@912 53
jjg@912 54 // run javadoc in separate process to ensure doclet executed under
jjg@912 55 // normal user conditions w.r.t. classloader
jjg@912 56 String thisClassName = TestStdDoclet.class.getName();
jjg@912 57 Process p = new ProcessBuilder()
jjg@912 58 .command(javadoc.getPath(),
jjg@912 59 "-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"),
jjg@912 60 "-package",
jjg@912 61 new File(testSrc, thisClassName + ".java").getPath())
jjg@912 62 .redirectErrorStream(true)
jjg@912 63 .start();
jjg@912 64
jjg@912 65 int actualDocletWarnCount = 0;
jjg@912 66 int reportedDocletWarnCount = 0;
jjg@912 67 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
jjg@912 68 try {
jjg@912 69 String line;
jjg@912 70 while ((line = in.readLine()) != null) {
jjg@912 71 System.err.println(line);
jjg@912 72 if (line.contains("DoesNotExist"))
jjg@912 73 actualDocletWarnCount++;
jjg@912 74 if (line.matches("[0-9]+ warning(s)?"))
jjg@912 75 reportedDocletWarnCount =
jjg@912 76 Integer.valueOf(line.substring(0, line.indexOf(" ")));
jjg@912 77 }
jjg@912 78 } finally {
jjg@912 79 in.close();
jjg@912 80 }
jjg@912 81 int rc = p.waitFor();
jjg@912 82 if (rc != 0)
jjg@912 83 System.err.println("javadoc failed, rc:" + rc);
jjg@912 84
jjg@912 85 int expectedDocletWarnCount = 2;
jjg@912 86 checkEqual("actual", actualDocletWarnCount, "expected", expectedDocletWarnCount);
jjg@912 87 checkEqual("actual", actualDocletWarnCount, "reported", reportedDocletWarnCount);
jjg@912 88 }
jjg@912 89
jjg@912 90 /**
jjg@912 91 * Private method should not cause a warning.
jjg@912 92 * @see DoesNotExist
jjg@912 93 */
jjg@912 94 private void checkEqual(String l1, int i1, String l2, int i2) throws Exception {
jjg@912 95 if (i1 != i2)
jjg@912 96 throw new Exception(l1 + " warn count, " + i1 + ", does not match "
jjg@912 97 + l2 + " warn count, " + i2);
jjg@912 98 }
jjg@912 99
jjg@912 100 }

mercurial