1/*
2 * Copyright (c) 2009, 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 6907575
27 * @modules jdk.jdeps/com.sun.tools.classfile
28 *          jdk.compiler/com.sun.tools.javac.file
29 *          jdk.compiler/com.sun.tools.javac.util
30 * @build GetDeps p.C1
31 * @run main T6907575
32 */
33
34import java.io.*;
35
36public class T6907575 {
37    public static void main(String... args) throws Exception {
38        new T6907575().run();
39    }
40
41    void run() throws Exception {
42        String testSrc = System.getProperty("test.src");
43        String testClasses = System.getProperty("test.classes");
44
45        StringWriter sw = new StringWriter();
46        PrintWriter pw = new PrintWriter(sw);
47        GetDeps gd = new GetDeps();
48        gd.run(pw, "-classpath", testClasses, "-t", "-p", "p", "p/C1");
49        pw.close();
50        System.out.println(sw);
51
52        String ref = readFile(new File(testSrc, "T6907575.out"));
53        diff(sw.toString().replaceAll("[\r\n]+", "\n"), ref);
54    }
55
56    void diff(String actual, String ref) throws Exception {
57        System.out.println("EXPECT:>>>" + ref + "<<<");
58        System.out.println("ACTUAL:>>>" + actual + "<<<");
59        if (!actual.equals(ref))
60            throw new Exception("output not as expected");
61    }
62
63    String readFile(File f) throws IOException {
64        Reader r = new FileReader(f);
65        char[] buf = new char[(int) f.length()];
66        int offset = 0;
67        int n;
68        while (offset < buf.length && (n = r.read(buf, offset, buf.length - offset)) != -1)
69            offset += n;
70        return new String(buf, 0, offset);
71    }
72}
73