author | jwilhelm |
Thu, 07 Feb 2013 15:51:25 +0100 | |
changeset 15605 | bf7de87bbe3a |
parent 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
3996
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
3996
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
4 |
* |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
8 |
* |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
14 |
* |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
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. |
|
3996
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
22 |
*/ |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
23 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
24 |
import java.io.DataInputStream; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
25 |
import java.io.File; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
26 |
import java.io.IOException; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
27 |
import java.io.InputStream; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
28 |
import java.io.PrintWriter; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
29 |
import java.io.StringWriter; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
30 |
import java.util.ArrayList; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
31 |
import java.util.Arrays; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
32 |
import java.util.Enumeration; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
33 |
import java.util.List; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
34 |
import java.util.Set; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
35 |
import java.util.TreeSet; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
36 |
import java.util.jar.JarEntry; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
37 |
import java.util.jar.JarFile; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
38 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.classfile.AccessFlags; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.classfile.ClassFile; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.classfile.ConstantPoolException; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.classfile.Method; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
43 |
import java.io.BufferedReader; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
44 |
import java.io.FileInputStream; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
45 |
import java.io.InputStreamReader; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
46 |
import java.util.LinkedHashSet; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
47 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
48 |
public class CompareTest { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
49 |
String[][] testCases = { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
50 |
{ }, |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
51 |
{ "-jni" }, |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
52 |
// { "-llni" }, |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
53 |
}; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
54 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
55 |
public static void main(String... args) throws Exception { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
56 |
new CompareTest().run(args); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
57 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
58 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
59 |
public void run(String... args) throws Exception { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
60 |
old_javah_cmd = new File(args[0]); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
61 |
rt_jar = new File(args[1]); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
62 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
63 |
Set<String> testClasses; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
64 |
if (args.length > 2) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
65 |
testClasses = new LinkedHashSet<String>(Arrays.asList(Arrays.copyOfRange(args, 2, args.length))); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
66 |
} else |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
67 |
testClasses = getNativeClasses(new JarFile(rt_jar)); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
68 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
69 |
for (String[] options: testCases) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
70 |
for (String name: testClasses) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
71 |
test(Arrays.asList(options), rt_jar, name); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
72 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
73 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
74 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
75 |
if (errors == 0) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
76 |
System.out.println(count + " tests passed"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
77 |
else |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
78 |
throw new Exception(errors + "/" + count + " tests failed"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
79 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
80 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
81 |
public void test(List<String> options, File bootclasspath, String className) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
82 |
throws IOException, InterruptedException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
83 |
System.err.println("test: " + options + " " + className); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
84 |
count++; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
85 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
86 |
testOptions = options; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
87 |
testClassName = className; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
88 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
89 |
File oldOutDir = initDir(file(new File("old"), className)); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
90 |
int old_rc = old_javah(options, oldOutDir, bootclasspath, className); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
91 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
92 |
File newOutDir = initDir(file(new File("new"), className)); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
93 |
int new_rc = new_javah(options, newOutDir, bootclasspath, className); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
94 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
95 |
if (old_rc != new_rc) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
96 |
error("return codes differ; old: " + old_rc + ", new: " + new_rc); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
97 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
98 |
compare(oldOutDir, newOutDir); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
99 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
100 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
101 |
int old_javah(List<String> options, File outDir, File bootclasspath, String className) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
102 |
throws IOException, InterruptedException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
103 |
List<String> cmd = new ArrayList<String>(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
104 |
cmd.add(old_javah_cmd.getPath()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
105 |
cmd.addAll(options); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
106 |
cmd.add("-d"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
107 |
cmd.add(outDir.getPath()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
108 |
cmd.add("-bootclasspath"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
109 |
cmd.add(bootclasspath.getPath()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
110 |
cmd.add(className); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
111 |
System.err.println("old_javah: " + cmd); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
112 |
ProcessBuilder pb = new ProcessBuilder(cmd); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
113 |
pb.redirectErrorStream(true); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
114 |
Process p = pb.start(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
115 |
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
116 |
String line; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
117 |
StringBuilder sb = new StringBuilder(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
118 |
while ((line = in.readLine()) != null) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
119 |
sb.append(line); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
120 |
sb.append("\n"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
121 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
122 |
System.err.println("old javah out: " + sb.toString()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
123 |
return p.waitFor(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
124 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
125 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
126 |
int new_javah(List<String> options, File outDir, File bootclasspath, String className) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
127 |
List<String> args = new ArrayList<String>(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
128 |
args.addAll(options); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
129 |
args.add("-d"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
130 |
args.add(outDir.getPath()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
131 |
args.add("-bootclasspath"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
132 |
args.add(bootclasspath.getPath()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
133 |
args.add(className); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
134 |
StringWriter sw = new StringWriter(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
135 |
PrintWriter pw = new PrintWriter(sw); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
136 |
int rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
137 |
pw.close(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
138 |
System.err.println("new javah out: " + sw.toString()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
139 |
return rc; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
140 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
141 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
142 |
Set<String> getNativeClasses(JarFile jar) throws IOException, ConstantPoolException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
143 |
System.err.println("getNativeClasses: " + jar.getName()); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
144 |
Set<String> results = new TreeSet<String>(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
145 |
Enumeration<JarEntry> e = jar.entries(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
146 |
while (e.hasMoreElements()) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
147 |
JarEntry je = e.nextElement(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
148 |
if (isNativeClass(jar, je)) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
149 |
String name = je.getName(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
150 |
results.add(name.substring(0, name.length() - 6).replace("/", ".")); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
151 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
152 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
153 |
return results; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
154 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
155 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
156 |
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
157 |
String name = entry.getName(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
158 |
if (name.startsWith("META-INF") || !name.endsWith(".class")) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
159 |
return false; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
160 |
//String className = name.substring(0, name.length() - 6).replace("/", "."); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
161 |
//System.err.println("check " + className); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
162 |
InputStream in = jar.getInputStream(entry); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
163 |
ClassFile cf = ClassFile.read(in); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
164 |
for (int i = 0; i < cf.methods.length; i++) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
165 |
Method m = cf.methods[i]; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
166 |
if (m.access_flags.is(AccessFlags.ACC_NATIVE)) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
167 |
// System.err.println(className); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
168 |
return true; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
169 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
170 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
171 |
return false; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
172 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
173 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
174 |
void compare(File f1, File f2) throws IOException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
175 |
if (f1.isFile() && f2.isFile()) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
176 |
compareFiles(f1, f2); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
177 |
else if (f1.isDirectory() && f2.isDirectory()) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
178 |
compareDirectories(f1, f2); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
179 |
else |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
180 |
error("files differ: " |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
181 |
+ f1 + " (" + getFileType(f1) + "), " |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
182 |
+ f2 + " (" + getFileType(f2) + ")"); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
183 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
184 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
185 |
void compareDirectories(File d1, File d2) throws IOException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
186 |
Set<String> list = new TreeSet<String>(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
187 |
list.addAll(Arrays.asList(d1.list())); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
188 |
list.addAll(Arrays.asList(d2.list())); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
189 |
for (String c: list) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
190 |
compare(new File(d1, c), new File(d2, c)); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
191 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
192 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
193 |
void compareFiles(File f1, File f2) throws IOException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
194 |
byte[] c1 = readFile(f1); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
195 |
byte[] c2 = readFile(f2); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
196 |
if (!Arrays.equals(c1, c2)) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
197 |
error("files differ: " + f1 + ", " + f2); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
198 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
199 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
200 |
byte[] readFile(File file) throws IOException { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
201 |
int size = (int) file.length(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
202 |
byte[] data = new byte[size]; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
203 |
DataInputStream in = new DataInputStream(new FileInputStream(file)); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
204 |
try { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
205 |
in.readFully(data); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
206 |
} finally { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
207 |
in.close(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
208 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
209 |
return data; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
210 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
211 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
212 |
String getFileType(File f) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
213 |
return f.isDirectory() ? "directory" |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
214 |
: f.isFile() ? "file" |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
215 |
: f.exists() ? "other" |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
216 |
: "not found"; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
217 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
218 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
219 |
/** |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
220 |
* Set up an empty directory. |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
221 |
*/ |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
222 |
public File initDir(File dir) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
223 |
if (dir.exists()) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
224 |
deleteAll(dir); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
225 |
dir.mkdirs(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
226 |
return dir; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
227 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
228 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
229 |
/** |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
230 |
* Delete a file or a directory (including all its contents). |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
231 |
*/ |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
232 |
boolean deleteAll(File file) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
233 |
if (file.isDirectory()) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
234 |
for (File f: file.listFiles()) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
235 |
deleteAll(f); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
236 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
237 |
return file.delete(); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
238 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
239 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
240 |
File file(File dir, String... path) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
241 |
File f = dir; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
242 |
for (String p: path) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
243 |
f = new File(f, p); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
244 |
return f; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
245 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
246 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
247 |
/** |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
248 |
* Report an error. |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
249 |
*/ |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
250 |
void error(String msg, String... more) { |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
251 |
System.err.println("test: " + testOptions + " " + testClassName); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
252 |
System.err.println("error: " + msg); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
253 |
for (String s: more) |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
254 |
System.err.println(s); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
255 |
errors++; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
256 |
System.exit(1); |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
257 |
} |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
258 |
|
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
259 |
File old_javah_cmd; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
260 |
File rt_jar; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
261 |
List<String> testOptions; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
262 |
String testClassName; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
263 |
int count; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
264 |
int errors; |
dc676a9093b3
6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff
changeset
|
265 |
} |