From 97a31a24f5a33cade471923111f1a437dcfc253d Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 16 Dec 2005 01:20:17 +0000 Subject: [PATCH] add native version/build date --- bindings/java/src/jni/javasigar.c | 14 ++++++++++ .../java/src/net/hyperic/sigar/Sigar.java | 27 ++++++++++++++++--- .../src/net/hyperic/sigar/cmd/Version.java | 12 +++++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/bindings/java/src/jni/javasigar.c b/bindings/java/src/jni/javasigar.c index 0814371b..f64179a3 100644 --- a/bindings/java/src/jni/javasigar.c +++ b/bindings/java/src/jni/javasigar.c @@ -197,6 +197,20 @@ JNIEXPORT jstring SIGAR_JNI(Sigar_formatSize) return JENV->NewStringUTF(env, buf); } +JNIEXPORT jstring SIGAR_JNI(Sigar_getNativeVersion) +(JNIEnv *env, jclass cls) +{ + sigar_version_t *version = sigar_version_get(); + return JENV->NewStringUTF(env, version->version); +} + +JNIEXPORT jstring SIGAR_JNI(Sigar_getNativeBuildDate) +(JNIEnv *env, jclass cls) +{ + sigar_version_t *version = sigar_version_get(); + return JENV->NewStringUTF(env, version->build_date); +} + JNIEXPORT void SIGAR_JNI(Sigar_open) (JNIEnv *env, jobject obj) { diff --git a/bindings/java/src/net/hyperic/sigar/Sigar.java b/bindings/java/src/net/hyperic/sigar/Sigar.java index 2700331c..fda5f857 100644 --- a/bindings/java/src/net/hyperic/sigar/Sigar.java +++ b/bindings/java/src/net/hyperic/sigar/Sigar.java @@ -24,17 +24,27 @@ public class Sigar implements SigarProxy { public static final long FIELD_NOTIMPL = -1; /** - * The Sigar version in String form. + * The Sigar java version. */ public static final String VERSION_STRING = SigarVersion.VERSION_STRING; /** - * The date on which the Sigar binaries were built. + * The Sigar native version. + */ + public static final String NATIVE_VERSION_STRING; + + /** + * The date on which sigar.jar was built. */ public static final String BUILD_DATE = SigarVersion.BUILD_DATE; + /** + * The date on which the sigar native binary was built. + */ + public static final String NATIVE_BUILD_DATE; + private static boolean enableLogging = "true".equals(System.getProperty("sigar.nativeLogging")); @@ -50,10 +60,11 @@ public class Sigar implements SigarProxy { private static SigarProxy instance = null; static { + boolean loaded = false; try { loadLibrary(); + loaded = true; } catch (SigarException e) { - loadError = "Sigar.load: " + e.getMessage(); try { SigarLog.debug(loadError, e); } catch (NoClassDefFoundError ne) { @@ -62,6 +73,13 @@ public class Sigar implements SigarProxy { e.printStackTrace(); } } + if (loaded) { + NATIVE_VERSION_STRING = getNativeVersion(); + NATIVE_BUILD_DATE = getNativeBuildDate(); + } + else { + NATIVE_VERSION_STRING = NATIVE_BUILD_DATE = "N/A"; + } } public static void load() throws SigarException { @@ -98,6 +116,9 @@ public class Sigar implements SigarProxy { */ public static native String formatSize(long size); + private static native String getNativeVersion(); + private static native String getNativeBuildDate(); + /** * Allocate and initialize the native Sigar object. */ diff --git a/bindings/java/src/net/hyperic/sigar/cmd/Version.java b/bindings/java/src/net/hyperic/sigar/cmd/Version.java index ae1d452f..b8d50f21 100644 --- a/bindings/java/src/net/hyperic/sigar/cmd/Version.java +++ b/bindings/java/src/net/hyperic/sigar/cmd/Version.java @@ -48,8 +48,16 @@ public class Version extends SigarCommandBase { public static void printInfo(PrintStream os) { String fqdn = getFQDN(); String host = getHostName(); - os.println("Sigar version......." + Sigar.VERSION_STRING); - os.println("Build date.........." + Sigar.BUILD_DATE); + + String version = + "java=" + Sigar.VERSION_STRING + + ", native=" + Sigar.NATIVE_VERSION_STRING; + String build = + "java=" + Sigar.BUILD_DATE + + ", native=" + Sigar.NATIVE_BUILD_DATE; + + os.println("Sigar version......." + version); + os.println("Build date.........." + build); os.println("Archlib............." + SigarLoader.getNativeLibraryName()); os.println("Current fqdn........" + fqdn);