T6729471.java revision 3294:9adfb22ff08f
1157351Smarcel/*
2157351Smarcel * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
3157351Smarcel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4157351Smarcel *
5157351Smarcel * This code is free software; you can redistribute it and/or modify it
6157351Smarcel * under the terms of the GNU General Public License version 2 only, as
7157351Smarcel * published by the Free Software Foundation.
8157351Smarcel *
9157351Smarcel * This code is distributed in the hope that it will be useful, but WITHOUT
10157351Smarcel * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11157351Smarcel * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12157351Smarcel * version 2 for more details (a copy is included in the LICENSE file that
13157351Smarcel * accompanied this code).
14157351Smarcel *
15157351Smarcel * You should have received a copy of the GNU General Public License version
16157351Smarcel * 2 along with this work; if not, write to the Free Software Foundation,
17157351Smarcel * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18157351Smarcel *
19157351Smarcel * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20157351Smarcel * or visit www.oracle.com if you need additional information or have any
21157351Smarcel * questions.
22157351Smarcel */
23157351Smarcel
24157351Smarcel/*
25157351Smarcel * @test
26157351Smarcel * @bug 6729471
27157351Smarcel * @summary javap does not output inner interfaces of an interface
28157351Smarcel * @library /tools/lib
29157351Smarcel * @modules jdk.compiler/com.sun.tools.javac.api
30157351Smarcel *          jdk.compiler/com.sun.tools.javac.file
31157351Smarcel *          jdk.compiler/com.sun.tools.javac.main
32157351Smarcel *          jdk.jdeps/com.sun.tools.javap
33157351Smarcel * @build ToolBox
34157351Smarcel * @run main T6729471
35157351Smarcel */
36157351Smarcel
37157351Smarcelimport java.io.*;
38157351Smarcelimport java.net.*;
39157351Smarcelimport java.util.*;
40157351Smarcelimport javax.tools.*;
41157351Smarcel
42157351Smarcelpublic class T6729471
43157351Smarcel{
44157351Smarcel    public static void main(String... args) throws IOException {
45157351Smarcel        new T6729471().run();
46157351Smarcel    }
47157351Smarcel
48157351Smarcel    void run() throws IOException {
49157351Smarcel        File testClasses = new File(System.getProperty("test.classes"));
50157351Smarcel
51157351Smarcel        // simple class
52157351Smarcel        verify("java.util.Map",
53157351Smarcel                "public abstract boolean containsKey(java.lang.Object)");
54157351Smarcel
55157351Smarcel        // inner class
56157351Smarcel        verify("java.util.Map.Entry",
57157351Smarcel                "public abstract K getKey()");
58157351Smarcel
59167822Smarcel        // file name
60157351Smarcel        verify(new File(testClasses, "T6729471.class").getPath(),
61157351Smarcel                "public static void main(java.lang.String...)");
62157351Smarcel
63157351Smarcel        // file url
64178600Smarcel        verify(new File(testClasses, "T6729471.class").toURI().toString(),
65178600Smarcel                "public static void main(java.lang.String...)");
66178600Smarcel
67178600Smarcel        // jar url
68178600Smarcel        File testJar = createJar("test.jar", "java.util.*");
69178600Smarcel        try {
70178600Smarcel            verify("jar:" + testJar.toURL() + "!/java/util/Map.class",
71157351Smarcel                "public abstract boolean containsKey(java.lang.Object)");
72157351Smarcel        } catch (MalformedURLException e) {
73157351Smarcel            error(e.toString());
74178600Smarcel        }
75157351Smarcel
76157351Smarcel        if (errors > 0)
77157351Smarcel            throw new Error(errors + " found.");
78157351Smarcel    }
79157351Smarcel
80157351Smarcel    File createJar(String name, String... paths) throws IOException {
81157351Smarcel        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
82157351Smarcel        try (JavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
83227843Smarius            File f = new File(name);
84227843Smarius            ToolBox tb = new ToolBox();
85157351Smarcel            tb.new JarTask(f.getPath())
86157351Smarcel                .files(fm, StandardLocation.PLATFORM_CLASS_PATH, paths)
87157351Smarcel                .run();
88157351Smarcel            return f;
89157351Smarcel        }
90157351Smarcel    }
91157351Smarcel
92157351Smarcel    void verify(String className, String... expects) {
93253900Smarius        String output = javap(className);
94        for (String expect: expects) {
95            if (output.indexOf(expect)< 0)
96                error(expect + " not found");
97        }
98    }
99
100    void error(String msg) {
101        System.err.println(msg);
102        errors++;
103    }
104
105    int errors;
106
107    String javap(String className) {
108        String testClasses = System.getProperty("test.classes", ".");
109        StringWriter sw = new StringWriter();
110        PrintWriter out = new PrintWriter(sw);
111        String[] args = { "-classpath", testClasses, className };
112        int rc = com.sun.tools.javap.Main.run(args, out);
113        out.close();
114        String output = sw.toString();
115        System.out.println("class " + className);
116        System.out.println(output);
117        if (rc != 0)
118            throw new Error("javap failed. rc=" + rc);
119        if (output.indexOf("Error:") != -1)
120            throw new Error("javap reported error.");
121        return output;
122    }
123}
124
125