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