changeset 22005:4270ada5dcd1

8025416: doclet not substituting {@docRoot} in some cases Reviewed-by: jjg
author bpatel
date Tue, 03 Dec 2013 14:21:45 -0800
parents 203318f0799d
children 07c1b61c0726
files langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java langtools/test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java langtools/test/com/sun/javadoc/testDocRootLink/pkg1/C1.java langtools/test/com/sun/javadoc/testDocRootLink/pkg1/package.html langtools/test/com/sun/javadoc/testDocRootLink/pkg2/C2.java langtools/test/com/sun/javadoc/testDocRootLink/pkg2/package.html
diffstat 7 files changed, 123 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue Dec 03 18:13:18 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue Dec 03 14:21:45 2013 -0800
@@ -148,43 +148,28 @@
         StringBuilder buf = new StringBuilder();
         int previndex = 0;
         while (true) {
-            if (configuration.docrootparent.length() > 0) {
-                final String docroot_parent = "{@docroot}/..";
-                // Search for lowercase version of {@docRoot}/..
-                index = lowerHtml.indexOf(docroot_parent, previndex);
-                // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
-                if (index < 0) {
-                    buf.append(htmlstr.substring(previndex));
-                    break;
-                }
-                // If next {@docroot}/.. pattern found, append htmlstr up to start of tag
-                buf.append(htmlstr.substring(previndex, index));
-                previndex = index + docroot_parent.length();
-                // Insert docrootparent absolute path where {@docRoot}/.. was located
-
+            final String docroot = "{@docroot}";
+            // Search for lowercase version of {@docRoot}
+            index = lowerHtml.indexOf(docroot, previndex);
+            // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
+            if (index < 0) {
+                buf.append(htmlstr.substring(previndex));
+                break;
+            }
+            // If next {@docroot} tag found, append htmlstr up to start of tag
+            buf.append(htmlstr.substring(previndex, index));
+            previndex = index + docroot.length();
+            if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) {
+                // Insert the absolute link if {@docRoot} is followed by "/..".
                 buf.append(configuration.docrootparent);
-                // Append slash if next character is not a slash
-                if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
-                    buf.append('/');
-                }
+                previndex += 3;
             } else {
-                final String docroot = "{@docroot}";
-                // Search for lowercase version of {@docRoot}
-                index = lowerHtml.indexOf(docroot, previndex);
-                // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
-                if (index < 0) {
-                    buf.append(htmlstr.substring(previndex));
-                    break;
-                }
-                // If next {@docroot} tag found, append htmlstr up to start of tag
-                buf.append(htmlstr.substring(previndex, index));
-                previndex = index + docroot.length();
                 // Insert relative path where {@docRoot} was located
                 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
-                // Append slash if next character is not a slash
-                if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
-                    buf.append('/');
-                }
+            }
+            // Append slash if next character is not a slash
+            if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
+                buf.append('/');
             }
         }
         return buf.toString();
@@ -1604,26 +1589,30 @@
                 result.addContent(seeTagToContent((SeeTag) tagelem));
             } else if (! tagName.equals("Text")) {
                 boolean wasEmpty = result.isEmpty();
-                Content output = TagletWriter.getInlineTagOuput(
-                    configuration.tagletManager, holderTag,
-                    tagelem, getTagletWriterInstance(isFirstSentence));
+                Content output;
+                if (configuration.docrootparent.length() > 0
+                        && tagelem.name().equals("@docRoot")
+                        && ((tags[i + 1]).text()).startsWith("/..")) {
+                    // If Xdocrootparent switch ON, set the flag to remove the /.. occurrence after
+                    // {@docRoot} tag in the very next Text tag.
+                    textTagChange = true;
+                    // Replace the occurrence of {@docRoot}/.. with the absolute link.
+                    output = new StringContent(configuration.docrootparent);
+                } else {
+                    output = TagletWriter.getInlineTagOuput(
+                            configuration.tagletManager, holderTag,
+                            tagelem, getTagletWriterInstance(isFirstSentence));
+                }
                 if (output != null)
                     result.addContent(output);
                 if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
                     break;
-                } else if (configuration.docrootparent.length() > 0 &&
-                        tagelem.name().equals("@docRoot") &&
-                        ((tags[i + 1]).text()).startsWith("/..")) {
-                    //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
-                    //{@docRoot} tag in the very next Text tag.
-                    textTagChange = true;
-                    continue;
                 } else {
                     continue;
                 }
             } else {
                 String text = tagelem.text();
-                //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
+                //If Xdocrootparent switch ON, remove the /.. occurrence after {@docRoot} tag.
                 if (textTagChange) {
                     text = text.replaceFirst("/..", "");
                     textTagChange = false;
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue Dec 03 18:13:18 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue Dec 03 14:21:45 2013 -0800
@@ -80,9 +80,7 @@
      */
     public Content getDocRootOutput() {
         String path;
-        if (configuration.docrootparent.length() > 0)
-            path = configuration.docrootparent;
-        else if (htmlWriter.pathToRoot.isEmpty())
+        if (htmlWriter.pathToRoot.isEmpty())
             path = ".";
         else
             path = htmlWriter.pathToRoot.getPath();
--- a/langtools/test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java	Tue Dec 03 18:13:18 2013 +0000
+++ b/langtools/test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java	Tue Dec 03 14:21:45 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6553182
+ * @bug 6553182 8025416
  * @summary This test verifies the -Xdocrootparent option.
  * @author Bhavesh Patel
  * @library ../lib/
@@ -35,43 +35,87 @@
     private static final String BUG_ID = "6553182";
     private static final String[][] TEST1 = {
         {BUG_ID + FS + "pkg1" + FS + "C1.html",
-            "<a href=\"../../technotes/guides/index.html\">"
+            "Refer <a href=\"../../technotes/guides/index.html\">Here</a>"
+        },
+        {BUG_ID + FS + "pkg1" + FS + "C1.html",
+            "This <a href=\"../pkg2/C2.html\">Here</a> should not be replaced" + NL +
+            " with an absolute link."
+        },
+        {BUG_ID + FS + "pkg1" + FS + "C1.html",
+            "Testing <a href=\"../technotes/guides/index.html\">Link 1</a> and" + NL +
+            " <a href=\"../pkg2/C2.html\">Link 2</a>."
         },
         {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
-            "<a href=\"../../technotes/guides/index.html\">"
+            "<a href=\"../../technotes/guides/index.html\">" + NL +
+            "            Test document 1</a>"
+        },
+        {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
+            "<a href=\"../pkg2/C2.html\">" + NL +
+            "            Another Test document 1</a>"
+        },
+        {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
+            "<a href=\"../technotes/guides/index.html\">" + NL +
+            "            Another Test document 2.</a>"
         }
     };
     private static final String[][] NEGATED_TEST1 = {
         {BUG_ID + FS + "pkg1" + FS + "C1.html",
             "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
         },
+        {BUG_ID + FS + "pkg1" + FS + "C1.html",
+            "<a href=\"http://download.oracle.com/javase/7/docs/pkg2/C2.html\">"
+        },
         {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
             "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
+        },
+        {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
+            "<a href=\"http://download.oracle.com/javase/7/docs/pkg2/C2.html\">"
         }
     };
     private static final String[][] TEST2 = {
-        {BUG_ID + FS + "pkg2" + FS + "C2.html",
-            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
+            "Refer <a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">Here</a>"
         },
-        {BUG_ID + FS + "pkg2" + FS + "package-summary.html",
-            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
+            "This <a href=\"../pkg1/C1.html\">Here</a> should not be replaced" + NL +
+            " with an absolute link."
+        },
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
+            "Testing <a href=\"../technotes/guides/index.html\">Link 1</a> and" + NL +
+            " <a href=\"../pkg1/C1.html\">Link 2</a>."
+        },
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
+            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">" + NL +
+            "            Test document 1</a>"
+        },
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
+            "<a href=\"../pkg1/C1.html\">" + NL + "            Another Test document 1</a>"
+        },
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
+            "<a href=\"../technotes/guides/index.html\">" + NL + "            Another Test document 2.</a>"
         }
     };
     private static final String[][] NEGATED_TEST2 = {
-        {BUG_ID + FS + "pkg2" + FS + "C2.html",
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
             "<a href=\"../../technotes/guides/index.html\">"
         },
-        {BUG_ID + FS + "pkg2" + FS + "package-summary.html",
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
+            "<a href=\"http://download.oracle.com/javase/7/docs/pkg1/C1.html\">"
+        },
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
             "<a href=\"../../technotes/guides/index.html\">"
+        },
+        {BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
+            "<a href=\"http://download.oracle.com/javase/7/docs/pkg1/C1.html\">"
         }
     };
     private static final String[] ARGS1 =
             new String[]{
-        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"
+        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1", "pkg2"
     };
     private static final String[] ARGS2 =
             new String[]{
-        "-d", BUG_ID, "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg2"
+        "-d", BUG_ID + "-1", "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg1", "pkg2"
     };
 
     /**
--- a/langtools/test/com/sun/javadoc/testDocRootLink/pkg1/C1.java	Tue Dec 03 18:13:18 2013 +0000
+++ b/langtools/test/com/sun/javadoc/testDocRootLink/pkg1/C1.java	Tue Dec 03 14:21:45 2013 -0800
@@ -25,7 +25,12 @@
 
 /**
  * Class 1. This is a test.
- * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works
- * or not.
+ * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. This link should
+ * not be replaced with an absolute link.
+ * This <a href="{@docRoot}/pkg2/C2.html">Here</a> should not be replaced
+ * with an absolute link.
+ * Testing <a href="{@docRoot}/technotes/guides/index.html">Link 1</a> and
+ * <a href="{@docRoot}/pkg2/C2.html">Link 2</a>. 2 back-to-back links using
+ * docroot. These should not be replaced with an absolute link.
  */
 public class C1 {}
--- a/langtools/test/com/sun/javadoc/testDocRootLink/pkg1/package.html	Tue Dec 03 18:13:18 2013 +0000
+++ b/langtools/test/com/sun/javadoc/testDocRootLink/pkg1/package.html	Tue Dec 03 14:21:45 2013 -0800
@@ -3,16 +3,16 @@
 <title>javax.management package</title>
 </head>
 <body bgcolor="white">
-This is a test.
-      <p id="spec">
-    @see <a href="{@docRoot}/../technotes/guides/index.html">
-      Test document 1</a>
-      in particular the
-      <a href="{@docRoot}/../technotes/guides/index.html">
+    This is a test.
+    <p id="spec">
+        @see <a href="{@docRoot}/../technotes/guides/index.html">
+            Test document 1</a> should not be replaced with an absolute link.
+        @see <a href="{@docRoot}/pkg2/C2.html">
+            Another Test document 1</a> which should not be replaced with an absolute link.
+        <a href="{@docRoot}/technotes/guides/index.html">
+            Another Test document 2.</a> which should not be replaced with an absolute link.
 
-      Test document 2.</a>
-
-	@since 1.5
+        @since 1.5
 
 </body>
 </html>
--- a/langtools/test/com/sun/javadoc/testDocRootLink/pkg2/C2.java	Tue Dec 03 18:13:18 2013 +0000
+++ b/langtools/test/com/sun/javadoc/testDocRootLink/pkg2/C2.java	Tue Dec 03 14:21:45 2013 -0800
@@ -24,8 +24,13 @@
 package pkg2;
 
 /**
- * Class 1. This is a test.
- * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works
- * or not.
+ * Class 2. This is a test.
+ * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a> should be
+ * replaced with an absolute link.
+ * This <a href="{@docRoot}/pkg1/C1.html">Here</a> should not be replaced
+ * with an absolute link.
+ * Testing <a href="{@docRoot}/technotes/guides/index.html">Link 1</a> and
+ * <a href="{@docRoot}/pkg1/C1.html">Link 2</a>. Both should not be replaced with
+ * an absolute link.
  */
 public class C2 {}
--- a/langtools/test/com/sun/javadoc/testDocRootLink/pkg2/package.html	Tue Dec 03 18:13:18 2013 +0000
+++ b/langtools/test/com/sun/javadoc/testDocRootLink/pkg2/package.html	Tue Dec 03 14:21:45 2013 -0800
@@ -3,16 +3,16 @@
 <title>javax.management package</title>
 </head>
 <body bgcolor="white">
-This is a test.
-      <p id="spec">
-    @see <a href="{@docRoot}/../technotes/guides/index.html">
-      Test document 1</a>
-      in particular the
-      <a href="{@docRoot}/../technotes/guides/index.html">
+    This is a test.
+    <p id="spec">
+        @see <a href="{@docRoot}/../technotes/guides/index.html">
+            Test document 1</a> should be replaced with an absolute link.
+        @see <a href="{@docRoot}/pkg1/C1.html">
+            Another Test document 1</a> which should not be replaced with an absolute link.
+        <a href="{@docRoot}/technotes/guides/index.html">
+            Another Test document 2.</a> which should not be replaced with an absolute link.
 
-      Test document 2.</a>
-
-	@since 1.5
+        @since 1.5
 
 </body>
 </html>