author | jjg |
Tue, 22 Apr 2014 17:41:11 -0700 | |
changeset 24071 | b0845717434e |
parent 24065 | fc4022e50129 |
child 24072 | e7549dcbc4af |
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 |
30 |
* @library ../lib/ |
|
9083
63f3c4d2d992
7010344: Some of the html files do not have element <a> in right context.
bpatel
parents:
7681
diff
changeset
|
31 |
* @build JavadocTester TestLinkOption |
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 { |
38 |
||
23974
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
39 |
private static final String BUG_ID = "4720957-5020118-8038976"; |
10 | 40 |
|
41 |
//Generate the documentation using -linkoffline and a URL as the first parameter. |
|
42 |
private static final String[] ARGS1 = new String[] { |
|
43 |
"-d", BUG_ID + "-1", "-sourcepath", SRC_DIR, |
|
44 |
"-linkoffline", "http://java.sun.com/j2se/1.4/docs/api/", |
|
45 |
SRC_DIR, "-package", "pkg", "java.lang" |
|
46 |
}; |
|
47 |
||
48 |
private static final String[][] TEST1 = { |
|
23971 | 49 |
{BUG_ID + "-1/pkg/C.html", |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
50 |
"<a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html?is-external=true\" " + |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
51 |
"title=\"class or interface in java.lang\"><code>Link to String Class</code></a>" |
10 | 52 |
}, |
53 |
//Make sure the parameters are indented properly when the -link option is used. |
|
23971 | 54 |
{BUG_ID + "-1/pkg/C.html", |
55 |
"(int p1,\n" + |
|
56 |
" int p2,\n" + |
|
57 |
" int p3)" |
|
10 | 58 |
}, |
23971 | 59 |
{BUG_ID + "-1/pkg/C.html", |
60 |
"(int p1,\n" + |
|
61 |
" int p2,\n" + |
|
62 |
" <a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\">" + |
|
63 |
"Object</a> p3)" |
|
10 | 64 |
}, |
23971 | 65 |
{BUG_ID + "-1/java/lang/StringBuilderChild.html", |
66 |
"<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n" + |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
67 |
"extends <a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true\" " + |
23971 | 68 |
"title=\"class or interface in java.lang\">Object</a></pre>" |
10 | 69 |
}, |
70 |
||
71 |
}; |
|
72 |
private static final String[][] NEGATED_TEST1 = NO_TEST; |
|
73 |
||
74 |
//Generate the documentation using -linkoffline and a relative path as the first parameter. |
|
75 |
//We will try linking to the docs generated in test 1 with a relative path. |
|
76 |
private static final String[] ARGS2 = new String[] { |
|
77 |
"-d", BUG_ID + "-2", "-sourcepath", SRC_DIR, |
|
23971 | 78 |
"-linkoffline", "../" + BUG_ID + "-1", |
79 |
BUG_ID + "-1", "-package", "pkg2" |
|
10 | 80 |
}; |
81 |
||
82 |
private static final String[][] TEST2 = { |
|
23971 | 83 |
{BUG_ID + "-2/pkg2/C2.html", |
84 |
"This is a link to <a href=\"../../" + BUG_ID + |
|
85 |
"-1/pkg/C.html?is-external=true\" " + |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
86 |
"title=\"class or interface in pkg\"><code>Class C</code></a>." |
10 | 87 |
} |
88 |
}; |
|
23974
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
89 |
/* |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
90 |
* 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
|
91 |
* 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
|
92 |
* 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
|
93 |
*/ |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
94 |
static String[] createArguments(boolean withTrailingSlash) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
95 |
String packagePath = new File(BUG_ID + "-1").getAbsolutePath(); |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
96 |
String outputDirName = BUG_ID; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
97 |
if (withTrailingSlash) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
98 |
// 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
|
99 |
if (!packagePath.endsWith(FS)) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
100 |
packagePath = packagePath + FS; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
101 |
} |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
102 |
outputDirName = outputDirName + "-3"; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
103 |
} else { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
104 |
// 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
|
105 |
if (packagePath.endsWith(FS)) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
106 |
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
|
107 |
} |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
108 |
outputDirName = outputDirName + "-4"; |
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 |
String args[] = { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
111 |
"-d", outputDirName, "-sourcepath", SRC_DIR, |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
112 |
"-link", "file:///" + packagePath, "-package", "pkg2" |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
113 |
}; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
114 |
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
|
115 |
return args; |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
116 |
} |
10 | 117 |
/** |
118 |
* The entry point of the test. |
|
119 |
* @param args the array of command line arguments. |
|
120 |
*/ |
|
121 |
public static void main(String[] args) { |
|
122 |
TestLinkOption tester = new TestLinkOption(); |
|
24065
fc4022e50129
8041150: Avoid silly use of static methods in JavadocTester
jjg
parents:
23974
diff
changeset
|
123 |
tester.run(ARGS1, TEST1, NEGATED_TEST1); |
24071 | 124 |
tester.run(ARGS1, TEST1, NEGATED_TEST1); |
125 |
tester.run(ARGS2, TEST2, NO_TEST); |
|
23974
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
126 |
tester.runJavadoc(createArguments(true)); // with trailing slash |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
127 |
tester.runJavadoc(createArguments(false)); // without trailing slash |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
128 |
tester.printSummary(); |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
129 |
if (tester.getWarningOutput().contains("warning - Error fetching URL")) { |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
130 |
throw new Error("URL rejected ?"); |
d53628eda3d1
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents:
23971
diff
changeset
|
131 |
} |
10 | 132 |
tester.printSummary(); |
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* {@inheritDoc} |
|
137 |
*/ |
|
138 |
public String getBugId() { |
|
139 |
return BUG_ID; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* {@inheritDoc} |
|
144 |
*/ |
|
145 |
public String getBugName() { |
|
146 |
return getClass().getName(); |
|
147 |
} |
|
148 |
} |