File: TestLinkOption.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (231 lines) | stat: -rw-r--r-- 11,265 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * @test
 * @bug 4720957 5020118 8026567 8038976 8184969 8164407 8182765 8205593
 * @summary Test to make sure that -link and -linkoffline link to
 * right files, and URLs with and without trailing slash are accepted.
 * @author jamieh
 * @library ../lib
 * @modules jdk.javadoc/jdk.javadoc.internal.tool
 * @build JavadocTester
 * @run main TestLinkOption
 */

import java.io.File;

public class TestLinkOption extends JavadocTester {
    /**
     * The entry point of the test.
     * @param args the array of command line arguments.
     */
    public static void main(String... args) throws Exception {
        TestLinkOption tester = new TestLinkOption();
        tester.runTests();
    }

    // The following test runs javadoc multiple times; it is important that the
    // first one is run first, since the subsequent runs refer to the output
    // it generates. Therefore we run everything serially in a single @Test
    // method and not in independent @Test methods.
    @Test
    void test() {
        String mylib = "mylib";
        String[] javacArgs = {
            "-d", mylib, testSrc + "/extra/StringBuilder.java"
        };
        com.sun.tools.javac.Main.compile(javacArgs);

        // Generate the documentation using -linkoffline and a URL as the first parameter.
        String out1 = "out1";
        String url = "http://acme.com/jdk/";
        javadoc("-d", out1,
                "-source", "8",
                "-classpath", mylib,
                "-sourcepath", testSrc,
                "-linkoffline", url, testSrc + "/jdk",
                "-package",
                "pkg", "mylib.lang");
        checkExit(Exit.ERROR);
        checkOutput(Output.OUT, true,
                "tag not supported in the generated HTML version: tt");

        checkOutput("pkg/C.html", true,
                "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
                + "title=\"class or interface in java.lang\" class=\"externalLink\"><code>Link to String Class</code></a>",
                //Make sure the parameters are indented properly when the -link option is used.
                "(int&nbsp;p1,\n"
                + "      int&nbsp;p2,\n"
                + "      int&nbsp;p3)",
                "(int&nbsp;p1,\n"
                + "      int&nbsp;p2,\n"
                + "      <a href=\"" + url + "java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\" class=\"externalLink\">"
                + "Object</a>&nbsp;p3)");

        checkOutput("pkg/B.html", true,
                "<div class=\"block\">A method with html tag the method "
                + "<a href=\"" + url + "java/lang/ClassLoader.html?is-external=true#getSystemClassLoader()\""
                + " title=\"class or interface in java.lang\" class=\"externalLink\"><code><tt>getSystemClassLoader()</tt>"
                + "</code></a> as the parent class loader.</div>",
                "<div class=\"block\">is equivalent to invoking <code>"
                + "<a href=\"#createTempFile(java.lang.String,java.lang.String,java.io.File)\">"
                + "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code></a></code>.</div>",
                "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
                + "title=\"class or interface in java.lang\" class=\"externalLink\">Link-Plain to String Class</a>",
                "<code><tt>getSystemClassLoader()</tt></code>",
                "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code>",
                "<dd><a href=\"http://www.ietf.org/rfc/rfc2279.txt\"><i>RFC&nbsp;2279: UTF-8, a\n" +
                " transformation format of ISO 10646</i></a>, <br><a " +
                "href=\"http://www.ietf.org/rfc/rfc2373.txt\"><i>RFC&nbsp;2373: IPv6 Addressing\n" +
                " Architecture</i></a>, <br><a href=\"http://www.ietf.org/rfc/rfc2396.txt\">" +
                "<i>RFC&nbsp;2396: Uniform\n" +
                " Resource Identifiers (URI): Generic Syntax</i></a>, " +
                "<br><a href=\"http://www.ietf.org/rfc/rfc2732.txt\"><i>RFC&nbsp;2732: Format for\n" +
                " Literal IPv6 Addresses in URLs</i></a>, <br><a href=\"URISyntaxException.html\">" +
                "URISyntaxException</a></dd>\n" +
                "</dl>");

        checkOutput("mylib/lang/StringBuilderChild.html", true,
                "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n"
                + "extends <a href=\"" + url + "java/lang/Object.html?is-external=true\" "
                + "title=\"class or interface in java.lang\" class=\"externalLink\">Object</a></pre>"
        );

        String out1_html4 = "out1-html4";
        javadoc("-d", out1_html4,
                "-source", "8",
                "-html4",
                "-classpath", mylib,
                "-sourcepath", testSrc,
                "-linkoffline", url, testSrc + "/jdk",
                "-package",
                "pkg", "mylib.lang");
        checkExit(Exit.OK);

        checkOutput("pkg/B.html", true,
                "<div class=\"block\">A method with html tag the method "
                + "<a href=\"" + url + "java/lang/ClassLoader.html?is-external=true#getSystemClassLoader--\""
                + " title=\"class or interface in java.lang\" class=\"externalLink\"><code><tt>getSystemClassLoader()</tt>"
                + "</code></a> as the parent class loader.</div>",
                "<div class=\"block\">is equivalent to invoking <code>"
                + "<a href=\"#createTempFile-java.lang.String-java.lang.String-java.io.File-\">"
                + "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code></a></code>.</div>");

        // Generate the documentation using -linkoffline and a relative path as the first parameter.
        // We will try linking to the docs generated in test 1 with a relative path.
        String out2 = "out2";
        javadoc("-d", out2,
                "-sourcepath", testSrc,
                "-linkoffline", "../" + out1, out1,
                "-package",
                "pkg2");
        checkExit(Exit.OK);
        checkOutput("pkg2/C2.html", true,
            "This is a link to <a href=\"../../" + out1 + "/pkg/C.html?is-external=true\" " +
            "title=\"class or interface in pkg\" class=\"externalLink\"><code>Class C</code></a>."
        );

        String out3 = "out3";
        javadoc(createArguments(out3, out1, true));  // with trailing slash
        checkExit(Exit.OK);

        String out4 = "out4";
        javadoc(createArguments(out4, out1, false)); // without trailing slash
        checkExit(Exit.OK);
        // Note: the following test is very weak, and will fail if ever the text
        // of the message is changed. We should have a separate test to verify
        // this is the text that is given when there is a problem with a URL
        checkOutput(Output.OUT, false,
                "warning - Error fetching URL");

        // check multiple link options
        javadoc("-d", "out5",
                "-sourcepath", testSrc,
                "-link", "../" + "out1",
                "-link", "../" + "out2",
                "pkg3");
        checkExit(Exit.OK);
        checkOutput("pkg3/A.html", true,
                "<pre>public class <span class=\"typeNameLabel\">A</span>\n"
                + "extends java.lang.Object</pre>\n"
                + "<div class=\"block\">Test links.\n"
                + " <br>\n"
                + " <a href=\"../../out2/pkg2/C2.html?is-external=true\" "
                + "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
                + " <br>\n"
                + " <a href=\"../../out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
                + "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
                + "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
        );

        // check multiple linkoffline options
        javadoc("-d", "out6",
                "-sourcepath", testSrc,
                "-linkoffline", "../copy/out1", "out1",
                "-linkoffline", "../copy/out2", "out2",
                "pkg3");
        checkExit(Exit.OK);
        checkOutput("pkg3/A.html", true,
                "<pre>public class <span class=\"typeNameLabel\">A</span>\n"
                        + "extends java.lang.Object</pre>\n"
                        + "<div class=\"block\">Test links.\n"
                        + " <br>\n"
                        + " <a href=\"../../copy/out2/pkg2/C2.html?is-external=true\" "
                        + "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
                        + " <br>\n"
                        + " <a href=\"../../copy/out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
                        + "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
                        + "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
        );
    }

    /*
     * Create the documentation using the -link option, vary the behavior with
     * both trailing and no trailing slash. We are only interested in ensuring
     * that the command executes with no errors or related warnings.
     */
    static String[] createArguments(String outDir, String packageDir, boolean withTrailingSlash) {
        String packagePath = new File(packageDir).getAbsolutePath();
        if (withTrailingSlash) {
            // add the trailing slash, if it is not present!
            if (!packagePath.endsWith(FS)) {
                packagePath = packagePath + FS;
            }
        } else {
            // remove the trailing slash, if it is present!
            if (packagePath.endsWith(FS)) {
                packagePath = packagePath.substring(0, packagePath.length() - 1);
            }
        }
        String args[] = {
            "-d", outDir,
            "-sourcepath", testSrc,
            "-link", "file:///" + packagePath,
            "-package",
            "pkg2"
        };
        System.out.println("packagePath: " + packagePath);
        return args;
    }
}