1 /* 2 * Copyright (c) 2004, 2015, 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 4979486 27 * @summary Make sure tool parses CR line separators properly. 28 * @author jamieh 29 * @library ../lib 30 * @modules jdk.javadoc 31 * @build JavadocTester 32 * @run main TestCRLineSeparator 33 */ 34 35 import java.io.*; 36 import java.util.*; 37 38 public class TestCRLineSeparator extends JavadocTester { 39 40 public static void main(String... args) throws Exception { 41 TestCRLineSeparator tester = new TestCRLineSeparator(); 42 tester.runTests(); 43 } 44 45 @Test 46 void test() throws IOException { 47 initFiles(new File(testSrc), new File("src"), "pkg"); 48 javadoc("-d", "out", 49 "-sourcepath", "src", 50 "pkg"); 51 checkExit(Exit.OK); 52 53 checkOutput("pkg/MyClass.html", true, 54 "Line 1\n" 55 + " Line 2"); 56 } 57 58 // recursively copy files from fromDir to toDir, replacing newlines 59 // with \r 60 void initFiles(File fromDir, File toDir, String f) throws IOException { 61 File from_f = new File(fromDir, f); 62 File to_f = new File(toDir, f); 63 if (from_f.isDirectory()) { 64 to_f.mkdirs(); 65 for (String child: from_f.list()) { 66 initFiles(from_f, to_f, child); 67 } 68 } else { 69 List<String> lines = new ArrayList<>(); 70 try (BufferedReader in = new BufferedReader(new FileReader(from_f))) { 71 String line; 72 while ((line = in.readLine()) != null) 73 lines.add(line); 74 } 75 try (BufferedWriter out = new BufferedWriter(new FileWriter(to_f))) { 76 for (String line: lines) { 77 out.write(line); 78 out.write("\r"); 79 } 80 } 81 } 82 } 83 }