author | goetz |
Wed, 27 Jan 2016 10:35:49 +0100 | |
changeset 35775 | 00710c1b504a |
parent 34752 | 9c262a013456 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
2 |
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. |
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
4 |
* |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
8 |
* |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
14 |
* |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
18 |
* |
5520 | 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. |
|
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
22 |
*/ |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
23 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
24 |
/* |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
25 |
* @test |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
26 |
* @bug 6729471 |
27323
babdaa819add
8062336: Revert tools/javap/T6729471.java to original test code
sogoel
parents:
27234
diff
changeset
|
27 |
* @summary javap does not output inner interfaces of an interface |
27579 | 28 |
* @library /tools/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
27579 | 32 |
* @build ToolBox |
33 |
* @run main T6729471 |
|
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
34 |
*/ |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
35 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
36 |
import java.io.*; |
3768 | 37 |
import java.net.*; |
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
38 |
import java.util.*; |
27579 | 39 |
import javax.tools.*; |
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
40 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
41 |
public class T6729471 |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
42 |
{ |
27579 | 43 |
public static void main(String... args) throws IOException { |
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
44 |
new T6729471().run(); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
45 |
} |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
46 |
|
27579 | 47 |
void run() throws IOException { |
7333
a9ed6bf644fc
7002346: javap test relies on location of scratch directory
jjg
parents:
5520
diff
changeset
|
48 |
File testClasses = new File(System.getProperty("test.classes")); |
a9ed6bf644fc
7002346: javap test relies on location of scratch directory
jjg
parents:
5520
diff
changeset
|
49 |
|
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
50 |
// simple class |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
51 |
verify("java.util.Map", |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
52 |
"public abstract boolean containsKey(java.lang.Object)"); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
53 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
54 |
// inner class |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
55 |
verify("java.util.Map.Entry", |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
56 |
"public abstract K getKey()"); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
57 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
58 |
// file name |
7333
a9ed6bf644fc
7002346: javap test relies on location of scratch directory
jjg
parents:
5520
diff
changeset
|
59 |
verify(new File(testClasses, "T6729471.class").getPath(), |
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
60 |
"public static void main(java.lang.String...)"); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
61 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
62 |
// file url |
7333
a9ed6bf644fc
7002346: javap test relies on location of scratch directory
jjg
parents:
5520
diff
changeset
|
63 |
verify(new File(testClasses, "T6729471.class").toURI().toString(), |
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
64 |
"public static void main(java.lang.String...)"); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
65 |
|
27579 | 66 |
// jar url |
67 |
File testJar = createJar("test.jar", "java.util.*"); |
|
3768 | 68 |
try { |
27579 | 69 |
verify("jar:" + testJar.toURL() + "!/java/util/Map.class", |
27323
babdaa819add
8062336: Revert tools/javap/T6729471.java to original test code
sogoel
parents:
27234
diff
changeset
|
70 |
"public abstract boolean containsKey(java.lang.Object)"); |
3768 | 71 |
} catch (MalformedURLException e) { |
72 |
error(e.toString()); |
|
73 |
} |
|
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
74 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
75 |
if (errors > 0) |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
76 |
throw new Error(errors + " found."); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
77 |
} |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
78 |
|
27579 | 79 |
File createJar(String name, String... paths) throws IOException { |
80 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
|
81 |
try (JavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
82 |
File f = new File(name); |
|
83 |
ToolBox tb = new ToolBox(); |
|
84 |
tb.new JarTask(f.getPath()) |
|
85 |
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, paths) |
|
86 |
.run(); |
|
87 |
return f; |
|
88 |
} |
|
89 |
} |
|
90 |
||
3548
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
91 |
void verify(String className, String... expects) { |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
92 |
String output = javap(className); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
93 |
for (String expect: expects) { |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
94 |
if (output.indexOf(expect)< 0) |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
95 |
error(expect + " not found"); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
96 |
} |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
97 |
} |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
98 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
99 |
void error(String msg) { |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
100 |
System.err.println(msg); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
101 |
errors++; |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
102 |
} |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
103 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
104 |
int errors; |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
105 |
|
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
106 |
String javap(String className) { |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
107 |
String testClasses = System.getProperty("test.classes", "."); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
108 |
StringWriter sw = new StringWriter(); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
109 |
PrintWriter out = new PrintWriter(sw); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
110 |
String[] args = { "-classpath", testClasses, className }; |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
111 |
int rc = com.sun.tools.javap.Main.run(args, out); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
112 |
out.close(); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
113 |
String output = sw.toString(); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
114 |
System.out.println("class " + className); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
115 |
System.out.println(output); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
116 |
if (rc != 0) |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
117 |
throw new Error("javap failed. rc=" + rc); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
118 |
if (output.indexOf("Error:") != -1) |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
119 |
throw new Error("javap reported error."); |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
120 |
return output; |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
121 |
} |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
122 |
} |
fd92f0d28cb9
6729471: javap should accept class files on the command line
jjg
parents:
diff
changeset
|
123 |