commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r764811 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/JavaVersion.java test/org/apache/commons/runtime/TestOS.java
Date Tue, 14 Apr 2009 14:58:15 GMT
Author: mturk
Date: Tue Apr 14 14:58:15 2009
New Revision: 764811

URL: http://svn.apache.org/viewvc?rev=764811&view=rev
Log:
Add JavaVersion class that uses system properties to match our OS class
for system name and processor. Used when extracting the native libraries from the .jar to
find
the correct path of dynamic shared library

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/JavaVersion.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/JavaVersion.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/JavaVersion.java?rev=764811&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/JavaVersion.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/JavaVersion.java
Tue Apr 14 14:58:15 2009
@@ -0,0 +1,91 @@
+/* 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.Properties;
+
+/** JavaVersion
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class JavaVersion {
+
+    private Properties props;
+
+    public JavaVersion() {
+        props = System.getProperties();
+    }
+
+    /**
+     * Name of the operating system implementation.
+     */
+    public String getSysname() {
+        String name = props.getProperty("os.name");
+        String platform = "unknown";
+
+        if (name.startsWith("Windows"))
+            platform = "windows";
+        else if (name.startsWith("Mac OS"))
+            platform = "darwin";
+        else if (name.endsWith("BSD"))
+            platform = "bsd";
+        else if (name.equals("Linux"))
+            platform = "linux";
+        else if (name.equals("Solaris"))
+            platform = "solaris";
+        else if (name.equals("SunOS"))
+            platform = "solaris";
+        else if (name.equals("HP-UX"))
+            platform = "hpux";
+        else if (name.equals("AIX"))
+            platform = "aix";
+
+        return platform;
+    }
+
+    /**
+     * Proccessor used.
+     */
+    public String getProcessor()
+    {
+        String cpu;
+        String arch = props.getProperty("os.arch");
+        String data = props.getProperty("sun.arch.data.model");
+
+        if (data == null) {
+            data = props.getProperty("com.ibm.vm.bitmode");
+        }
+        if (data == null) {
+            data = "32";
+        }
+        if (arch.endsWith("86"))
+            cpu = "ia" + data;
+        else if (arch.startsWith("PA_RISC"))
+            cpu = "pa" + data;
+        else if (arch.startsWith("IA64"))
+            cpu = "ia64";
+        else if (arch.startsWith("sparc"))
+            cpu = "sparc" + data;
+        else if (arch.equals("amd64"))
+            cpu = "x86_64";
+        else
+            cpu = arch;
+        return cpu;
+    }
+
+}

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

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java?rev=764811&r1=764810&r2=764811&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java Tue Apr
14 14:58:15 2009
@@ -58,6 +58,10 @@
         System.out.println("Processor  " + OS.getProcessor());
         System.out.println("Data Model " + OS.getDataModel());
         System.out.println("Hardware   " + OS.getHardwarePlatform());
+        JavaVersion v = new JavaVersion();
+        System.out.println("JavaVerion:");
+        System.out.println("Name       " + v.getSysname());
+        System.out.println("Processor  " + v.getProcessor());
 
     }
 



Mime
View raw message