summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/os
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-09-19 13:48:45 +0200
committerSven Gothel <[email protected]>2011-09-19 13:48:45 +0200
commit69d537e4f9e6e5d206719723094ea192ab51ef43 (patch)
treee9611865f1eec76d13fe4725dd3ad4f5023f49c7 /src/java/com/jogamp/common/os
parent0711792f00e462e340e0d3731dfe71b0e8ec6022 (diff)
Enhancement/GenericStyle:
- NativeLibrary: - add isValidNativeLibraryName(..) - generic style - Platform - add getOSAndArch(), getOSAndArch(..) - IOUtil - add getClassFileName(..) - add getBasename(..) - add getDirname(..) - added doc - ReflectionUtil - generic style
Diffstat (limited to 'src/java/com/jogamp/common/os')
-rwxr-xr-xsrc/java/com/jogamp/common/os/NativeLibrary.java71
-rw-r--r--src/java/com/jogamp/common/os/Platform.java119
2 files changed, 162 insertions, 28 deletions
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<String> 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<String> 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 <br>
+ *
+ * @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<prefixes.length; i++) {
+ if (libNameLC.startsWith(prefixes[i])) {
+ for(int j=0; j<suffixes.length; j++) {
+ if (libNameLC.endsWith(suffixes[j])) {
+ final int s = prefixes[i].length();
+ final int e = suffixes[j].length();
+ return libName.substring(s, libName.length()-e);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
/** Given the base library names (no prefixes/suffixes) for the
various platforms, enumerate the possible locations and names of
the indicated native library on the system. */
- private static List enumerateLibraryPaths(String windowsLibName,
- String unixLibName,
- String macOSXLibName,
- boolean searchSystemPathFirst,
- ClassLoader loader) {
- List paths = new ArrayList();
+ private static List<String> enumerateLibraryPaths(String windowsLibName,
+ String unixLibName,
+ String macOSXLibName,
+ boolean searchSystemPathFirst,
+ ClassLoader loader) {
+ List<String> paths = new ArrayList<String>();
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<String>() {
+ 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<String>() {
+ 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<String> 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<Object>() {
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<String>() {
+ 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<String>() {
+ public String run() {
return System.getProperty("java.runtime.name");
}
});
@@ -347,6 +349,111 @@ public class Platform {
}
/**
+ * Returns the GlueGen common name for the currently running OSType and CPUType
+ * as implemented in the build system in 'gluegen-cpptasks-base.xml'.<br>
+ *
+ * @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'.<br>
+ *
+ * A list of currently supported <code>os.and.arch</code> strings:
+ * <ul>
+ * <li>freebsd-i586</li>
+ * <li>freebsd-amd64</li>
+ * <li>hpux-hppa</li>
+ * <li>linux-amd64</li>
+ * <li>linux-ia64</li>
+ * <li>linux-i586</li>
+ * <li>linux-armv7</li>
+ * <li>android-armv7</li>
+ * <li>macosx-universal</li>
+ * <li>solaris-sparc</li>
+ * <li>solaris-sparcv9</li>
+ * <li>solaris-amd64</li>
+ * <li>solaris-i586</li>
+ * <li>windows-amd64</li>
+ * <li>windows-i586</li>
+ * </ul>
+ * @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.
*/
public static String getJavaVendor() {
@@ -411,6 +518,6 @@ public class Platform {
*/
public static MachineDescription getMachineDescription() {
return machineDescription;
- }
+ }
}