langtools/test/com/sun/javadoc/testLinkOption/TestLinkOption.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 24399 af1a0220d0fa
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:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 24399
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    26
 * @bug 4720957 5020118 8026567 8038976
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary Test to make sure that -link and -linkoffline link to
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    28
 * right files, and URLs with and without trailing slash are accepted.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 * @author jamieh
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    30
 * @library ../lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 24399
diff changeset
    31
 * @modules jdk.javadoc
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    32
 * @build JavadocTester
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * @run main TestLinkOption
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    36
import java.io.File;
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    37
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
public class TestLinkOption extends JavadocTester {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    39
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    40
     * The entry point of the test.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    41
     * @param args the array of command line arguments.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    42
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    43
    public static void main(String... args) throws Exception {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    44
        TestLinkOption tester = new TestLinkOption();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    45
        tester.runTests();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    46
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    48
    // The following test runs javadoc multiple times; it is important that the
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    49
    // first one is run first, since the subsequent runs refer to the output
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    50
    // it generates. Therefore we run everything serially in a single @Test
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    51
    // method and not in independent @Test methods.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    52
    @Test
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    53
    void test() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    54
        // Generate the documentation using -linkoffline and a URL as the first parameter.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    55
        String out1 = "out1";
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    56
        String url = "http://java.sun.com/j2se/1.4/docs/api/";
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    57
        javadoc("-d", out1,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    58
                "-sourcepath", testSrc,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    59
                "-linkoffline", url, testSrc,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    60
                "-package",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    61
                "pkg", "java.lang");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    62
        checkExit(Exit.OK);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    64
        checkOutput("pkg/C.html", true,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    65
                "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    66
                + "title=\"class or interface in java.lang\"><code>Link to String Class</code></a>",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    67
                //Make sure the parameters are indented properly when the -link option is used.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    68
                "(int&nbsp;p1,\n"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    69
                + "      int&nbsp;p2,\n"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    70
                + "      int&nbsp;p3)",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    71
                "(int&nbsp;p1,\n"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    72
                + "      int&nbsp;p2,\n"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    73
                + "      <a href=\"" + url + "java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\">"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    74
                + "Object</a>&nbsp;p3)");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    75
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    76
        checkOutput("java/lang/StringBuilderChild.html", true,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    77
                "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    78
                + "extends <a href=\"" + url + "java/lang/Object.html?is-external=true\" "
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    79
                + "title=\"class or interface in java.lang\">Object</a></pre>"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    80
        );
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    82
        // Generate the documentation using -linkoffline and a relative path as the first parameter.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    83
        // We will try linking to the docs generated in test 1 with a relative path.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    84
        String out2 = "out2";
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    85
        javadoc("-d", out2,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    86
                "-sourcepath", testSrc,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    87
                "-linkoffline", "../" + out1, out1,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    88
                "-package",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    89
                "pkg2");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    90
        checkExit(Exit.OK);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    91
        checkOutput("pkg2/C2.html", true,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    92
            "This is a link to <a href=\"../../" + out1 + "/pkg/C.html?is-external=true\" " +
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    93
            "title=\"class or interface in pkg\"><code>Class C</code></a>."
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    94
        );
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    96
        String out3 = "out3";
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    97
        javadoc(createArguments(out3, out1, true));  // with trailing slash
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    98
        checkExit(Exit.OK);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   100
        String out4 = "out4";
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   101
        javadoc(createArguments(out4, out1, false)); // without trailing slash
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   102
        checkExit(Exit.OK);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   103
        // Note: the following test is very weak, and will fail if ever the test
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   104
        // of the message is changed. We should have a separate test to verify
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   105
        // this is the text that is given when there is a problem with a URL
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   106
        checkOutput(Output.WARNING, false,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   107
                "warning - Error fetching URL");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   108
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   109
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   110
    /*
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   111
     * Create the documentation using the -link option, vary the behavior with
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   112
     * both trailing and no trailing slash. We are only interested in ensuring
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   113
     * that the command executes with no errors or related warnings.
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   114
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   115
    static String[] createArguments(String outDir, String packageDir, boolean withTrailingSlash) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   116
        String packagePath = new File(packageDir).getAbsolutePath();
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   117
        if (withTrailingSlash) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   118
            // add the trailing slash, if it is not present!
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   119
            if (!packagePath.endsWith(FS)) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   120
                packagePath = packagePath + FS;
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   121
            }
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   122
        } else {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   123
            // remove the trailing slash, if it is present!
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   124
            if (packagePath.endsWith(FS)) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   125
                packagePath = packagePath.substring(0, packagePath.length() - 1);
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   126
            }
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   127
        }
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   128
        String args[] = {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   129
            "-d", outDir,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   130
            "-sourcepath", testSrc,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   131
            "-link", "file:///" + packagePath,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   132
            "-package",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   133
            "pkg2"
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   134
        };
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   135
        System.out.println("packagePath: " + packagePath);
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   136
        return args;
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   137
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
}