'Ensure that we will be running the right version of Java.
The point here is to fail quickly with a concise message if not. Otherwise,
the runtime will perform a check and give an obscure lengthy exception
trace about a version mismatch which is not at all apparent as to what the
actual problem is.'

@staticmethod
def check_java_version():

    try:
        p = subprocess.Popen('java    -version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        (stdout, stderr) = p.communicate()
        code = p.returncode
    except OSError as error:
        return str(error)
    info = stdout
    if (code != 0):
        return 'Java    does    not    appear    to    be    installed.'
    m = re.search('(?m)^openjdk    version    "(.*)"', info)
    if (not m):
        m = re.search('(?m)^java    version    "(.*)"', info)
    if (not m):
        raise SystemExit('Unrecognized    java    version:\n{0}'.format(info))
    if (m.group(1)[0:3] != '1.8'):
        raise SystemExit('You    are    running    Java    version    {version}.    However,    Java    version    1.8    is    required    for    Spinnaker.    Your    PATH    may    be    wrong,    or    you    may    need    to    install    Java    1.8.'.format(version=m.group(1)))
