Path: blob/master/test/langtools/jdk/javadoc/tool/QuietOption.java
40957 views
/*1* Copyright (c) 2015, 2020, 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 8035473 818276526* @summary make sure tool is quiet when told to, and chatty otherwise27*/282930import java.io.BufferedReader;31import java.io.File;32import java.io.InputStreamReader;33import java.util.ArrayList;34import java.util.Iterator;35import java.util.List;3637/**38* Dummy javadoc comment.39*/40public class QuietOption {4142final File javadoc;43final File testSrc;44final String thisClassName;4546/**47* Dummy javadoc comment.48*/49public QuietOption() {50File javaHome = new File(System.getProperty("java.home"));51if (javaHome.getName().endsWith("jre"))52javaHome = javaHome.getParentFile();53javadoc = new File(new File(javaHome, "bin"), "javadoc");54testSrc = new File(System.getProperty("test.src"));55thisClassName = QuietOption.class.getName();56}5758/**59* Dummy javadoc comment.60* @param args dummy61* @throws Exception if error62*/63public static void main(String... args) throws Exception {64QuietOption test = new QuietOption();65test.run1();66test.run2();67}6869// make sure javadoc is quiet70void run1() throws Exception {71List<String> output = doTest(javadoc.getPath(),72"-classpath", ".", // insulates us from ambient classpath73"-quiet",74new File(testSrc, thisClassName + ".java").getPath());7576if (!output.isEmpty()) {77// Remove any lines that might have been generated by the runtime78Iterator<String> iter = output.iterator();79while (iter.hasNext()) {80String line = iter.next();81if (line.matches("^Picked up .*JAVA.*OPTIONS:.*")) {82System.out.println("IGNORING: " + line);83iter.remove();84}85}86}8788if (!output.isEmpty()) {89System.out.println(output);90throw new Exception("run1: Shhh!, very chatty javadoc!.");91}92}9394// make sure javadoc is chatty95void run2() throws Exception {96List<String> output = doTest(javadoc.getPath(),97"-classpath", ".", // insulates us from ambient classpath98new File(testSrc, thisClassName + ".java").getPath());99100if (output.isEmpty()) {101System.out.println(output);102throw new Exception("run2: speak up and please be heard!.");103}104}105106/**107* More dummy comments.108*/109List<String> doTest(String... args) throws Exception {110List<String> output = new ArrayList<>();111// run javadoc in separate process to ensure doclet executed under112// normal user conditions w.r.t. classloader113Process p = new ProcessBuilder()114.command(args)115.redirectErrorStream(true)116.start();117try (BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()))) {118String line = in.readLine();119while (line != null) {120output.add(line.trim());121line = in.readLine();122}123}124int rc = p.waitFor();125if (rc != 0) {126throw new Exception("javadoc failed, rc:" + rc);127}128return output;129}130}131132133