1 /*
   2  * Copyright (c) 2018, 2019, 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 5076751 8234746
  27  * @summary System properties documentation needed in javadocs
  28  * @library /tools/lib ../../lib
  29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  30  * @build javadoc.tester.* toolbox.ToolBox builder.ClassBuilder
  31  * @run main TestSystemPropertyTaglet
  32  */
  33 
  34 import java.nio.file.Path;
  35 import java.nio.file.Paths;
  36 
  37 import builder.ClassBuilder;
  38 import builder.ClassBuilder.MethodBuilder;
  39 import toolbox.ToolBox;
  40 
  41 import javadoc.tester.JavadocTester;
  42 
  43 public class TestSystemPropertyTaglet extends JavadocTester {
  44 
  45     final ToolBox tb;
  46 
  47     public static void main(String... args) throws Exception {
  48         TestSystemPropertyTaglet tester = new TestSystemPropertyTaglet();
  49         tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
  50     }
  51 
  52     TestSystemPropertyTaglet() {
  53         tb = new ToolBox();
  54     }
  55 
  56     @Test
  57     public void test(Path base) throws Exception {
  58         javadoc("-d", base.resolve("out").toString(),
  59                 "--module-source-path", testSrc,
  60                 "--module", "mymodule");
  61 
  62         checkExit(Exit.OK);
  63 
  64         checkOrder("mymodule/mypackage/MyAnnotation.html",
  65                    "<h1 title=\"Annotation Type MyAnnotation\" class=\"title\">Annotation Type MyAnnotation</h1>",
  66                    "(annotation) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
  67                    "<h2>Element Details</h2>",
  68                    "(annotation/method) the <code><span id=\"test.property-1\" class=\"searchTagResult\">test.property</span></code> system property.",
  69                    "");
  70 
  71         checkOrder("mymodule/mypackage/MyClass.html",
  72                    "<h1 title=\"Class MyClass\" class=\"title\">Class MyClass</h1>",
  73                    "(class) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
  74                    "<h2>Field Details</h2>",
  75                    "(class/field) the <code><span id=\"test.property-1\" class=\"searchTagResult\">test.property</span></code> system property.",
  76                    "(class/static-field) the <code><span id=\"test.property-2\" class=\"searchTagResult\">test.property</span></code> system property.",
  77                    "<h2>Constructor Details</h2>",
  78                    "(class/constructor) the <code><span id=\"test.property-3\" class=\"searchTagResult\">test.property</span></code> system property.",
  79                    "<h2>Method Details</h2>",
  80                    "(class/static-method) the <code><span id=\"test.property-4\" class=\"searchTagResult\">test.property</span></code> system property.",
  81                    "(class/method) the <code><span id=\"test.property-5\" class=\"searchTagResult\">test.property</span></code> system property.",
  82                    "");
  83 
  84         checkOrder("mymodule/mypackage/MyEnum.html",
  85                    "<h1 title=\"Enum MyEnum\" class=\"title\">Enum MyEnum</h1>",
  86                    "(enum) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
  87                    "<h2>Enum Constant Details</h2>",
  88                    "(enum/constant) the <code><span id=\"test.property-1\" class=\"searchTagResult\">test.property</span></code> system property.",
  89                    "");
  90 
  91         checkOrder("mymodule/mypackage/MyError.html",
  92                    "<h1 title=\"Class MyError\" class=\"title\">Class MyError</h1>",
  93                    "(error) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
  94                    "<h2>Constructor Details</h2>",
  95                    "(error/constructor) the <code><span id=\"test.property-1\" class=\"searchTagResult\">test.property</span></code> system property.",
  96                    "");
  97 
  98         checkOrder("mymodule/mypackage/MyException.html",
  99                    "<h1 title=\"Class MyException\" class=\"title\">Class MyException</h1>",
 100                    "(exception) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
 101                    "<h2>Constructor Details</h2>",
 102                    "(exception/constructor) the <code><span id=\"test.property-1\" class=\"searchTagResult\">test.property</span></code>",
 103                    "");
 104 
 105         checkOrder("mymodule/mypackage/MyInterface.html",
 106                    "<h1 title=\"Interface MyInterface\" class=\"title\">Interface MyInterface</h1>",
 107                    "(interface) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
 108                    "<h2>Field Details</h2>",
 109                    "(interface/constant) the <code><span id=\"test.property-1\" class=\"searchTagResult\">test.property</span></code> system property.",
 110                    "<h2>Method Details</h2>",
 111                    "(interface/method-1) the <code><span id=\"test.property-2\" class=\"searchTagResult\">test.property</span></code> system property.",
 112                    "(interface/method-2) the <code><span id=\"test.property-3\" class=\"searchTagResult\">test.property</span></code> system property.",
 113                    "");
 114 
 115         checkOrder("mymodule/module-summary.html",
 116                    "<h1 title=\"Module\" class=\"title\">Module&nbsp;mymodule</h1>",
 117                    "(module) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
 118                    "");
 119 
 120         checkOrder("mymodule/mypackage/package-summary.html",
 121                    "<h1 title=\"Package\" class=\"title\">Package&nbsp;mypackage</h1>",
 122                    "(package) the <code><span id=\"test.property\" class=\"searchTagResult\">test.property</span></code> system property.",
 123                    "");
 124 
 125         checkOrder("index-all.html",
 126                    "<h2 class=\"title\" id=\"I:T\">T</h2>",
 127                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyAnnotation.html#test.property\">test.property</a></span>" +
 128                            " - Search tag in annotation type mypackage.MyAnnotation</dt>\n<dd>System Property</dd>",
 129                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyClass.html#test.property\">test.property</a></span>" +
 130                            " - Search tag in class mypackage.MyClass</dt>\n<dd>System Property</dd>",
 131                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyEnum.html#test.property\">test.property</a></span>" +
 132                            " - Search tag in enum mypackage.MyEnum</dt>\n<dd>System Property</dd>",
 133                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyError.html#test.property\">test.property</a></span>" +
 134                            " - Search tag in error mypackage.MyError</dt>\n<dd>System Property</dd>",
 135                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyException.html#test.property\">test.property</a></span>" +
 136                            " - Search tag in exception mypackage.MyException</dt>\n<dd>System Property</dd>",
 137                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyInterface.html#test.property\">test.property</a></span>" +
 138                            " - Search tag in interface mypackage.MyInterface</dt>\n<dd>System Property</dd>",
 139                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/module-summary.html#test.property\">test.property</a></span>" +
 140                            " - Search tag in module mymodule</dt>\n<dd>System Property</dd>",
 141                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyAnnotation.html#test.property-1\">test.property</a></span>" +
 142                            " - Search tag in mypackage.MyAnnotation.value()</dt>\n<dd>System Property</dd>",
 143                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyClass.html#test.property-2\">test.property</a></span>" +
 144                            " - Search tag in mypackage.MyClass.INT_CONSTANT</dt>\n<dd>System Property</dd>",
 145                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyClass.html#test.property-3\">test.property</a></span>" +
 146                            " - Search tag in mypackage.MyClass.MyClass()</dt>\n<dd>System Property</dd>",
 147                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyClass.html#test.property-1\">test.property</a></span>" +
 148                            " - Search tag in mypackage.MyClass.intField</dt>\n<dd>System Property</dd>",
 149                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyClass.html#test.property-5\">test.property</a></span>" +
 150                            " - Search tag in mypackage.MyClass.run()</dt>\n<dd>System Property</dd>",
 151                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyClass.html#test.property-4\">test.property</a></span>" +
 152                            " - Search tag in mypackage.MyClass.value()</dt>\n<dd>System Property</dd>",
 153                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyEnum.html#test.property-1\">test.property</a></span>" +
 154                            " - Search tag in mypackage.MyEnum.X</dt>\n<dd>System Property</dd>",
 155                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyEnum.html#test.property-2\">test.property</a></span>" +
 156                            " - Search tag in mypackage.MyEnum.m()</dt>\n<dd>System Property</dd>",
 157                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyError.html#test.property-1\">test.property</a></span>" +
 158                            " - Search tag in mypackage.MyError.MyError()</dt>\n<dd>System Property</dd>",
 159                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyException.html#test.property-1\">test.property</a></span>" +
 160                            " - Search tag in mypackage.MyException.MyException()</dt>\n<dd>System Property</dd>",
 161                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyInterface.html#test.property-1\">test.property</a></span>" +
 162                            " - Search tag in mypackage.MyInterface.INT_CONSTANT</dt>\n<dd>System Property</dd>",
 163                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyInterface.html#test.property-2\">test.property</a></span>" +
 164                            " - Search tag in mypackage.MyInterface.m()</dt>\n<dd>System Property</dd>",
 165                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/MyInterface.html#test.property-3\">test.property</a></span>" +
 166                            " - Search tag in mypackage.MyInterface.m(String...)</dt>\n<dd>System Property</dd>",
 167                    "<dt><span class=\"searchTagLink\"><a href=\"mymodule/mypackage/package-summary.html#test.property\">test.property</a></span>" +
 168                            " - Search tag in package mypackage</dt>\n<dd>System Property</dd>",
 169                    "");
 170 
 171         checkOutput("tag-search-index.js", true,
 172                     "{\"l\":\"test.property\",\"h\":\"annotation type mypackage.MyAnnotation\"" +
 173                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyAnnotation.html#test.property\"}",
 174                     "{\"l\":\"test.property\",\"h\":\"class mypackage.MyClass\"" +
 175                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyClass.html#test.property\"}",
 176                     "{\"l\":\"test.property\",\"h\":\"enum mypackage.MyEnum\"" +
 177                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyEnum.html#test.property\"}",
 178                     "{\"l\":\"test.property\",\"h\":\"error mypackage.MyError\"" +
 179                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyError.html#test.property\"}",
 180                     "{\"l\":\"test.property\",\"h\":\"exception mypackage.MyException\"" +
 181                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyException.html#test.property\"}",
 182                     "{\"l\":\"test.property\",\"h\":\"interface mypackage.MyInterface\"" +
 183                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyInterface.html#test.property\"}",
 184                     "{\"l\":\"test.property\",\"h\":\"module mymodule\"" +
 185                             ",\"d\":\"System Property\",\"u\":\"mymodule/module-summary.html#test.property\"}",
 186                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyAnnotation.value()\"" +
 187                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyAnnotation.html#test.property-1\"}",
 188                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyClass.INT_CONSTANT\"" +
 189                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyClass.html#test.property-2\"}",
 190                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyClass.MyClass()\"" +
 191                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyClass.html#test.property-3\"}",
 192                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyClass.intField\"" +
 193                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyClass.html#test.property-1\"}",
 194                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyClass.run()\"" +
 195                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyClass.html#test.property-5\"}",
 196                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyClass.value()\"" +
 197                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyClass.html#test.property-4\"}",
 198                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyEnum.X\"" +
 199                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyEnum.html#test.property-1\"}",
 200                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyEnum.m()\"" +
 201                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyEnum.html#test.property-2\"}",
 202                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyError.MyError()\"" +
 203                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyError.html#test.property-1\"}",
 204                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyException.MyException()\"" +
 205                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyException.html#test.property-1\"}",
 206                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyInterface.INT_CONSTANT\"" +
 207                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyInterface.html#test.property-1\"}",
 208                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyInterface.m()\"" +
 209                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyInterface.html#test.property-2\"}",
 210                     "{\"l\":\"test.property\",\"h\":\"mypackage.MyInterface.m(String...)\"" +
 211                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/MyInterface.html#test.property-3\"}",
 212                     "{\"l\":\"test.property\",\"h\":\"package mypackage\"" +
 213                             ",\"d\":\"System Property\",\"u\":\"mymodule/mypackage/package-summary.html#test.property\"}",
 214                     "");
 215     }
 216 
 217     @Test
 218     public void testSystemPropertyWithinATag(Path base) throws Exception {
 219         Path srcDir = base.resolve("src");
 220         Path outDir = base.resolve("out");
 221 
 222         new ClassBuilder(tb, "pkg2.A")
 223                 .setModifiers("public", "class")
 224                 .addMembers(MethodBuilder.parse("public void func(){}")
 225                         .setComments("a within a : <a href='..'>{@systemProperty user.name}</a>"))
 226                 .write(srcDir);
 227 
 228         javadoc("-d", outDir.toString(),
 229                 "-sourcepath", srcDir.toString(),
 230                 "pkg2");
 231 
 232         checkExit(Exit.OK);
 233 
 234         checkOutput(Output.OUT, true,
 235                 "warning: {@systemProperty} tag, which expands to <a>, within <a>");
 236     }
 237 }