package net.hyperic.sigar.cmd;

import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;

import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;

import net.hyperic.sigar.SigarLoader;
/**
 * Display Sigar, java and system version information.
 */
public class Version extends SigarCommandBase {
    private static String[] SYS_PROPS = {
        "os.name",
        "os.version",
        "os.arch",
        "java.vm.version",
        "java.vm.vendor",
        "sun.arch.data.model",
        "sun.cpu.endian",
        "sun.os.patch.level",
    };

    public Version(Shell shell) {
        super(shell);
    }

    public Version() {
        super();
    }

    public String getUsageShort() {
        return "Display sigar version";
    }

    private static String getHostName() {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            return "unknown";
        }
    }

    private static String getFQDN() {
        try {
            return Sigar.getInstance().getFQDN();
        } catch (SigarException e) {
            return "unknown";
        }
    }

    public static void printInfo(PrintStream os) {
        String fqdn = getFQDN();
        String host = getHostName();
        os.println("Sigar version=" + Sigar.VERSION_STRING);
        os.println("Sigar build date=" + Sigar.BUILD_DATE);
        os.println("Sigar archlib=" +
                   SigarLoader.getNativeLibraryName());
        os.println("Current fqdn=" + fqdn);
        if (!fqdn.equals(host)) {
            os.println("Current host=" + host);
        }
        os.println("");

        for (int i=0; i<SYS_PROPS.length; i++) {
            String prop = SYS_PROPS[i];
            os.println(prop + "=" + 
                       System.getProperty(prop));
        }
    }

    public void output(String[] args) {
        printInfo(this.out);
    }

    public static void main(String[] args) throws Exception {
        new Version().processCommand(args);
    }
}

@@ -113,32 +113,74 @@
 HostException;%0A%0A
+import net.hyperic.sigar.OperatingSystem;%0A
 import net.hyper
@@ -389,257 +389,8 @@
 se %7B
-%0A    private static String%5B%5D SYS_PROPS = %7B%0A        %22os.name%22,%0A        %22os.version%22,%0A        %22os.arch%22,%0A        %22java.vm.version%22,%0A        %22java.vm.vendor%22,%0A        %22sun.arch.data.model%22,%0A        %22sun.cpu.endian%22,%0A        %22sun.os.patch.level%22,%0A    %7D;
 %0A%0A  
@@ -563,23 +563,39 @@
 y sigar 
+and system 
 version
+ info
 %22;%0A    %7D
@@ -1143,17 +1143,23 @@
  version
-=
+.......
 %22 + Siga
@@ -1201,15 +1201,9 @@
 ln(%22
-Sigar b
+B
 uild
@@ -1207,17 +1207,26 @@
 ild date
-=
+..........
 %22 + Siga
@@ -1264,22 +1264,28 @@
 ln(%22
-Sigar archlib=
+Archlib.............
 %22 +%0A
@@ -1372,17 +1372,24 @@
 ent fqdn
-=
+........
 %22 + fqdn
@@ -1453,21 +1453,28 @@
 ln(%22
-Current host=
+Hostname............
 %22 + 
@@ -1514,16 +1514,24 @@
 ln(%22%22);%0A
+        
 %0A       
@@ -1535,185 +1535,869 @@
     
-for (int i=0; i%3CSYS_PROPS.length; i++) %7B%0A            String prop = SYS_PROPS%5Bi%5D;%0A            os.println(prop + %22=%22 + %0A                       System.getProperty(prop));%0A        %7D
+OperatingSystem sys = OperatingSystem.getInstance();%0A        os.println(%22OS name.............%22 + sys.getName());%0A        os.println(%22OS arch.............%22 + sys.getArch());%0A        os.println(%22OS version..........%22 + sys.getVersion());%0A        os.println(%22OS patch level......%22 + sys.getPatchLevel());%0A        os.println(%22OS vendor...........%22 + sys.getVendor());%0A        os.println(%22OS vendor version...%22 + sys.getVendorVersion());%0A        os.println(%22OS data model.......%22 + sys.getDataModel());%0A        os.println(%22OS cpu endian.......%22 + sys.getCpuEndian());%0A%0A        os.println(%22Java vm version.....%22 + %0A                   System.getProperty(%22java.vm.version%22));%0A        os.println(%22Java vm vendor......%22 + %0A                System.getProperty(%22java.vm.vendor%22));%0A        os.println(%22Java home...........%22 +%0A                System.getProperty(%22java.home%22));
 %0A   

add OpereratingSystem and java stuff, format output