author | lana |
Mon, 11 Aug 2014 09:25:30 -0700 | |
changeset 25880 | e5967ea9bde2 |
parent 24399 | af1a0220d0fa |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
23971 | 2 |
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
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 | 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 | 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 |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
31 |
* @build JavadocTester |
10 | 32 |
* @run main TestLinkOption |
33 |
*/ |
|
34 |
||
23974
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
35 |
import java.io.File; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
36 |
|
10 | 37 |
public class TestLinkOption extends JavadocTester { |
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
38 |
/** |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
39 |
* The entry point of the test. |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
40 |
* @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
|
41 |
*/ |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
42 |
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
|
43 |
TestLinkOption tester = new TestLinkOption(); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
44 |
tester.runTests(); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
45 |
} |
10 | 46 |
|
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
47 |
// 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
|
48 |
// 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
|
49 |
// 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
|
50 |
// 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
|
51 |
@Test |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
52 |
void test() { |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
53 |
// 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
|
54 |
String out1 = "out1"; |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
55 |
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
|
56 |
javadoc("-d", out1, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
57 |
"-sourcepath", testSrc, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
58 |
"-linkoffline", url, testSrc, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
59 |
"-package", |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
60 |
"pkg", "java.lang"); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
61 |
checkExit(Exit.OK); |
10 | 62 |
|
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
63 |
checkOutput("pkg/C.html", true, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
64 |
"<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
|
65 |
+ "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
|
66 |
//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
|
67 |
"(int p1,\n" |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
68 |
+ " int p2,\n" |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
69 |
+ " int p3)", |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
70 |
"(int p1,\n" |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
71 |
+ " int p2,\n" |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
72 |
+ " <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
|
73 |
+ "Object</a> p3)"); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
74 |
|
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
75 |
checkOutput("java/lang/StringBuilderChild.html", true, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
76 |
"<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
|
77 |
+ "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
|
78 |
+ "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
|
79 |
); |
10 | 80 |
|
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
81 |
// 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
|
82 |
// 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
|
83 |
String out2 = "out2"; |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
84 |
javadoc("-d", out2, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
85 |
"-sourcepath", testSrc, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
86 |
"-linkoffline", "../" + out1, out1, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
87 |
"-package", |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
88 |
"pkg2"); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
89 |
checkExit(Exit.OK); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
90 |
checkOutput("pkg2/C2.html", true, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
91 |
"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
|
92 |
"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
|
93 |
); |
10 | 94 |
|
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
95 |
String out3 = "out3"; |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
96 |
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
|
97 |
checkExit(Exit.OK); |
10 | 98 |
|
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
99 |
String out4 = "out4"; |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
100 |
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
|
101 |
checkExit(Exit.OK); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
102 |
// 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
|
103 |
// 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
|
104 |
// 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
|
105 |
checkOutput(Output.WARNING, false, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
106 |
"warning - Error fetching URL"); |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
107 |
} |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
108 |
|
23974
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
109 |
/* |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
110 |
* 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
|
111 |
* 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
|
112 |
* 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
|
113 |
*/ |
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
if (withTrailingSlash) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
117 |
// 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
|
118 |
if (!packagePath.endsWith(FS)) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
119 |
packagePath = packagePath + FS; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
120 |
} |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
121 |
} else { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
122 |
// 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
|
123 |
if (packagePath.endsWith(FS)) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
124 |
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
|
125 |
} |
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 |
String args[] = { |
24399
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
128 |
"-d", outDir, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
129 |
"-sourcepath", testSrc, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
130 |
"-link", "file:///" + packagePath, |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
131 |
"-package", |
af1a0220d0fa
8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents:
24217
diff
changeset
|
132 |
"pkg2" |
23974
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
133 |
}; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
134 |
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
|
135 |
return args; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
136 |
} |
10 | 137 |
} |