|
1 /* |
|
2 * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 4510979 |
|
27 * @summary Test to make sure that the source documentation is indented properly |
|
28 * when -linksourcetab is used. |
|
29 * @author jamieh |
|
30 * @library ../lib/ |
|
31 * @build JavadocTester |
|
32 * @build TestSourceTab |
|
33 * @run main TestSourceTab |
|
34 */ |
|
35 |
|
36 import java.io.*; |
|
37 |
|
38 public class TestSourceTab extends JavadocTester { |
|
39 |
|
40 private static final String BUG_ID = "4510979"; |
|
41 private static final String TMP_SRC_DIR = "tmpSrc"; |
|
42 private static final String OUTPUT_DIR1 = BUG_ID + "-tabLengthEight"; |
|
43 private static final String OUTPUT_DIR2 = BUG_ID + "-tabLengthFour"; |
|
44 private static final String[][] TEST = NO_TEST; |
|
45 private static final String[][] NEGATED_TEST = NO_TEST; |
|
46 |
|
47 //Run Javadoc on a source file with that is indented with a single tab per line |
|
48 private static final String[] ARGS1 = |
|
49 new String[] { |
|
50 "-d", OUTPUT_DIR1, "-sourcepath", TMP_SRC_DIR, |
|
51 "-notimestamp", "-linksource", TMP_SRC_DIR + FS + "SingleTab" + FS + "C.java" |
|
52 }; |
|
53 |
|
54 //Run Javadoc on a source file with that is indented with a two tab per line |
|
55 //If we double the tabs and decrease the tab length by a half, the output should |
|
56 //be the same as the one generated above. |
|
57 private static final String[] ARGS2 = |
|
58 new String[] { |
|
59 "-d", OUTPUT_DIR2, "-sourcepath", TMP_SRC_DIR, |
|
60 "-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + FS + "DoubleTab" + FS + "C.java" |
|
61 }; |
|
62 |
|
63 //Files to diff |
|
64 private static final String[][] FILES_TO_DIFF = { |
|
65 {OUTPUT_DIR1 + FS + "src-html" + FS + "C.html", |
|
66 OUTPUT_DIR2 + FS + "src-html" + FS + "C.html" |
|
67 }, |
|
68 {OUTPUT_DIR1 + FS + "C.html", |
|
69 OUTPUT_DIR2 + FS + "C.html" |
|
70 } |
|
71 |
|
72 }; |
|
73 |
|
74 /** |
|
75 * The entry point of the test. |
|
76 * @param args the array of command line arguments. |
|
77 */ |
|
78 public static void main(String[] args) throws IOException { |
|
79 TestSourceTab tester = new TestSourceTab(); |
|
80 run(tester, ARGS1, TEST, NEGATED_TEST); |
|
81 run(tester, ARGS2, TEST, NEGATED_TEST); |
|
82 tester.runDiffs(FILES_TO_DIFF); |
|
83 } |
|
84 |
|
85 TestSourceTab() throws IOException { |
|
86 initTabs(new File(SRC_DIR), new File(TMP_SRC_DIR)); |
|
87 } |
|
88 |
|
89 void initTabs(File from, File to) throws IOException { |
|
90 for (File f: from.listFiles()) { |
|
91 File t = new File(to, f.getName()); |
|
92 if (f.isDirectory()) { |
|
93 initTabs(f, t); |
|
94 } else if (f.getName().endsWith(".java")) { |
|
95 write(t, read(f).replace("\\t", "\t")); |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 String read(File f) throws IOException { |
|
101 StringBuilder sb = new StringBuilder(); |
|
102 BufferedReader in = new BufferedReader(new FileReader(f)); |
|
103 try { |
|
104 String line; |
|
105 while ((line = in.readLine()) != null) { |
|
106 sb.append(line); |
|
107 sb.append("\n"); |
|
108 } |
|
109 } finally { |
|
110 in.close(); |
|
111 } |
|
112 return sb.toString(); |
|
113 } |
|
114 |
|
115 void write(File f, String s) throws IOException { |
|
116 f.getParentFile().mkdirs(); |
|
117 Writer out = new FileWriter(f); |
|
118 try { |
|
119 out.write(s); |
|
120 } finally { |
|
121 out.close(); |
|
122 } |
|
123 } |
|
124 |
|
125 /** |
|
126 * {@inheritDoc} |
|
127 */ |
|
128 public String getBugId() { |
|
129 return BUG_ID; |
|
130 } |
|
131 |
|
132 /** |
|
133 * {@inheritDoc} |
|
134 */ |
|
135 public String getBugName() { |
|
136 return getClass().getName(); |
|
137 } |
|
138 } |