Thu, 07 Aug 2014 12:24:46 +0100
Merge
jjg@1483 | 1 | /* |
jjg@1483 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@1483 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1483 | 4 | * |
jjg@1483 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1483 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1483 | 7 | * published by the Free Software Foundation. |
jjg@1483 | 8 | * |
jjg@1483 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1483 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1483 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1483 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1483 | 13 | * accompanied this code). |
jjg@1483 | 14 | * |
jjg@1483 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@1483 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1483 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1483 | 18 | * |
jjg@1483 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1483 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@1483 | 21 | * questions. |
jjg@1483 | 22 | */ |
jjg@1483 | 23 | |
jjg@1483 | 24 | /* |
jjg@1483 | 25 | * @test |
jjg@1483 | 26 | * @bug 8005644 |
jjg@1483 | 27 | * @summary set default max errs and max warns |
jjg@1483 | 28 | */ |
jjg@1483 | 29 | |
jjg@1483 | 30 | import java.io.File; |
jjg@1483 | 31 | import java.io.FileWriter; |
jjg@1483 | 32 | import java.io.IOException; |
jjg@1483 | 33 | import java.io.PrintWriter; |
jjg@1483 | 34 | import java.io.StringWriter; |
jjg@1483 | 35 | import java.util.regex.Matcher; |
jjg@1483 | 36 | import java.util.regex.Pattern; |
jjg@1483 | 37 | |
jjg@1483 | 38 | |
jjg@1483 | 39 | public class MaxWarns { |
jjg@1483 | 40 | public static void main(String... args) throws Exception { |
jjg@1483 | 41 | new MaxWarns().run(); |
jjg@1483 | 42 | } |
jjg@1483 | 43 | |
jjg@1483 | 44 | void run() throws Exception { |
jjg@1483 | 45 | final int defaultMaxWarns = 100; |
jjg@1483 | 46 | final int genWarns = 150; |
jjg@1483 | 47 | File f = genSrc(genWarns); |
jjg@1483 | 48 | String out = javadoc(f); |
jjg@1483 | 49 | check(out, defaultMaxWarns); |
jjg@1483 | 50 | |
jjg@1483 | 51 | if (errors > 0) |
jjg@1483 | 52 | throw new Exception(errors + " errors occurred"); |
jjg@1483 | 53 | } |
jjg@1483 | 54 | |
jjg@1483 | 55 | File genSrc(int count) throws IOException { |
jjg@1483 | 56 | StringBuilder sb = new StringBuilder(); |
jjg@1483 | 57 | sb.append("package p;\n") |
jjg@1483 | 58 | .append("public class C {\n") |
jjg@1483 | 59 | .append(" /**\n"); |
jjg@1483 | 60 | for (int i = 0; i < count; i++) |
jjg@1483 | 61 | sb.append(" * @param i").append(i).append(" does not exist!\n"); |
jjg@1483 | 62 | sb.append(" */\n") |
jjg@1483 | 63 | .append(" public void m() { }\n") |
jjg@1483 | 64 | .append("}\n"); |
jjg@1483 | 65 | File srcDir = new File("src"); |
jjg@1483 | 66 | srcDir.mkdirs(); |
jjg@1483 | 67 | File f = new File(srcDir, "C.java"); |
jjg@1483 | 68 | try (FileWriter fw = new FileWriter(f)) { |
jjg@1483 | 69 | fw.write(sb.toString()); |
jjg@1483 | 70 | } |
jjg@1483 | 71 | return f; |
jjg@1483 | 72 | } |
jjg@1483 | 73 | |
jjg@1483 | 74 | String javadoc(File f) { |
jjg@1483 | 75 | StringWriter sw = new StringWriter(); |
jjg@1483 | 76 | PrintWriter pw = new PrintWriter(sw); |
jjg@1490 | 77 | String[] args = { "-Xdoclint:none", "-d", "api", f.getPath() }; |
jjg@1483 | 78 | int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, |
jjg@1483 | 79 | com.sun.tools.doclets.standard.Standard.class.getName(), args); |
jjg@1483 | 80 | pw.flush(); |
jjg@1483 | 81 | return sw.toString(); |
jjg@1483 | 82 | } |
jjg@1483 | 83 | |
jjg@1483 | 84 | void check(String out, int count) { |
jjg@1483 | 85 | System.err.println(out); |
jjg@1483 | 86 | Pattern warn = Pattern.compile("warning - @param argument \"i[0-9]+\" is not a parameter name"); |
jjg@1483 | 87 | Matcher m = warn.matcher(out); |
jjg@1483 | 88 | int n = 0; |
jjg@1483 | 89 | for (int start = 0; m.find(start); start = m.start() + 1) { |
jjg@1483 | 90 | n++; |
jjg@1483 | 91 | } |
jjg@1483 | 92 | if (n != count) |
jjg@1483 | 93 | error("unexpected number of warnings reported: " + n + "; expected: " + count); |
jjg@1483 | 94 | |
jjg@1483 | 95 | Pattern warnCount = Pattern.compile("(?ms).*^([0-9]+) warnings$.*"); |
jjg@1483 | 96 | m = warnCount.matcher(out); |
jjg@1483 | 97 | if (m.matches()) { |
jjg@1483 | 98 | n = Integer.parseInt(m.group(1)); |
jjg@1483 | 99 | if (n != count) |
jjg@1483 | 100 | error("unexpected number of warnings reported: " + n + "; expected: " + count); |
jjg@1483 | 101 | } else |
jjg@1483 | 102 | error("total count not found"); |
jjg@1483 | 103 | } |
jjg@1483 | 104 | |
jjg@1483 | 105 | void error(String msg) { |
jjg@1483 | 106 | System.err.println("Error: " + msg); |
jjg@1483 | 107 | errors++; |
jjg@1483 | 108 | } |
jjg@1483 | 109 | |
jjg@1483 | 110 | int errors; |
jjg@1483 | 111 | } |
jjg@1483 | 112 |