aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-11-18 01:38:42 +0100
committerMichael Bien <[email protected]>2010-11-18 01:38:42 +0100
commit1e0288b397dfd914532c0f0cde850f4e5c5bc91d (patch)
tree966939bd5c6dca6f5910f4e91435710e248ea912 /src/java/com
parentdeedd4f67b19919d4a231224bfa6a7edbd36e608 (diff)
Version info debugging works now even without native libs.
- Platform is now useable without gluegen-rt libs in library path. - JogampVersion: fixed equals, added Impl url to manifest. - VersionUtil: getManifest should be now more relieable and passed all manual tests, e.g java jar lib.jar without specified classpath.
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/jogamp/common/GlueGenVersion.java5
-rw-r--r--src/java/com/jogamp/common/os/Platform.java37
-rw-r--r--src/java/com/jogamp/common/util/JogampVersion.java75
-rw-r--r--src/java/com/jogamp/common/util/VersionUtil.java50
4 files changed, 96 insertions, 71 deletions
diff --git a/src/java/com/jogamp/common/GlueGenVersion.java b/src/java/com/jogamp/common/GlueGenVersion.java
index e73d4bb..c59e96b 100644
--- a/src/java/com/jogamp/common/GlueGenVersion.java
+++ b/src/java/com/jogamp/common/GlueGenVersion.java
@@ -34,7 +34,7 @@ import java.util.jar.Manifest;
public class GlueGenVersion extends JogampVersion {
- protected static GlueGenVersion jogampCommonVersionInfo;
+ protected static volatile GlueGenVersion jogampCommonVersionInfo;
protected GlueGenVersion(String packageName, Manifest mf) {
super(packageName, mf);
@@ -45,8 +45,7 @@ public class GlueGenVersion extends JogampVersion {
synchronized(GlueGenVersion.class) {
if( null == jogampCommonVersionInfo ) {
final String packageName = "com.jogamp.common";
- final String fullClazzName = GlueGenVersion.class.getName();
- final Manifest mf = VersionUtil.getManifest(GlueGenVersion.class.getClassLoader(), fullClazzName);
+ final Manifest mf = VersionUtil.getManifest(GlueGenVersion.class.getClassLoader(), "com.jogamp.common");
jogampCommonVersionInfo = new GlueGenVersion(packageName, mf);
}
}
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index aac72af..c6075e3 100644
--- a/src/java/com/jogamp/common/os/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -59,8 +59,7 @@ public class Platform {
private static final int pointerSizeInBits;
static {
- NativeLibrary.ensureNativeLibLoaded();
-
+
// We don't seem to need an AccessController.doPrivileged() block
// here as these system properties are visible even to unsigned
// applets
@@ -72,16 +71,29 @@ public class Platform {
JAVA_VERSION = System.getProperty("java.version");
NEWLINE = System.getProperty("line.separator");
- pointerSizeInBits = getPointerSizeInBitsImpl();
- is32Bit = initArch();
JAVA_SE = initIsJavaSE();
LITTLE_ENDIAN = initByteOrder();
+
+ boolean libsLoaded = true;
+ try{
+ NativeLibrary.ensureNativeLibLoaded();
+ }catch (UnsatisfiedLinkError err){
+ libsLoaded = false;
+ }
+
+ if(libsLoaded) {
+ pointerSizeInBits = getPointerSizeInBitsImpl();
+ }else{
+ pointerSizeInBits = -1;
+ }
+
+ is32Bit = initArch();
+
}
private Platform() {}
private static boolean initArch() throws RuntimeException {
- // Try to use Sun's sun.ARCH.data.model first ..
if ( 32 == pointerSizeInBits || 64 == pointerSizeInBits ) {
return 32 == pointerSizeInBits;
}else {
@@ -188,28 +200,28 @@ public class Platform {
}
/**
- * Returns the JAVA vendor
+ * Returns the JAVA.
*/
public static String getJavaVendor() {
return JAVA_VENDOR;
}
/**
- * Returns the JAVA vendor url
+ * Returns the JAVA vendor url.
*/
public static String getJavaVendorURL() {
return JAVA_VENDOR_URL;
}
/**
- * Returns the JAVA vendor
+ * Returns the JAVA vendor.
*/
public static String getJavaVersion() {
return JAVA_VERSION;
}
/**
- * Returns the JAVA vendor
+ * Returns the JAVA vendor.
*/
public static String getNewline() {
return NEWLINE;
@@ -222,6 +234,13 @@ public class Platform {
return is32Bit;
}
+ /**
+ * Returns true if this JVM is a 64bit JVM.
+ */
+ public static boolean is64Bit() {
+ return !is32Bit;
+ }
+
public static int getPointerSizeInBits() {
return pointerSizeInBits;
}
diff --git a/src/java/com/jogamp/common/util/JogampVersion.java b/src/java/com/jogamp/common/util/JogampVersion.java
index 914da3d..aae6d77 100644
--- a/src/java/com/jogamp/common/util/JogampVersion.java
+++ b/src/java/com/jogamp/common/util/JogampVersion.java
@@ -39,6 +39,8 @@ public class JogampVersion {
public static Attributes.Name IMPLEMENTATION_BRANCH = new Attributes.Name("Implementation-Branch");
public static Attributes.Name IMPLEMENTATION_COMMIT = new Attributes.Name("Implementation-Commit");
+
+ protected static final String SEPERATOR = "-----------------------------------------------------------------------------------------------------";
private String packageName;
private Manifest mf;
@@ -59,8 +61,8 @@ public class JogampVersion {
}
public final boolean equals(Object o) {
- if (o instanceof GlueGenVersion) {
- return mf.equals(((GlueGenVersion) o).getManifest());
+ if (o instanceof JogampVersion) {
+ return mf.equals(((JogampVersion) o).getManifest());
}
return false;
}
@@ -119,6 +121,10 @@ public class JogampVersion {
return this.getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR_ID);
}
+ public final String getImplementationURL() {
+ return this.getAttribute(Attributes.Name.IMPLEMENTATION_URL);
+ }
+
public final String getImplementationVersion() {
return this.getAttribute(Attributes.Name.IMPLEMENTATION_VERSION);
}
@@ -139,63 +145,44 @@ public class JogampVersion {
return VersionUtil.getFullManifestInfo(getManifest(), sb);
}
+ public StringBuffer getPlatformInfo(StringBuffer sb) {
+ return VersionUtil.getPlatformInfo(sb);
+ }
+
public StringBuffer getManifestInfo(StringBuffer sb) {
if(null==sb) {
sb = new StringBuffer();
}
- sb.append("Package: ");
- sb.append(getPackageName());
- sb.append(Platform.getNewline());
- sb.append("Extension Name: ");
- sb.append(getExtensionName());
- sb.append(Platform.getNewline());
- sb.append("Specification Title: ");
- sb.append(getSpecificationTitle());
- sb.append(Platform.getNewline());
- sb.append("Specification Vendor: ");
- sb.append(getSpecificationVendor());
- sb.append(Platform.getNewline());
- sb.append("Specification Version: ");
- sb.append(getSpecificationVersion());
- sb.append(Platform.getNewline());
- sb.append("Implementation Title: ");
- sb.append(getImplementationTitle());
- sb.append(Platform.getNewline());
- sb.append("Implementation Vendor: ");
- sb.append(getImplementationVendor());
- sb.append(Platform.getNewline());
- sb.append("Implementation Vendor ID: ");
- sb.append(getImplementationVendorID());
- sb.append(Platform.getNewline());
- sb.append("Implementation Version: ");
- sb.append(getImplementationVersion());
- sb.append(Platform.getNewline());
- sb.append("Implementation Branch: ");
- sb.append(getImplementationBranch());
- sb.append(Platform.getNewline());
- sb.append("Implementation Commit: ");
- sb.append(getImplementationCommit());
- sb.append(Platform.getNewline());
+ String nl = Platform.getNewline();
+ sb.append("Package: ").append(getPackageName()).append(nl);
+ sb.append("Extension Name: ").append(getExtensionName()).append(nl);
+ sb.append("Specification Title: ").append(getSpecificationTitle()).append(nl);
+ sb.append("Specification Vendor: ").append(getSpecificationVendor()).append(nl);
+ sb.append("Specification Version: ").append(getSpecificationVersion()).append(nl);
+ sb.append("Implementation Title: ").append(getImplementationTitle()).append(nl);
+ sb.append("Implementation Vendor: ").append(getImplementationVendor()).append(nl);
+ sb.append("Implementation Vendor ID: ").append(getImplementationVendorID()).append(nl);
+ sb.append("Implementation URL: ").append(getImplementationURL()).append(nl);
+ sb.append("Implementation Version: ").append(getImplementationVersion()).append(nl);
+ sb.append("Implementation Branch: ").append(getImplementationBranch()).append(nl);
+ sb.append("Implementation Commit: ").append(getImplementationCommit()).append(nl);
return sb;
}
- public StringBuffer toStringBuffer(StringBuffer sb) {
+ public StringBuffer toString(StringBuffer sb) {
if(null==sb) {
sb = new StringBuffer();
}
- sb.append(Platform.getNewline());
- sb.append("-----------------------------------------------------------------------------------------------------");
- sb.append(Platform.getNewline());
- VersionUtil.getPlatformInfo(sb);
- sb.append(Platform.getNewline());
+ String nl = Platform.getNewline();
+ sb.append(SEPERATOR).append(nl);
getManifestInfo(sb);
- sb.append("-----------------------------------------------------------------------------------------------------");
- sb.append(Platform.getNewline());
+ sb.append(SEPERATOR).append(nl);
return sb;
}
+
public String toString() {
- return toStringBuffer(null).toString();
+ return toString(null).toString();
}
}
diff --git a/src/java/com/jogamp/common/util/VersionUtil.java b/src/java/com/jogamp/common/util/VersionUtil.java
index a4e625e..ac4d0b8 100644
--- a/src/java/com/jogamp/common/util/VersionUtil.java
+++ b/src/java/com/jogamp/common/util/VersionUtil.java
@@ -31,9 +31,8 @@ package com.jogamp.common.util;
import com.jogamp.common.os.Platform;
import java.io.IOException;
-import java.net.JarURLConnection;
import java.net.URL;
-import java.net.URLConnection;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.Set;
import java.util.jar.Attributes;
@@ -41,32 +40,53 @@ import java.util.jar.Manifest;
public class VersionUtil {
+ /**
+ * Appends environment information like OS, JVM and CPU architecture properties to the StringBuffer.
+ */
public static StringBuffer getPlatformInfo(StringBuffer sb) {
- if(null==sb) {
+ if(null == sb) {
sb = new StringBuffer();
}
- sb.append("Platform: ").append(Platform.getOS()).append(" ").append(Platform.getOSVersion()).append(" (os), ").append(Platform.getArch()).append(" (arch)");
+ // environment
+ sb.append("Platform: ").append(Platform.getOS()).append(' ').append(Platform.getOSVersion()).append(" (os), ");
+ sb.append(Platform.getArch()).append(" (arch) ").append(Runtime.getRuntime().availableProcessors()).append(" cores");
sb.append(Platform.getNewline());
- sb.append("Platform: littleEndian ").append(Platform.isLittleEndian()).append(", 32Bit ").append(Platform.is32Bit()).append(", a-ptr bit-size ").append(Platform.getPointerSizeInBits());
+
+ // arch
+ sb.append("Platform: littleEndian ").append(Platform.isLittleEndian()).append(", 32Bit ");
+ sb.append(Platform.is32Bit()).append(", a-ptr bit-size ").append(Platform.getPointerSizeInBits());
sb.append(Platform.getNewline());
- sb.append("Platform: Java ").append(Platform.getJavaVersion()).append(", ").append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL()).append(", is JavaSE: ").append(Platform.isJavaSE());
+
+ // JVM/JRE
+ sb.append("Platform: Java ").append(Platform.getJavaVersion()).append(", ").append(System.getProperty("java.vm.name")).append(", ");
+ sb.append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL()).append(", is JavaSE: ").append(Platform.isJavaSE());
sb.append(Platform.getNewline());
return sb;
}
- public static Manifest getManifest(ClassLoader cl, String fullClazzName) {
- String fullClazzFileName = "/" + fullClazzName.replace('.', '/') + ".class" ;
- URL url = cl.getClass().getResource(fullClazzFileName);
- Manifest mf = null;
+ /**
+ * Returns the manifest of the jar which contains the specified extension.
+ * The provided ClassLoader is used for resource loading.
+ * @param cl A ClassLoader which should find the manifest.
+ * @param extension The value of the 'Extension-Name' jar-manifest attribute; used to identify the manifest.
+ * @return the requested manifest or null when not found.
+ */
+ public static Manifest getManifest(ClassLoader cl, String extension) {
try {
- URLConnection urlConn = url.openConnection();
- if(urlConn instanceof JarURLConnection) {
- mf = ((JarURLConnection)urlConn).getManifest();
+ Enumeration resources = cl.getResources("META-INF/MANIFEST.MF");
+ while (resources.hasMoreElements()) {
+ Manifest manifest = new Manifest(((URL)resources.nextElement()).openStream());
+ Attributes attributes = manifest.getMainAttributes();
+ if(attributes != null && extension.equals(attributes.getValue(Attributes.Name.EXTENSION_NAME))) {
+ return manifest;
+ }
}
- } catch (IOException ex) { }
- return mf;
+ } catch (IOException ex) {
+ throw new RuntimeException("Unable to read manifest.", ex);
+ }
+ return null;
}
public static StringBuffer getFullManifestInfo(Manifest mf, StringBuffer sb) {