langtools/test/tools/javac/doclint/IncludePackagesTest.java
author jlahoda
Wed, 11 Mar 2015 22:24:05 +0100
changeset 29427 44f4e6905b67
child 30730 d3ce7619db2c
permissions -rw-r--r--
8071851: Provide filtering of doclint checking based on packages Summary: Introducing -Xdoclint/package:<packages> doclint option to enable/disable checking of specified packages. Reviewed-by: jjg, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     1
/*
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     4
 *
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     8
 *
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    14
 *
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    18
 *
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    21
 * questions.
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    22
 */
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    23
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    24
/*
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    25
 * @test
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    26
 * @bug 8071851
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    27
 * @summary Test the -Xdoclint/package option
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    28
 */
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    29
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    30
import java.io.File;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    31
import java.io.PrintWriter;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    32
import java.io.StringWriter;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    33
import java.net.URI;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    34
import java.util.Arrays;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    35
import java.util.List;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    36
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    37
import javax.tools.Diagnostic;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    38
import javax.tools.JavaCompiler;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    39
import javax.tools.JavaFileObject;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    40
import javax.tools.SimpleJavaFileObject;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    41
import javax.tools.StandardJavaFileManager;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    42
import javax.tools.StandardLocation;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    43
import javax.tools.ToolProvider;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    44
import static javax.tools.Diagnostic.Kind.*;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    45
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    46
import com.sun.source.util.JavacTask;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    47
import com.sun.tools.javac.main.Main;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    48
import java.util.ArrayList;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    49
import java.util.EnumSet;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    50
import java.util.Set;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    51
import java.util.regex.Matcher;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    52
import java.util.regex.Pattern;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    53
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    54
public class IncludePackagesTest {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    55
    public static void main(String... args) throws Exception {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    56
        new IncludePackagesTest().run();
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    57
    }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    58
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    59
    JavaCompiler javac;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    60
    StandardJavaFileManager fm;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    61
    List<JavaFileObject> files;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    62
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    63
    final String[] sources = new String[] {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    64
        "p1/p1T.java",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    65
        "package p1;\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    66
        "/** Syntax < error. */\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    67
        "public class p1T {\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    68
        "}\n",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    69
        "p1/sp1/p1sp1T.java",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    70
        "package p1.sp1;\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    71
        "/** Syntax < error. */\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    72
        "public class p1sp1T {\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    73
        "}\n",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    74
        "p1/sp1/sp2/p1sp1sp2T.java",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    75
        "package p1.sp1.sp2;\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    76
        "/** Syntax < error. */\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    77
        "public class p1sp1sp2T {\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    78
        "}\n",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    79
        "p2/p2T.java",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    80
        "package p2;\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    81
        "/** Syntax < error. */\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    82
        "public class p2T {\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    83
        "}\n",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    84
        "Default.java",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    85
        "/** Syntax < error. */\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    86
        "public class Default {\n" +
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    87
        "}\n",
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    88
    };
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    89
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    90
    final String rawDiags = "-XDrawDiagnostics";
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    91
    private enum Message {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    92
        // doclint messages
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    93
        p1T(ERROR, "p1T.java:2:12: compiler.err.proc.messager: malformed HTML"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    94
        p1sp1T(ERROR, "p1sp1T.java:2:12: compiler.err.proc.messager: malformed HTML"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    95
        p1sp1sp2T(ERROR, "p1sp1sp2T.java:2:12: compiler.err.proc.messager: malformed HTML"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    96
        p2T(ERROR, "p2T.java:2:12: compiler.err.proc.messager: malformed HTML"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    97
        Default(ERROR, "Default.java:1:12: compiler.err.proc.messager: malformed HTML"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    98
        INVALID_PACKAGE_ERROR(ERROR, "invalid flag: -Xdoclint/package:wrong+package");
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
    99
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   100
        final Diagnostic.Kind kind;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   101
        final String text;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   102
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   103
        static Message get(String text) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   104
            for (Message m: values()) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   105
                if (m.text.equals(text))
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   106
                    return m;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   107
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   108
            return null;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   109
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   110
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   111
        Message(Diagnostic.Kind kind, String text) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   112
            this.kind = kind;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   113
            this.text = text;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   114
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   115
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   116
        @Override
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   117
        public String toString() {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   118
            return "[" + kind + ",\"" + text + "\"]";
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   119
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   120
    }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   121
    void run() throws Exception {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   122
        javac = ToolProvider.getSystemJavaCompiler();
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   123
        fm = javac.getStandardFileManager(null, null, null);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   124
        try {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   125
            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   126
            files = new ArrayList<>();
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   127
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   128
            for (int si = 0; si < sources.length; si += 2) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   129
                files.add(new JFOImpl(sources[si], sources[si + 1]));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   130
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   131
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   132
            test(Arrays.asList(rawDiags, "-Xdoclint"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   133
                    Main.Result.ERROR,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   134
                    EnumSet.of(Message.p1T, Message.p1sp1T, Message.p1sp1sp2T,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   135
                               Message.p2T, Message.Default));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   136
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   137
            test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:p1"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   138
                    Main.Result.ERROR,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   139
                    EnumSet.of(Message.p1T));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   140
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   141
            test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:p1.*"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   142
                    Main.Result.ERROR,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   143
                    EnumSet.of(Message.p1sp1T, Message.p1sp1sp2T));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   144
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   145
            test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:p1.*,-p1.sp1"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   146
                    Main.Result.ERROR,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   147
                    EnumSet.of(Message.p1sp1sp2T));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   148
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   149
            test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:-p1.sp1"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   150
                    Main.Result.ERROR,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   151
                    EnumSet.of(Message.p1T, Message.p1sp1sp2T, Message.p2T, Message.Default));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   152
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   153
            test(Arrays.asList(rawDiags, "-Xdoclint", "-Xdoclint/package:wrong+package"),
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   154
                    Main.Result.CMDERR,
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   155
                    EnumSet.of(Message.INVALID_PACKAGE_ERROR));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   156
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   157
            if (errors > 0)
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   158
                throw new Exception(errors + " errors occurred");
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   159
        } finally {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   160
            fm.close();
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   161
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   162
    }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   163
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   164
    void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   165
        System.err.println("test: " + opts);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   166
        StringWriter sw = new StringWriter();
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   167
        PrintWriter pw = new PrintWriter(sw);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   168
        try {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   169
            JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   170
            boolean ok = t.call();
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   171
            pw.close();
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   172
            String out = sw.toString().replaceAll("[\r\n]+", "\n");
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   173
            if (!out.isEmpty())
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   174
                System.err.println(out);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   175
            if (ok && expectResult != Main.Result.OK) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   176
                error("Compilation succeeded unexpectedly");
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   177
            } else if (!ok && expectResult != Main.Result.ERROR) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   178
                error("Compilation failed unexpectedly");
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   179
            } else
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   180
                check(out, expectMessages);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   181
        } catch (IllegalArgumentException e) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   182
            System.err.println(e);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   183
            String expectOut = expectMessages.iterator().next().text;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   184
            if (expectResult != Main.Result.CMDERR)
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   185
                error("unexpected exception caught");
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   186
            else if (!e.getMessage().equals(expectOut)) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   187
                error("unexpected exception message: "
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   188
                        + e.getMessage()
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   189
                        + " expected: " + expectOut);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   190
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   191
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   192
    }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   193
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   194
    private void check(String out, Set<Message> expect) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   195
        Pattern stats = Pattern.compile("^([1-9]+) (error|warning)(s?)");
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   196
        Set<Message> found = EnumSet.noneOf(Message.class);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   197
        int e = 0, w = 0;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   198
        if (!out.isEmpty()) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   199
            for (String line: out.split("[\r\n]+")) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   200
                Matcher s = stats.matcher(line);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   201
                if (s.matches()) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   202
                    int i = Integer.valueOf(s.group(1));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   203
                    if (s.group(2).equals("error"))
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   204
                        e++;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   205
                    else
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   206
                        w++;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   207
                    continue;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   208
                }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   209
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   210
                Message m = Message.get(line);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   211
                if (m == null)
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   212
                    error("Unexpected line: " + line);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   213
                else
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   214
                    found.add(m);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   215
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   216
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   217
        for (Message m: expect) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   218
            if (!found.contains(m))
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   219
                error("expected message not found: " + m.text);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   220
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   221
        for (Message m: found) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   222
            if (!expect.contains(m))
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   223
                error("unexpected message found: " + m.text);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   224
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   225
    }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   226
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   227
    void error(String msg) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   228
        System.err.println("Error: " + msg);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   229
        errors++;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   230
    }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   231
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   232
    int errors;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   233
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   234
    class JFOImpl extends SimpleJavaFileObject {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   235
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   236
        private final String code;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   237
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   238
        public JFOImpl(String fileName, String code) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   239
            super(URI.create(fileName), JavaFileObject.Kind.SOURCE);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   240
            this.code = code;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   241
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   242
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   243
        @Override
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   244
        public CharSequence getCharContent(boolean ignoreEncoding) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   245
            return code;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   246
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   247
    }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff changeset
   248
}