jjg@1483: /* jjg@1483: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. jjg@1483: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@1483: * jjg@1483: * This code is free software; you can redistribute it and/or modify it jjg@1483: * under the terms of the GNU General Public License version 2 only, as jjg@1483: * published by the Free Software Foundation. jjg@1483: * jjg@1483: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@1483: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@1483: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@1483: * version 2 for more details (a copy is included in the LICENSE file that jjg@1483: * accompanied this code). jjg@1483: * jjg@1483: * You should have received a copy of the GNU General Public License version jjg@1483: * 2 along with this work; if not, write to the Free Software Foundation, jjg@1483: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@1483: * jjg@1483: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@1483: * or visit www.oracle.com if you need additional information or have any jjg@1483: * questions. jjg@1483: */ jjg@1483: jjg@1483: /* jjg@1483: * @test jjg@1483: * @bug 8005644 jjg@1483: * @summary set default max errs and max warns jjg@1483: */ jjg@1483: jjg@1483: import java.io.File; jjg@1483: import java.io.FileWriter; jjg@1483: import java.io.IOException; jjg@1483: import java.io.PrintWriter; jjg@1483: import java.io.StringWriter; jjg@1483: import java.util.regex.Matcher; jjg@1483: import java.util.regex.Pattern; jjg@1483: jjg@1483: jjg@1483: public class MaxWarns { jjg@1483: public static void main(String... args) throws Exception { jjg@1483: new MaxWarns().run(); jjg@1483: } jjg@1483: jjg@1483: void run() throws Exception { jjg@1483: final int defaultMaxWarns = 100; jjg@1483: final int genWarns = 150; jjg@1483: File f = genSrc(genWarns); jjg@1483: String out = javadoc(f); jjg@1483: check(out, defaultMaxWarns); jjg@1483: jjg@1483: if (errors > 0) jjg@1483: throw new Exception(errors + " errors occurred"); jjg@1483: } jjg@1483: jjg@1483: File genSrc(int count) throws IOException { jjg@1483: StringBuilder sb = new StringBuilder(); jjg@1483: sb.append("package p;\n") jjg@1483: .append("public class C {\n") jjg@1483: .append(" /**\n"); jjg@1483: for (int i = 0; i < count; i++) jjg@1483: sb.append(" * @param i").append(i).append(" does not exist!\n"); jjg@1483: sb.append(" */\n") jjg@1483: .append(" public void m() { }\n") jjg@1483: .append("}\n"); jjg@1483: File srcDir = new File("src"); jjg@1483: srcDir.mkdirs(); jjg@1483: File f = new File(srcDir, "C.java"); jjg@1483: try (FileWriter fw = new FileWriter(f)) { jjg@1483: fw.write(sb.toString()); jjg@1483: } jjg@1483: return f; jjg@1483: } jjg@1483: jjg@1483: String javadoc(File f) { jjg@1483: StringWriter sw = new StringWriter(); jjg@1483: PrintWriter pw = new PrintWriter(sw); jjg@1490: String[] args = { "-Xdoclint:none", "-d", "api", f.getPath() }; jjg@1483: int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, jjg@1483: com.sun.tools.doclets.standard.Standard.class.getName(), args); jjg@1483: pw.flush(); jjg@1483: return sw.toString(); jjg@1483: } jjg@1483: jjg@1483: void check(String out, int count) { jjg@1483: System.err.println(out); jjg@1483: Pattern warn = Pattern.compile("warning - @param argument \"i[0-9]+\" is not a parameter name"); jjg@1483: Matcher m = warn.matcher(out); jjg@1483: int n = 0; jjg@1483: for (int start = 0; m.find(start); start = m.start() + 1) { jjg@1483: n++; jjg@1483: } jjg@1483: if (n != count) jjg@1483: error("unexpected number of warnings reported: " + n + "; expected: " + count); jjg@1483: jjg@1483: Pattern warnCount = Pattern.compile("(?ms).*^([0-9]+) warnings$.*"); jjg@1483: m = warnCount.matcher(out); jjg@1483: if (m.matches()) { jjg@1483: n = Integer.parseInt(m.group(1)); jjg@1483: if (n != count) jjg@1483: error("unexpected number of warnings reported: " + n + "; expected: " + count); jjg@1483: } else jjg@1483: error("total count not found"); jjg@1483: } jjg@1483: jjg@1483: void error(String msg) { jjg@1483: System.err.println("Error: " + msg); jjg@1483: errors++; jjg@1483: } jjg@1483: jjg@1483: int errors; jjg@1483: } jjg@1483: