|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. |
| 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 | + * |
| 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. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8164408 |
| 27 | + * @summary Add module support for see, link and linkplain javadoc tags |
| 28 | + * @library /tools/lib ../../lib |
| 29 | + * @modules |
| 30 | + * jdk.javadoc/jdk.javadoc.internal.tool |
| 31 | + * jdk.compiler/com.sun.tools.javac.api |
| 32 | + * jdk.compiler/com.sun.tools.javac.main |
| 33 | + * @build javadoc.tester.* |
| 34 | + * @run main TestSeeTagWithModule |
| 35 | + */ |
| 36 | + |
| 37 | +import java.nio.file.Path; |
| 38 | +import java.nio.file.Paths; |
| 39 | + |
| 40 | +import builder.ClassBuilder; |
| 41 | +import builder.ClassBuilder.*; |
| 42 | +import toolbox.ModuleBuilder; |
| 43 | +import toolbox.ToolBox; |
| 44 | + |
| 45 | +import javadoc.tester.JavadocTester; |
| 46 | + |
| 47 | +public class TestSeeTagWithModule extends JavadocTester { |
| 48 | + |
| 49 | + final ToolBox tb; |
| 50 | + private final Path src; |
| 51 | + |
| 52 | + public static void main(String... args) throws Exception { |
| 53 | + TestSeeTagWithModule tester = new TestSeeTagWithModule(); |
| 54 | + tester.runTests(m -> new Object[]{Paths.get(m.getName())}); |
| 55 | + } |
| 56 | + |
| 57 | + TestSeeTagWithModule() throws Exception { |
| 58 | + tb = new ToolBox(); |
| 59 | + src = Paths.get("src"); |
| 60 | + generateSources(); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testSeeModuleInternal(Path base) throws Exception { |
| 65 | + Path out = base.resolve("out"); |
| 66 | + |
| 67 | + javadoc("-d", out.toString(), |
| 68 | + "--module-source-path", src.toString(), |
| 69 | + "--module", "m1,m2,m3", |
| 70 | + "m2/com.m2.lib"); |
| 71 | + |
| 72 | + checkExit(Exit.OK); |
| 73 | + checkOutput("m3/com/m3/app/App.html", true, |
| 74 | + """ |
| 75 | + <dt>See Also:</dt> |
| 76 | + <dd><a href="../../../../m1/module-summary.html"><code>m1</code></a>,\s |
| 77 | + <a href="../../../../m1/module-summary.html"><code>m1</code></a>,\s |
| 78 | + <a href="../../../../m1/com/m1/lib/package-summary.html"><code>com.m1.lib</code></a>,\s |
| 79 | + <a href="../../../../m1/com/m1/lib/Lib.html" title="class in com.m1.lib"><code>Lib</code></a>,\s |
| 80 | + <a href="../../../../m1/com/m1/lib/Lib.html#method(java.lang.String)"><code>Lib.method(java.lang.String)</code></a>,\s |
| 81 | + <a href="../../../../m1/com/m1/lib/Lib.html#method(java.lang.String)"><code>Lib.method(String)</code></a>,\s |
| 82 | + <a href="../../../../m2/module-summary.html"><code>m2</code></a>,\s |
| 83 | + <a href="../../../../m2/module-summary.html"><code>m2</code></a>,\s |
| 84 | + <a href="../../../../m2/com/m2/lib/package-summary.html"><code>com.m2.lib</code></a>,\s |
| 85 | + <a href="../../../../m2/com/m2/lib/Lib.html" title="class in com.m2.lib"><code>Lib</code></a>,\s |
| 86 | + <a href="../../../../m2/com/m2/lib/Lib.html#method(java.lang.String)"><code>Lib.method(java.lang.String)</code></a>,\s |
| 87 | + <a href="../../../../m2/com/m2/lib/Lib.html#method(java.lang.String)"><code>Lib.method(String)</code></a></dd> |
| 88 | + """); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void testSeeModuleExternal(Path base) throws Exception { |
| 93 | + Path out1 = base.resolve("out1"), out2 = base.resolve("out2"); |
| 94 | + |
| 95 | + javadoc("-d", out1.toString(), |
| 96 | + "--module-source-path", src.toString(), |
| 97 | + "--module", "m1,m2", |
| 98 | + "m2/com.m2.lib"); |
| 99 | + javadoc("-d", out2.toString(), |
| 100 | + "--module-source-path", src.toString(), |
| 101 | + "--add-modules", "m2", |
| 102 | + "--module", "m3", |
| 103 | + "-link", "../" + out1.getFileName()); |
| 104 | + |
| 105 | + checkExit(Exit.OK); |
| 106 | + checkOutput("m3/com/m3/app/App.html", true, |
| 107 | + """ |
| 108 | + <dt>See Also:</dt> |
| 109 | + <dd><a href="../../../../../out1/m1/module-summary.html" class="external-link"><code>m1</code></a>,\s |
| 110 | + <a href="../../../../../out1/m1/module-summary.html" class="external-link"><code>m1</code></a>,\s |
| 111 | + <a href="../../../../../out1/m1/com/m1/lib/package-summary.html" class="external-link"><code>m1/com.m1.lib</code></a>,\s |
| 112 | + <a href="../../../../../out1/m1/com/m1/lib/Lib.html" title="class or interface in com.m1.lib" class="external-link"><code>Lib</code></a>,\s |
| 113 | + <a href="../../../../../out1/m1/com/m1/lib/Lib.html#method(java.lang.String)" title="class or \ |
| 114 | + interface in com.m1.lib" class="external-link"><code>Lib.method(java.lang.String)</code></a>,\s |
| 115 | + <a href="../../../../../out1/m1/com/m1/lib/Lib.html#method(java.lang.String)" title="class or \ |
| 116 | + interface in com.m1.lib" class="external-link"><code>Lib.method(String)</code></a>,\s |
| 117 | + <a href="../../../../../out1/m2/module-summary.html" class="external-link"><code>m2</code></a>,\s |
| 118 | + <a href="../../../../../out1/m2/module-summary.html" class="external-link"><code>m2</code></a>,\s |
| 119 | + <a href="../../../../../out1/m2/com/m2/lib/package-summary.html" class="external-link"><code>m2/com.m2.lib</code></a>,\s |
| 120 | + <a href="../../../../../out1/m2/com/m2/lib/Lib.html" title="class or interface in com.m2.lib" class="external-link"><code>Lib</code></a>,\s |
| 121 | + <a href="../../../../../out1/m2/com/m2/lib/Lib.html#method(java.lang.String)" title="class or \ |
| 122 | + interface in com.m2.lib" class="external-link"><code>Lib.method(java.lang.String)</code></a>,\s |
| 123 | + <a href="../../../../../out1/m2/com/m2/lib/Lib.html#method(java.lang.String)" title="class or \ |
| 124 | + interface in com.m2.lib" class="external-link"><code>Lib.method(String)</code></a></dd> |
| 125 | + """); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + public void testSeeModuleSameNameInternal(Path base) throws Exception { |
| 130 | + Path out = base.resolve("out"); |
| 131 | + |
| 132 | + javadoc("-d", out.toString(), |
| 133 | + "--module-source-path", src.toString(), |
| 134 | + "--module", "com.ex1,com.ex2"); |
| 135 | + |
| 136 | + checkExit(Exit.OK); |
| 137 | + checkOutput("com.ex2/com/ex2/B.html", true, |
| 138 | + """ |
| 139 | + <dt>See Also:</dt> |
| 140 | + <dd><a href="../../../com.ex1/com/ex1/package-summary.html"><code>com.ex1</code></a>,\s |
| 141 | + <a href="../../../com.ex1/module-summary.html"><code>com.ex1</code></a>,\s |
| 142 | + <a href="../../../com.ex1/com/ex1/package-summary.html"><code>com.ex1</code></a>,\s |
| 143 | + <a href="../../../com.ex1/com/ex1/A.html" title="class in com.ex1"><code>A</code></a>,\s |
| 144 | + <a href="../../../com.ex1/com/ex1/A.html#m()"><code>A.m()</code></a>,\s |
| 145 | + <a href="../../../com.ex1/com/ex1/A.html#m()"><code>A.m()</code></a>,\s |
| 146 | + <a href="package-summary.html"><code>com.ex2</code></a>,\s |
| 147 | + <a href="../../module-summary.html"><code>com.ex2</code></a></dd> |
| 148 | + """); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void testSeeModuleSameNameExternal(Path base) throws Exception { |
| 153 | + Path out1 = base.resolve("out1"), out2 = base.resolve("out2"); |
| 154 | + |
| 155 | + javadoc("-d", out1.toString(), |
| 156 | + "--module-source-path", src.toString(), |
| 157 | + "--module", "com.ex1"); |
| 158 | + javadoc("-d", out2.toString(), |
| 159 | + "--module-source-path", src.toString(), |
| 160 | + "--module", "com.ex2", |
| 161 | + "-link", "../" + out1.getFileName()); |
| 162 | + |
| 163 | + checkExit(Exit.OK); |
| 164 | + checkOutput("com.ex2/com/ex2/B.html", true, |
| 165 | + """ |
| 166 | + <dt>See Also:</dt> |
| 167 | + <dd><a href="../../../../out1/com.ex1/com/ex1/package-summary.html" class="external-link"><code>com.ex1</code></a>,\s |
| 168 | + <a href="../../../../out1/com.ex1/module-summary.html" class="external-link"><code>com.ex1</code></a>,\s |
| 169 | + <a href="../../../../out1/com.ex1/com/ex1/package-summary.html" class="external-link"><code>com.ex1/com.ex1</code></a>,\s |
| 170 | + <a href="../../../../out1/com.ex1/com/ex1/A.html" title="class or interface in com.ex1" class="external-link"><code>A</code></a>,\s |
| 171 | + <a href="../../../../out1/com.ex1/com/ex1/A.html#m()" title="class or interface in com.ex1" class="external-link"><code>A.m()</code></a>,\s |
| 172 | + <a href="../../../../out1/com.ex1/com/ex1/A.html#m()" title="class or interface in com.ex1" class="external-link"><code>A.m()</code></a>,\s |
| 173 | + <a href="package-summary.html"><code>com.ex2</code></a>,\s |
| 174 | + <a href="../../module-summary.html"><code>com.ex2</code></a></dd> |
| 175 | + """); |
| 176 | + } |
| 177 | + |
| 178 | + @Test |
| 179 | + public void testMissingType(Path base) throws Exception { |
| 180 | + Path out = base.resolve("outMissingType"); |
| 181 | + |
| 182 | + javadoc("-d", out.toString(), |
| 183 | + "--module-source-path", src.toString(), |
| 184 | + "--module", "fail"); |
| 185 | + |
| 186 | + checkExit(Exit.ERROR); |
| 187 | + } |
| 188 | + |
| 189 | + void generateSources() throws Exception { |
| 190 | + new ModuleBuilder(tb, "m1") |
| 191 | + .exports("com.m1.lib") |
| 192 | + .classes(""" |
| 193 | + package com.m1.lib; |
| 194 | + public class Lib { |
| 195 | + public String method(String s) { |
| 196 | + return s; |
| 197 | + } |
| 198 | + }""") |
| 199 | + .write(src); |
| 200 | + new ModuleBuilder(tb, "m2") |
| 201 | + .classes(""" |
| 202 | + package com.m2.lib; |
| 203 | + public class Lib { |
| 204 | + public String method(String s) { |
| 205 | + return s; |
| 206 | + } |
| 207 | + }""") |
| 208 | + .write(src); |
| 209 | + new ModuleBuilder(tb, "m3") |
| 210 | + .exports("com.m3.app") |
| 211 | + .requires("m1") |
| 212 | + .classes(""" |
| 213 | + package com.m3.app;\s |
| 214 | + public class App{ |
| 215 | + /** |
| 216 | + * @see m1 |
| 217 | + * @see m1/ |
| 218 | + * @see m1/com.m1.lib |
| 219 | + * @see m1/com.m1.lib.Lib |
| 220 | + * @see m1/com.m1.lib.Lib#method |
| 221 | + * @see m1/com.m1.lib.Lib#method(String) |
| 222 | + * @see m2 |
| 223 | + * @see m2/ |
| 224 | + * @see m2/com.m2.lib |
| 225 | + * @see m2/com.m2.lib.Lib |
| 226 | + * @see m2/com.m2.lib.Lib#method |
| 227 | + * @see m2/com.m2.lib.Lib#method(String) |
| 228 | + */ |
| 229 | + public App(){} |
| 230 | + } |
| 231 | + """) |
| 232 | + .write(src); |
| 233 | + |
| 234 | + new ModuleBuilder(tb, "com.ex1") |
| 235 | + .exports("com.ex1") |
| 236 | + .classes(""" |
| 237 | + package com.ex1; |
| 238 | + public class A{ |
| 239 | + public void m() {} |
| 240 | + }""", |
| 241 | + """ |
| 242 | + package com.ex1; |
| 243 | + public class B {}""") |
| 244 | + .write(src); |
| 245 | + |
| 246 | + new ModuleBuilder(tb, "com.ex2") |
| 247 | + .requires("com.ex1") |
| 248 | + .exports("com.ex2") |
| 249 | + .classes(""" |
| 250 | + package com.ex2;\s |
| 251 | + import com.ex1.A; |
| 252 | + public class B{ |
| 253 | + /** |
| 254 | + * @see com.ex1 |
| 255 | + * @see com.ex1/ |
| 256 | + * @see com.ex1/com.ex1 |
| 257 | + * @see com.ex1/com.ex1.A |
| 258 | + * @see com.ex1/com.ex1.A#m |
| 259 | + * @see com.ex1/com.ex1.A#m() |
| 260 | + * @see com.ex2 |
| 261 | + * @see com.ex2/ |
| 262 | + */ |
| 263 | + public B(A obj){} |
| 264 | + } |
| 265 | + """) |
| 266 | + .write(src); |
| 267 | + |
| 268 | + new ModuleBuilder(tb, "fail") |
| 269 | + .exports("pkg.fail") |
| 270 | + .classes(""" |
| 271 | + package pkg.fail; |
| 272 | + /** |
| 273 | + * @see fail/#foo() |
| 274 | + */ |
| 275 | + public class F { |
| 276 | + public void foo() {} |
| 277 | + } |
| 278 | + """) |
| 279 | + .write(src); |
| 280 | + |
| 281 | + } |
| 282 | + |
| 283 | +} |
0 commit comments