Tue, 25 May 2010 15:54:51 -0700
6943119: Rebrand source copyright notices
Reviewed-by: darcy
jjg@350 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
jjg@350 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@350 | 4 | * |
jjg@350 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@350 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@350 | 7 | * published by the Free Software Foundation. |
jjg@350 | 8 | * |
jjg@350 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@350 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@350 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@350 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@350 | 13 | * accompanied this code). |
jjg@350 | 14 | * |
jjg@350 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@350 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@350 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@350 | 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. |
jjg@350 | 22 | */ |
jjg@350 | 23 | |
jjg@350 | 24 | |
jjg@350 | 25 | /* |
jjg@350 | 26 | * @test |
jjg@350 | 27 | * @bug 6729471 |
jjg@350 | 28 | * @summary javap does not output inner interfaces of an interface |
jjg@350 | 29 | */ |
jjg@350 | 30 | |
jjg@350 | 31 | import java.io.*; |
jjg@386 | 32 | import java.net.*; |
jjg@350 | 33 | import java.util.*; |
jjg@350 | 34 | |
jjg@350 | 35 | public class T6729471 |
jjg@350 | 36 | { |
jjg@350 | 37 | public static void main(String... args) { |
jjg@350 | 38 | new T6729471().run(); |
jjg@350 | 39 | } |
jjg@350 | 40 | |
jjg@350 | 41 | void run() { |
jjg@350 | 42 | // simple class |
jjg@350 | 43 | verify("java.util.Map", |
jjg@350 | 44 | "public abstract boolean containsKey(java.lang.Object)"); |
jjg@350 | 45 | |
jjg@350 | 46 | // inner class |
jjg@350 | 47 | verify("java.util.Map.Entry", |
jjg@350 | 48 | "public abstract K getKey()"); |
jjg@350 | 49 | |
jjg@350 | 50 | // file name |
jjg@350 | 51 | verify("../classes/tools/javap/T6729471.class", |
jjg@350 | 52 | "public static void main(java.lang.String...)"); |
jjg@350 | 53 | |
jjg@350 | 54 | // file url |
jjg@350 | 55 | verify("file:../classes/tools/javap/T6729471.class", |
jjg@350 | 56 | "public static void main(java.lang.String...)"); |
jjg@350 | 57 | |
jjg@350 | 58 | // jar url: rt.jar |
jjg@350 | 59 | File java_home = new File(System.getProperty("java.home")); |
jjg@350 | 60 | if (java_home.getName().equals("jre")) |
jjg@350 | 61 | java_home = java_home.getParentFile(); |
jjg@350 | 62 | File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar"); |
jjg@386 | 63 | try { |
jjg@386 | 64 | verify("jar:" + rt_jar.toURL() + "!/java/util/Map.class", |
jjg@350 | 65 | "public abstract boolean containsKey(java.lang.Object)"); |
jjg@386 | 66 | } catch (MalformedURLException e) { |
jjg@386 | 67 | error(e.toString()); |
jjg@386 | 68 | } |
jjg@350 | 69 | |
jjg@350 | 70 | // jar url: ct.sym, if it exists |
jjg@350 | 71 | File ct_sym = new File(new File(java_home, "lib"), "ct.sym"); |
jjg@350 | 72 | if (ct_sym.exists()) { |
jjg@386 | 73 | try { |
jjg@386 | 74 | verify("jar:" + ct_sym.toURL() + "!/META-INF/sym/rt.jar/java/util/Map.class", |
jjg@386 | 75 | "public abstract boolean containsKey(java.lang.Object)"); |
jjg@386 | 76 | } catch (MalformedURLException e) { |
jjg@386 | 77 | error(e.toString()); |
jjg@386 | 78 | } |
jjg@350 | 79 | } else |
jjg@350 | 80 | System.err.println("warning: ct.sym not found"); |
jjg@350 | 81 | |
jjg@350 | 82 | if (errors > 0) |
jjg@350 | 83 | throw new Error(errors + " found."); |
jjg@350 | 84 | } |
jjg@350 | 85 | |
jjg@350 | 86 | void verify(String className, String... expects) { |
jjg@350 | 87 | String output = javap(className); |
jjg@350 | 88 | for (String expect: expects) { |
jjg@350 | 89 | if (output.indexOf(expect)< 0) |
jjg@350 | 90 | error(expect + " not found"); |
jjg@350 | 91 | } |
jjg@350 | 92 | } |
jjg@350 | 93 | |
jjg@350 | 94 | void error(String msg) { |
jjg@350 | 95 | System.err.println(msg); |
jjg@350 | 96 | errors++; |
jjg@350 | 97 | } |
jjg@350 | 98 | |
jjg@350 | 99 | int errors; |
jjg@350 | 100 | |
jjg@350 | 101 | String javap(String className) { |
jjg@350 | 102 | String testClasses = System.getProperty("test.classes", "."); |
jjg@350 | 103 | StringWriter sw = new StringWriter(); |
jjg@350 | 104 | PrintWriter out = new PrintWriter(sw); |
jjg@350 | 105 | String[] args = { "-classpath", testClasses, className }; |
jjg@350 | 106 | int rc = com.sun.tools.javap.Main.run(args, out); |
jjg@350 | 107 | out.close(); |
jjg@350 | 108 | String output = sw.toString(); |
jjg@350 | 109 | System.out.println("class " + className); |
jjg@350 | 110 | System.out.println(output); |
jjg@350 | 111 | if (rc != 0) |
jjg@350 | 112 | throw new Error("javap failed. rc=" + rc); |
jjg@350 | 113 | if (output.indexOf("Error:") != -1) |
jjg@350 | 114 | throw new Error("javap reported error."); |
jjg@350 | 115 | return output; |
jjg@350 | 116 | } |
jjg@350 | 117 | } |
jjg@350 | 118 |