From 69d537e4f9e6e5d206719723094ea192ab51ef43 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 19 Sep 2011 13:48:45 +0200 Subject: Enhancement/GenericStyle: - NativeLibrary: - add isValidNativeLibraryName(..) - generic style - Platform - add getOSAndArch(), getOSAndArch(..) - IOUtil - add getClassFileName(..) - add getBasename(..) - add getDirname(..) - added doc - ReflectionUtil - generic style --- src/java/com/jogamp/common/os/NativeLibrary.java | 71 +++++++++----- src/java/com/jogamp/common/os/Platform.java | 119 +++++++++++++++++++++-- 2 files changed, 162 insertions(+), 28 deletions(-) (limited to 'src/java/com/jogamp/common/os') diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index 1df0e61..f5c3264 100755 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -39,6 +39,7 @@ package com.jogamp.common.os; +import com.jogamp.common.util.IOUtil; import com.jogamp.gluegen.runtime.NativeLibLoader; import jogamp.common.Debug; import jogamp.common.os.MacOSXDynamicLinkerImpl; @@ -162,14 +163,14 @@ public class NativeLibrary implements DynamicLookupHelper { String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader, boolean global) { - List possiblePaths = enumerateLibraryPaths(windowsLibName, - unixLibName, - macOSXLibName, - searchSystemPathFirst, - loader); + List possiblePaths = enumerateLibraryPaths(windowsLibName, + unixLibName, + macOSXLibName, + searchSystemPathFirst, + loader); // Iterate down these and see which one if any we can actually find. - for (Iterator iter = possiblePaths.iterator(); iter.hasNext(); ) { - String path = (String) iter.next(); + for (Iterator iter = possiblePaths.iterator(); iter.hasNext(); ) { + String path = iter.next(); if (DEBUG) { System.err.println("Trying to load " + path); } @@ -232,15 +233,41 @@ public class NativeLibrary implements DynamicLookupHelper { dynLink.closeLibrary(handle); } + /** + * Comparison of prefix and suffix of the given libName's basename + * is performed case insensitive
+ * + * @param libName the full path library name with prefix and suffix + * @param isLowerCaseAlready indicates if libName is already lower-case + * + * @return basename of libName w/o path, ie. /usr/lib/libDrinkBeer.so -> DrinkBeer on Unix systems, but null on Windows. + */ + public static String isValidNativeLibraryName(String libName, boolean isLowerCaseAlready) { + libName = IOUtil.getBasename(libName); + final String libNameLC = isLowerCaseAlready ? libName : libName.toLowerCase(); + for(int i=0; i enumerateLibraryPaths(String windowsLibName, + String unixLibName, + String macOSXLibName, + boolean searchSystemPathFirst, + ClassLoader loader) { + List paths = new ArrayList(); String libName = selectName(windowsLibName, unixLibName, macOSXLibName); if (libName == null) { return paths; @@ -274,8 +301,8 @@ public class NativeLibrary implements DynamicLookupHelper { // Add entries from java.library.path String javaLibraryPath = - (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction() { + public String run() { return System.getProperty("java.library.path"); } }); @@ -288,8 +315,8 @@ public class NativeLibrary implements DynamicLookupHelper { // Add current working directory String userDir = - (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction() { + public String run() { return System.getProperty("user.dir"); } }); @@ -372,7 +399,7 @@ public class NativeLibrary implements DynamicLookupHelper { return res; } - private static void addPaths(String path, String[] baseNames, List paths) { + private static void addPaths(String path, String[] baseNames, List paths) { for (int j = 0; j < baseNames.length; j++) { paths.add(path + File.separator + baseNames[j]); } @@ -384,7 +411,7 @@ public class NativeLibrary implements DynamicLookupHelper { if (loader == null) return null; if (!initializedFindLibraryMethod) { - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { findLibraryMethod = ClassLoader.class.getDeclaredMethod("findLibrary", @@ -400,10 +427,10 @@ public class NativeLibrary implements DynamicLookupHelper { } if (findLibraryMethod != null) { try { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction() { + public String run() { try { - return findLibraryMethod.invoke(loader, new Object[] { libName }); + return (String) findLibraryMethod.invoke(loader, new Object[] { libName }); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index a1e8bd5..78daf4c 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -40,8 +40,7 @@ import jogamp.common.os.MachineDescriptionRuntime; /** * Utility class for querying platform specific properties. - * @author Michael Bien - * @author Sven Gothel + * @author Michael Bien, Sven Gothel, et. al. */ public class Platform { @@ -130,8 +129,9 @@ public class Platform { private static final MachineDescription machineDescription; + private static final String os_and_arch; + static { - // We don't seem to need an AccessController.doPrivileged() block // here as these system properties are visible even to unsigned // applets @@ -182,6 +182,8 @@ public class Platform { } OS_TYPE = getOSTypeImpl(); + os_and_arch = getOSAndArch(OS_TYPE, CPU_ARCH); + MachineDescription md = MachineDescriptionRuntime.getRuntime(); if(null == md) { MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic(); @@ -263,8 +265,8 @@ public class Platform { private static String getJavaRuntimeNameImpl() { // the fast path, check property Java SE instead of traversing through the ClassLoader - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction() { + public String run() { return System.getProperty("java.runtime.name"); } }); @@ -346,6 +348,111 @@ public class Platform { return CPU_ARCH; } + /** + * Returns the GlueGen common name for the currently running OSType and CPUType + * as implemented in the build system in 'gluegen-cpptasks-base.xml'.
+ * + * @see #getOSAndArch(OSType, CPUType) + */ + public static String getOSAndArch() { + return os_and_arch; + } + + /** + * Returns the GlueGen common name for the given OSType and CPUType + * as implemented in the build system in 'gluegen-cpptasks-base.xml'.
+ * + * A list of currently supported os.and.arch strings: + *
    + *
  • freebsd-i586
  • + *
  • freebsd-amd64
  • + *
  • hpux-hppa
  • + *
  • linux-amd64
  • + *
  • linux-ia64
  • + *
  • linux-i586
  • + *
  • linux-armv7
  • + *
  • android-armv7
  • + *
  • macosx-universal
  • + *
  • solaris-sparc
  • + *
  • solaris-sparcv9
  • + *
  • solaris-amd64
  • + *
  • solaris-i586
  • + *
  • windows-amd64
  • + *
  • windows-i586
  • + *
+ * @return + */ + public static String getOSAndArch(OSType osType, CPUType cpuType) { + String _os_and_arch; + + switch( CPU_ARCH ) { + case X86_32: + _os_and_arch = "i586"; + break; + case ARM: + _os_and_arch = "amdv7"; // TODO: sync with gluegen-cpptasks-base.xml + break; + case ARMv5: + _os_and_arch = "amdv5"; + break; + case ARMv6: + _os_and_arch = "amdv5"; + break; + case ARMv7: + _os_and_arch = "amdv7"; + break; + case SPARC_32: + _os_and_arch = "sparc"; + break; + case PPC: + _os_and_arch = "ppc"; // TODO: sync with gluegen-cpptasks-base.xml + break; + case X86_64: + _os_and_arch = "amd64"; + break; + case IA64: + _os_and_arch = "ia64"; + break; + case SPARCV9_64: + _os_and_arch = "sparcv9"; + break; + case PA_RISC2_0: + _os_and_arch = "risc2.0"; // TODO: sync with gluegen-cpptasks-base.xml + break; + default: + throw new InternalError("Complete case block"); + } + switch(OS_TYPE) { + case ANDROID: + _os_and_arch = "android-" + _os_and_arch; + break; + case MACOS: + _os_and_arch = "macosx-universal"; + break; + case WINDOWS: + _os_and_arch = "windows-" + _os_and_arch; + break; + case OPENKODE: + _os_and_arch = "openkode-" + _os_and_arch; // TODO: think about that + break; + case LINUX: + _os_and_arch = "linux-" + _os_and_arch; + break; + case FREEBSD: + _os_and_arch = "freebsd-" + _os_and_arch; + break; + case SUNOS: + _os_and_arch = "solaris-" + _os_and_arch; + break; + case HPUX: + _os_and_arch = "hpux-hppa"; // TODO: really only hppa ? + break; + default: + throw new InternalError("Complete case block"); + } + return _os_and_arch; + } + /** * Returns the JAVA. */ @@ -411,6 +518,6 @@ public class Platform { */ public static MachineDescription getMachineDescription() { return machineDescription; - } + } } -- cgit v1.2.3