Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/MaxWarns.java
32285 views
/*1* Copyright (c) 2013, 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 800564426* @summary set default max errs and max warns27*/2829import java.io.File;30import java.io.FileWriter;31import java.io.IOException;32import java.io.PrintWriter;33import java.io.StringWriter;34import java.util.regex.Matcher;35import java.util.regex.Pattern;363738public class MaxWarns {39public static void main(String... args) throws Exception {40new MaxWarns().run();41}4243void run() throws Exception {44final int defaultMaxWarns = 100;45final int genWarns = 150;46File f = genSrc(genWarns);47String out = javadoc(f);48check(out, defaultMaxWarns);4950if (errors > 0)51throw new Exception(errors + " errors occurred");52}5354File genSrc(int count) throws IOException {55StringBuilder sb = new StringBuilder();56sb.append("package p;\n")57.append("public class C {\n")58.append(" /**\n");59for (int i = 0; i < count; i++)60sb.append(" * @param i").append(i).append(" does not exist!\n");61sb.append(" */\n")62.append(" public void m() { }\n")63.append("}\n");64File srcDir = new File("src");65srcDir.mkdirs();66File f = new File(srcDir, "C.java");67try (FileWriter fw = new FileWriter(f)) {68fw.write(sb.toString());69}70return f;71}7273String javadoc(File f) {74StringWriter sw = new StringWriter();75PrintWriter pw = new PrintWriter(sw);76String[] args = { "-Xdoclint:none", "-d", "api", f.getPath() };77int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw,78com.sun.tools.doclets.standard.Standard.class.getName(), args);79pw.flush();80return sw.toString();81}8283void check(String out, int count) {84System.err.println(out);85Pattern warn = Pattern.compile("warning - @param argument \"i[0-9]+\" is not a parameter name");86Matcher m = warn.matcher(out);87int n = 0;88for (int start = 0; m.find(start); start = m.start() + 1) {89n++;90}91if (n != count)92error("unexpected number of warnings reported: " + n + "; expected: " + count);9394Pattern warnCount = Pattern.compile("(?ms).*^([0-9]+) warnings$.*");95m = warnCount.matcher(out);96if (m.matches()) {97n = Integer.parseInt(m.group(1));98if (n != count)99error("unexpected number of warnings reported: " + n + "; expected: " + count);100} else101error("total count not found");102}103104void error(String msg) {105System.err.println("Error: " + msg);106errors++;107}108109int errors;110}111112113114