< prev index next >

test/langtools/jdk/javadoc/doclet/testLinkOption/TestLinkOption.java

Print this page




  57         String[] javacArgs = {
  58             "-d", mylib, testSrc + "/extra/StringBuilder.java"
  59         };
  60         com.sun.tools.javac.Main.compile(javacArgs);
  61 
  62         // Generate the documentation using -linkoffline and a URL as the first parameter.
  63         String out1 = "out1";
  64         String url = "http://acme.com/jdk/";
  65         javadoc("-d", out1,
  66                 "-source", "8",
  67                 "-classpath", mylib,
  68                 "-sourcepath", testSrc,
  69                 "-linkoffline", url, testSrc + "/jdk",
  70                 "-package",
  71                 "pkg", "mylib.lang");
  72         checkExit(Exit.OK);
  73 
  74         checkOutput("pkg/C.html", true,
  75                 "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
  76                 + "title=\"class or interface in java.lang\" class=\"externalLink\"><code>Link to String Class</code></a>",
  77                 //Make sure the parameters are indented properly when the -link option is used.
  78                 "(int&nbsp;p1,\n"
  79                 + "      int&nbsp;p2,\n"
  80                 + "      int&nbsp;p3)",
  81                 "(int&nbsp;p1,\n"
  82                 + "      int&nbsp;p2,\n"
  83                 + "      <a href=\"" + url + "java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\" class=\"externalLink\">"
  84                 + "Object</a>&nbsp;p3)");
  85 
  86         checkOutput("pkg/B.html", true,
  87                 "<div class=\"block\">A method with html tag the method "
  88                 + "<a href=\"" + url + "java/lang/ClassLoader.html?is-external=true#getSystemClassLoader()\""
  89                 + " title=\"class or interface in java.lang\" class=\"externalLink\"><code><b>getSystemClassLoader()</b>"
  90                 + "</code></a> as the parent class loader.</div>",
  91                 "<div class=\"block\">is equivalent to invoking <code>"
  92                 + "<a href=\"#createTempFile(java.lang.String,java.lang.String,java.io.File)\">"
  93                 + "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code></a></code>.</div>",
  94                 "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
  95                 + "title=\"class or interface in java.lang\" class=\"externalLink\">Link-Plain to String Class</a>",
  96                 "<code><b>getSystemClassLoader()</b></code>",
  97                 "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code>",
  98                 "<dd><a href=\"http://www.ietf.org/rfc/rfc2279.txt\"><i>RFC&nbsp;2279: UTF-8, a\n" +
  99                 " transformation format of ISO 10646</i></a>, <br><a " +
 100                 "href=\"http://www.ietf.org/rfc/rfc2373.txt\"><i>RFC&nbsp;2373: IPv6 Addressing\n" +
 101                 " Architecture</i></a>, <br><a href=\"http://www.ietf.org/rfc/rfc2396.txt\">" +
 102                 "<i>RFC&nbsp;2396: Uniform\n" +
 103                 " Resource Identifiers (URI): Generic Syntax</i></a>, " +
 104                 "<br><a href=\"http://www.ietf.org/rfc/rfc2732.txt\"><i>RFC&nbsp;2732: Format for\n" +
 105                 " Literal IPv6 Addresses in URLs</i></a>, <br><a href=\"C.html\">" +
 106                 "A nearby file</a></dd>\n" +
 107                 "</dl>");
 108 
 109         checkOutput("mylib/lang/StringBuilderChild.html", true,
 110                 "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n"
 111                 + "extends <a href=\"" + url + "java/lang/Object.html?is-external=true\" "
 112                 + "title=\"class or interface in java.lang\" class=\"externalLink\">Object</a></pre>"
 113         );
 114 
 115         // Generate the documentation using -linkoffline and a relative path as the first parameter.
 116         // We will try linking to the docs generated in test 1 with a relative path.
 117         String out2 = "out2";
 118         javadoc("-d", out2,
 119                 "-sourcepath", testSrc,
 120                 "-linkoffline", "../" + out1, out1,
 121                 "-package",
 122                 "pkg2");
 123         checkExit(Exit.OK);
 124         checkOutput("pkg2/C2.html", true,
 125             "This is a link to <a href=\"../../" + out1 + "/pkg/C.html?is-external=true\" " +
 126             "title=\"class or interface in pkg\" class=\"externalLink\"><code>Class C</code></a>."
 127         );
 128 
 129         String out3 = "out3";
 130         javadoc(createArguments(out3, out1, true));  // with trailing slash
 131         checkExit(Exit.OK);
 132 
 133         String out4 = "out4";
 134         javadoc(createArguments(out4, out1, false)); // without trailing slash
 135         checkExit(Exit.OK);
 136         // Note: the following test is very weak, and will fail if ever the text
 137         // of the message is changed. We should have a separate test to verify
 138         // this is the text that is given when there is a problem with a URL
 139         checkOutput(Output.OUT, false,
 140                 "warning - Error fetching URL");
 141 
 142         // check multiple link options
 143         javadoc("-d", "out5",
 144                 "-sourcepath", testSrc,
 145                 "-link", "../" + "out1",
 146                 "-link", "../" + "out2",
 147                 "pkg3");
 148         checkExit(Exit.OK);
 149         checkOutput("pkg3/A.html", true,
 150                 "<pre>public class <span class=\"typeNameLabel\">A</span>\n"
 151                 + "extends java.lang.Object</pre>\n"
 152                 + "<div class=\"block\">Test links.\n"
 153                 + " <br>\n"
 154                 + " <a href=\"../../out2/pkg2/C2.html?is-external=true\" "
 155                 + "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
 156                 + " <br>\n"
 157                 + " <a href=\"../../out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
 158                 + "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
 159                 + "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
 160         );
 161 
 162         // check multiple linkoffline options
 163         setAutomaticCheckLinks(false); // The example code has toy/bad links
 164         javadoc("-d", "out6",
 165                 "-sourcepath", testSrc,
 166                 "-linkoffline", "../copy/out1", "out1",
 167                 "-linkoffline", "../copy/out2", "out2",
 168                 "pkg3");
 169         checkExit(Exit.OK);
 170         checkOutput("pkg3/A.html", true,
 171                 "<pre>public class <span class=\"typeNameLabel\">A</span>\n"
 172                         + "extends java.lang.Object</pre>\n"
 173                         + "<div class=\"block\">Test links.\n"
 174                         + " <br>\n"
 175                         + " <a href=\"../../copy/out2/pkg2/C2.html?is-external=true\" "
 176                         + "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
 177                         + " <br>\n"
 178                         + " <a href=\"../../copy/out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
 179                         + "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
 180                         + "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
 181         );
 182 
 183         setAutomaticCheckLinks(true); // re-enable checks
 184     }
 185 
 186     /*
 187      * Create the documentation using the -link option, vary the behavior with
 188      * both trailing and no trailing slash. We are only interested in ensuring
 189      * that the command executes with no errors or related warnings.
 190      */
 191     static String[] createArguments(String outDir, String packageDir, boolean withTrailingSlash) {




  57         String[] javacArgs = {
  58             "-d", mylib, testSrc + "/extra/StringBuilder.java"
  59         };
  60         com.sun.tools.javac.Main.compile(javacArgs);
  61 
  62         // Generate the documentation using -linkoffline and a URL as the first parameter.
  63         String out1 = "out1";
  64         String url = "http://acme.com/jdk/";
  65         javadoc("-d", out1,
  66                 "-source", "8",
  67                 "-classpath", mylib,
  68                 "-sourcepath", testSrc,
  69                 "-linkoffline", url, testSrc + "/jdk",
  70                 "-package",
  71                 "pkg", "mylib.lang");
  72         checkExit(Exit.OK);
  73 
  74         checkOutput("pkg/C.html", true,
  75                 "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
  76                 + "title=\"class or interface in java.lang\" class=\"externalLink\"><code>Link to String Class</code></a>",
  77                 //Make sure the parameters are formatted properly when the -link option is used.
  78                 "(int&nbsp;p1,\n"
  79                 + "int&nbsp;p2,\n"
  80                 + "int&nbsp;p3)",
  81                 "(int&nbsp;p1,\n"
  82                 + "int&nbsp;p2,\n"
  83                 + "<a href=\"" + url + "java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\" class=\"externalLink\">"
  84                 + "Object</a>&nbsp;p3)");
  85 
  86         checkOutput("pkg/B.html", true,
  87                 "<div class=\"block\">A method with html tag the method "
  88                 + "<a href=\"" + url + "java/lang/ClassLoader.html?is-external=true#getSystemClassLoader()\""
  89                 + " title=\"class or interface in java.lang\" class=\"externalLink\"><code><b>getSystemClassLoader()</b>"
  90                 + "</code></a> as the parent class loader.</div>",
  91                 "<div class=\"block\">is equivalent to invoking <code>"
  92                 + "<a href=\"#createTempFile(java.lang.String,java.lang.String,java.io.File)\">"
  93                 + "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code></a></code>.</div>",
  94                 "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
  95                 + "title=\"class or interface in java.lang\" class=\"externalLink\">Link-Plain to String Class</a>",
  96                 "<code><b>getSystemClassLoader()</b></code>",
  97                 "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code>",
  98                 "<dd><a href=\"http://www.ietf.org/rfc/rfc2279.txt\"><i>RFC&nbsp;2279: UTF-8, a\n" +
  99                 " transformation format of ISO 10646</i></a>, <br><a " +
 100                 "href=\"http://www.ietf.org/rfc/rfc2373.txt\"><i>RFC&nbsp;2373: IPv6 Addressing\n" +
 101                 " Architecture</i></a>, <br><a href=\"http://www.ietf.org/rfc/rfc2396.txt\">" +
 102                 "<i>RFC&nbsp;2396: Uniform\n" +
 103                 " Resource Identifiers (URI): Generic Syntax</i></a>, " +
 104                 "<br><a href=\"http://www.ietf.org/rfc/rfc2732.txt\"><i>RFC&nbsp;2732: Format for\n" +
 105                 " Literal IPv6 Addresses in URLs</i></a>, <br><a href=\"C.html\">" +
 106                 "A nearby file</a></dd>\n" +
 107                 "</dl>");
 108 
 109         checkOutput("mylib/lang/StringBuilderChild.html", true,
 110                 "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n"
 111                 + "extends <a href=\"" + url + "java/lang/Object.html?is-external=true\" "
 112                 + "title=\"class or interface in java.lang\" class=\"externalLink\">Object</a></pre>"
 113         );
 114 
 115         // Generate the documentation using -linkoffline and a relative path as the first parameter.
 116         // We will try linking to the docs generated in test 1 with a relative path.
 117         String out2 = "out2";
 118         javadoc("-d", out2,
 119                 "-sourcepath", testSrc,
 120                 "-linkoffline", "../" + out1, out1,
 121                 "-package",
 122                 "pkg2");
 123         checkExit(Exit.OK);
 124         checkOutput("pkg2/C2.html", true,
 125             "This is a link to <a href=\"../../" + out1 + "/pkg/C.html?is-external=true\" " +
 126             "title=\"class or interface in pkg\" class=\"externalLink\"><code>Class C</code></a>."
 127         );
 128 
 129         String out3 = "out3";
 130         javadoc(createArguments(out3, out1, true));  // with trailing slash
 131         checkExit(Exit.OK);
 132 
 133         String out4 = "out4";
 134         javadoc(createArguments(out4, out1, false)); // without trailing slash
 135         checkExit(Exit.OK);
 136         // Note: the following test is very weak, and will fail if ever the text
 137         // of the message is changed. We should have a separate test to verify
 138         // this is the text that is given when there is a problem with a URL
 139         checkOutput(Output.OUT, false,
 140                 "warning - Error fetching URL");
 141 
 142         // check multiple link options
 143         javadoc("-d", "out5",
 144                 "-sourcepath", testSrc,
 145                 "-link", "../" + "out1",
 146                 "-link", "../" + "out2",
 147                 "pkg3");
 148         checkExit(Exit.OK);
 149         checkOutput("pkg3/A.html", true,
 150                 "<pre>public class <span class=\"typeNameLabel\">A</span>\n"
 151                 + "extends java.lang.Object</pre>\n"
 152                 + "<div class=\"block\">Test links.\n"
 153                 + " <br>\n"
 154                 + " <a href=\"../../out2/pkg2/C2.html?is-external=true\" "
 155                 + "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
 156                 + " <br>\n"
 157                 + " <a href=\"../../out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
 158                 + "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
 159                 + "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
 160         );
 161 
 162         // check multiple linkoffline options
 163         setAutomaticCheckLinks(false); // The example code has toy/bad links
 164         javadoc("-d", "out6",
 165                 "-sourcepath", testSrc,
 166                 "-linkoffline", "../copy/out1", "out1",
 167                 "-linkoffline", "../copy/out2", "out2",
 168                 "pkg3");
 169         checkExit(Exit.OK);
 170         checkOutput("pkg3/A.html", true,
 171                 "<pre>public class <span class=\"typeNameLabel\">A</span>\n"
 172                         + "extends java.lang.Object</pre>\n"
 173                         + "<div class=\"block\">Test links.\n"
 174                         + " <br>\n"
 175                         + " <a href=\"../../copy/out2/pkg2/C2.html?is-external=true\" "
 176                         + "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
 177                         + " <br>\n"
 178                         + " <a href=\"../../copy/out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
 179                         + "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
 180                         + "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
 181         );
 182 
 183         setAutomaticCheckLinks(true); // re-enable checks
 184     }
 185 
 186     /*
 187      * Create the documentation using the -link option, vary the behavior with
 188      * both trailing and no trailing slash. We are only interested in ensuring
 189      * that the command executes with no errors or related warnings.
 190      */
 191     static String[] createArguments(String outDir, String packageDir, boolean withTrailingSlash) {


< prev index next >