Mon, 13 Dec 2010 13:44:47 -0800
7006270: Several javadoc regression tests are failing on windows
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Fri Dec 10 07:38:28 2010 -0800 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Mon Dec 13 13:44:47 2010 -0800 1.3 @@ -239,7 +239,7 @@ 1.4 Type superclass = Util.getFirstVisibleSuperClass(classDoc, 1.5 configuration()); 1.6 if (superclass != null) { 1.7 - pre.addContent("\n"); 1.8 + pre.addContent(DocletConstants.NL); 1.9 pre.addContent("extends "); 1.10 Content link = new RawHtml(getLink(new LinkInfoImpl( 1.11 LinkInfoImpl.CONTEXT_CLASS_SIGNATURE_PARENT_NAME, 1.12 @@ -257,7 +257,7 @@ 1.13 continue; 1.14 } 1.15 if (counter == 0) { 1.16 - pre.addContent("\n"); 1.17 + pre.addContent(DocletConstants.NL); 1.18 pre.addContent(isInterface? "extends " : "implements "); 1.19 } else { 1.20 pre.addContent(", ");
2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java Fri Dec 10 07:38:28 2010 -0800 2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java Mon Dec 13 13:44:47 2010 -0800 2.3 @@ -144,11 +144,12 @@ 2.4 !configuration.nohelp) { 2.5 HelpWriter.generate(configuration); 2.6 } 2.7 - // If a stylesheet file is not specified, copy the default stylesheet. 2.8 + // If a stylesheet file is not specified, copy the default stylesheet 2.9 + // and replace newline with platform-specific newline. 2.10 if (configuration.stylesheetfile.length() == 0) { 2.11 Util.copyFile(configuration, "stylesheet.css", Util.RESOURCESDIR, 2.12 (configdestdir.isEmpty()) ? 2.13 - System.getProperty("user.dir") : configdestdir, false); 2.14 + System.getProperty("user.dir") : configdestdir, false, true); 2.15 } 2.16 } 2.17
3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Fri Dec 10 07:38:28 2010 -0800 3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Mon Dec 13 13:44:47 2010 -0800 3.3 @@ -216,15 +216,15 @@ 3.4 public Content getAllClassesLinkScript(String id) { 3.5 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT); 3.6 script.addAttr(HtmlAttr.TYPE, "text/javascript"); 3.7 - String scriptCode = "<!--\n" + 3.8 - " allClassesLink = document.getElementById(\"" + id + "\");\n" + 3.9 - " if(window==top) {\n" + 3.10 - " allClassesLink.style.display = \"block\";\n" + 3.11 - " }\n" + 3.12 - " else {\n" + 3.13 - " allClassesLink.style.display = \"none\";\n" + 3.14 - " }\n" + 3.15 - " //-->\n"; 3.16 + String scriptCode = "<!--" + DocletConstants.NL + 3.17 + " allClassesLink = document.getElementById(\"" + id + "\");" + DocletConstants.NL + 3.18 + " if(window==top) {" + DocletConstants.NL + 3.19 + " allClassesLink.style.display = \"block\";" + DocletConstants.NL + 3.20 + " }" + DocletConstants.NL + 3.21 + " else {" + DocletConstants.NL + 3.22 + " allClassesLink.style.display = \"none\";" + DocletConstants.NL + 3.23 + " }" + DocletConstants.NL + 3.24 + " //-->" + DocletConstants.NL; 3.25 Content scriptContent = new RawHtml(scriptCode); 3.26 script.addContent(scriptContent); 3.27 Content div = HtmlTree.DIV(script);
4.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java Fri Dec 10 07:38:28 2010 -0800 4.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java Mon Dec 13 13:44:47 2010 -0800 4.3 @@ -82,9 +82,9 @@ 4.4 */ 4.5 public void write(StringBuilder contentBuilder) { 4.6 if (!endsWithNewLine(contentBuilder)) 4.7 - contentBuilder.append("\n"); 4.8 + contentBuilder.append(DocletConstants.NL); 4.9 contentBuilder.append("<!-- "); 4.10 contentBuilder.append(commentText); 4.11 - contentBuilder.append(" -->\n"); 4.12 + contentBuilder.append(" -->" + DocletConstants.NL); 4.13 } 4.14 }
5.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java Fri Dec 10 07:38:28 2010 -0800 5.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java Mon Dec 13 13:44:47 2010 -0800 5.3 @@ -48,7 +48,7 @@ 5.4 */ 5.5 private DocType(String type, String dtd) { 5.6 docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " + type + 5.7 - "//EN\" \"" + dtd + "\">\n"; 5.8 + "//EN\" \"" + dtd + "\">" + DocletConstants.NL; 5.9 } 5.10 5.11 /**
6.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Fri Dec 10 07:38:28 2010 -0800 6.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Mon Dec 13 13:44:47 2010 -0800 6.3 @@ -753,7 +753,7 @@ 6.4 */ 6.5 public void write(StringBuilder contentBuilder) { 6.6 if (!isInline() && !endsWithNewLine(contentBuilder)) 6.7 - contentBuilder.append("\n"); 6.8 + contentBuilder.append(DocletConstants.NL); 6.9 String tagString = htmlTag.toString(); 6.10 contentBuilder.append("<" + tagString); 6.11 Iterator<HtmlAttr> iterator = attrs.keySet().iterator(); 6.12 @@ -772,6 +772,6 @@ 6.13 if (htmlTag.endTagRequired()) 6.14 contentBuilder.append("</" + tagString + ">"); 6.15 if (!isInline()) 6.16 - contentBuilder.append("\n"); 6.17 + contentBuilder.append(DocletConstants.NL); 6.18 } 6.19 }
7.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Fri Dec 10 07:38:28 2010 -0800 7.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Mon Dec 13 13:44:47 2010 -0800 7.3 @@ -287,11 +287,11 @@ 7.4 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT); 7.5 if(winTitle != null && winTitle.length() > 0) { 7.6 script.addAttr(HtmlAttr.TYPE, "text/javascript"); 7.7 - String scriptCode = "<!--\n" + 7.8 - " if (location.href.indexOf('is-external=true') == -1) {\n" + 7.9 - " parent.document.title=\"" + winTitle + "\";\n" + 7.10 - " }\n" + 7.11 - "//-->\n"; 7.12 + String scriptCode = "<!--" + DocletConstants.NL + 7.13 + " if (location.href.indexOf('is-external=true') == -1) {" + DocletConstants.NL + 7.14 + " parent.document.title=\"" + winTitle + "\";" + DocletConstants.NL + 7.15 + " }" + DocletConstants.NL + 7.16 + "//-->" + DocletConstants.NL; 7.17 RawHtml scriptContent = new RawHtml(scriptCode); 7.18 script.addContent(scriptContent); 7.19 } 7.20 @@ -306,15 +306,15 @@ 7.21 protected Content getFramesetJavaScript(){ 7.22 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT); 7.23 script.addAttr(HtmlAttr.TYPE, "text/javascript"); 7.24 - String scriptCode = "\n targetPage = \"\" + window.location.search;\n" + 7.25 - " if (targetPage != \"\" && targetPage != \"undefined\")\n" + 7.26 - " targetPage = targetPage.substring(1);\n" + 7.27 - " if (targetPage.indexOf(\":\") != -1)\n" + 7.28 - " targetPage = \"undefined\";\n" + 7.29 - " function loadFrames() {\n" + 7.30 - " if (targetPage != \"\" && targetPage != \"undefined\")\n" + 7.31 - " top.classFrame.location = top.targetPage;\n" + 7.32 - " }\n"; 7.33 + String scriptCode = DocletConstants.NL + " targetPage = \"\" + window.location.search;" + DocletConstants.NL + 7.34 + " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL + 7.35 + " targetPage = targetPage.substring(1);" + DocletConstants.NL + 7.36 + " if (targetPage.indexOf(\":\") != -1)" + DocletConstants.NL + 7.37 + " targetPage = \"undefined\";" + DocletConstants.NL + 7.38 + " function loadFrames() {" + DocletConstants.NL + 7.39 + " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL + 7.40 + " top.classFrame.location = top.targetPage;" + DocletConstants.NL + 7.41 + " }" + DocletConstants.NL; 7.42 RawHtml scriptContent = new RawHtml(scriptCode); 7.43 script.addContent(scriptContent); 7.44 return script;
8.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java Fri Dec 10 07:38:28 2010 -0800 8.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java Mon Dec 13 13:44:47 2010 -0800 8.3 @@ -101,6 +101,6 @@ 8.4 */ 8.5 public boolean endsWithNewLine(StringBuilder contentBuilder) { 8.6 return ((contentBuilder.length() == 0) || 8.7 - (contentBuilder.substring(contentBuilder.length() - 1).equals("\n"))); 8.8 + (contentBuilder.toString().endsWith(DocletConstants.NL))); 8.9 } 8.10 }
9.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java Fri Dec 10 07:38:28 2010 -0800 9.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java Mon Dec 13 13:44:47 2010 -0800 9.3 @@ -211,14 +211,14 @@ 9.4 try { 9.5 while ((len = input.read(bytearr)) != -1) { 9.6 output.write(bytearr, 0, len); 9.7 - } 9.8 + } 9.9 } catch (FileNotFoundException exc) { 9.10 } catch (SecurityException exc) { 9.11 - } finally { 9.12 + } finally { 9.13 input.close(); 9.14 output.close(); 9.15 + } 9.16 } 9.17 - } 9.18 9.19 /** 9.20 * Copy the given directory contents from the source package directory 9.21 @@ -330,7 +330,7 @@ 9.22 String resourcefile, boolean overwrite) { 9.23 String destresourcesdir = configuration.destDirName + RESOURCESDIR; 9.24 copyFile(configuration, resourcefile, RESOURCESDIR, destresourcesdir, 9.25 - overwrite); 9.26 + overwrite, false); 9.27 } 9.28 9.29 /** 9.30 @@ -345,23 +345,46 @@ 9.31 * @param overwrite A flag to indicate whether the file in the 9.32 * destination directory will be overwritten if 9.33 * it already exists. 9.34 + * @param replaceNewLine true if the newline needs to be replaced with platform- 9.35 + * specific newline. 9.36 */ 9.37 public static void copyFile(Configuration configuration, String file, String source, 9.38 - String destination, boolean overwrite) { 9.39 + String destination, boolean overwrite, boolean replaceNewLine) { 9.40 DirectoryManager.createDirectory(configuration, destination); 9.41 File destfile = new File(destination, file); 9.42 if(destfile.exists() && (! overwrite)) return; 9.43 try { 9.44 InputStream in = Configuration.class.getResourceAsStream( 9.45 - source + DirectoryManager.URL_FILE_SEPARATOR + file); 9.46 + source + DirectoryManager.URL_FILE_SEPARATOR + file); 9.47 if(in==null) return; 9.48 OutputStream out = new FileOutputStream(destfile); 9.49 - byte[] buf = new byte[2048]; 9.50 - int n; 9.51 - while((n = in.read(buf))>0) out.write(buf,0,n); 9.52 - in.close(); 9.53 - out.close(); 9.54 - } catch(Throwable t) {} 9.55 + try { 9.56 + if (!replaceNewLine) { 9.57 + byte[] buf = new byte[2048]; 9.58 + int n; 9.59 + while((n = in.read(buf))>0) out.write(buf,0,n); 9.60 + } else { 9.61 + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 9.62 + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); 9.63 + try { 9.64 + String line; 9.65 + while ((line = reader.readLine()) != null) { 9.66 + writer.write(line); 9.67 + writer.write(DocletConstants.NL); 9.68 + } 9.69 + } finally { 9.70 + reader.close(); 9.71 + writer.close(); 9.72 + } 9.73 + } 9.74 + } finally { 9.75 + in.close(); 9.76 + out.close(); 9.77 + } 9.78 + } catch (IOException ie) { 9.79 + ie.printStackTrace(); 9.80 + throw new DocletAbortException(); 9.81 + } 9.82 } 9.83 9.84 /**
10.1 --- a/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java Fri Dec 10 07:38:28 2010 -0800 10.2 +++ b/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java Mon Dec 13 13:44:47 2010 -0800 10.3 @@ -44,6 +44,7 @@ 10.4 private static final String BUGID = "6851834"; 10.5 private static final String BUGNAME = "TestHtmlDocument"; 10.6 private static final String FS = System.getProperty("file.separator"); 10.7 + private static final String LS = System.getProperty("line.separator"); 10.8 private static String srcdir = System.getProperty("test.src", "."); 10.9 10.10 // Entry point 10.11 @@ -143,13 +144,17 @@ 10.12 System.out.println("\nFILE DOES NOT EXIST: " + filename); 10.13 } 10.14 BufferedReader in = new BufferedReader(new FileReader(file)); 10.15 + StringBuilder fileString = new StringBuilder(); 10.16 // Create an array of characters the size of the file 10.17 - char[] allChars = new char[(int)file.length()]; 10.18 - // Read the characters into the allChars array 10.19 - in.read(allChars, 0, (int)file.length()); 10.20 - in.close(); 10.21 - // Convert to a string 10.22 - String allCharsString = new String(allChars); 10.23 - return allCharsString; 10.24 + try { 10.25 + String line; 10.26 + while ((line = in.readLine()) != null) { 10.27 + fileString.append(line); 10.28 + fileString.append(LS); 10.29 + } 10.30 + } finally { 10.31 + in.close(); 10.32 + } 10.33 + return fileString.toString(); 10.34 } 10.35 }