changeset 1057:dbc4ced9d171

6553182: Need to modify javadoc doclet for GPL Reviewed-by: jjg
author bpatel
date Mon, 02 May 2011 10:10:31 -0700
parents 384ea9a98912
children 14ff19ca715f
files src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java test/com/sun/javadoc/testDocRootLink/pkg1/C1.java test/com/sun/javadoc/testDocRootLink/pkg1/package.html test/com/sun/javadoc/testDocRootLink/pkg2/C2.java test/com/sun/javadoc/testDocRootLink/pkg2/package.html test/com/sun/javadoc/testHelpOption/TestHelpOption.java
diffstat 10 files changed, 281 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Mon May 02 12:05:41 2011 +0100
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Mon May 02 10:10:31 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, 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
@@ -31,6 +31,7 @@
 import com.sun.javadoc.*;
 import java.util.*;
 import java.io.*;
+import java.net.*;
 
 /**
  * Configure the output based on the command line options.
@@ -48,6 +49,7 @@
  * @author Robert Field.
  * @author Atul Dambalkar.
  * @author Jamie Ho
+ * @author Bhavesh Patel (Modified)
  */
 public class ConfigurationImpl extends Configuration {
 
@@ -110,6 +112,11 @@
     public String stylesheetfile = "";
 
     /**
+     * Argument for command line option "-Xdocrootparent".
+     */
+    public String docrootparent = "";
+
+    /**
      * True if command line option "-nohelp" is used. Default value is false.
      */
     public boolean nohelp = false;
@@ -239,6 +246,8 @@
                 stylesheetfile =  os[1];
             } else  if (opt.equals("-charset")) {
                 charset =  os[1];
+            } else if (opt.equals("-xdocrootparent")) {
+                docrootparent = os[1];
             } else  if (opt.equals("-nohelp")) {
                 nohelp = true;
             } else  if (opt.equals("-splitindex")) {
@@ -322,7 +331,8 @@
                    option.equals("-helpfile") ||
                    option.equals("-stylesheetfile") ||
                    option.equals("-charset") ||
-                   option.equals("-overview")) {
+                   option.equals("-overview") ||
+                   option.equals("-xdocrootparent")) {
             return 2;
         } else {
             return 0;
@@ -372,6 +382,13 @@
                     return false;
                 }
                 nohelp = true;
+            } else if (opt.equals("-xdocrootparent")) {
+                try {
+                    new URL(os[1]);
+                } catch (MalformedURLException e) {
+                    reporter.printError(getText("doclet.MalformedURL", os[1]));
+                    return false;
+                }
             } else if (opt.equals("-overview")) {
                 if (nooverview == true) {
                     reporter.printError(getText("doclet.Option_conflict",
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Mon May 02 12:05:41 2011 +0100
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Mon May 02 10:10:31 2011 -0700
@@ -159,22 +159,42 @@
         StringBuilder buf = new StringBuilder();
         int previndex = 0;
         while (true) {
-            // 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 + 10;  // length for {@docroot} string
-            // Insert relative path where {@docRoot} was located
-            buf.append(relativepathNoSlash);
-            // Append slash if next character is not a slash
-            if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length()
-                    && htmlstr.charAt(previndex) != '/') {
-                buf.append(DirectoryManager.URL_FILE_SEPARATOR);
+            if (configuration.docrootparent.length() > 0) {
+                // Search for lowercase version of {@docRoot}/..
+                index = lowerHtml.indexOf("{@docroot}/..", 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 + 13;  // length for {@docroot}/.. string
+                // Insert docrootparent absolute path where {@docRoot}/.. was located
+
+                buf.append(configuration.docrootparent);
+                // Append slash if next character is not a slash
+                if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
+                    buf.append(DirectoryManager.URL_FILE_SEPARATOR);
+                }
+            } else {
+                // 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 + 10;  // length for {@docroot} string
+                // Insert relative path where {@docRoot} was located
+                buf.append(relativepathNoSlash);
+                // Append slash if next character is not a slash
+                if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length() &&
+                        htmlstr.charAt(previndex) != '/') {
+                    buf.append(DirectoryManager.URL_FILE_SEPARATOR);
+                }
             }
         }
         return buf.toString();
@@ -2318,6 +2338,7 @@
     public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
             boolean isFirstSentence) {
         StringBuilder result = new StringBuilder();
+        boolean textTagChange = false;
         // Array of all possible inline tags for this javadoc run
         configuration.tagletManager.checkTags(doc, tags, true);
         for (int i = 0; i < tags.length; i++) {
@@ -2333,13 +2354,26 @@
                 result.append(output == null ? "" : output.toString());
                 if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) {
                     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;
+                    continue;
                 }
             } else {
+                String text = tagelem.text();
+                //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
+                if (textTagChange) {
+                    text = text.replaceFirst("/..", "");
+                    textTagChange = false;
+                }
                 //This is just a regular text tag.  The text may contain html links (<a>)
                 //or inline tag {@docRoot}, which will be handled as special cases.
-                String text = redirectRelativeLinks(tagelem.holder(), tagelem.text());
+                text = redirectRelativeLinks(tagelem.holder(), text);
 
                 // Replace @docRoot only if not represented by an instance of DocRootTaglet,
                 // that is, only if it was not present in a source file doc comment.
--- a/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Mon May 02 12:05:41 2011 +0100
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Mon May 02 10:10:31 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, 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
@@ -59,7 +59,10 @@
      * {@inheritDoc}
      */
     public TagletOutput getDocRootOutput() {
-        return new TagletOutputImpl(htmlWriter.relativepathNoSlash);
+        if (htmlWriter.configuration.docrootparent.length() > 0)
+            return new TagletOutputImpl(htmlWriter.configuration.docrootparent);
+        else
+            return new TagletOutputImpl(htmlWriter.relativepathNoSlash);
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Mon May 02 12:05:41 2011 +0100
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Mon May 02 10:10:31 2011 -0700
@@ -247,6 +247,7 @@
   -tag <name>:<locations>:<header>  Specify single argument custom tags\n\
   -taglet                           The fully qualified name of Taglet to register\n\
   -tagletpath                       The path to Taglets\n\
+  -Xdocrootparent <url>             Replaces all appearances of @docRoot followed by /.. in doc comments with <url>\n\
   -charset <charset>                Charset for cross-platform viewing of generated documentation.\n\
   -helpfile <file>                  Include file that help link links to\n\
   -linksource                       Generate source in HTML\n\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java	Mon May 02 10:10:31 2011 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2011, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6553182
+ * @summary This test verifies the -Xdocrootparent option.
+ * @author Bhavesh Patel
+ * @library ../lib/
+ * @build JavadocTester TestDocRootLink
+ * @run main TestDocRootLink
+ */
+public class TestDocRootLink extends JavadocTester {
+
+    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\">"
+        },
+        {BUG_ID + FS + "pkg1" + FS + "package-summary.html",
+            "<a href=\"../../technotes/guides/index.html\">"
+        }
+    };
+    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 + "package-summary.html",
+            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.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 + FS + "pkg2" + FS + "package-summary.html",
+            "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
+        }
+    };
+    private static final String[][] NEGATED_TEST2 = {
+        {BUG_ID + FS + "pkg2" + FS + "C2.html",
+            "<a href=\"../../technotes/guides/index.html\">"
+        },
+        {BUG_ID + FS + "pkg2" + FS + "package-summary.html",
+            "<a href=\"../../technotes/guides/index.html\">"
+        }
+    };
+    private static final String[] ARGS1 =
+            new String[]{
+        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"
+    };
+    private static final String[] ARGS2 =
+            new String[]{
+        "-d", BUG_ID, "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg2"
+    };
+
+    /**
+     * The entry point of the test.
+     * @param args the array of command line arguments.
+     */
+    public static void main(String[] args) {
+        TestDocRootLink tester = new TestDocRootLink();
+        run(tester, ARGS1, TEST1, NEGATED_TEST1);
+        run(tester, ARGS2, TEST2, NEGATED_TEST2);
+        tester.printSummary();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getBugId() {
+        return BUG_ID;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getBugName() {
+        return getClass().getName();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testDocRootLink/pkg1/C1.java	Mon May 02 10:10:31 2011 -0700
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2011, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg1;
+
+/**
+ * Class 1. This is a test.
+ * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works
+ * or not.
+ */
+public class C1 {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testDocRootLink/pkg1/package.html	Mon May 02 10:10:31 2011 -0700
@@ -0,0 +1,18 @@
+<html>
+<head>
+<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">
+
+      Test document 2.</a>
+
+	@since 1.5
+
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testDocRootLink/pkg2/C2.java	Mon May 02 10:10:31 2011 -0700
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2011, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+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.
+ */
+public class C2 {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testDocRootLink/pkg2/package.html	Mon May 02 10:10:31 2011 -0700
@@ -0,0 +1,18 @@
+<html>
+<head>
+<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">
+
+      Test document 2.</a>
+
+	@since 1.5
+
+</body>
+</html>
--- a/test/com/sun/javadoc/testHelpOption/TestHelpOption.java	Mon May 02 12:05:41 2011 +0100
+++ b/test/com/sun/javadoc/testHelpOption/TestHelpOption.java	Mon May 02 10:10:31 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, 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,20 +23,19 @@
 
 /*
  * @test
- * @bug      4934778 4777599
+ * @bug      4934778 4777599 6553182
  * @summary  Make sure that the -help option works properly.  Make sure
  *           the help link appears in the documentation.
  * @author   jamieh
  * @library  ../lib/
- * @build    JavadocTester
- * @build    TestHelpOption
+ * @build    JavadocTester TestHelpOption
  * @run main TestHelpOption
  */
 
 public class TestHelpOption extends JavadocTester {
 
     //Test information.
-    private static final String BUG_ID = "4934778-4777599";
+    private static final String BUG_ID = "4934778-4777599-6553182";
 
     //Javadoc arguments.
     private static final String[] ARGS = new String[] {
@@ -79,6 +78,7 @@
         {STANDARD_OUTPUT, "-tag "},
         {STANDARD_OUTPUT, "-taglet "},
         {STANDARD_OUTPUT, "-tagletpath "},
+        {STANDARD_OUTPUT, "-Xdocrootparent "},
         {STANDARD_OUTPUT, "-charset "},
         {STANDARD_OUTPUT, "-helpfile "},
         {STANDARD_OUTPUT, "-linksource "},