test/tools/javap/classfile/deps/T6907575.java

Sat, 12 Dec 2009 09:28:40 -0800

author
jjg
date
Sat, 12 Dec 2009 09:28:40 -0800
changeset 451
fbeb560f39e7
child 554
9d9f26857129
permissions
-rw-r--r--

6907575: [classfile] add support for classfile dependency analysis
Reviewed-by: ksrini

jjg@451 1 /*
jjg@451 2 * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
jjg@451 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@451 4 *
jjg@451 5 * This code is free software; you can redistribute it and/or modify it
jjg@451 6 * under the terms of the GNU General Public License version 2 only, as
jjg@451 7 * published by the Free Software Foundation. Sun designates this
jjg@451 8 * particular file as subject to the "Classpath" exception as provided
jjg@451 9 * by Sun in the LICENSE file that accompanied this code.
jjg@451 10 *
jjg@451 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@451 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@451 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@451 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@451 15 * accompanied this code).
jjg@451 16 *
jjg@451 17 * You should have received a copy of the GNU General Public License version
jjg@451 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@451 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@451 20 *
jjg@451 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@451 22 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@451 23 * have any questions.
jjg@451 24 */
jjg@451 25
jjg@451 26 /*
jjg@451 27 * @test
jjg@451 28 * @bug 6907575
jjg@451 29 * @build GetDeps p.C1
jjg@451 30 * @run main T6907575
jjg@451 31 */
jjg@451 32
jjg@451 33 import java.io.*;
jjg@451 34
jjg@451 35 public class T6907575 {
jjg@451 36 public static void main(String... args) throws Exception {
jjg@451 37 new T6907575().run();
jjg@451 38 }
jjg@451 39
jjg@451 40 void run() throws Exception {
jjg@451 41 String testSrc = System.getProperty("test.src");
jjg@451 42 String testClasses = System.getProperty("test.classes");
jjg@451 43
jjg@451 44 StringWriter sw = new StringWriter();
jjg@451 45 PrintWriter pw = new PrintWriter(sw);
jjg@451 46 GetDeps gd = new GetDeps();
jjg@451 47 gd.run(pw, "-classpath", testClasses, "-t", "-p", "p", "p/C1");
jjg@451 48 pw.close();
jjg@451 49 System.out.println(sw);
jjg@451 50
jjg@451 51 String ref = readFile(new File(testSrc, "T6907575.out"));
jjg@451 52 diff(sw.toString().replaceAll("[\r\n]+", "\n"), ref);
jjg@451 53 }
jjg@451 54
jjg@451 55 void diff(String actual, String ref) throws Exception {
jjg@451 56 System.out.println("EXPECT:>>>" + ref + "<<<");
jjg@451 57 System.out.println("ACTUAL:>>>" + actual + "<<<");
jjg@451 58 if (!actual.equals(ref))
jjg@451 59 throw new Exception("output not as expected");
jjg@451 60 }
jjg@451 61
jjg@451 62 String readFile(File f) throws IOException {
jjg@451 63 Reader r = new FileReader(f);
jjg@451 64 char[] buf = new char[(int) f.length()];
jjg@451 65 int offset = 0;
jjg@451 66 int n;
jjg@451 67 while (offset < buf.length && (n = r.read(buf, offset, buf.length - offset)) != -1)
jjg@451 68 offset += n;
jjg@451 69 return new String(buf, 0, offset);
jjg@451 70 }
jjg@451 71 }

mercurial