commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1084975 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ native/ native/include/acr/ native/port/ native/shared/ test/org/apache/commons/runtime/
Date Thu, 24 Mar 2011 14:46:31 GMT
Author: mturk
Date: Thu Mar 24 14:46:30 2011
New Revision: 1084975

URL: http://svn.apache.org/viewvc?rev=1084975&view=rev
Log:
Add more of old code

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java  
(with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java   (with
props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Local.java   (with
props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java   (with
props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java 
 (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/native/port/bsdsys.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/native.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
Thu Mar 24 14:46:30 2011
@@ -33,14 +33,6 @@ runtime.version.pname = @VERSION_PNAME@
 runtime.version.built = @VERSION_BUILT@
 runtime.version.uuid  = @VERSION_UUID@
 
-# Indicates the caching policy for lookups on cpu object.
-# The TTL is number of milliseconds between two counter lookups.
-cpu.cache.ttl = 100
-cpu.cache.ttl.min = 1
-
-# Maximum number of opened OS descriptors
-os.open.max = 65536
-
 # Native library name
 # See platform/<os>/Default.properties for any additional libraries
 # that has to be loaded before this library

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java Thu
Mar 24 14:46:30 2011
@@ -0,0 +1,212 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons.runtime;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.lang.reflect.Method;
+
+/**
+ * Loads the native libraries.
+ * <p>
+ * This class wraps the {@code System.load} and {@code System.loadLibrary}
+ * calls.
+ * </p>
+ *
+ * @since Runtime 1.0
+ *
+ */
+public final class Library
+{
+    private static String packageName;
+    private Library()
+    {
+        // No instance.
+    }
+
+    static {
+        packageName = Library.class.getPackage().getName();
+    }
+
+    /**
+     * Return the decorated shared object name.
+     * It prepends the {@code name} with {@code lib} on
+     * windows platform
+     */
+    private static String getSoName(String name)
+    {
+        String so;
+        if (!SystemId.getSysname().equals("windows"))
+            so = "lib" + name;
+        else
+            so = name;
+        return so + "." + SystemId.getSoExtension();
+    }
+
+    private static String getResName(String name, boolean arch)
+    {
+        String res = packageName.replace('.', '/') + "/platform/" +
+                     SystemId.getSysname() + "/";
+        if (arch)
+            return res + SystemId.getDataModel() + "/" + name;
+        else
+            return res + name;
+    }
+
+    private static File extractResource(InputStream is, String name,
+                                        boolean arch)
+        throws IllegalArgumentException, IOException
+    {
+        File f = Loader.libFile(System.mapLibraryName(name), arch);
+        try {
+            byte [] buf = new byte[4096];
+            FileOutputStream os = new FileOutputStream(f);
+            while (true) {
+                int rd = is.read(buf);
+                if (rd > 0) {
+                    os.write(buf, 0, rd);
+                }
+                else
+                    break;
+            }
+            os.close();
+            /* Some platforms like HP-UX require the library
+             * to have executable permissions set.
+             * This requires Java 6 however
+             */
+            f.setExecutable(true);
+            /* Mark the extracted file for delete on JVM exit.
+             * Although windows platform cannot delete this file
+             * if library is successfully loaded it will succeed if
+             * load fails.
+             */
+            f.deleteOnExit();
+            return f;
+        } catch (Exception ex) {
+            if (f.exists()) {
+                /* File already exists in the specified location.
+                 * Usually this happens if the library is already
+                 * in use.
+                 */
+                return f;
+            }
+             else
+                return null;
+        }
+    }
+
+    /**
+     * Load the library specified by the {@code libname} parameter.
+     * <p>
+     * Loading a library is a platform dependent operation. First the
+     * {@code System.loadLibrary(libname)} is tried.
+     * </p>
+     * @param libname the name of the library
+     * @return {@code true} if the library was successfully loaded;
+     *          {@code false} othervise.
+     */
+    public static boolean load(String libname)
+    {
+
+        if (Loader.has(libname)) {
+            /* Already loaded by a previous call
+             */
+            return true;
+        }
+        /* Step 1.
+         * Try to load from the acr.library.path
+         * property (eg. -Dacr.library.path=/some/location)
+         */
+        String path = System.getProperty("acr.library.path");
+        if (path != null) {
+            try {
+                File f = new File(path, getSoName(libname));
+                System.load(f.getPath());
+                Loader.add(libname, f);
+                return true;
+            } catch (Throwable ex) {
+                // Cannot load from acr.boot.path
+                // Continue...
+            }
+        }
+        /* Step 2.
+         * Try standard System.loadLibrary
+         */
+        try {
+            System.loadLibrary(libname);
+            Loader.add(libname, null);
+            return true;
+        } catch (UnsatisfiedLinkError ue) {
+            // Ignore
+        }
+        /* Step 3.
+         * Try to load from classpath/platform/os/32|64/libname.
+         */
+        String resname;
+        InputStream is = null;
+        resname = getResName(getSoName(libname), true);
+        try {
+            is = Library.class.getClassLoader().getResourceAsStream(resname);
+        } catch (Exception ex) {
+            // Ignore
+        }
+        if (is != null) {
+            /* We have found a libname.
+             */
+            try {
+                File f = extractResource(is, libname, true);
+                if (f != null) {
+                    System.load(f.getPath());
+                    Loader.add(libname, f);
+                    return true;
+                }
+            } catch (Exception ex) {
+            }
+        }
+
+        /* Step 4.
+         * Try to load from classpath/platform/os/libname.
+         */
+        resname = getResName(getSoName(libname), false);
+        try {
+            is = Library.class.getClassLoader().getResourceAsStream(resname);
+        } catch (Exception ex) {
+            // Ignore
+        }
+        if (is != null) {
+            /* We have found a libname.
+             */
+            try {
+                File f = extractResource(is, libname, false);
+                if (f != null) {
+                    System.load(f.getPath());
+                    Loader.add(libname, f);
+                    return true;
+                }
+            } catch (Exception ex) {
+            }
+        }
+
+        /* No luck :(
+         * Return false to the caller.
+         */
+        return false;
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java Thu
Mar 24 14:46:30 2011
@@ -0,0 +1,277 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons.runtime;
+
+import org.apache.commons.runtime.exception.UnsupportedOperatingSystemException;
+import org.apache.commons.runtime.util.Utils;
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+
+/**
+ * Loader keeps track of loaded native libraries.
+ *
+ * @since Runtime 1.0
+ *
+ */
+public final class Loader
+{
+
+    private static HashMap<String, File> libs;
+    private static HashMap<String, Byte> mods;
+    private static File     path     = null;
+    private static boolean  isLoaded = false;
+
+    private Loader()
+    {
+        // Static class. No instance.
+    }
+
+    static {
+        libs = new HashMap<String, File>();
+        mods = new HashMap<String, Byte>();
+    }
+
+    /**
+     * Return the location of the {@code Jar} file from
+     * which this class is loaded.
+     *
+     * @return Abstract pathname to the jar file this class was
+     *         loaded from or {@code null} in case it was not loaded
+     *         from {@code Jar}.
+     */
+    public static File getLocation()
+    {
+        URL url   = null;
+        Class cls = Loader.class;
+        try {
+            if (cls.getProtectionDomain() == null ||
+                cls.getProtectionDomain().getCodeSource() == null) {
+                // Can this happen for non System class?
+                return null;
+            }
+            url = cls.getProtectionDomain().getCodeSource().getLocation();
+        } catch (SecurityException ex) {
+            // Someone limited the RuntimePermission("getProtectionDomain")
+        }
+        if (url == null)
+            return null;
+        else {
+            File jar = new File(url.getFile());
+            if (jar.isDirectory()) {
+                return null;
+            }
+            else
+                return jar;
+        }
+    }
+
+    /**
+     * Get the path to temporary location for extracting the
+     * libraries from resource.
+     */
+    protected static File libFile(String name, boolean arch)
+    {
+        synchronized(Loader.class) {
+            if (path == null) {
+                try {
+                    if (SystemId.getSysname().equals("windows")) {
+                        String acr = "_acr-" + Properties.VERSION_UUID;
+                        path = new File(Utils.getTempPath(), acr);
+                        if (path.mkdir()) {
+                            /* Delete on exit will work only if library load
+                             * fails. In all other cases the directory will
+                             * remain open.
+                             */
+                            path.deleteOnExit();
+                        }
+                        if (arch) {
+                            path = new File(path, SystemId.getDataModel());
+                            if (path.mkdir()) {
+                                path.deleteOnExit();
+                            }
+                        }
+                    }
+                    else {
+                        path = Utils.createTempDirectory("_acr-");
+                        path.deleteOnExit();
+                        if (arch) {
+                            path = new File(path, SystemId.getDataModel());
+                            if (path.mkdir()) {
+                                path.deleteOnExit();
+                            }
+                        }
+                    }
+                } catch (Exception io) {
+                    // Cannot create temp dir
+                    return null;
+                }
+                try {
+                    String load = System.getProperty("java.library.path");
+                    if (load == null)
+                        load = path.getPath();
+                    else
+                        load = path.getPath() + File.pathSeparator + load;
+                    System.setProperty("java.library.path", load);
+                } catch (Exception ex) {
+                    // SecurityException ?
+                }
+            }
+            return new File(path, name);
+        }
+    }
+
+    /**
+     * Add the {@code libname} referenced by {@code file} to the list
+     * of loaded libraries.
+     *
+     * @param libname The name of the library
+     */
+    protected static void add(String libname, File file)
+    {
+        libs.put(libname, file);
+    }
+
+    /**
+     * Check if the {@code libname} was already loaded.
+     *
+     * @return {@code true} if the library was already loaded.
+     */
+    public static boolean has(String libname)
+    {
+        return libs.containsKey(libname);
+    }
+
+    /**
+     * Check if the any of the native libraries was loaded.
+     *
+     * @return {@code true} if one of the native libraries was
+     *         loaded.
+     */
+    public static boolean isEmpty()
+    {
+        return libs.isEmpty();
+    }
+
+    /**
+     * Load all native libraries in proper order according
+     * to the rules specified in {@code Default.properties} files.
+     *
+     * @return {@code true} if the final native library was
+     *         loaded.
+     */
+    public static boolean load()
+        throws UnsupportedOperatingSystemException
+    {
+        if (isLoaded)
+            return true;
+
+        boolean rc = false;
+        if (Properties.NATIVE_LIBS != null) {
+            for (int i = 0; i < Properties.NATIVE_LIBS.length; i++) {
+                boolean s = Library.load(Properties.NATIVE_LIBS[i]);
+                if (i == (Properties.NATIVE_LIBS.length - 1)) {
+                    /* Record the result of the last entry in the
+                     * library dependency list (library itself).
+                     */
+                    rc  = s;
+                }
+            }
+        }
+        if (rc) {
+            /* Initialize Native library.
+             */
+            isLoaded = Native.initialize();
+            return isLoaded;
+        }
+        else
+            return false;
+    }
+
+    /**
+     * Load module.
+     */
+    public static boolean load(String module)
+        throws UnsupportedOperatingSystemException
+    {
+        if (!isLoaded) {
+            /* Cannot load module if main library wasn't initialized.
+             */
+            return false;
+        }
+        if (mods.containsKey(module))
+            return true;
+
+        byte cnt = 0;
+        boolean rc = false;
+        String [] md = Properties.getArray("library.load." + module, null);
+        if (md == null) {
+            /* Not listed inside .properties file
+             */
+            rc = Library.load(module);
+            cnt++;
+        }
+        else {
+            for (int i = 0; i < md.length; i++) {
+                boolean s = Library.load(md[i]);
+                if (i == (md.length - 1)) {
+                    /* Record the result of the last entry in the
+                     * module dependency list (module itself).
+                     */
+                    rc  = s;
+                }
+                cnt++;
+            }
+        }
+        if (rc) {
+            /* Add the module to the list of loaded modules.
+             */
+            mods.put(module, new Byte(cnt));
+            return true;
+        }
+        else
+            return false;
+    }
+
+    /**
+     * Temporary debug method that dumps loaded natives to stdout.
+     */
+    @Deprecated
+    protected static void dump()
+    {
+        if (Properties.NATIVE_LIBS != null) {
+            System.out.println("Required libraries: ");
+            for (int i = 0; i < Properties.NATIVE_LIBS.length; i++) {
+                System.out.println("[" + i + "] " +  Properties.NATIVE_LIBS[i]);
+            }
+            System.out.println();
+            if (!isEmpty()) {
+                System.out.println("Loaded from classpath: ");
+                for (int i = 0; i < Properties.NATIVE_LIBS.length; i++) {
+                    File f =  libs.get(Properties.NATIVE_LIBS[i]);
+                    String from;
+                    if (f != null)
+                        from = f.getPath();
+                    else
+                        from = "${java.library.path}";
+                    System.out.println("[" + i + "] " + from);
+                }
+                System.out.println();
+            }
+        }
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Local.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Local.java?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Local.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Local.java Thu
Mar 24 14:46:30 2011
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons.runtime;
+import org.apache.commons.runtime.util.StringManager;
+
+/** Package private constants
+ */
+class Local
+{
+
+    public static final String Package = "org.apache.commons.runtime";
+    public static final StringManager sm;
+
+    static {
+        sm = StringManager.getManager(Package);
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Local.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties
Thu Mar 24 14:46:30 2011
@@ -15,6 +15,3 @@
 
 os.ENOTIMPL=Apache Commons Runtime does not support this operating system
 os.EVERSION=Apache Commons Runtime does not support this operating system version
-waithow.EINVAL=Invalid WaitHow enum initializer ({0})
-reslimit.EINVAL=Invalid ResourceLimit enum initializer ({0})
-killcond.EINVAL=Invalid KillConditions enum initializer ({0})

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java Thu
Mar 24 14:46:30 2011
@@ -0,0 +1,77 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons.runtime;
+
+import org.apache.commons.runtime.exception.UnsupportedOperatingSystemException;
+
+/**
+ * Native library management.
+ *
+ * @since Runtime 1.0
+ *
+ */
+public final class Native
+{
+
+    private Native()
+    {
+        // No instance.
+    }
+
+    private static boolean initialized = false;
+    private static native boolean init0()
+        throws Throwable;
+    private static native boolean isdbg0();
+
+    /**
+     * True if the native code compiled with debugging support.
+     */
+    public static final boolean HAS_MAINTAINER_MODE = isdbg0();
+
+    /**
+     * Initialize Apache Commons Runtime native library.
+     * <p>
+     * This method must be called after the {@code native} library
+     * has been loaded into current VM address space and before any
+     * other classes are used. This method ensures that native part
+     * of the library properly initialize.
+     * </p>
+     * @return {@code true} if the library was properly initialized.
+     * @throws UnsupportedOperatingSystemException in case of
+     *         unsupported operating system
+     */
+    public static boolean initialize()
+        throws UnsupportedOperatingSystemException
+    {
+        if (!initialized) {
+            try {
+                initialized = init0();
+            } catch (Throwable t) {
+                // Ignore
+                System.out.println(t.toString());
+            }
+
+            if (!Platform.supported()) {
+                throw new UnsupportedOperatingSystemException(
+                    "Apache Commons Runtime does not support this " +
+                    "operating system"
+                );
+            }
+        }
+        return initialized;
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java Thu
Mar 24 14:46:30 2011
@@ -0,0 +1,141 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons.runtime;
+import java.nio.charset.Charset;
+
+/**
+ * Running Platform version info.
+ * Package private
+ *
+ * @since Runtime 1.0
+ *
+ */
+class Platform
+{
+
+    private Platform()
+    {
+        // No class instance
+    }
+
+    /**
+     * Check the platform validity.
+     * The caller should throw the {@code UnsupportedOperatingSystemException}
+     * if this call returns {@code false}.
+     */
+    public static native boolean supported();
+
+    /*
+     * Get Platform integer property value.
+     */
+    private static native void init0(int[] p);
+    private static final int default_charset()
+    {
+        int cs;
+        try {
+            String cp = Charset.defaultCharset().name();
+            if (cp == null)
+                cs = -1;
+            else if (cp.equals("ISO-8859-1"))
+                cs = 1;
+            else if (cp.equals("US-ASCII"))
+                cs = 1;
+            else if (cp.equals("UTF-8"))
+                cs = 2;
+            else
+                cs = 0;
+        } catch (Exception e) {
+            // Cannot determine
+            cs = -1;
+        }
+        return cs;
+    }
+
+    static {
+        int [] i = new int[16];
+
+        i[0] = default_charset();
+        init0(i);
+
+        SIZEOF_INT                      =   i[0];
+        SIZEOF_LONG                     =   i[1];
+        SIZEOF_SIZE_T                   =   i[2];
+        SIZEOF_POINTER                  =   i[3];
+        SIZEOF_WCHAR                    =   i[4];
+        DATA_MODEL                      =   i[5];
+        MAX_PATH_ELEMENT                =   i[6];
+        MAX_PATH                        =   i[7];
+        PAGESIZE                        =   i[8];
+        GRANULARITY                     =   i[9];
+    }
+
+    /**
+     * Size of the native platform {@code int} type in bytes.
+     */
+    public static final int SIZEOF_INT;
+
+    /**
+     * Size of the native platform {@code long} type in bytes.
+     */
+    public static final int SIZEOF_LONG;
+
+    /**
+     * Size of the native platform {@code size_t} type in bytes.
+     */
+    public static final int SIZEOF_SIZE_T;
+
+    /**
+     * Size of the native platform {@code pointer} type in bytes.
+     */
+    public static final int SIZEOF_POINTER;
+
+    /**
+     * Size of the native platform {@code size_t} type in bytes.
+     */
+    public static final int SIZEOF_WCHAR;
+
+
+    /**
+     * Platfrom data model {@code 32} or {@code 64} bits.
+     */
+    public static final int DATA_MODEL;
+
+    /**
+     * Maximum {@code file} path length this platfrom supports.
+     * On some platforms like {@code Microsoft Windows} this
+     * is maximum length of each {@code path} elements.
+     */
+    public static final int MAX_PATH_ELEMENT;
+
+    /**
+     * Absolute maximum {@code file} path length this platfrom supports.
+     */
+    public static final int MAX_PATH;
+
+    /**
+     * Size of the {@code memory} page allocation granularity.
+     */
+    public static final int PAGESIZE;
+
+    /**
+     * The granualarity of the starting address at wich {@code memory} pages
+     * can be allocated.
+     */
+    public static final int GRANULARITY;
+
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
Thu Mar 24 14:46:30 2011
@@ -0,0 +1,194 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons.runtime;
+
+import java.util.ArrayList;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/** The Properties class is used to obtain the various
+ * Apache Commons Runtime settings. Their default values are
+ * specified inside {@code Default.properties} file.
+ * @since Runtime 1.0
+ *
+ */
+public final class Properties
+{
+    private Properties() {
+        try {
+            String name = Properties.class.getPackage().getName() + ".Default";
+            defres = ResourceBundle.getBundle(name);
+        } catch (MissingResourceException ex) {
+            // Ignore
+        }
+        try {
+            String name = Properties.class.getPackage().getName() + ".platform." +
+                                            SystemId.getSysname() + ".Default";
+            sysres = ResourceBundle.getBundle(name);
+        } catch (MissingResourceException ex) {
+            // Ignore
+        }
+    }
+
+    private ResourceBundle defres;
+    private ResourceBundle sysres;
+    private static Properties instance;
+
+    static {
+        instance = new Properties();
+    }
+
+    /** Get resource property value.
+     * @param key Resource name to get.
+     * @param def Default value in case {@code key} was not found.
+     */
+    public static String get(String key, String def)
+    {
+        String rv = def;
+        if (instance.sysres != null) {
+            try {
+                rv = instance.sysres.getString(key);
+            } catch (MissingResourceException mx) {
+                if (instance.defres != null) {
+                    try {
+                        rv = instance.defres.getString(key);
+                    } catch (MissingResourceException ex) {
+                        // Ignore
+                    }
+                }
+            }
+        }
+        else {
+            if (instance.defres != null) {
+                try {
+                    rv = instance.defres.getString(key);
+                } catch (MissingResourceException ex) {
+                    // Ignore
+                }
+            }
+        }
+        return rv;
+    }
+
+    /** Get resource property value.
+     * @param key Resource name to get. In case the propery is not present
+     * this method returns {@code null}.
+     */
+    public static String get(String key)
+    {
+        return get(key, null);
+    }
+
+    private static int getI(String key, int def)
+    {
+        String val = get(key);
+        if (val != null)
+            return Integer.parseInt(val);
+        else
+            return def;
+    }
+
+    private static int getI(String key)
+    {
+        return getI(key, 0);
+    }
+
+    private static String getS(String key)
+    {
+        return get(key, "(error)");
+    }
+
+    private static long getL(String key, long def)
+    {
+        String val = get(key);
+        if (val != null)
+            return Long.parseLong(val);
+        else
+            return def;
+    }
+
+    private static long getL(String key)
+    {
+        return getL(key, 0L);
+    }
+
+    /* Get string array with keys that are prefixed
+     * using key.0 ... key.N
+     */
+    private static String[] getA(String key)
+    {
+        ArrayList<String> a = new ArrayList<String>();
+        int i = 0;
+        while (true) {
+            String val = get(key + "." + i++);
+            if (val == null)
+                break;
+            else
+                a.add(val);
+        }
+        // Finally load the key itself
+        String val = get(key);
+        if (val != null)
+            a.add(val);
+        if (a.size() > 0) {
+            String [] s = new String[a.size()];
+            return a.toArray(s);
+        }
+        else
+            return null;
+    }
+
+    public static String[] getArray(String key, String def)
+    {
+        String [] rv = getA(key);
+        if (rv == null && def != null) {
+            rv = new String[1];
+            rv[0] = def;
+        }
+        return rv;
+    }
+
+    //
+    // Version info section.
+    //
+    /** Major version of the runtime library
+     */
+    public static final int      VERSION_MAJOR = getI("runtime.version.major");
+    /** Minor version of the runtime library
+     */
+    public static final int      VERSION_MINOR = getI("runtime.version.minor");
+    /** Patch version of the runtime library
+     */
+    public static final int      VERSION_PATCH = getI("runtime.version.patch");
+    /** Product name of the runtime library
+     */
+    public static final String   VERSION_PNAME = getS("runtime.version.pname");
+    /** Build Time stamp.
+     */
+    public static final String   VERSION_BUILT  = getS("runtime.version.built");
+    /** Build UUID.
+     * <p>
+     * Generated at build time ensurig no two builds have the same signature.
+     * </p>
+     */
+    public static final String   VERSION_UUID  = getS("runtime.version.uuid");
+
+    /** List of the native libraries to load.
+     */
+    public static final String[] NATIVE_LIBS   = getA("library.load");
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Thu Mar 24 14:46:30 2011
@@ -59,7 +59,9 @@ ZLIB_SOURCES=\
 ASMSOURCES=\
 	@zlib_asm_sources@
 
-UNIX_SOURCES=
+UNIX_SOURCES=\
+	$(TOPDIR)/os/unix/platform.c
+
 
 LINUX_SOURCES=
 
@@ -80,10 +82,12 @@ LIBSOURCES=\
 	$(@platform@_SOURCES) \
 	$(TOPDIR)/port/bsdpath.c \
 	$(TOPDIR)/port/bsdstring.c \
+	$(TOPDIR)/port/bsdsys.c \
 	$(TOPDIR)/shared/clazz.c \
 	$(TOPDIR)/shared/bzip2.c \
 	$(TOPDIR)/shared/error.c \
 	$(TOPDIR)/shared/memory.c \
+	$(TOPDIR)/shared/native.c \
 	$(TOPDIR)/shared/string.c \
 	$(TOPDIR)/shared/buildmark.c
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h Thu Mar 24 14:46:30 2011
@@ -44,6 +44,10 @@ char *_bsd_dirname_r(const char *, char 
 #if !HAVE_DIRNAME_R
 # define dirname_r      _bsd_dirname_r
 #endif
+size_t      _bsd_getpagesize(void);
+#if !HAVE_GETPAGESIZE
+# define getpagesize    _bsd_getpagesize
+#endif
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h Thu Mar 24 14:46:30
2011
@@ -35,13 +35,16 @@ extern "C" {
  *
  */
 
+int
+AcrGetNativeCodePage(const char *cs);
+
 /** Convert java string to wide char string
  * @param env Current JNI environment.
  * @param s String to convert.
  * @remark When done use ACR_Free to free the allocated memory.
  */
 wchar_t *
-ACR_GetJavaStringW(JNI_STDENV, jstring s, wchar_t *b);
+AcrGetJavaStringW(JNI_STDENV, jstring s, wchar_t *b);
 
 /** Convert java string to platform char string.
  * @param env Current JNI environment.
@@ -49,7 +52,7 @@ ACR_GetJavaStringW(JNI_STDENV, jstring s
  * @remark When done use ACR_Free to free the allocated memory.
  */
 char *
-ACR_GetJavaStringA(JNI_STDENV, jstring s, char *b);
+AcrGetJavaStringA(JNI_STDENV, jstring s, char *b);
 
 /** Convert java string array to platform char string array.
  * @param env Current JNI environment.
@@ -57,7 +60,7 @@ ACR_GetJavaStringA(JNI_STDENV, jstring s
  * @remark When done use ACR_FreeStringArrayA to free the allocated memory.
  */
 char **
-ACR_GetJavaStringArrayA(JNI_STDENV, jobjectArray a);
+AcrGetJavaStringArrayA(JNI_STDENV, jobjectArray a);
 
 /** Convert java string array to wide char string array.
  * @param env Current JNI environment.
@@ -65,28 +68,28 @@ ACR_GetJavaStringArrayA(JNI_STDENV, jobj
  * @remark When done use ACR_FreeStringArrayW to free the allocated memory.
  */
 wchar_t **
-ACR_GetJavaStringArrayW(JNI_STDENV, jobjectArray a);
+AcrGetJavaStringArrayW(JNI_STDENV, jobjectArray a);
 
 /** Convert wchar_t to java string
  * @param env Current JNI environment.
  * @param s String to convert.
  */
 jstring
-ACR_NewJavaStringW(JNI_STDENV, const wchar_t *s);
+AcrNewJavaStringW(JNI_STDENV, const wchar_t *s);
 
 /** Convert platform string to java string
  * @param env Current JNI environment.
  * @param s String to convert.
  */
 jstring
-ACR_NewJavaStringA(JNI_STDENV, const char *s);
+AcrNewJavaStringA(JNI_STDENV, const char *s);
 
 /** Convert UTF-8 encoded string to java string
  * @param env Current JNI environment.
  * @param s String to convert.
  */
 jstring
-ACR_NewJavaStringU(JNI_STDENV, const char *s);
+AcrNewJavaStringU(JNI_STDENV, const char *s);
 
 /**
  * Convert the multipart string to Java String array.
@@ -95,7 +98,7 @@ ACR_NewJavaStringU(JNI_STDENV, const cha
  * @return Java string array.
  */
 jobjectArray
-ACR_MszStrToStringArrayA(JNI_STDENV, const char *s);
+AcrMszStrToStringArrayA(JNI_STDENV, const char *s);
 
 /**
  * Convert the multipart string to Java String array.
@@ -103,7 +106,7 @@ ACR_MszStrToStringArrayA(JNI_STDENV, con
  * @return Java string array.
  */
 jobjectArray
-ACR_MszStrToStringArrayW(JNI_STDENV, const wchar_t *s);
+AcrMszStrToStringArrayW(JNI_STDENV, const wchar_t *s);
 
 #ifdef __cplusplus
 }

Added: commons/sandbox/runtime/trunk/src/main/native/port/bsdsys.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/port/bsdsys.c?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/port/bsdsys.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/port/bsdsys.c Thu Mar 24 14:46:30 2011
@@ -0,0 +1,46 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#include "acr/port.h"
+
+#if !defined(_WINDOWS)
+#include <sys/time.h>
+#endif
+
+#if defined(_WINDOWS)
+extern LPSYSTEM_INFO _pr_osinf;
+size_t _bsd_getpagesize()
+{
+    if (_pr_osinf == 0)
+        GetSystemInfo(_pr_osinf);
+    return _pr_osinf->dwPageSize;
+}
+#elif defined(_SC_PAGESIZE)
+size_t _bsd_getpagesize()
+{
+    return (size_t)sysconf(_SC_PAGESIZE);
+}
+#elif defined(_SC_PAGE_SIZE)
+size_t _bsd_getpagesize()
+{
+    return (size_t)sysconf(_SC_PAGE_SIZE);
+}
+#else
+size_t _bsd_getpagesize()
+{
+    return 8192;
+}
+#endif

Propchange: commons/sandbox/runtime/trunk/src/main/native/port/bsdsys.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Thu Mar 24 14:46:30 2011
@@ -153,7 +153,7 @@ ACR_CLASS_LOADER(Class)
 {
     int rv;
 
-    if ((rv = ApLoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+    if ((rv = AcrLoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
         return rv;
     J_LOAD_METHOD(0000);
     J_LOAD_METHOD(0001);
@@ -253,7 +253,7 @@ AcrGetOptionalClass(int clazz)
 jobjectArray
 AcrNewCoreObjectArray(JNI_STDENV, int clazz, jsize len)
 {
-    jclass cc = ACR_GetCoreClass(clazz);
+    jclass cc = AcrGetCoreClass(clazz);
     if (cc)
         return (*_E)->NewObjectArray(_E, len, cc, NULL);
     else

Added: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/native.c?rev=1084975&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Thu Mar 24 14:46:30 2011
@@ -0,0 +1,31 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#include "acr/string.h"
+
+ACR_JNI_EXPORT(jboolean, Native, isdbg0)(JNI_STDARGS)
+{
+#if defined(DEBUG) || defined(_DEBUG)
+    return JNI_TRUE;
+#else
+    return JNI_FALSE;
+#endif
+}
+
+ACR_JNI_EXPORT(jboolean, Native, init0)(JNI_STDARGS)
+{
+    return JNI_TRUE;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Thu Mar 24 14:46:30 2011
@@ -18,7 +18,7 @@
 #include "acr/memory.h"
 #include "acr/clazz.h"
 
-extern int acr_native_codepage;
+int acr_native_codepage;
 
 J_DECLARE_CLAZZ = {
     NULL,

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java?rev=1084975&r1=1084974&r2=1084975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
Thu Mar 24 14:46:30 2011
@@ -29,7 +29,7 @@ public class TestUtils
     @BeforeClass
     public void setUp()
     {
-        // code that will be invoked when this test is instantiated
+        Assert.assertTrue(Loader.load());
     }
 
     @Test(groups = { "utils" })



Mime
View raw message