1/* 2 * Copyright (c) 2002, 2016, 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 * @modules jdk.javadoc/jdk.javadoc.internal.tool 32 * @build JavadocTester 33 * @run main TestSourceTab 34 */ 35 36import java.io.*; 37 38public class TestSourceTab extends JavadocTester { 39 40 public static void main(String... args) throws Exception { 41 TestSourceTab tester = new TestSourceTab(); 42 tester.runTests(); 43 } 44 45 @Test 46 void test() throws Exception { 47 String tmpSrcDir = "tmpSrc"; 48 String outdir1 = "out-tabLengthEight"; 49 String outdir2 = "out-tabLengthFour"; 50 initTabs(new File(testSrc), new File(tmpSrcDir)); 51 52 // Run Javadoc on a source file with that is indented with a single tab per line 53 javadoc("-d", outdir1, 54 "-sourcepath", tmpSrcDir, 55 "-notimestamp", 56 "-linksource", 57 tmpSrcDir + "/SingleTab/C.java"); 58 checkExit(Exit.OK); 59 60 // Run Javadoc on a source file with that is indented with a two tab per line 61 // If we double the tabs and decrease the tab length by a half, the output should 62 // be the same as the one generated above. 63 javadoc("-d", outdir2, 64 "-sourcepath", tmpSrcDir, 65 "-notimestamp", 66 "-sourcetab", "4", 67 tmpSrcDir + "/DoubleTab/C.java"); 68 checkExit(Exit.OK); 69 70 diff(outdir1, outdir2, 71 "src-html/C.html", 72 "C.html"); 73 } 74 75 void initTabs(File from, File to) throws IOException { 76 for (File f: from.listFiles()) { 77 File t = new File(to, f.getName()); 78 if (f.isDirectory()) { 79 initTabs(f, t); 80 } else if (f.getName().endsWith(".java")) { 81 write(t, read(f).replace("\\t", "\t")); 82 } 83 } 84 } 85 86 String read(File f) throws IOException { 87 StringBuilder sb = new StringBuilder(); 88 try (BufferedReader in = new BufferedReader(new FileReader(f))) { 89 String line; 90 while ((line = in.readLine()) != null) { 91 sb.append(line); 92 sb.append(NL); 93 } 94 } 95 return sb.toString(); 96 } 97 98 void write(File f, String s) throws IOException { 99 f.getParentFile().mkdirs(); 100 try (Writer out = new FileWriter(f)) { 101 out.write(s); 102 } 103 } 104} 105