Mon, 02 May 2011 10:10:31 -0700
6553182: Need to modify javadoc doclet for GPL
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Mon May 02 12:05:41 2011 +0100 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Mon May 02 10:10:31 2011 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -31,6 +31,7 @@ 1.11 import com.sun.javadoc.*; 1.12 import java.util.*; 1.13 import java.io.*; 1.14 +import java.net.*; 1.15 1.16 /** 1.17 * Configure the output based on the command line options. 1.18 @@ -48,6 +49,7 @@ 1.19 * @author Robert Field. 1.20 * @author Atul Dambalkar. 1.21 * @author Jamie Ho 1.22 + * @author Bhavesh Patel (Modified) 1.23 */ 1.24 public class ConfigurationImpl extends Configuration { 1.25 1.26 @@ -110,6 +112,11 @@ 1.27 public String stylesheetfile = ""; 1.28 1.29 /** 1.30 + * Argument for command line option "-Xdocrootparent". 1.31 + */ 1.32 + public String docrootparent = ""; 1.33 + 1.34 + /** 1.35 * True if command line option "-nohelp" is used. Default value is false. 1.36 */ 1.37 public boolean nohelp = false; 1.38 @@ -239,6 +246,8 @@ 1.39 stylesheetfile = os[1]; 1.40 } else if (opt.equals("-charset")) { 1.41 charset = os[1]; 1.42 + } else if (opt.equals("-xdocrootparent")) { 1.43 + docrootparent = os[1]; 1.44 } else if (opt.equals("-nohelp")) { 1.45 nohelp = true; 1.46 } else if (opt.equals("-splitindex")) { 1.47 @@ -322,7 +331,8 @@ 1.48 option.equals("-helpfile") || 1.49 option.equals("-stylesheetfile") || 1.50 option.equals("-charset") || 1.51 - option.equals("-overview")) { 1.52 + option.equals("-overview") || 1.53 + option.equals("-xdocrootparent")) { 1.54 return 2; 1.55 } else { 1.56 return 0; 1.57 @@ -372,6 +382,13 @@ 1.58 return false; 1.59 } 1.60 nohelp = true; 1.61 + } else if (opt.equals("-xdocrootparent")) { 1.62 + try { 1.63 + new URL(os[1]); 1.64 + } catch (MalformedURLException e) { 1.65 + reporter.printError(getText("doclet.MalformedURL", os[1])); 1.66 + return false; 1.67 + } 1.68 } else if (opt.equals("-overview")) { 1.69 if (nooverview == true) { 1.70 reporter.printError(getText("doclet.Option_conflict",
2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Mon May 02 12:05:41 2011 +0100 2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Mon May 02 10:10:31 2011 -0700 2.3 @@ -159,22 +159,42 @@ 2.4 StringBuilder buf = new StringBuilder(); 2.5 int previndex = 0; 2.6 while (true) { 2.7 - // Search for lowercase version of {@docRoot} 2.8 - index = lowerHtml.indexOf("{@docroot}", previndex); 2.9 - // If next {@docRoot} tag not found, append rest of htmlstr and exit loop 2.10 - if (index < 0) { 2.11 - buf.append(htmlstr.substring(previndex)); 2.12 - break; 2.13 - } 2.14 - // If next {@docroot} tag found, append htmlstr up to start of tag 2.15 - buf.append(htmlstr.substring(previndex, index)); 2.16 - previndex = index + 10; // length for {@docroot} string 2.17 - // Insert relative path where {@docRoot} was located 2.18 - buf.append(relativepathNoSlash); 2.19 - // Append slash if next character is not a slash 2.20 - if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length() 2.21 - && htmlstr.charAt(previndex) != '/') { 2.22 - buf.append(DirectoryManager.URL_FILE_SEPARATOR); 2.23 + if (configuration.docrootparent.length() > 0) { 2.24 + // Search for lowercase version of {@docRoot}/.. 2.25 + index = lowerHtml.indexOf("{@docroot}/..", previndex); 2.26 + // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop 2.27 + if (index < 0) { 2.28 + buf.append(htmlstr.substring(previndex)); 2.29 + break; 2.30 + } 2.31 + // If next {@docroot}/.. pattern found, append htmlstr up to start of tag 2.32 + buf.append(htmlstr.substring(previndex, index)); 2.33 + previndex = index + 13; // length for {@docroot}/.. string 2.34 + // Insert docrootparent absolute path where {@docRoot}/.. was located 2.35 + 2.36 + buf.append(configuration.docrootparent); 2.37 + // Append slash if next character is not a slash 2.38 + if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') { 2.39 + buf.append(DirectoryManager.URL_FILE_SEPARATOR); 2.40 + } 2.41 + } else { 2.42 + // Search for lowercase version of {@docRoot} 2.43 + index = lowerHtml.indexOf("{@docroot}", previndex); 2.44 + // If next {@docRoot} tag not found, append rest of htmlstr and exit loop 2.45 + if (index < 0) { 2.46 + buf.append(htmlstr.substring(previndex)); 2.47 + break; 2.48 + } 2.49 + // If next {@docroot} tag found, append htmlstr up to start of tag 2.50 + buf.append(htmlstr.substring(previndex, index)); 2.51 + previndex = index + 10; // length for {@docroot} string 2.52 + // Insert relative path where {@docRoot} was located 2.53 + buf.append(relativepathNoSlash); 2.54 + // Append slash if next character is not a slash 2.55 + if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length() && 2.56 + htmlstr.charAt(previndex) != '/') { 2.57 + buf.append(DirectoryManager.URL_FILE_SEPARATOR); 2.58 + } 2.59 } 2.60 } 2.61 return buf.toString(); 2.62 @@ -2318,6 +2338,7 @@ 2.63 public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags, 2.64 boolean isFirstSentence) { 2.65 StringBuilder result = new StringBuilder(); 2.66 + boolean textTagChange = false; 2.67 // Array of all possible inline tags for this javadoc run 2.68 configuration.tagletManager.checkTags(doc, tags, true); 2.69 for (int i = 0; i < tags.length; i++) { 2.70 @@ -2333,13 +2354,26 @@ 2.71 result.append(output == null ? "" : output.toString()); 2.72 if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) { 2.73 break; 2.74 + } else if (configuration.docrootparent.length() > 0 && 2.75 + tagelem.name().equals("@docRoot") && 2.76 + ((tags[i + 1]).text()).startsWith("/..")) { 2.77 + //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after 2.78 + //{@docRoot} tag in the very next Text tag. 2.79 + textTagChange = true; 2.80 + continue; 2.81 } else { 2.82 - continue; 2.83 + continue; 2.84 } 2.85 } else { 2.86 + String text = tagelem.text(); 2.87 + //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag. 2.88 + if (textTagChange) { 2.89 + text = text.replaceFirst("/..", ""); 2.90 + textTagChange = false; 2.91 + } 2.92 //This is just a regular text tag. The text may contain html links (<a>) 2.93 //or inline tag {@docRoot}, which will be handled as special cases. 2.94 - String text = redirectRelativeLinks(tagelem.holder(), tagelem.text()); 2.95 + text = redirectRelativeLinks(tagelem.holder(), text); 2.96 2.97 // Replace @docRoot only if not represented by an instance of DocRootTaglet, 2.98 // that is, only if it was not present in a source file doc comment.
3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java Mon May 02 12:05:41 2011 +0100 3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java Mon May 02 10:10:31 2011 -0700 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 2003, 2011, 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 @@ -59,7 +59,10 @@ 3.11 * {@inheritDoc} 3.12 */ 3.13 public TagletOutput getDocRootOutput() { 3.14 - return new TagletOutputImpl(htmlWriter.relativepathNoSlash); 3.15 + if (htmlWriter.configuration.docrootparent.length() > 0) 3.16 + return new TagletOutputImpl(htmlWriter.configuration.docrootparent); 3.17 + else 3.18 + return new TagletOutputImpl(htmlWriter.relativepathNoSlash); 3.19 } 3.20 3.21 /**
4.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Mon May 02 12:05:41 2011 +0100 4.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Mon May 02 10:10:31 2011 -0700 4.3 @@ -247,6 +247,7 @@ 4.4 -tag <name>:<locations>:<header> Specify single argument custom tags\n\ 4.5 -taglet The fully qualified name of Taglet to register\n\ 4.6 -tagletpath The path to Taglets\n\ 4.7 + -Xdocrootparent <url> Replaces all appearances of @docRoot followed by /.. in doc comments with <url>\n\ 4.8 -charset <charset> Charset for cross-platform viewing of generated documentation.\n\ 4.9 -helpfile <file> Include file that help link links to\n\ 4.10 -linksource Generate source in HTML\n\
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/com/sun/javadoc/testDocRootLink/TestDocRootLink.java Mon May 02 10:10:31 2011 -0700 5.3 @@ -0,0 +1,101 @@ 5.4 +/* 5.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test 5.29 + * @bug 6553182 5.30 + * @summary This test verifies the -Xdocrootparent option. 5.31 + * @author Bhavesh Patel 5.32 + * @library ../lib/ 5.33 + * @build JavadocTester TestDocRootLink 5.34 + * @run main TestDocRootLink 5.35 + */ 5.36 +public class TestDocRootLink extends JavadocTester { 5.37 + 5.38 + private static final String BUG_ID = "6553182"; 5.39 + private static final String[][] TEST1 = { 5.40 + {BUG_ID + FS + "pkg1" + FS + "C1.html", 5.41 + "<a href=\"../../technotes/guides/index.html\">" 5.42 + }, 5.43 + {BUG_ID + FS + "pkg1" + FS + "package-summary.html", 5.44 + "<a href=\"../../technotes/guides/index.html\">" 5.45 + } 5.46 + }; 5.47 + private static final String[][] NEGATED_TEST1 = { 5.48 + {BUG_ID + FS + "pkg1" + FS + "C1.html", 5.49 + "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">" 5.50 + }, 5.51 + {BUG_ID + FS + "pkg1" + FS + "package-summary.html", 5.52 + "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">" 5.53 + } 5.54 + }; 5.55 + private static final String[][] TEST2 = { 5.56 + {BUG_ID + FS + "pkg2" + FS + "C2.html", 5.57 + "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">" 5.58 + }, 5.59 + {BUG_ID + FS + "pkg2" + FS + "package-summary.html", 5.60 + "<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">" 5.61 + } 5.62 + }; 5.63 + private static final String[][] NEGATED_TEST2 = { 5.64 + {BUG_ID + FS + "pkg2" + FS + "C2.html", 5.65 + "<a href=\"../../technotes/guides/index.html\">" 5.66 + }, 5.67 + {BUG_ID + FS + "pkg2" + FS + "package-summary.html", 5.68 + "<a href=\"../../technotes/guides/index.html\">" 5.69 + } 5.70 + }; 5.71 + private static final String[] ARGS1 = 5.72 + new String[]{ 5.73 + "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1" 5.74 + }; 5.75 + private static final String[] ARGS2 = 5.76 + new String[]{ 5.77 + "-d", BUG_ID, "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg2" 5.78 + }; 5.79 + 5.80 + /** 5.81 + * The entry point of the test. 5.82 + * @param args the array of command line arguments. 5.83 + */ 5.84 + public static void main(String[] args) { 5.85 + TestDocRootLink tester = new TestDocRootLink(); 5.86 + run(tester, ARGS1, TEST1, NEGATED_TEST1); 5.87 + run(tester, ARGS2, TEST2, NEGATED_TEST2); 5.88 + tester.printSummary(); 5.89 + } 5.90 + 5.91 + /** 5.92 + * {@inheritDoc} 5.93 + */ 5.94 + public String getBugId() { 5.95 + return BUG_ID; 5.96 + } 5.97 + 5.98 + /** 5.99 + * {@inheritDoc} 5.100 + */ 5.101 + public String getBugName() { 5.102 + return getClass().getName(); 5.103 + } 5.104 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg1/C1.java Mon May 02 10:10:31 2011 -0700 6.3 @@ -0,0 +1,31 @@ 6.4 +/* 6.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +package pkg1; 6.28 + 6.29 +/** 6.30 + * Class 1. This is a test. 6.31 + * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works 6.32 + * or not. 6.33 + */ 6.34 +public class C1 {}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg1/package.html Mon May 02 10:10:31 2011 -0700 7.3 @@ -0,0 +1,18 @@ 7.4 +<html> 7.5 +<head> 7.6 +<title>javax.management package</title> 7.7 +</head> 7.8 +<body bgcolor="white"> 7.9 +This is a test. 7.10 + <p id="spec"> 7.11 + @see <a href="{@docRoot}/../technotes/guides/index.html"> 7.12 + Test document 1</a> 7.13 + in particular the 7.14 + <a href="{@docRoot}/../technotes/guides/index.html"> 7.15 + 7.16 + Test document 2.</a> 7.17 + 7.18 + @since 1.5 7.19 + 7.20 +</body> 7.21 +</html>
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg2/C2.java Mon May 02 10:10:31 2011 -0700 8.3 @@ -0,0 +1,31 @@ 8.4 +/* 8.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +package pkg2; 8.28 + 8.29 +/** 8.30 + * Class 1. This is a test. 8.31 + * Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works 8.32 + * or not. 8.33 + */ 8.34 +public class C2 {}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/com/sun/javadoc/testDocRootLink/pkg2/package.html Mon May 02 10:10:31 2011 -0700 9.3 @@ -0,0 +1,18 @@ 9.4 +<html> 9.5 +<head> 9.6 +<title>javax.management package</title> 9.7 +</head> 9.8 +<body bgcolor="white"> 9.9 +This is a test. 9.10 + <p id="spec"> 9.11 + @see <a href="{@docRoot}/../technotes/guides/index.html"> 9.12 + Test document 1</a> 9.13 + in particular the 9.14 + <a href="{@docRoot}/../technotes/guides/index.html"> 9.15 + 9.16 + Test document 2.</a> 9.17 + 9.18 + @since 1.5 9.19 + 9.20 +</body> 9.21 +</html>
10.1 --- a/test/com/sun/javadoc/testHelpOption/TestHelpOption.java Mon May 02 12:05:41 2011 +0100 10.2 +++ b/test/com/sun/javadoc/testHelpOption/TestHelpOption.java Mon May 02 10:10:31 2011 -0700 10.3 @@ -1,5 +1,5 @@ 10.4 /* 10.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 10.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 10.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.8 * 10.9 * This code is free software; you can redistribute it and/or modify it 10.10 @@ -23,20 +23,19 @@ 10.11 10.12 /* 10.13 * @test 10.14 - * @bug 4934778 4777599 10.15 + * @bug 4934778 4777599 6553182 10.16 * @summary Make sure that the -help option works properly. Make sure 10.17 * the help link appears in the documentation. 10.18 * @author jamieh 10.19 * @library ../lib/ 10.20 - * @build JavadocTester 10.21 - * @build TestHelpOption 10.22 + * @build JavadocTester TestHelpOption 10.23 * @run main TestHelpOption 10.24 */ 10.25 10.26 public class TestHelpOption extends JavadocTester { 10.27 10.28 //Test information. 10.29 - private static final String BUG_ID = "4934778-4777599"; 10.30 + private static final String BUG_ID = "4934778-4777599-6553182"; 10.31 10.32 //Javadoc arguments. 10.33 private static final String[] ARGS = new String[] { 10.34 @@ -79,6 +78,7 @@ 10.35 {STANDARD_OUTPUT, "-tag "}, 10.36 {STANDARD_OUTPUT, "-taglet "}, 10.37 {STANDARD_OUTPUT, "-tagletpath "}, 10.38 + {STANDARD_OUTPUT, "-Xdocrootparent "}, 10.39 {STANDARD_OUTPUT, "-charset "}, 10.40 {STANDARD_OUTPUT, "-helpfile "}, 10.41 {STANDARD_OUTPUT, "-linksource "},