jjg@416: /* ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. jjg@416: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@416: * jjg@416: * This code is free software; you can redistribute it and/or modify it jjg@416: * under the terms of the GNU General Public License version 2 only, as jjg@416: * published by the Free Software Foundation. jjg@416: * jjg@416: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@416: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@416: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@416: * version 2 for more details (a copy is included in the LICENSE file that jjg@416: * accompanied this code). jjg@416: * jjg@416: * You should have received a copy of the GNU General Public License version jjg@416: * 2 along with this work; if not, write to the Free Software Foundation, jjg@416: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@416: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@416: */ jjg@416: jjg@416: import java.io.IOException; jjg@416: import java.io.InputStream; jjg@416: import java.util.Enumeration; jjg@416: import java.util.jar.JarEntry; jjg@416: import java.util.jar.JarFile; jjg@416: jjg@416: import com.sun.tools.classfile.AccessFlags; jjg@416: import com.sun.tools.classfile.ClassFile; jjg@416: import com.sun.tools.classfile.ConstantPoolException; jjg@416: import com.sun.tools.classfile.Method; jjg@416: import java.util.Comparator; jjg@416: import java.util.Set; jjg@416: import java.util.TreeSet; jjg@416: jjg@416: public class FindNativeFiles { jjg@416: public static void main(String[] args) throws IOException, ConstantPoolException { jjg@416: new FindNativeFiles().run(args); jjg@416: } jjg@416: jjg@416: public void run(String[] args) throws IOException, ConstantPoolException { jjg@416: JarFile jar = new JarFile(args[0]); jjg@416: Set entries = getNativeClasses(jar); jjg@416: for (JarEntry e: entries) { jjg@416: String name = e.getName(); jjg@416: String className = name.substring(0, name.length() - 6).replace("/", "."); jjg@416: System.out.println(className); jjg@416: } jjg@416: } jjg@416: jjg@416: Set getNativeClasses(JarFile jar) throws IOException, ConstantPoolException { jjg@416: Set results = new TreeSet(new Comparator() { jjg@416: public int compare(JarEntry o1, JarEntry o2) { jjg@416: return o1.getName().compareTo(o2.getName()); jjg@416: } jjg@416: }); jjg@416: Enumeration e = jar.entries(); jjg@416: while (e.hasMoreElements()) { jjg@416: JarEntry je = e.nextElement(); jjg@416: if (isNativeClass(jar, je)) jjg@416: results.add(je); jjg@416: } jjg@416: return results; jjg@416: } jjg@416: jjg@416: boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException { jjg@416: String name = entry.getName(); jjg@416: if (name.startsWith("META-INF") || !name.endsWith(".class")) jjg@416: return false; jjg@416: //String className = name.substring(0, name.length() - 6).replace("/", "."); jjg@416: //System.err.println("check " + className); jjg@416: InputStream in = jar.getInputStream(entry); jjg@416: ClassFile cf = ClassFile.read(in); jjg@416: in.close(); jjg@416: for (int i = 0; i < cf.methods.length; i++) { jjg@416: Method m = cf.methods[i]; jjg@416: if (m.access_flags.is(AccessFlags.ACC_NATIVE)) { jjg@416: // System.err.println(className); jjg@416: return true; jjg@416: } jjg@416: } jjg@416: return false; jjg@416: } jjg@416: }