8025416: doclet not substituting {@docRoot} in some cases

Tue, 03 Dec 2013 14:21:45 -0800

author
bpatel
date
Tue, 03 Dec 2013 14:21:45 -0800
changeset 2212
4cb9de4dd420
parent 2211
fb8c59cf26c8
child 2213
1b69023743be

8025416: doclet not substituting {@docRoot} in some cases
Reviewed-by: jjg

src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testDocRootLink/pkg1/C1.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testDocRootLink/pkg1/package.html file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testDocRootLink/pkg2/C2.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testDocRootLink/pkg2/package.html file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue Dec 03 18:13:18 2013 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue Dec 03 14:21:45 2013 -0800
     1.3 @@ -148,43 +148,28 @@
     1.4          StringBuilder buf = new StringBuilder();
     1.5          int previndex = 0;
     1.6          while (true) {
     1.7 -            if (configuration.docrootparent.length() > 0) {
     1.8 -                final String docroot_parent = "{@docroot}/..";
     1.9 -                // Search for lowercase version of {@docRoot}/..
    1.10 -                index = lowerHtml.indexOf(docroot_parent, previndex);
    1.11 -                // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
    1.12 -                if (index < 0) {
    1.13 -                    buf.append(htmlstr.substring(previndex));
    1.14 -                    break;
    1.15 -                }
    1.16 -                // If next {@docroot}/.. pattern found, append htmlstr up to start of tag
    1.17 -                buf.append(htmlstr.substring(previndex, index));
    1.18 -                previndex = index + docroot_parent.length();
    1.19 -                // Insert docrootparent absolute path where {@docRoot}/.. was located
    1.20 -
    1.21 +            final String docroot = "{@docroot}";
    1.22 +            // Search for lowercase version of {@docRoot}
    1.23 +            index = lowerHtml.indexOf(docroot, previndex);
    1.24 +            // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
    1.25 +            if (index < 0) {
    1.26 +                buf.append(htmlstr.substring(previndex));
    1.27 +                break;
    1.28 +            }
    1.29 +            // If next {@docroot} tag found, append htmlstr up to start of tag
    1.30 +            buf.append(htmlstr.substring(previndex, index));
    1.31 +            previndex = index + docroot.length();
    1.32 +            if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) {
    1.33 +                // Insert the absolute link if {@docRoot} is followed by "/..".
    1.34                  buf.append(configuration.docrootparent);
    1.35 -                // Append slash if next character is not a slash
    1.36 -                if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
    1.37 -                    buf.append('/');
    1.38 -                }
    1.39 +                previndex += 3;
    1.40              } else {
    1.41 -                final String docroot = "{@docroot}";
    1.42 -                // Search for lowercase version of {@docRoot}
    1.43 -                index = lowerHtml.indexOf(docroot, previndex);
    1.44 -                // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
    1.45 -                if (index < 0) {
    1.46 -                    buf.append(htmlstr.substring(previndex));
    1.47 -                    break;
    1.48 -                }
    1.49 -                // If next {@docroot} tag found, append htmlstr up to start of tag
    1.50 -                buf.append(htmlstr.substring(previndex, index));
    1.51 -                previndex = index + docroot.length();
    1.52                  // Insert relative path where {@docRoot} was located
    1.53                  buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
    1.54 -                // Append slash if next character is not a slash
    1.55 -                if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
    1.56 -                    buf.append('/');
    1.57 -                }
    1.58 +            }
    1.59 +            // Append slash if next character is not a slash
    1.60 +            if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
    1.61 +                buf.append('/');
    1.62              }
    1.63          }
    1.64          return buf.toString();
    1.65 @@ -1604,26 +1589,30 @@
    1.66                  result.addContent(seeTagToContent((SeeTag) tagelem));
    1.67              } else if (! tagName.equals("Text")) {
    1.68                  boolean wasEmpty = result.isEmpty();
    1.69 -                Content output = TagletWriter.getInlineTagOuput(
    1.70 -                    configuration.tagletManager, holderTag,
    1.71 -                    tagelem, getTagletWriterInstance(isFirstSentence));
    1.72 +                Content output;
    1.73 +                if (configuration.docrootparent.length() > 0
    1.74 +                        && tagelem.name().equals("@docRoot")
    1.75 +                        && ((tags[i + 1]).text()).startsWith("/..")) {
    1.76 +                    // If Xdocrootparent switch ON, set the flag to remove the /.. occurrence after
    1.77 +                    // {@docRoot} tag in the very next Text tag.
    1.78 +                    textTagChange = true;
    1.79 +                    // Replace the occurrence of {@docRoot}/.. with the absolute link.
    1.80 +                    output = new StringContent(configuration.docrootparent);
    1.81 +                } else {
    1.82 +                    output = TagletWriter.getInlineTagOuput(
    1.83 +                            configuration.tagletManager, holderTag,
    1.84 +                            tagelem, getTagletWriterInstance(isFirstSentence));
    1.85 +                }
    1.86                  if (output != null)
    1.87                      result.addContent(output);
    1.88                  if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
    1.89                      break;
    1.90 -                } else if (configuration.docrootparent.length() > 0 &&
    1.91 -                        tagelem.name().equals("@docRoot") &&
    1.92 -                        ((tags[i + 1]).text()).startsWith("/..")) {
    1.93 -                    //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
    1.94 -                    //{@docRoot} tag in the very next Text tag.
    1.95 -                    textTagChange = true;
    1.96 -                    continue;
    1.97                  } else {
    1.98                      continue;
    1.99                  }
   1.100              } else {
   1.101                  String text = tagelem.text();
   1.102 -                //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
   1.103 +                //If Xdocrootparent switch ON, remove the /.. occurrence after {@docRoot} tag.
   1.104                  if (textTagChange) {
   1.105                      text = text.replaceFirst("/..", "");
   1.106                      textTagChange = false;
     2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue Dec 03 18:13:18 2013 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue Dec 03 14:21:45 2013 -0800
     2.3 @@ -80,9 +80,7 @@
     2.4       */
     2.5      public Content getDocRootOutput() {
     2.6          String path;
     2.7 -        if (configuration.docrootparent.length() > 0)
     2.8 -            path = configuration.docrootparent;
     2.9 -        else if (htmlWriter.pathToRoot.isEmpty())
    2.10 +        if (htmlWriter.pathToRoot.isEmpty())
    2.11              path = ".";
    2.12          else
    2.13              path = htmlWriter.pathToRoot.getPath();
     3.1 --- a/test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java	Tue Dec 03 18:13:18 2013 +0000
     3.2 +++ b/test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java	Tue Dec 03 14:21:45 2013 -0800
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -23,7 +23,7 @@
    3.11  
    3.12  /*
    3.13   * @test
    3.14 - * @bug 6553182
    3.15 + * @bug 6553182 8025416
    3.16   * @summary This test verifies the -Xdocrootparent option.
    3.17   * @author Bhavesh Patel
    3.18   * @library ../lib/
    3.19 @@ -35,43 +35,87 @@
    3.20      private static final String BUG_ID = "6553182";
    3.21      private static final String[][] TEST1 = {
    3.22          {BUG_ID + FS + "pkg1" + FS + "C1.html",
    3.23 -            "<a href=\"../../technotes/guides/index.html\">"
    3.24 +            "Refer <a href=\"../../technotes/guides/index.html\">Here</a>"
    3.25 +        },
    3.26 +        {BUG_ID + FS + "pkg1" + FS + "C1.html",
    3.27 +            "This <a href=\"../pkg2/C2.html\">Here</a> should not be replaced" + NL +
    3.28 +            " with an absolute link."
    3.29 +        },
    3.30 +        {BUG_ID + FS + "pkg1" + FS + "C1.html",
    3.31 +            "Testing <a href=\"../technotes/guides/index.html\">Link 1</a> and" + NL +
    3.32 +            " <a href=\"../pkg2/C2.html\">Link 2</a>."
    3.33          },
    3.34          {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
    3.35 -            "<a href=\"../../technotes/guides/index.html\">"
    3.36 +            "<a href=\"../../technotes/guides/index.html\">" + NL +
    3.37 +            "            Test document 1</a>"
    3.38 +        },
    3.39 +        {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
    3.40 +            "<a href=\"../pkg2/C2.html\">" + NL +
    3.41 +            "            Another Test document 1</a>"
    3.42 +        },
    3.43 +        {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
    3.44 +            "<a href=\"../technotes/guides/index.html\">" + NL +
    3.45 +            "            Another Test document 2.</a>"
    3.46          }
    3.47      };
    3.48      private static final String[][] NEGATED_TEST1 = {
    3.49          {BUG_ID + FS + "pkg1" + FS + "C1.html",
    3.50              "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
    3.51          },
    3.52 +        {BUG_ID + FS + "pkg1" + FS + "C1.html",
    3.53 +            "<a href=\"http://download.oracle.com/javase/7/docs/pkg2/C2.html\">"
    3.54 +        },
    3.55          {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
    3.56              "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
    3.57 +        },
    3.58 +        {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
    3.59 +            "<a href=\"http://download.oracle.com/javase/7/docs/pkg2/C2.html\">"
    3.60          }
    3.61      };
    3.62      private static final String[][] TEST2 = {
    3.63 -        {BUG_ID + FS + "pkg2" + FS + "C2.html",
    3.64 -            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
    3.65 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
    3.66 +            "Refer <a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">Here</a>"
    3.67          },
    3.68 -        {BUG_ID + FS + "pkg2" + FS + "package-summary.html",
    3.69 -            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
    3.70 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
    3.71 +            "This <a href=\"../pkg1/C1.html\">Here</a> should not be replaced" + NL +
    3.72 +            " with an absolute link."
    3.73 +        },
    3.74 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
    3.75 +            "Testing <a href=\"../technotes/guides/index.html\">Link 1</a> and" + NL +
    3.76 +            " <a href=\"../pkg1/C1.html\">Link 2</a>."
    3.77 +        },
    3.78 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
    3.79 +            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">" + NL +
    3.80 +            "            Test document 1</a>"
    3.81 +        },
    3.82 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
    3.83 +            "<a href=\"../pkg1/C1.html\">" + NL + "            Another Test document 1</a>"
    3.84 +        },
    3.85 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
    3.86 +            "<a href=\"../technotes/guides/index.html\">" + NL + "            Another Test document 2.</a>"
    3.87          }
    3.88      };
    3.89      private static final String[][] NEGATED_TEST2 = {
    3.90 -        {BUG_ID + FS + "pkg2" + FS + "C2.html",
    3.91 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
    3.92              "<a href=\"../../technotes/guides/index.html\">"
    3.93          },
    3.94 -        {BUG_ID + FS + "pkg2" + FS + "package-summary.html",
    3.95 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
    3.96 +            "<a href=\"http://download.oracle.com/javase/7/docs/pkg1/C1.html\">"
    3.97 +        },
    3.98 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
    3.99              "<a href=\"../../technotes/guides/index.html\">"
   3.100 +        },
   3.101 +        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
   3.102 +            "<a href=\"http://download.oracle.com/javase/7/docs/pkg1/C1.html\">"
   3.103          }
   3.104      };
   3.105      private static final String[] ARGS1 =
   3.106              new String[]{
   3.107 -        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"
   3.108 +        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1", "pkg2"
   3.109      };
   3.110      private static final String[] ARGS2 =
   3.111              new String[]{
   3.112 -        "-d", BUG_ID, "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg2"
   3.113 +        "-d", BUG_ID + "-1", "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg1", "pkg2"
   3.114      };
   3.115  
   3.116      /**
     4.1 --- a/test/com/sun/javadoc/testDocRootLink/pkg1/C1.java	Tue Dec 03 18:13:18 2013 +0000
     4.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg1/C1.java	Tue Dec 03 14:21:45 2013 -0800
     4.3 @@ -25,7 +25,12 @@
     4.4  
     4.5  /**
     4.6   * Class 1. This is a test.
     4.7 - * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works
     4.8 - * or not.
     4.9 + * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. This link should
    4.10 + * not be replaced with an absolute link.
    4.11 + * This <a href="{@docRoot}/pkg2/C2.html">Here</a> should not be replaced
    4.12 + * with an absolute link.
    4.13 + * Testing <a href="{@docRoot}/technotes/guides/index.html">Link 1</a> and
    4.14 + * <a href="{@docRoot}/pkg2/C2.html">Link 2</a>. 2 back-to-back links using
    4.15 + * docroot. These should not be replaced with an absolute link.
    4.16   */
    4.17  public class C1 {}
     5.1 --- a/test/com/sun/javadoc/testDocRootLink/pkg1/package.html	Tue Dec 03 18:13:18 2013 +0000
     5.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg1/package.html	Tue Dec 03 14:21:45 2013 -0800
     5.3 @@ -3,16 +3,16 @@
     5.4  <title>javax.management package</title>
     5.5  </head>
     5.6  <body bgcolor="white">
     5.7 -This is a test.
     5.8 -      <p id="spec">
     5.9 -    @see <a href="{@docRoot}/../technotes/guides/index.html">
    5.10 -      Test document 1</a>
    5.11 -      in particular the
    5.12 -      <a href="{@docRoot}/../technotes/guides/index.html">
    5.13 +    This is a test.
    5.14 +    <p id="spec">
    5.15 +        @see <a href="{@docRoot}/../technotes/guides/index.html">
    5.16 +            Test document 1</a> should not be replaced with an absolute link.
    5.17 +        @see <a href="{@docRoot}/pkg2/C2.html">
    5.18 +            Another Test document 1</a> which should not be replaced with an absolute link.
    5.19 +        <a href="{@docRoot}/technotes/guides/index.html">
    5.20 +            Another Test document 2.</a> which should not be replaced with an absolute link.
    5.21  
    5.22 -      Test document 2.</a>
    5.23 -
    5.24 -	@since 1.5
    5.25 +        @since 1.5
    5.26  
    5.27  </body>
    5.28  </html>
     6.1 --- a/test/com/sun/javadoc/testDocRootLink/pkg2/C2.java	Tue Dec 03 18:13:18 2013 +0000
     6.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg2/C2.java	Tue Dec 03 14:21:45 2013 -0800
     6.3 @@ -24,8 +24,13 @@
     6.4  package pkg2;
     6.5  
     6.6  /**
     6.7 - * Class 1. This is a test.
     6.8 - * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works
     6.9 - * or not.
    6.10 + * Class 2. This is a test.
    6.11 + * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a> should be
    6.12 + * replaced with an absolute link.
    6.13 + * This <a href="{@docRoot}/pkg1/C1.html">Here</a> should not be replaced
    6.14 + * with an absolute link.
    6.15 + * Testing <a href="{@docRoot}/technotes/guides/index.html">Link 1</a> and
    6.16 + * <a href="{@docRoot}/pkg1/C1.html">Link 2</a>. Both should not be replaced with
    6.17 + * an absolute link.
    6.18   */
    6.19  public class C2 {}
     7.1 --- a/test/com/sun/javadoc/testDocRootLink/pkg2/package.html	Tue Dec 03 18:13:18 2013 +0000
     7.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg2/package.html	Tue Dec 03 14:21:45 2013 -0800
     7.3 @@ -3,16 +3,16 @@
     7.4  <title>javax.management package</title>
     7.5  </head>
     7.6  <body bgcolor="white">
     7.7 -This is a test.
     7.8 -      <p id="spec">
     7.9 -    @see <a href="{@docRoot}/../technotes/guides/index.html">
    7.10 -      Test document 1</a>
    7.11 -      in particular the
    7.12 -      <a href="{@docRoot}/../technotes/guides/index.html">
    7.13 +    This is a test.
    7.14 +    <p id="spec">
    7.15 +        @see <a href="{@docRoot}/../technotes/guides/index.html">
    7.16 +            Test document 1</a> should be replaced with an absolute link.
    7.17 +        @see <a href="{@docRoot}/pkg1/C1.html">
    7.18 +            Another Test document 1</a> which should not be replaced with an absolute link.
    7.19 +        <a href="{@docRoot}/technotes/guides/index.html">
    7.20 +            Another Test document 2.</a> which should not be replaced with an absolute link.
    7.21  
    7.22 -      Test document 2.</a>
    7.23 -
    7.24 -	@since 1.5
    7.25 +        @since 1.5
    7.26  
    7.27  </body>
    7.28  </html>

mercurial