langtools/test/tools/doclint/tool/PathsTest.java
author chegar
Wed, 03 Dec 2014 14:25:46 +0000
changeset 27579 d1a63c99cdd5
parent 15370 c1c9a9e11b26
child 30730 d3ce7619db2c
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: jlahoda, ksrini Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     1
/*
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
     2
 * Copyright (c) 2013, 2014, 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
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    29
 * @build ToolBox
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    30
 * @run main PathsTest
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    31
 */
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    32
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    33
import com.sun.tools.javac.util.Context;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    34
import com.sun.tools.javac.file.JavacFileManager;
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    35
import com.sun.tools.doclint.DocLint;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    36
import com.sun.tools.doclint.DocLint.BadArgs;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    37
import java.io.File;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    38
import java.io.FileWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    39
import java.io.IOException;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    40
import java.io.PrintWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    41
import java.io.StringWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    42
import java.util.regex.Pattern;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    43
import javax.tools.StandardLocation;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    44
import javax.tools.JavaFileManager;
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    45
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    46
public class PathsTest {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    47
    public static void main(String... args) throws Exception {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    48
        new PathsTest().run();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    49
    }
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
    void run() throws Exception {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    52
        String PS = File.pathSeparator;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    53
        writeFile("src1/p/A.java",
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    54
                "package p; public class A { }");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    55
        compile("-d", "classes1", "src1/p/A.java");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    56
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    57
        writeFile("src2/q/B.java",
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    58
                "package q; public class B extends p.A { }");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    59
        compile("-d", "classes2", "-classpath", "classes1", "src2/q/B.java");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    60
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    61
        writeFile("src/Test.java",
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    62
                "/** &0; */ class Test extends q.B { }");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    63
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    64
        test("src/Test.java", "-sourcepath", "src1" + PS + "src2");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    65
        test("src/Test.java", "-classpath", "classes1" + PS + "classes2");
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    66
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    67
        File testJar = createJar();
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    68
        String sysBootClassPath = System.getProperty("sun.boot.class.path");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    69
        test("src/Test.java", "-bootclasspath",
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    70
                testJar + PS + "classes1" + PS + "classes2");
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    71
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    72
        if (errors > 0)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    73
            throw new Exception(errors + " errors found");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    74
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    75
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    76
    Pattern pkgNotFound = Pattern.compile("package [a-z]+ does not exist");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    77
    Pattern badHtmlEntity = Pattern.compile("bad HTML entity");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    78
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    79
    void test(String file, String pathOpt, String path) throws BadArgs, IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    80
        System.err.println("test " + pathOpt);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    81
        String out1 = doclint("-Xmsgs", file);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    82
        if (!pkgNotFound.matcher(out1).find())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    83
            error("message not found: " + pkgNotFound);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    84
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    85
        String out2 = doclint("-Xmsgs", pathOpt, path, file);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    86
        if (pkgNotFound.matcher(out2).find())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    87
            error("unexpected message found: " + pkgNotFound);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    88
        if (!badHtmlEntity.matcher(out1).find())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    89
            error("message not found: " + badHtmlEntity);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    90
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    91
        try {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    92
            doclint("-Xmsgs", pathOpt);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    93
            error("expected exception not thrown");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    94
        } catch (BadArgs e) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    95
            System.err.println(e);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    96
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    97
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    98
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
    99
    File createJar() throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   100
        File f = new File("test.jar");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   101
        try (JavaFileManager fm = new JavacFileManager(new Context(), false, null)) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   102
            ToolBox tb = new ToolBox();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   103
            tb.new JarTask(f.getPath())
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   104
                .files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*")
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   105
                .run();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   106
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   107
        return f;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   108
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 15370
diff changeset
   109
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   110
    void compile(String... args) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   111
        for (int i = 0; i < args.length; i++) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   112
            if (args[i].equals("-d")) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   113
                new File(args[++i]).mkdirs();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   114
                break;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   115
            }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   116
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   117
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   118
        StringWriter sw = new StringWriter();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   119
        PrintWriter pw = new PrintWriter(sw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   120
        int rc = com.sun.tools.javac.Main.compile(args, pw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   121
        pw.close();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   122
        String out = sw.toString();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   123
        if (!out.isEmpty())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   124
            System.err.println(out);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   125
        if (rc != 0)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   126
            error("compilation failed: rc=" + rc);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   127
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   128
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   129
    String doclint(String... args) throws BadArgs, IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   130
        StringWriter sw = new StringWriter();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   131
        PrintWriter pw = new PrintWriter(sw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   132
        DocLint dl = new DocLint();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   133
        dl.run(pw, args);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   134
        pw.close();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   135
        String out = sw.toString();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   136
        if (!out.isEmpty())
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   137
            System.err.println(out);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   138
        return out;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   139
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   140
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   141
    File writeFile(String path, String body) throws IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   142
        File f = new File(path);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   143
        f.getParentFile().mkdirs();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   144
        try (FileWriter fw = new FileWriter(path)) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   145
            fw.write(body);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   146
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   147
        return f;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   148
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   149
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   150
    void error(String msg) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   151
        System.err.println("Error: " + msg);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   152
        errors++;
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
    int errors;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   156
}