harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r480696 - in /harmony/enhanced/jdktools/trunk/modules/tools/src: main/java/org/apache/harmony/tools/ main/java/org/apache/harmony/tools/javah/ main/java/org/apache/harmony/tools/javah/anttask/ test/java/org/apache/harmony/tests/tools/javah/...
Date Wed, 29 Nov 2006 19:45:46 GMT
Author: geirm
Date: Wed Nov 29 11:45:45 2006
New Revision: 480696

URL: http://svn.apache.org/viewvc?view=rev&rev=480696
Log:
HARMONY-1217

Modified package conventions on commit to switch from "ijh -> javah" in 
package names, and also move the test code down into proper place 
in tree structure


Added:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/ClassProvider.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/Mangler.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Clazz.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzField.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzMethod.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Main.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/anttask/
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/anttask/Adapter.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/
    harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test/
    harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test/Test01.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test02.java   (with props)

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/ClassProvider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/ClassProvider.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/ClassProvider.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/ClassProvider.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,156 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.util.ClassPath;
+
+/**
+ * This class locates a class in the given class path with the given name. You
+ * can use this class to get a JavaClass object which represents the found 
+ * class.
+ *
+ * This class depends on Apache Byte Code Engineering Library (BCEL) 5.0 or
+ * later. Please see http://jakarta.apache.org/bcel for more information
+ * about this library.
+ */
+public class ClassProvider {
+
+    /**
+     * Loading class files from a class path.
+     */
+    private ClassPath classpath;
+
+    /**
+     * Verbose output or not.
+     */
+    private boolean verbose;
+
+    /**
+     * Keeps loaded and parsed class files.
+     */
+    private Map cache;
+
+    /**
+     * Constructs a <code>ClassProvider</code> object.
+     * 
+     * @param bootClasspath - a path that will be prepended to the default 
+     * class path.
+     * @param classpath - a path that will be apppended to the default class 
+     * path.
+     * @param verbose - a verbose output.
+     */
+    public ClassProvider(String bootClasspath, String classpath, boolean verbose) {
+        StringBuffer pathString = new StringBuffer();
+
+        // Append the given boot class path, if any.
+        if (bootClasspath != null) {
+            pathString.append(bootClasspath).append(File.pathSeparatorChar);
+        }
+
+        // Append the default class path.
+        pathString.append(getSystemClassPath()).append(File.pathSeparatorChar);
+
+        // Append the given class path, if any.
+        if (classpath != null) {
+            pathString.append(classpath).append(File.pathSeparatorChar);
+        }
+
+        if (verbose) {
+            System.out.println("class.path: " + pathString.toString());
+        }
+
+        this.classpath = new ClassPath(pathString.toString());
+        this.verbose = verbose;
+        this.cache = new HashMap();
+    }
+
+    /**
+     * Returns the system class path.
+     *
+     * @return the system class path.
+     */
+    private String getSystemClassPath() {
+        String sep = System.getProperty("path.separator");
+        StringBuffer cp = new StringBuffer();
+        for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) {
+            // Enumerate all the system properties.
+            String prop = (String) e.nextElement();
+            if (prop.endsWith("class.path")) {
+                // Add the value of a property to the class path, if its
+                // name ends with "class.path".
+                cp.append(System.getProperty(prop)).append(sep);
+            }
+        }
+        return cp.toString();
+    }
+
+    /**
+     * Returns a JavaClass object which represents a class file with the given
+     * name.
+     * 
+     * @param name - a fully qualified name of a class.
+     * @return a JavaClass object which represents a class file with the given
+     * name.
+     * @throws ClassNotFoundException if a class file with the given name is
+     * not found.
+     */
+    public synchronized JavaClass getJavaClass(String name)
+            throws ClassNotFoundException {
+        try {
+            // Try to get the class from the cache.
+            JavaClass result = (JavaClass) cache.get(name);
+            // If cache doesn't contain such a class load it from a class path.
+            if (result == null) {
+                // Get a file and parse its contents.
+                ClassPath.ClassFile cf = classpath.getClassFile(name);
+                InputStream is = cf.getInputStream();
+                ClassParser parser = new ClassParser(is, cf.getPath());
+                result = parser.parse();
+                // Put the parsed class file into the cache.
+                cache.put(name, result);
+
+                if (verbose) {
+                    StringBuffer s = new StringBuffer();
+                    // If we use BCEL 5.1 or later one day we definitely
+                    // should remove the following if and replace 
+                    // cf.getPath() with cf.getBase()!
+                    if (!(is instanceof FileInputStream)) {
+                        s.append("class.path:");
+                    }
+                    s.append(cf.getPath());
+                    System.out.println(name + " loaded from " + s);
+                }
+            } else {
+                if (verbose) {
+                    System.out.println(name + " retrieved from a cache");
+                }
+            }
+            return result;
+        } catch (Exception e) {
+            throw new ClassNotFoundException(name, e);
+        }
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/ClassProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/Mangler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/Mangler.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/Mangler.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/Mangler.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,196 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools;
+
+/**
+ * A helper class to mangle a string according to the Java Native Interface
+ * Specification.
+ */
+public class Mangler {
+
+    /**
+     * An array of the <code>String</code> pairs. This array 
+     * contains the common substitute string pairs.
+     */
+    private static final String COMMON_TABLE[] = {
+        "_", "_1",
+        ";", "_2",
+        "[", "_3",
+        "./", "_"
+    };
+
+    /**
+     * A field names substitution table.
+     */
+    private static final String FIELD_TABLE[][] = {
+        { ".$", "_" }
+    };
+    
+    /**
+     * A method names substitution table.
+     */
+    private static final String METHOD_TABLE[][] = {
+        COMMON_TABLE,
+        { "$", "_" }
+    };
+
+    /**
+     * A class names substitution table.
+     */
+    private static final String CLASS_TABLE[][] = {
+        COMMON_TABLE,
+        { "$", "_00024" }
+    };
+    
+    /**
+     * A macros substitution table.
+     */
+    private static final String MACRO_TABLE[][] = {
+        { ".$", "_" }
+    };
+    
+    /**
+     * A file names substitution table.
+     */
+    private static final String FILE_TABLE[][] = {
+        { ".$", "_" }
+    };
+    
+    /**
+     * Returns a mangled string. The given string will be translated according
+     * the given substitution table. This table consists of one or more
+     * <code>String</code> arrays that contain the substitute string pair.
+     * The first element of each <code>String</code> pair in the array
+     * contains a set of chars represented as a string. Any of the given 
+     * chars will be replaced with the second string of the pair
+     * in the result string. If table is null all the unicode
+     * chars will be replaced with an appropriate substitute string only.
+     * 
+     * @param name - a string to be mangled.
+     * @param table - a substitution table. <code>null</code> is possible.
+     * @return a mangled string.
+     */
+    private static String mangle(String name, String table[][]) {
+        StringBuffer result = new StringBuffer();
+
+        for (int i = 0; i < name.length(); i++) {
+            char c = name.charAt(i);
+
+            // Check the given table, if it is not null.
+            if (table != null) {
+                boolean found = false;
+                for (int k = 0; !found && k < table.length; k++) {
+                    int l = 0;
+                    while (l < table[k].length) {
+                        if (table[k][l].indexOf(c) != -1) {
+                            result.append(table[k][l + 1]);
+                            found = true;
+                            break;
+                        }
+                        l += 2;
+                    }
+                }
+                // If c is found in the given substitution table we continue.
+                if (found) {
+                    continue;
+                }
+            }
+
+            if (Character.UnicodeBlock.of(c) != Character.UnicodeBlock.BASIC_LATIN) {
+                // We have to prepare a string that looks like "_0XXXX",
+                // where "XXXX" is a string representation of a Unicode
+                // character. If the given string length is less than 4
+                // we have to prepend a missing number of '0' to the result.
+                String s = Integer.toHexString((int) c);
+                char code[] = new char[] {'0','0','0','0'};
+                int len = s.length();
+                int align = code.length - len;
+                int begin = len - code.length;
+                s.getChars(begin < 0 ? 0 : begin, len, code,
+                        align < 0 ? 0 : align);
+                result.append("_0").append(code);
+            } else {
+                result.append(c);
+            }
+        }
+
+        return result.toString();
+    }
+
+    /**
+     * Returns a mangled string. All the unicode chars of the given string
+     * will be replaced with the <code>_0XXXX</code> char sequence,
+     * where XXXX is a numeric representation of a Unicode character.
+     * 
+     * @param name - a string to be mangled.
+     * @return a mangled string.
+     */
+    public static String mangleUnicode(String name) {
+        return Mangler.mangle(name, null);
+    }
+
+    /**
+     * Returns a mangled string that represents the given field name.
+     * 
+     * @param name - a string to be mangled.
+     * @return a mangled string.
+     */
+    public static String mangleFieldName(String name) {
+        return Mangler.mangle(name, FIELD_TABLE);
+    }
+
+    /**
+     * Returns a mangled string that represents the given method name.
+     * 
+     * @param name - a string to be mangled.
+     * @return a mangled string.
+     */
+    public static String mangleMethodName(String name) {
+        return Mangler.mangle(name, METHOD_TABLE);
+    }
+
+    /**
+     * Returns a mangled string that represents the given class name.
+     * 
+     * @param name - a string to be mangled.
+     * @return a mangled string.
+     */
+    public static String mangleClassName(String name) {
+        return Mangler.mangle(name, CLASS_TABLE);
+    }
+
+    /**
+     * Returns a mangled string that represents the given macro.
+     * 
+     * @param name - a string to be mangled.
+     * @return a mangled string.
+     */
+    public static String mangleMacro(String name) {
+        return Mangler.mangle(name, MACRO_TABLE);
+    }
+
+    /**
+     * Returns a mangled string that represents the given file name.
+     * 
+     * @param name - a string to be mangled.
+     * @return a mangled string.
+     */
+    public static String mangleFileName(String name) {
+        return Mangler.mangle(name, FILE_TABLE);
+    }
+
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/Mangler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Clazz.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Clazz.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Clazz.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Clazz.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,227 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.javah;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Attribute;
+import org.apache.bcel.classfile.Field;
+import org.apache.bcel.classfile.InnerClass;
+import org.apache.bcel.classfile.InnerClasses;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.Utility;
+import org.apache.bcel.generic.BasicType;
+import org.apache.bcel.generic.Type;
+import org.apache.harmony.tools.ClassProvider;
+import org.apache.harmony.tools.Mangler;
+
+/**
+ * This class is a wrapper of BCEL's Class class.
+ *
+ * This class depends on Apache Byte Code Engineering Library (BCEL) 5.0 or
+ * later. Please see http://jakarta.apache.org/bcel for more information
+ * about this library.
+ */
+public class Clazz {
+
+    /**
+     * A wrapped class.
+     */
+    private JavaClass wrappedClass;
+
+    /**
+     * Inner classes of a wrapped class.
+     */
+    private String innerClassNames[];
+
+    /**
+     * Fields that will be included in a header file.
+     */
+    private Vector fields;
+
+    /**
+     * Methods that will be included in a header file.
+     */
+    private Vector methods;
+
+    /**
+     * Constructs a <code>Clazz</code> object.
+     * 
+     * @param classProvider - a helper that provides the class information.
+     * @param className - a fully qualified name of a class.
+     */
+    public Clazz(ClassProvider classProvider, String className) 
+            throws ClassNotFoundException {
+        wrappedClass = classProvider.getJavaClass(className);
+
+        // Assign an empty array by default.
+        Vector foundInners = new Vector();
+        // Get the class attributes.
+        Attribute attrs[] = wrappedClass.getAttributes();
+        for (int i = 0; i < attrs.length; i++) {
+            // Find the InnerClasses attribute, if any.
+            if (attrs[i] instanceof InnerClasses) {
+                // The InnerClasses attribute is found.
+                InnerClasses innerAttr = (InnerClasses) attrs[i];
+
+                // Get an array of the inner classes.
+                InnerClass inners[] = innerAttr.getInnerClasses();
+                for (int j = 0; j < inners.length; j++) {
+
+                    // Get the inner class name from a constant pool.
+                    String innerClassName = Utility.compactClassName(
+                            innerAttr.getConstantPool().getConstantString(
+                                    inners[j].getInnerClassIndex(), 
+                                    Constants.CONSTANT_Class),
+                            false);
+
+                    // The inner class has the InnerClasses attribute as well
+                    // as its outer class. So, we should ignore such an inner 
+                    // class.
+                    if (!innerClassName.equals(className)) {
+                        foundInners.addElement(innerClassName);
+                    }
+                }
+                break;
+            }
+        }
+        // Fill in the inner class array with the found inner classes.
+        innerClassNames = new String[foundInners.size()];
+        foundInners.toArray(innerClassNames);
+
+        // Collect up fields of the given class and all its ancestors.
+        fields = new Vector();
+        JavaClass clss = wrappedClass;
+        while (true) {
+            searchForFields(clss);
+            String superClassName = clss.getSuperclassName();
+            if (clss.getClassName().equals(superClassName)) {
+                break;
+            }
+            // Retrieve the next super class.
+            clss = classProvider.getJavaClass(superClassName);
+        }
+
+        // Collect up methods.
+        methods = new Vector();
+        searchForMethods(wrappedClass);
+    }
+
+    /**
+     * Returns a name of a wrapped class.
+     * 
+     * @return a class name.
+     */
+    public String getName() {
+        return wrappedClass.getClassName();
+    }
+
+    /**
+     * Returns a mangled name of a wrapped method.
+     * 
+     * @return a mangled method name.
+     */
+    public String getMangledName() {
+        return Mangler.mangleClassName(getName());
+    }
+
+    /**
+     * Returns an array of inner classes of this class.
+     * 
+     * @return an array of inner class names.
+     */
+    public String[] getInnerClassNames() {
+        return innerClassNames;
+    }
+
+    /**
+     * Searches the given class for the static final fields type of which
+     * is a primitive data type.
+     * 
+     * @param clss - a searched class.
+     */
+    private void searchForFields(JavaClass clss) {
+        Field field[] = clss.getFields();
+        for (int i = 0; i < field.length; i++) {
+            Field f = field[i];
+            if (f.isStatic() && f.isFinal()) {
+                if (Type.getReturnType(f.getSignature()) instanceof BasicType) {
+                    fields.addElement(new ClazzField(this, f));
+                }
+            }
+        }
+    }
+
+    /**
+     * Searches the given class for the native methods.
+     * 
+     * @param clss - a searched class.
+     */
+    private void searchForMethods(JavaClass clss) {
+        Method method[] = clss.getMethods();
+        for (int i = 0; i < method.length; i++) {
+            Method m = method[i];
+            if (m.isNative()) {
+                boolean overloaded = false;
+                // Check if the current method is overloaded.
+                for (int j = 0; j < method.length; j++) {
+                    Method mj = method[j];
+                    if (mj != m 
+                            && mj.isNative() 
+                            && mj.getName().equals(m.getName())) {
+                        overloaded = true;
+                    }
+                }
+                methods.addElement(new ClazzMethod(this, m, overloaded));
+            }
+        }
+    }
+
+    /**
+     * Returns a string that represents a class part of
+     * a JNI-style header file.
+     */
+    public String toString() {
+        String n = System.getProperty("line.separator");
+        StringBuffer result = new StringBuffer();
+
+        if (fields.size() > 0) {
+            result.append(n);
+            result.append("/* Static final fields */" + n);
+            result.append(n);
+
+            for (Enumeration e = fields.elements(); e.hasMoreElements();) {
+                result.append((ClazzField) e.nextElement());
+            }
+        }
+
+        if (methods.size() > 0) {
+            result.append(n);
+            result.append("/* Native methods */" + n);
+            result.append(n);
+
+            for (Enumeration e = methods.elements(); e.hasMoreElements();) {
+                result.append(((ClazzMethod) e.nextElement()).toString());
+            }
+        }
+
+        return result.toString();
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Clazz.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzField.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzField.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzField.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzField.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,150 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.javah;
+
+import org.apache.bcel.classfile.ConstantValue;
+import org.apache.bcel.classfile.Field;
+import org.apache.bcel.generic.Type;
+import org.apache.harmony.tools.Mangler;
+
+/**
+ * This class is a wrapper of BCEL's Field class.
+ *
+ * This class depends on Apache Byte Code Engineering Library (BCEL) 5.0 or
+ * later. Please see http://jakarta.apache.org/bcel for more information
+ * about this library.
+ */
+public class ClazzField {
+
+    /**
+     * An owner class.
+     */
+    private Clazz clazz;
+
+    /**
+     * A wrapped field.
+     */
+    private Field wrappedField;
+
+    /**
+     * Constructs a <code>ClazzField</code> object.
+     * 
+     * @param clazz - an owner.
+     * @param field - a wrapped Field object.
+     */
+    public ClazzField(Clazz clazz, Field wrappedField) {
+        this.clazz = clazz;
+        this.wrappedField = wrappedField;
+    }
+
+    /**
+     * Returns a type of the wrapped field.
+     * 
+     * @return a field type.
+     */
+    private Type getType() {
+        return Type.getReturnType(wrappedField.getSignature());
+    }
+
+    /**
+     * Returns a name of the wrapped field.
+     * 
+     * @return a field name.
+     */
+    public String getName() {
+        return wrappedField.getName();
+    }
+
+    /**
+     * Returns a mangled name of a wrapped field.
+     * 
+     * @return a mangled field name.
+     */
+    public String getMangledName() {
+        return Mangler.mangleFieldName(clazz.getName())
+                + "_" + Mangler.mangleFieldName(getName());
+    }
+
+    /**
+     * Returns a string representation of a native value
+     * based on a wrapped field value.
+     * 
+     * @return a string that represents a wrapped field value
+     * as a native data type.
+     * @throws Exception - if the wrapped field value is inaccessible.
+     */
+    public String getNativeValue() throws Exception {
+        return ClazzField.getNativeValue(getType(), 
+                wrappedField.getConstantValue());
+    }
+
+    /**
+     * Returns a string that represents a field part of
+     * a JNI-style header file.
+     */
+    public String toString() {
+        String n = System.getProperty("line.separator");
+        StringBuffer result = new StringBuffer();
+
+        String mangledName = getMangledName();
+        try {
+            String field = "#undef " + mangledName + n
+                    + "#define " + mangledName + " " + getNativeValue() + n;
+
+            // We add the field string only if there was no exception.
+            result.append(field);
+            result.append(n);
+        } catch (Exception e) {
+            result.append("/* Static field " + getName()
+                    + " is not accessible */" + n);
+            result.append(n);
+        }
+
+        return result.toString();
+    }
+
+    /**
+     * Returns a string representation of a given object native value.
+     * 
+     * @param type - a Class object that wraps a data type.
+     * @param value - an object that wraps a value of a primitive data type.
+     * @return a string that represents a native data type.
+     */
+    public static String getNativeValue(Type type, ConstantValue value) {
+        StringBuffer result = new StringBuffer();
+
+        if (type == Type.INT) {
+            result.append(value.toString()).append('L');
+        } else if (type == Type.BYTE) {
+            result.append(value.toString()).append('L');
+        } else if (type == Type.LONG) {
+            result.append(value.toString()).append("LL");
+        } else if (type == Type.FLOAT) {
+            result.append(value.toString()).append('f');
+        } else if (type == Type.DOUBLE) {
+            result.append(value.toString());
+        } else if (type == Type.SHORT) {
+            result.append(value.toString()).append('L');
+        } else if (type == Type.CHAR) {
+            result.append(value.toString()).append('L');
+        } else if (type == Type.BOOLEAN) {
+            result.append(value.toString()).append('L');
+        }
+
+        return result.toString();
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzMethod.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzMethod.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzMethod.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzMethod.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,304 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.javah;
+
+import org.apache.bcel.classfile.ExceptionTable;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.ArrayType;
+import org.apache.bcel.generic.ObjectType;
+import org.apache.bcel.generic.Type;
+import org.apache.harmony.tools.Mangler;
+
+/**
+ * This class is a wrapper of BCEL's Method class.
+ *
+ * This class depends on Apache Byte Code Engineering Library (BCEL) 5.0 or
+ * later. Please see http://jakarta.apache.org/bcel for more information
+ * about this library.
+ */
+public class ClazzMethod {
+
+    /**
+     * An owner class.
+     */
+    private Clazz clazz;
+
+    /**
+     * A wrapped method.
+     */
+    private Method wrappedMethod;
+
+    /**
+     * Indicates if a wrapped method is overloaded.
+     */
+    private boolean overloaded;
+
+    /**
+     * Constructs a <code>ClazzMethod</code> object.
+     * 
+     * @param clazz - an owner.
+     * @param wrappedMethod - a wrapped Method class.
+     * @param overloaded - <code>true</code> if the wrapped method
+     * is overloaded; <code>false</code> otherwise.
+     */
+    public ClazzMethod(Clazz clazz, Method wrappedMethod, boolean overloaded) {
+        this.clazz = clazz;
+        this.wrappedMethod = wrappedMethod;
+        this.overloaded = overloaded;
+    }
+
+    /**
+     * Returns the argument types.
+     * 
+     * @return an array of the argument types.
+     */
+    private Type[] getArgumentTypes() {
+        return Type.getArgumentTypes(wrappedMethod.getSignature());
+    }
+
+    /**
+     * Returns the return type.
+     * 
+     * @return the return type.
+     */
+    private Type getReturnType() {
+        return Type.getReturnType(wrappedMethod.getSignature());
+    }
+
+    /**
+     * Returns a parameters signature.
+     * 
+     * @return a parameters signature string.
+     */
+    private String getParamsSignature() {
+        StringBuffer result = new StringBuffer();
+
+        Type types[] = getArgumentTypes();
+        for (int i = 0; i < types.length; i++) {
+            result.append(types[i].getSignature());
+        }
+
+        return result.toString();
+    }
+
+    /**
+     * Returns a method signature.
+     * 
+     * @return a method signature string.
+     */
+    public String getSignature() {
+        return wrappedMethod.getSignature();
+    }
+
+    /**
+     * Determines if a wrapped method is static.
+     * 
+     * @return <code>true</code> if a wrapped method is static;
+     * <code>false</code> otherwise.
+     */
+    private boolean isStatic() {
+        return wrappedMethod.isStatic();
+    }
+
+    /**
+     * Returns a name of a wrapped method.
+     * 
+     * @return a method name.
+     */
+    public String getName() {
+        return wrappedMethod.getName();
+    }
+
+    /**
+     * Returns a mangled name of a wrapped method.
+     * 
+     * @return a mangled method name.
+     */
+    public String getMangledName() {
+        String result = Mangler.mangleMethodName(getName());
+        if (overloaded) {
+            result = result + "__" + Mangler.mangleMethodName(getParamsSignature());
+        }
+        return result;
+    }
+
+    /**
+     * Returns a JNI-style representation of the method return data type.
+     * 
+     * @return a return type JNI-style representation.
+     */
+    private String getJNIReturnType() {
+        return ClazzMethod.getJNIType(getReturnType());
+    }
+
+    /**
+     * Returns a string that represents a method part of
+     * a JNI-style header file.
+     */
+    public String toString() {
+        String n = System.getProperty("line.separator");
+        StringBuffer result = new StringBuffer();
+
+        String methodName = Mangler.mangleUnicode(
+                clazz.getName() + "." + getName() + getSignature());
+
+        // Print a method comment.
+        result.append("/*" + n);
+        result.append(" * Method: " + methodName + n);
+
+        // Print the thrown exceptions.
+        ExceptionTable etable = wrappedMethod.getExceptionTable();
+        if (etable != null) {
+            String e = etable.toString();
+            if (e.length() > 0) {
+                result.append(" * Throws: ");
+                result.append(e);
+                result.append(n);
+            }
+        }
+
+        result.append(" */" + n);
+
+        // Print a method declaration in a readable way.
+        result.append("JNIEXPORT " + getJNIReturnType() + " JNICALL" + n);
+        result.append("Java_" + clazz.getMangledName() + "_" + getMangledName());
+
+        result.append('(');
+        result.append("JNIEnv *");
+        if (isStatic()) {
+            result.append(", jclass");
+        } else {
+            result.append(", jobject");
+        }
+        Type types[] = getArgumentTypes();
+        for (int i = 0; i < types.length; i++) {
+            result.append(", ");
+            if (i == 0) {
+                result.append(n);
+                result.append("    ");
+            }
+            result.append(ClazzMethod.getJNIType(types[i]));
+        }
+        result.append(");" + n);
+        result.append(n);
+
+        return result.toString();
+    }
+
+    /**
+     * Returns an alternative string that represents a method part of
+     * a JNI-style header file.
+     */
+    public String toAlternativeString() {
+        String n = System.getProperty("line.separator");
+        StringBuffer result = new StringBuffer();
+
+        // Print a method comment.
+        result.append("/*" + n);
+        result.append(" * Class:     " + Mangler.mangleUnicode(clazz.getName())
+                + n);
+        result.append(" * Method:    " + Mangler.mangleUnicode(getName()) + n);
+        result.append(" * Signature: " + getSignature() + n);
+
+        // Print the thrown exceptions.
+        ExceptionTable etable = wrappedMethod.getExceptionTable();
+        if (etable != null) {
+            String e = etable.toString();
+            if (e.length() > 0) {
+                result.append(" * Throws:    ");
+                result.append(e);
+                result.append(n);
+            }
+        }
+
+        result.append(" */" + n);
+
+        // Print a method declaration in a readable way.
+        result.append("JNIEXPORT " + getJNIReturnType() + " JNICALL "
+                + "Java_" + clazz.getMangledName() + "_" + getMangledName() + n);
+
+        result.append("  (JNIEnv *, ");
+        if (isStatic()) {
+            result.append("jclass");
+        } else {
+            result.append("jobject");
+        }
+        Type types[] = getArgumentTypes();
+        for (int i = 0; i < types.length; i++) {
+            result.append(", ");
+            result.append(ClazzMethod.getJNIType(types[i]));
+        }
+        result.append(");" + n);
+        result.append(n);
+
+        return result.toString();
+    }
+
+    /**
+     * Returns a JNI-style representation of the given data type passed
+     * as a Class object.
+     * 
+     * @param type - a Class object that wraps a data type.
+     * @return a string that represents a JNI-style data type.
+     */
+    public static String getJNIType(Type type) {
+        StringBuffer result = new StringBuffer();
+
+        String suffix = "";
+        if (type instanceof ArrayType) {
+            suffix = "Array";
+            type = ((ArrayType) type).getElementType();
+        }
+
+        if (type instanceof ObjectType) {
+            String objectType = "jobject";
+            // The suffix length is 0 only if the given type is not an array.
+            if (suffix.length() == 0) {
+                if (type.equals(Type.STRING)) {
+                    objectType = "jstring";
+                } else if (type.equals(Type.THROWABLE)) {
+                    objectType = "jthrowable";
+                } else if (((ObjectType) type).getClassName()
+                        .equals("java.lang.Class")) {
+                    objectType = "jclass";
+                }
+            }
+            result.append(objectType);
+        } else if (type == Type.INT) {
+            result.append("jint");
+        } else if (type == Type.BYTE) {
+            result.append("jbyte");
+        } else if (type == Type.LONG) {
+            result.append("jlong");
+        } else if (type == Type.FLOAT) {
+            result.append("jfloat");
+        } else if (type == Type.DOUBLE) {
+            result.append("jdouble");
+        } else if (type == Type.SHORT) {
+            result.append("jshort");
+        } else if (type == Type.CHAR) {
+            result.append("jchar");
+        } else if (type == Type.BOOLEAN) {
+            result.append("jboolean");
+        } else if (type == Type.VOID) {
+            result.append("void");
+        }
+
+        return result.append(suffix).toString();
+    }
+
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/ClazzMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Main.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Main.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Main.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,332 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.javah;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.harmony.tools.ClassProvider;
+import org.apache.harmony.tools.Mangler;
+
+/**
+ * This is a tool that allows you to create JNI-style header files.
+ */
+public class Main {
+
+    /**
+     * Prints the usage information.
+     */
+    public static void usage() {
+        System.out.println("JNI-style header files generator.");
+        System.out.println();
+        System.out.println("Usage: " + Main.class.getName()
+                + " [options] <class names>\n");
+        System.out.println("[options]");
+        System.out.println("  -bootclasspath <path> The given path will be prepended to");
+        System.out.println("                        the default class path.\n");
+        System.out.println("  -classpath <path>     The given path will be appended to");
+        System.out.println("                        the default class path.\n");
+        System.out.println("  -o <file>             All the output will be redirected into");
+        System.out.println("                        the specified file.\n");
+        System.out.println("  -d <directory>        All the header files will be created in the specified");
+        System.out.println("                        directory which will be created if it is necessary.\n");
+        System.out.println("  -inner                Inner classes will be processed automatically.\n");
+        System.out.println("  -verbose              Allows running commentary.\n");
+        System.out.println("<class names>           A list of the fully qualified class names");
+        System.out.println("                        separated by a space.");
+    }
+
+    /**
+     * A convenient way to run this tool from a command line.
+     */
+    public static void main(String args[]) {
+        if (args.length < 1) {
+            usage();
+            System.exit(1);
+        }
+
+        String pathSep = null;
+        try {
+            pathSep = System.getProperty("path.separator");
+        } catch (SecurityException e) {
+            // ignore
+        }
+        
+        Set names = new HashSet();
+        Map options = new HashMap();
+        int i = 0;
+        while (i < args.length) {
+            if (args[i].equals("-bootclasspath") || args[i].equals("-classpath")) {
+                String path = (String) args[i + 1];
+
+                // We can concatenate several options, if there is no 
+                // security restriction; otherwise, the new option replaces
+                // the old one.
+                if (pathSep != null) {
+                    String prevPath = (String) options.get(args[i]);
+                    if (prevPath != null) {
+                        path = prevPath + pathSep + path;
+                    }
+                }
+
+                options.put(args[i], path);
+                i++;
+            } else if (args[i].equals("-d") || args[i].equals("-o")) {
+                options.put(args[i], new File(args[i + 1]));
+                i++;
+            } else if (args[i].equals("-inner") || args[i].equals("-verbose")) {
+                options.put(args[i], Boolean.valueOf(true));
+            } else {
+                names.add(args[i]);
+            }
+            i++;
+        }
+        System.exit(run(options, names));
+    }
+
+    /**
+     * Runs a tool.
+     * 
+     * @param options - a <code>java.util.Map</code> of the following key-value
+     * pairs.
+     * <p> Note, "-d" can not be specified with "-o" at the same time.
+     * 
+     * <li> <i>key</i> - "-d"
+     * <li> <i>value</i> - a <code>java.io.File</code> object which represents 
+     * a directory where the generated header files will be created. 
+     * If this directory does not exist it will be created.
+     * 
+     * <li> <i>key</i> - "-o"
+     * <li> <i>value</i> - a <code>java.io.File</code> object where 
+     * the output will be directed to.
+     * 
+     * <li> <i>key</i> - "-bootclasspath"
+     * <li> <i>value</i> - a <code>java.lang.String</code> which is a path 
+     * where bootstrap classes are located.
+     * 
+     * <li> <i>key</i> - "-classpath"
+     * <li> <i>value</i> - a <code>java.lang.String</code> which is a path 
+     * where classes are located.
+     * 
+     * <li> <i>key</i> - "-inner"
+     * <li> <i>value</i> - a <code>java.lang.Boolean</code> which is equal to
+     * <code>true</code>, if inner classes should be processed automatically,
+     * that is, as if they are specified as elements of 
+     * the <code>classNames</code> parameter.
+     * 
+     * <li> <i>key</i> - "-verbose"
+     * <li> <i>value</i> - a <code>java.lang.Boolean</code> which is equal to
+     * <code>true</code>, if the verbose output is needed.
+     * 
+     * @param classNames - a set of the fully qualified class names.
+     * @return <code>0</code> if there is no error; <code>1</code> otherwise.
+     */
+    public static int run(Map options, Set classNames) {
+        File outDirectory = getFile(options, "-d");
+        File outFile = getFile(options, "-o");
+
+        if (outDirectory != null && outFile != null) {
+            System.err.println("Error: You can not use both -d and -o options.");
+            System.err.println();
+            usage();
+            return 1;
+        }
+
+        String bootClasspath = getString(options, "-bootclasspath");
+        String classpath = getString(options, "-classpath");
+
+        boolean inner = getBoolean(options, "-inner");
+        boolean verbose = getBoolean(options, "-verbose");
+
+        ClassProvider classProvider = new ClassProvider(bootClasspath,
+                classpath, verbose);
+        try {
+            String n = System.getProperty("line.separator");
+            String warning =
+                  "/*" + n
+                + " * THE FILE HAS BEEN AUTOGENERATED BY THE IJH TOOL." + n
+                + " * Please be aware that all changes made to this file manually" + n
+                + " * will be overwritten by the tool if it runs again." + n
+                + " */" + n
+                + n
+                + "#include <jni.h>" + n
+                + n;
+
+            StringBuffer result = new StringBuffer();
+            Set innerNames = new HashSet();
+            File file = outFile;
+            Iterator namesIter = classNames.iterator();
+            while (namesIter.hasNext()) {
+
+                // Parse the next class.
+                Clazz clazz = new Clazz(classProvider, (String) namesIter.next());
+
+                if (inner) {
+                    // Get the inner class names and store them 
+                    // in a separate set.
+                    String innerClassNames[] = clazz.getInnerClassNames();
+                    for (int i = 0; i < innerClassNames.length; i++) {
+                        innerNames.add(innerClassNames[i]);
+                    }
+                }
+
+                if (outFile == null) {
+                    // Each header should be written into the separate file.
+
+                    String fileName = Mangler.mangleFileName(
+                            clazz.getName()) + ".h";
+
+                    if (outDirectory != null) {
+                        if (!outDirectory.exists()) {
+                            outDirectory.mkdir();
+                        }
+                        fileName = outDirectory.getPath() + File.separator
+                                + fileName;
+                    }
+
+                    // Reset the output file.
+                    file = new File(fileName);
+
+                    // Reset the result buffer.
+                    result = new StringBuffer();
+                }
+
+                // Append the next header.
+                result.append(Main.getHeader(clazz));
+
+                // Process the inner class names, if any.
+                if (!namesIter.hasNext() && !innerNames.isEmpty()) {
+                    // Remove the inner class names that have already
+                    // been processed.
+                    innerNames.removeAll(classNames);
+
+                    // Reset the loop iterator.
+                    classNames = new HashSet(innerNames);
+                    namesIter = classNames.iterator();
+
+                    // Clear the set of the inner class names.
+                    innerNames.clear();
+                }
+
+                // Write the result into a file.
+                if (outFile == null || !namesIter.hasNext()) {
+                    FileWriter writer = new FileWriter(file);
+                    try {
+                        writer.write(warning);
+                        writer.write(result.toString());
+                        if (verbose) {
+                            System.out.println(file.getName() + " created");
+                        }
+                    } finally {
+                        writer.close();
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            System.err.println("Error:");
+            e.printStackTrace();
+            return 1;
+        }
+
+        return 0;
+    }
+
+    /**
+     * Returns a value of an option with the given name. The return type
+     * is <code>java.io.File</code>. 
+     */
+    private static File getFile(Map options, String name) {
+        try {
+            return (File) options.get(name);
+        } catch (ClassCastException e) {
+            throw new RuntimeException(
+                    "'" + name + "': expected java.io.File", e);
+        }
+    }
+    
+    /**
+     * Returns a value of an option with the given name. The return type
+     * is <code>java.lang.String</code>. 
+     */
+    private static String getString(Map options, String name) {
+        try {
+            return (String) options.get(name);
+        } catch (ClassCastException e) {
+            throw new RuntimeException(
+                    "'" + name + "': expected java.lang.String", e);
+        }
+    }
+    
+    /**
+     * Returns a value of an option with the given name. The return type
+     * is <code>java.lang.Boolean</code>. 
+     */
+    private static boolean getBoolean(Map options, String name) {
+        try {
+            Object value = options.get(name);
+            if (value != null) {
+                return ((Boolean) value).booleanValue();
+            }
+        } catch (ClassCastException e) {
+            throw new RuntimeException(
+                    "'" + name + "': expected java.lang.Boolean", e);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a string that represents a JNI-style header file.
+     */
+    public static String getHeader(Clazz clazz) {
+        String n = System.getProperty("line.separator");
+        StringBuffer result = new StringBuffer();
+
+        result.append(n);
+        result.append("/* Header for class " + clazz.getName() + " */" + n);
+        result.append(n);
+
+        String headerMacro = "_" + 
+                Mangler.mangleMacro(clazz.getName()).toUpperCase() + "_H";
+        result.append("#ifndef " + headerMacro + n);
+        result.append("#define " + headerMacro + n);
+        result.append(n);
+
+        result.append("#ifdef __cplusplus" + n);
+        result.append("extern \"C\" {" + n);
+        result.append("#endif" + n);
+        result.append(n);
+
+        result.append(clazz);
+        result.append(n);
+
+        result.append("#ifdef __cplusplus" + n);
+        result.append("}" + n);
+        result.append("#endif" + n);
+        result.append(n);
+
+        result.append("#endif /* " + headerMacro + " */" + n);
+        result.append(n);
+
+        return result.toString();
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/anttask/Adapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/anttask/Adapter.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/anttask/Adapter.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/anttask/Adapter.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,141 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.ijh.anttask;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.launch.Locator;
+import org.apache.tools.ant.taskdefs.ExecuteJava;
+import org.apache.tools.ant.taskdefs.optional.Javah;
+import org.apache.tools.ant.taskdefs.optional.javah.JavahAdapter;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Path;
+
+/**
+ * Adapter to org.apache.harmony.tools.ijh.Main.
+ *
+ * This class depends on Apache Ant tool 1.6.5 or later.
+ * Please see http://ant.apache.org for more information about this tool.
+ */
+public class Adapter implements JavahAdapter {
+
+    /**
+     * Runs our implementation of the <code>javah</code>.
+     * 
+     * @param javah is the Javah task.
+     * @return <code>true</code> if there is no error; Otherwise
+     *         <code>false</code>.
+     */
+    public boolean compile(Javah javah) throws BuildException {
+        Class clss = null;
+
+        // Try to load the main class of the tool.
+        try {
+            clss = Class.forName("org.apache.harmony.tools.ijh.Main");
+        } catch (ClassNotFoundException e) {
+            throw new BuildException("Can't load a class", e, 
+                    javah.getLocation());
+        }
+
+        // Prepare a command to launch the tool.
+        Commandline cmd = setupCommand(javah);
+        cmd.setExecutable(clss.getName());
+
+        // Prepare a java command.
+        ExecuteJava java = new ExecuteJava();
+        java.setJavaCommand(cmd);
+
+        // Find a file or a jar which represents the required class.
+        File file = Locator.getClassSource(clss);
+        if (file != null) {
+            // The found file should be included into the class path.
+            Path classpath = new Path(javah.getProject(), file.getPath());
+
+            // Try to load BCEL's ClassPath utility class.
+            try {
+                clss = Class.forName("org.apache.bcel.util.ClassPath");
+            } catch (ClassNotFoundException e) {
+                throw new BuildException("Can't load BCEL", e, 
+                        javah.getLocation());
+            }
+
+            // Find a file or a jar which represents the required class.
+            file = Locator.getClassSource(clss);
+            if (file != null) {
+                // Add the found file to the class path.
+                classpath.append(new Path(javah.getProject(), file.getPath()));
+            }
+
+            // Set the class path.
+            java.setClasspath(classpath);
+        }
+
+        // Run the java command.
+        return java.fork(javah) == 0;
+    }
+
+    /**
+     * Prepare a command line that includes all parameters.
+     * 
+     * @param javah is the Javah task.
+     * @return The prepared command line.
+     */
+    private Commandline setupCommand(Javah javah) {
+        Commandline cmd = new Commandline();
+
+        // Add a destination directory if any.
+        if (javah.getDestdir() != null) {
+            cmd.createArgument().setValue("-d");
+            cmd.createArgument().setFile(javah.getDestdir());
+        }
+
+        // Add an output file if any.
+        if (javah.getOutputfile() != null) {
+            cmd.createArgument().setValue("-o");
+            cmd.createArgument().setFile(javah.getOutputfile());
+        }
+
+        // Add a class path if any.
+        if (javah.getClasspath() != null) {
+            cmd.createArgument().setValue("-classpath");
+            cmd.createArgument().setPath(javah.getClasspath());
+        }
+
+        // Add a verbose flag if any.
+        if (javah.getVerbose()) {
+            cmd.createArgument().setValue("-verbose");
+        }
+
+        // Add a boot class path if any.
+        Path bootClasspath = new Path(javah.getProject());
+        if (javah.getBootclasspath() != null) {
+            bootClasspath.append(javah.getBootclasspath());
+        }
+        if (bootClasspath.size() > 0) {
+            cmd.createArgument().setValue("-bootclasspath");
+            cmd.createArgument().setPath(bootClasspath);
+        }
+
+        // Add settings given as nested arg elements.
+        cmd.addArguments(javah.getCurrentArgs());
+
+        // Add and log the parameters and source files.
+        javah.logAndAddFiles(cmd);
+        return cmd;
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javah/anttask/Adapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test/Test01.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test/Test01.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test/Test01.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test/Test01.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,36 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tests.tools.javah.Test;
+
+public class Test01 {
+
+    static final int xxx = 1;
+
+    private static final long xxx2 = 1;
+
+    final int xxx3 = 1;
+
+    static int xxx4 = 1;
+
+    static final int xxx5arr[] = {1,2};
+
+    static final int xxx6 = 1;
+    
+    native int zzz();
+
+    protected native int zzz2();
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test/Test01.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test02.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test02.java?view=auto&rev=480696
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test02.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test02.java Wed Nov 29 11:45:45 2006
@@ -0,0 +1,62 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tests.tools.javah;
+import Test.*;
+
+public class Test02 extends Test01 {
+
+    private static final byte ZZZ_çèìà = 22;
+
+    private static final byte zzz11 = 2;
+    private static final short zzz12 = 2;
+    private static final int zzz13 = 2;
+    private static final long zzz14 = 2;
+    private static final float zzz15 = 2;
+    private static final double zzz16 = 2.0;
+    private static final boolean zzz17 = true;
+    private static final char zzz18 = '2';
+    private static final int zzz19[] = null;
+    private static final int zzz20[] = {20};
+
+    protected native int zzz2(String v);
+
+    private native long zzz2(long v);
+
+    public native String zzz2(boolean v);
+
+    native void zzz2_zzz2(Thread v, String s[], Class c[], Object o[]) throws Exception;
+
+    native void zzz2_zzz2(Thread v, char c, Class z, String s, Object o) throws Exception;
+
+    native void zzz2_zzz2(Thread v, char[] c) throws Exception;
+
+    native void zzz2_zzz2(int[] i, Thread v, char[] c) throws Exception;
+
+    native Throwable zzz2_zzz2_è_âàñÿ(Throwable[] i, Throwable v, char[] c)
+            throws Exception, IndexOutOfBoundsException;
+
+    class nested {
+        static final long nested_yes = -2;
+        static final long nested = 2;
+
+        native void nested2_nested2(boolean v);
+
+        private native long nested2(long v);
+
+        public native int nested2(boolean v);
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/test/java/org/apache/harmony/tests/tools/javah/Test02.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message