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