1752
|
1 |
/*
|
|
2 |
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
|
10
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any 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 |
|
1752
|
36 |
import java.io.*;
|
|
37 |
|
10
|
38 |
public class TestSourceTab extends JavadocTester {
|
1752
|
39 |
|
10
|
40 |
private static final String BUG_ID = "4510979";
|
1752
|
41 |
private static final String TMP_SRC_DIR = "tmpSrc";
|
10
|
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;
|
1752
|
46 |
|
10
|
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[] {
|
1752
|
50 |
"-d", OUTPUT_DIR1, "-sourcepath", TMP_SRC_DIR,
|
|
51 |
"-notimestamp", "-linksource", TMP_SRC_DIR + FS + "SingleTab" + FS + "C.java"
|
10
|
52 |
};
|
1752
|
53 |
|
10
|
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[] {
|
1752
|
59 |
"-d", OUTPUT_DIR2, "-sourcepath", TMP_SRC_DIR,
|
|
60 |
"-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + FS + "DoubleTab" + FS + "C.java"
|
10
|
61 |
};
|
1752
|
62 |
|
10
|
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"
|
1752
|
67 |
},
|
10
|
68 |
{OUTPUT_DIR1 + FS + "C.html",
|
|
69 |
OUTPUT_DIR2 + FS + "C.html"
|
|
70 |
}
|
1752
|
71 |
|
10
|
72 |
};
|
1752
|
73 |
|
10
|
74 |
/**
|
|
75 |
* The entry point of the test.
|
|
76 |
* @param args the array of command line arguments.
|
|
77 |
*/
|
1752
|
78 |
public static void main(String[] args) throws IOException {
|
10
|
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 |
}
|
1752
|
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 |
|
10
|
125 |
/**
|
|
126 |
* {@inheritDoc}
|
|
127 |
*/
|
|
128 |
public String getBugId() {
|
|
129 |
return BUG_ID;
|
|
130 |
}
|
1752
|
131 |
|
10
|
132 |
/**
|
|
133 |
* {@inheritDoc}
|
|
134 |
*/
|
|
135 |
public String getBugName() {
|
|
136 |
return getClass().getName();
|
|
137 |
}
|
|
138 |
}
|