test/tools/javadoc/T4994049/T4994049.java

changeset 710
68cf07910d74
parent 554
9d9f26857129
child 798
4868a36f6fd8
equal deleted inserted replaced
709:5b5d965900b8 710:68cf07910d74
28 * @author Peter von der Ah\u00e9 28 * @author Peter von der Ah\u00e9
29 * @run main T4994049 FileWithTabs.java 29 * @run main T4994049 FileWithTabs.java
30 */ 30 */
31 31
32 import com.sun.javadoc.*; 32 import com.sun.javadoc.*;
33 import java.io.File; 33 import java.io.*;
34 import static com.sun.tools.javadoc.Main.execute; 34 import static com.sun.tools.javadoc.Main.execute;
35 35
36 public class T4994049 extends Doclet { 36 public class T4994049 extends Doclet {
37 37
38 public static boolean start(RootDoc root) { 38 public static boolean start(RootDoc root) {
50 } 50 }
51 } 51 }
52 return false; 52 return false;
53 } 53 }
54 54
55 public static void main(String... args) { 55 public static void main(String... args) throws Exception {
56 File testSrc = new File(System.getProperty("test.src"));
57 File tmpSrc = new File("tmpSrc");
58 initTabs(testSrc, tmpSrc);
59
56 for (String file : args) { 60 for (String file : args) {
57 File source = new File(System.getProperty("test.src", "."), file); 61 File source = new File(tmpSrc, file);
58 if (execute("javadoc", "T4994049", T4994049.class.getClassLoader(), 62 int rc = execute("javadoc", "T4994049", T4994049.class.getClassLoader(),
59 new String[]{source.getPath()} ) != 0) 63 new String[]{ source.getPath() } );
60 throw new Error(); 64 if (rc != 0)
65 throw new Error("Unexpected return code from javadoc: " + rc);
66 }
67 }
68
69 static void initTabs(File from, File to) throws IOException {
70 for (File f: from.listFiles()) {
71 File t = new File(to, f.getName());
72 if (f.isDirectory()) {
73 initTabs(f, t);
74 } else if (f.getName().endsWith(".java")) {
75 write(t, read(f).replace("\\t", "\t"));
76 }
77 }
78 }
79
80 static String read(File f) throws IOException {
81 StringBuilder sb = new StringBuilder();
82 try (BufferedReader in = new BufferedReader(new FileReader(f))) {
83 String line;
84 while ((line = in.readLine()) != null) {
85 sb.append(line);
86 sb.append("\n");
87 }
88 }
89 return sb.toString();
90 }
91
92 static void write(File f, String s) throws IOException {
93 f.getParentFile().mkdirs();
94 try (Writer out = new FileWriter(f)) {
95 out.write(s);
61 } 96 }
62 } 97 }
63 98
64 } 99 }

mercurial