Path: blob/master/test/langtools/jdk/javadoc/tool/MaxWarns.java
40957 views
/*1* Copyright (c) 2013, 2021, 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 8005644 818276526* @summary set default max errs and max warns27* @modules jdk.javadoc/jdk.javadoc.internal.tool28*/2930import java.io.File;31import java.io.FileWriter;32import java.io.IOException;33import java.io.PrintWriter;34import java.io.StringWriter;35import java.util.regex.Matcher;36import java.util.regex.Pattern;373839public class MaxWarns {40public static void main(String... args) throws Exception {41new MaxWarns().run();42}4344void run() throws Exception {45final int defaultMaxWarns = 100;46final int genWarns = 150;47File f = genSrc(genWarns);48String out = javadoc(f);49check(out, defaultMaxWarns);5051if (errors > 0)52throw new Exception(errors + " errors occurred");53}5455File genSrc(int count) throws IOException {56StringBuilder sb = new StringBuilder();57sb.append("package p;\n")58.append("public class C {\n")59.append(" /**\n");60for (int i = 0; i < count; i++)61sb.append(" * @param i").append(i).append(" does not exist!\n");62sb.append(" */\n")63.append(" public void m() { }\n")64.append("}\n");65File srcDir = new File("src");66srcDir.mkdirs();67File f = new File(srcDir, "C.java");68try (FileWriter fw = new FileWriter(f)) {69fw.write(sb.toString());70}71return f;72}7374String javadoc(File f) {75StringWriter sw = new StringWriter();76PrintWriter pw = new PrintWriter(sw);77String[] args = { "-Xdoclint:none", "--no-platform-links", "-d", "api", f.getPath() };78int rc = jdk.javadoc.internal.tool.Main.execute(args, pw);79pw.flush();80return sw.toString();81}8283void check(String out, int count) {84System.err.println(out);85Pattern warn = Pattern.compile("""86warning: @param argument "i[0-9]+" is not a parameter name""");87Matcher m = warn.matcher(out);88int n = 0;89for (int start = 0; m.find(start); start = m.start() + 1) {90n++;91}92if (n != count)93error("unexpected number of warnings reported: " + n + "; expected: " + count);9495Pattern warnCount = Pattern.compile("(?ms).*^([0-9]+) warnings$.*");96m = warnCount.matcher(out);97if (m.matches()) {98n = Integer.parseInt(m.group(1));99if (n != count)100error("unexpected number of warnings reported: " + n + "; expected: " + count);101} else102error("total count not found");103}104105void error(String msg) {106System.err.println("Error: " + msg);107errors++;108}109110int errors;111}112113114115