1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# HG changeset patch
# User bpatel
# Date 1292276687 28800
# Node ID 445134ee98c84b6d139fab0f9a9d8718c686c63b
# Parent 5761891cfee48bc9382dd68e5e1bf164cff9bfbf
7006270: Several javadoc regression tests are failing on windows
Reviewed-by: jjg
diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java b/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java
--- langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java
+++ langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java
@@ -239,7 +239,7 @@
Type superclass = Util.getFirstVisibleSuperClass(classDoc,
configuration());
if (superclass != null) {
- pre.addContent("\n");
+ pre.addContent(DocletConstants.NL);
pre.addContent("extends ");
Content link = new RawHtml(getLink(new LinkInfoImpl(
LinkInfoImpl.CONTEXT_CLASS_SIGNATURE_PARENT_NAME,
@@ -257,7 +257,7 @@
continue;
}
if (counter == 0) {
- pre.addContent("\n");
+ pre.addContent(DocletConstants.NL);
pre.addContent(isInterface? "extends " : "implements ");
} else {
pre.addContent(", ");
diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java
--- langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java
+++ langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java
@@ -144,11 +144,12 @@
!configuration.nohelp) {
HelpWriter.generate(configuration);
}
- // If a stylesheet file is not specified, copy the default stylesheet.
+ // If a stylesheet file is not specified, copy the default stylesheet
+ // and replace newline with platform-specific newline.
if (configuration.stylesheetfile.length() == 0) {
Util.copyFile(configuration, "stylesheet.css", Util.RESOURCESDIR,
(configdestdir.isEmpty()) ?
- System.getProperty("user.dir") : configdestdir, false);
+ System.getProperty("user.dir") : configdestdir, false, true);
}
}
diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
--- langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
+++ langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
@@ -216,15 +216,15 @@
public Content getAllClassesLinkScript(String id) {
HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
script.addAttr(HtmlAttr.TYPE, "text/javascript");
- String scriptCode = "<!--\n" +
- " allClassesLink = document.getElementById(\"" + id + "\");\n" +
- " if(window==top) {\n" +
- " allClassesLink.style.display = \"block\";\n" +
- " }\n" +
- " else {\n" +
- " allClassesLink.style.display = \"none\";\n" +
- " }\n" +
- " //-->\n";
+ String scriptCode = "<!--" + DocletConstants.NL +
+ " allClassesLink = document.getElementById(\"" + id + "\");" + DocletConstants.NL +
+ " if(window==top) {" + DocletConstants.NL +
+ " allClassesLink.style.display = \"block\";" + DocletConstants.NL +
+ " }" + DocletConstants.NL +
+ " else {" + DocletConstants.NL +
+ " allClassesLink.style.display = \"none\";" + DocletConstants.NL +
+ " }" + DocletConstants.NL +
+ " //-->" + DocletConstants.NL;
Content scriptContent = new RawHtml(scriptCode);
script.addContent(scriptContent);
Content div = HtmlTree.DIV(script);
diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java b/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java
--- langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java
+++ langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java
@@ -82,9 +82,9 @@
*/
public void write(StringBuilder contentBuilder) {
if (!endsWithNewLine(contentBuilder))
- contentBuilder.append("\n");
+ contentBuilder.append(DocletConstants.NL);
contentBuilder.append("<!-- ");
contentBuilder.append(commentText);
- contentBuilder.append(" -->\n");
+ contentBuilder.append(" -->" + DocletConstants.NL);
}
}
diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java b/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java
--- langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java
+++ langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java
@@ -48,7 +48,7 @@
*/
private DocType(String type, String dtd) {
docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " + type +
- "//EN\" \"" + dtd + "\">\n";
+ "//EN\" \"" + dtd + "\">" + DocletConstants.NL;
}
/**
diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java
--- langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java
+++ langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java
@@ -753,7 +753,7 @@
*/
public void write(StringBuilder contentBuilder) {
if (!isInline() && !endsWithNewLine(contentBuilder))
- contentBuilder.append("\n");
+ contentBuilder.append(DocletConstants.NL);
String tagString = htmlTag.toString();
contentBuilder.append("<" + tagString);
Iterator<HtmlAttr> iterator = attrs.keySet().iterator();
@@ -772,6 +772,6 @@
if (htmlTag.endTagRequired())
contentBuilder.append("</" + tagString + ">");
if (!isInline())
- contentBuilder.append("\n");
+ contentBuilder.append(DocletConstants.NL);
}
}
diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java
--- langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java
+++ langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java
@@ -287,11 +287,11 @@
HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
if(winTitle != null && winTitle.length() > 0) {
script.addAttr(HtmlAttr.TYPE, "text/javascript");
- String scriptCode = "<!--\n" +
- " if (location.href.indexOf('is-external=true') == -1) {\n" +
- " parent.document.title=\"" + winTitle + "\";\n" +
- " }\n" +
- "//-->\n";
+ String scriptCode = "<!--" + DocletConstants.NL +
+ " if (location.href.indexOf('is-external=true') == -1) {" + DocletConstants.NL +
+ " parent.document.title=\"" + winTitle + "\";" + DocletConstants.NL +
+ " }" + DocletConstants.NL +
+ "//-->" + DocletConstants.NL;
RawHtml scriptContent = new RawHtml(scriptCode);
script.addContent(scriptContent);
}
@@ -306,15 +306,15 @@
protected Content getFramesetJavaScript(){
HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
script.addAttr(HtmlAttr.TYPE, "text/javascript");
- String scriptCode = "\n targetPage = \"\" + window.location.search;\n" +
- " if (targetPage != \"\" && targetPage != \"undefined\")\n" +
- " targetPage = targetPage.substring(1);\n" +
- " if (targetPage.indexOf(\":\") != -1)\n" +
- " targetPage = \"undefined\";\n" +
- " function loadFrames() {\n" +
- " if (targetPage != \"\" && targetPage != \"undefined\")\n" +
- " top.classFrame.location = top.targetPage;\n" +
- " }\n";
+ String scriptCode = DocletConstants.NL + " targetPage = \"\" + window.location.search;" + DocletConstants.NL +
+ " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
+ " targetPage = targetPage.substring(1);" + DocletConstants.NL +
+ " if (targetPage.indexOf(\":\") != -1)" + DocletConstants.NL +
+ " targetPage = \"undefined\";" + DocletConstants.NL +
+ " function loadFrames() {" + DocletConstants.NL +
+ " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
+ " top.classFrame.location = top.targetPage;" + DocletConstants.NL +
+ " }" + DocletConstants.NL;
RawHtml scriptContent = new RawHtml(scriptCode);
script.addContent(scriptContent);
return script;
diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java
--- langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java
+++ langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java
@@ -101,6 +101,6 @@
*/
public boolean endsWithNewLine(StringBuilder contentBuilder) {
return ((contentBuilder.length() == 0) ||
- (contentBuilder.substring(contentBuilder.length() - 1).equals("\n")));
+ (contentBuilder.toString().endsWith(DocletConstants.NL)));
}
}
diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
--- langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
+++ langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
@@ -211,14 +211,14 @@
try {
while ((len = input.read(bytearr)) != -1) {
output.write(bytearr, 0, len);
- }
+ }
} catch (FileNotFoundException exc) {
} catch (SecurityException exc) {
- } finally {
+ } finally {
input.close();
output.close();
+ }
}
- }
/**
* Copy the given directory contents from the source package directory
@@ -330,7 +330,7 @@
String resourcefile, boolean overwrite) {
String destresourcesdir = configuration.destDirName + RESOURCESDIR;
copyFile(configuration, resourcefile, RESOURCESDIR, destresourcesdir,
- overwrite);
+ overwrite, false);
}
/**
@@ -345,23 +345,46 @@
* @param overwrite A flag to indicate whether the file in the
* destination directory will be overwritten if
* it already exists.
+ * @param replaceNewLine true if the newline needs to be replaced with platform-
+ * specific newline.
*/
public static void copyFile(Configuration configuration, String file, String source,
- String destination, boolean overwrite) {
+ String destination, boolean overwrite, boolean replaceNewLine) {
DirectoryManager.createDirectory(configuration, destination);
File destfile = new File(destination, file);
if(destfile.exists() && (! overwrite)) return;
try {
InputStream in = Configuration.class.getResourceAsStream(
- source + DirectoryManager.URL_FILE_SEPARATOR + file);
+ source + DirectoryManager.URL_FILE_SEPARATOR + file);
if(in==null) return;
OutputStream out = new FileOutputStream(destfile);
- byte[] buf = new byte[2048];
- int n;
- while((n = in.read(buf))>0) out.write(buf,0,n);
- in.close();
- out.close();
- } catch(Throwable t) {}
+ try {
+ if (!replaceNewLine) {
+ byte[] buf = new byte[2048];
+ int n;
+ while((n = in.read(buf))>0) out.write(buf,0,n);
+ } else {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
+ try {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ writer.write(line);
+ writer.write(DocletConstants.NL);
+ }
+ } finally {
+ reader.close();
+ writer.close();
+ }
+ }
+ } finally {
+ in.close();
+ out.close();
+ }
+ } catch (IOException ie) {
+ ie.printStackTrace();
+ throw new DocletAbortException();
+ }
}
/**
diff --git a/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java b/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java
--- langtools/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java
+++ langtools/test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java
@@ -44,6 +44,7 @@
private static final String BUGID = "6851834";
private static final String BUGNAME = "TestHtmlDocument";
private static final String FS = System.getProperty("file.separator");
+ private static final String LS = System.getProperty("line.separator");
private static String srcdir = System.getProperty("test.src", ".");
// Entry point
@@ -143,13 +144,17 @@
System.out.println("\nFILE DOES NOT EXIST: " + filename);
}
BufferedReader in = new BufferedReader(new FileReader(file));
+ StringBuilder fileString = new StringBuilder();
// Create an array of characters the size of the file
- char[] allChars = new char[(int)file.length()];
- // Read the characters into the allChars array
- in.read(allChars, 0, (int)file.length());
- in.close();
- // Convert to a string
- String allCharsString = new String(allChars);
- return allCharsString;
+ try {
+ String line;
+ while ((line = in.readLine()) != null) {
+ fileString.append(line);
+ fileString.append(LS);
+ }
+ } finally {
+ in.close();
+ }
+ return fileString.toString();
}
}
|