JavaValidator.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.util;
00002 
00003 import java.util.Iterator;
00004 import java.util.Map.Entry;
00005 import java.util.Properties;
00006 import java.util.Set;
00007 
00008 public class JavaValidator {
00009 
00010     // minimum Java supported
00011     private final static int JavaMinVersion = 5;
00012     
00013     static public void main(String []args) {
00014         if (isGCJ()) {
00015             System.out.println("Unsupported JVM: GNU GCJ");
00016         } else {
00017             if (isCorrectJavaVersion())
00018                 System.out.println("Valid JVM");
00019             else
00020                 System.out.println("Invalid JVM: Needs to be higher or equal than " 
00021                         + JavaMinVersion);
00022         }
00023     }
00024     
00025     
00026     /***
00027      * print all the JVM properties
00028      */
00029     static public void printProperties() {
00030         Properties p = System.getProperties();
00031         Set<Entry<Object, Object>> set = p.entrySet();
00032         Iterator<Entry<Object, Object>> iterator = set.iterator();
00033         
00034         while(iterator.hasNext()) {
00035             Entry<Object, Object> entry = iterator.next();
00036             System.out.println(entry.getKey() + " = " + entry.getValue());
00037         }
00038     }
00039     
00040     /****
00041      * check if JVM is from GNU
00042      * @return
00043      */
00044     static public boolean isGCJ() {
00045         // GNU JVM has "Free Software Foundation" as the vendor
00046         return getJavaVendor().indexOf("Free")>=0;
00047     }
00048     
00049     /****
00050      * check if JVM has the correct version
00051      * @return
00052      */
00053     static public boolean isCorrectJavaVersion() {
00054         String version = getJavaVersion();
00055         String []items = version.split("\\.");
00056         int v = Integer.valueOf(items[1]);
00057         return (v>=JavaMinVersion);
00058     }
00059     
00060     /****
00061      * retrieve the vendor (Sun, IBM, Free Foundation, ....)
00062      * @return
00063      */
00064     static public String getJavaVendor() {
00065         return System.getProperty("java.vendor");
00066     }
00067     
00068     /*****
00069      * retrieve Java version
00070      * @return
00071      */
00072     static public String getJavaVersion() {
00073         return System.getProperty("java.version");
00074     }
00075 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1