
    )                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
 ddl	mZ  G d	 d
ej                        Z G d de      ZddZy)z;Utility functions for interacting with a java installation.    )absolute_import)division)unicode_literalsN)
exceptionsencoding)filesc                       e Zd Zy)	JavaErrorN__name__
__module____qualname__     +lib/googlecloudsdk/command_lib/util/java.pyr   r          r   r   c                       e Zd Zy)JavaVersionErrorNr   r   r   r   r   r   !   r   r   r   c                    t        j                  d      }|st        dj                  | |            	 t	        j
                  t        j                  |ddgt        j                        d      }t        d
j                  ||             }t        j                  d|      }|r5t        j                  d|      }|s|t        |j                  d            }n4t        j                  d|      }|s|t        |j                  d            }||k  r||S # t        j                  $ r t        d	j                  | |            w xY w)aI  Require that a certain version of Java is installed.

  Args:
    for_text: str, the text explaining what Java is necessary for.
    min_version: int, the minimum major version to check for.

  Raises:
    JavaError: if a Java executable is not found or has the wrong version.

  Returns:
    str, Path to the Java executable.
  javazPTo use the {for_text}, a Java {v}+ JRE must be installed and on your system PATH)for_textvz-Dfile.encoding=UTF-8z-version)stderrzutf-8r   zUnable to execute the java that was found on your PATH. The {for_text} requires a Java {v}+ JRE installed and on your system PATHzThe java executable on your PATH is not a Java {v}+ JRE. The {for_text} requires a Java {v}+ JRE installed and on your system PATH)r   r   zversion "1\.zversion "(\d+)\.(\d+)\.   zversion "([1-9][0-9]*)   )r	   FindExecutableOnPathr   formatr   Decode
subprocesscheck_outputSTDOUTCalledProcessErrorr   researchintgroup)r   min_version	java_pathoutputjava_exec_version_errormatchmajor_versions          r   RequireJavaInstalledr.   %   s\    ((0)	
 ..4fh7B /5 /DE E	Q__/<$$	& 	F -+AC ))OV
,%
 II0&9E##A'M II/8E##A'M[ 
!!	; 
	&	& Q
 ''-vx;v'OQ QQs   =D 0E)   )__doc__
__future__r   r   r   r$   r    googlecloudsdk.corer   googlecloudsdk.core.utilr   r	   Errorr   r   r.   r   r   r   <module>r5      sF    B &  ' 	  * - *
   y 5r   