langtools/test/tools/doclint/tool/PathsTest.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 27579 d1a63c99cdd5
child 36526 3b41f1c69604
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     4
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     8
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    13
 * accompanied this code).
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    14
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    18
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    21
 * questions.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    22
 */
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    23
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    24
/*
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    25
 * @test
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    26
 * @bug 8006263
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    27
 * @summary Supplementary test cases needed for doclint
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    28
 * @library /tools/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.doclint
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.api
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.file
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.main
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
    33
 *          jdk.compiler/com.sun.tools.javac.util
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    34
 * @build ToolBox
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    35
 * @run main PathsTest
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    36
 */
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    37
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    38
import com.sun.tools.javac.util.Context;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    39
import com.sun.tools.javac.file.JavacFileManager;
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    40
import com.sun.tools.doclint.DocLint;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    41
import com.sun.tools.doclint.DocLint.BadArgs;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    42
import java.io.File;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    43
import java.io.FileWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    44
import java.io.IOException;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    45
import java.io.PrintWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    46
import java.io.StringWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    47
import java.util.regex.Pattern;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    48
import javax.tools.StandardLocation;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    49
import javax.tools.JavaFileManager;
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    50
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    51
public class PathsTest {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    52
    public static void main(String... args) throws Exception {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    53
        new PathsTest().run();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    54
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    55
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    56
    void run() throws Exception {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    57
        String PS = File.pathSeparator;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    58
        writeFile("src1/p/A.java",
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    59
                "package p; public class A { }");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    60
        compile("-d", "classes1", "src1/p/A.java");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    61
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    62
        writeFile("src2/q/B.java",
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    63
                "package q; public class B extends p.A { }");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    64
        compile("-d", "classes2", "-classpath", "classes1", "src2/q/B.java");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    65
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    66
        writeFile("src/Test.java",
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    67
                "/** &0; */ class Test extends q.B { }");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    68
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    69
        test("src/Test.java", "-sourcepath", "src1" + PS + "src2");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    70
        test("src/Test.java", "-classpath", "classes1" + PS + "classes2");
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    71
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    72
        File testJar = createJar();
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    73
        String sysBootClassPath = System.getProperty("sun.boot.class.path");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    74
        test("src/Test.java", "-bootclasspath",
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    75
                testJar + PS + "classes1" + PS + "classes2");
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    76
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    77
        if (errors > 0)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    78
            throw new Exception(errors + " errors found");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    79
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    80
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    81
    Pattern pkgNotFound = Pattern.compile("package [a-z]+ does not exist");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    82
    Pattern badHtmlEntity = Pattern.compile("bad HTML entity");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    83
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    84
    void test(String file, String pathOpt, String path) throws BadArgs, IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    85
        System.err.println("test " + pathOpt);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    86
        String out1 = doclint("-Xmsgs", file);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    87
        if (!pkgNotFound.matcher(out1).find())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    88
            error("message not found: " + pkgNotFound);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    89
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    90
        String out2 = doclint("-Xmsgs", pathOpt, path, file);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    91
        if (pkgNotFound.matcher(out2).find())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    92
            error("unexpected message found: " + pkgNotFound);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    93
        if (!badHtmlEntity.matcher(out1).find())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    94
            error("message not found: " + badHtmlEntity);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    95
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    96
        try {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    97
            doclint("-Xmsgs", pathOpt);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    98
            error("expected exception not thrown");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    99
        } catch (BadArgs e) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   100
            System.err.println(e);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   101
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   102
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   103
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   104
    File createJar() throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   105
        File f = new File("test.jar");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   106
        try (JavaFileManager fm = new JavacFileManager(new Context(), false, null)) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   107
            ToolBox tb = new ToolBox();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   108
            tb.new JarTask(f.getPath())
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   109
                .files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*")
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   110
                .run();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   111
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   112
        return f;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   113
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   114
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   115
    void compile(String... args) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   116
        for (int i = 0; i < args.length; i++) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   117
            if (args[i].equals("-d")) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   118
                new File(args[++i]).mkdirs();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   119
                break;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   120
            }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   121
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   122
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   123
        StringWriter sw = new StringWriter();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   124
        PrintWriter pw = new PrintWriter(sw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   125
        int rc = com.sun.tools.javac.Main.compile(args, pw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   126
        pw.close();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   127
        String out = sw.toString();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   128
        if (!out.isEmpty())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   129
            System.err.println(out);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   130
        if (rc != 0)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   131
            error("compilation failed: rc=" + rc);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   132
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   133
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   134
    String doclint(String... args) throws BadArgs, IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   135
        StringWriter sw = new StringWriter();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   136
        PrintWriter pw = new PrintWriter(sw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   137
        DocLint dl = new DocLint();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   138
        dl.run(pw, args);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   139
        pw.close();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   140
        String out = sw.toString();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   141
        if (!out.isEmpty())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   142
            System.err.println(out);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   143
        return out;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   144
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   145
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   146
    File writeFile(String path, String body) throws IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   147
        File f = new File(path);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   148
        f.getParentFile().mkdirs();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   149
        try (FileWriter fw = new FileWriter(path)) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   150
            fw.write(body);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   151
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   152
        return f;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   153
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   154
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   155
    void error(String msg) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   156
        System.err.println("Error: " + msg);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   157
        errors++;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   158
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   159
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   160
    int errors;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   161
}