author | jjg |
Fri, 18 Apr 2014 17:25:43 -0700 | |
changeset 24065 | fc4022e50129 |
parent 23971 | f5ff1f5a8dee |
child 24071 | b0845717434e |
permissions | -rw-r--r-- |
1752 | 1 |
/* |
23971 | 2 |
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. 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 |
* |
|
5520 | 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. |
|
10 | 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, |
23971 | 51 |
"-notimestamp", "-linksource", TMP_SRC_DIR + "/SingleTab/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, |
23971 | 60 |
"-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + "/DoubleTab/C.java" |
10 | 61 |
}; |
1752 | 62 |
|
10 | 63 |
//Files to diff |
64 |
private static final String[][] FILES_TO_DIFF = { |
|
23971 | 65 |
{OUTPUT_DIR1 + "/src-html/C.html", |
66 |
OUTPUT_DIR2 + "/src-html/C.html" |
|
1752 | 67 |
}, |
23971 | 68 |
{OUTPUT_DIR1 + "/C.html", |
69 |
OUTPUT_DIR2 + "/C.html" |
|
10 | 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(); |
24065
fc4022e50129
8041150: Avoid silly use of static methods in JavadocTester
jjg
parents:
23971
diff
changeset
|
80 |
tester.run(ARGS1, TEST, NEGATED_TEST); |
fc4022e50129
8041150: Avoid silly use of static methods in JavadocTester
jjg
parents:
23971
diff
changeset
|
81 |
tester.run(ARGS2, TEST, NEGATED_TEST); |
10 | 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 |
} |