<s> import sublime <EOL> import hashlib <EOL> import os <EOL> import shlex <EOL> from . dependency_manager import DependencyManager <EOL> from . generic_shell import GenericBlockShell <EOL> from . logger import Logger <EOL> from . settings import Settings <EOL> class _HelperService : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def instance ( cls ) : <EOL> if not hasattr ( cls , "<STR_LIT>" ) : <EOL> cls . _instance = cls ( ) <EOL> return cls . _instance <EOL> def startup ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers = sublime . find_resources ( "<STR_LIT>" ) <EOL> installed = False <EOL> for helper in helpers : <EOL> if helper [ : <NUM_LIT:9> ] == "<STR_LIT>" : <EOL> helper = os . path . join ( sublime . packages_path ( ) , helper [ <NUM_LIT:9> : ] ) <EOL> if os . path . exists ( helper ) and self . verify_helper ( helper ) : <EOL> installed = True <EOL> break <EOL> if not installed : <EOL> Logger ( ) . info ( "<STR_LIT>" ) <EOL> file_path = os . path . join ( <EOL> sublime . packages_path ( ) , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) <EOL> if os . path . exists ( file_path ) : <EOL> os . remove ( file_path ) <EOL> if not os . path . isdir ( os . path . dirname ( file_path ) ) : <EOL> try : <EOL> os . makedirs ( os . path . dirname ( file_path ) ) <EOL> except : <EOL> pass <EOL> helper_file = open ( file_path , "<STR_LIT:wb>" ) <EOL> helper_file . write ( sublime . load_binary_resource ( <EOL> "<STR_LIT>" <EOL> ) ) <EOL> helper_file . close ( ) <EOL> def verify_helper ( self , path ) : <EOL> """<STR_LIT>""" <EOL> helper_file = open ( path , "<STR_LIT:rb>" ) <EOL> actual_hash = hashlib . sha256 ( <EOL> helper_file . read ( ) <EOL> ) . hexdigest ( ) <EOL> helper_file . close ( ) <EOL> expected_hash = hashlib . sha256 ( sublime . load_binary_resource ( <EOL> "<STR_LIT>" <EOL> ) ) . hexdigest ( ) <EOL> return actual_hash == expected_hash <EOL> def query_data ( self , query ) : <EOL> from . jdk_manager import JDKManager <EOL> helpers = sublime . find_resources ( "<STR_LIT>" ) <EOL> helper_file = None <EOL> for helper in helpers : <EOL> if helper [ : <NUM_LIT:9> ] == "<STR_LIT>" : <EOL> helper = os . path . join ( sublime . packages_path ( ) , helper [ <NUM_LIT:9> : ] ) <EOL> if os . path . exists ( helper ) and self . verify_helper ( helper ) : <EOL> helper_file = helper <EOL> break <EOL> if not helper_file : <EOL> return None <EOL> executable = JDKManager ( ) . get_executable ( "<STR_LIT>" ) <EOL> if not executable : <EOL> return None <EOL> dependencies = [ <EOL> dependency [ <NUM_LIT:0> ] <EOL> for dependency <EOL> in DependencyManager ( ) . get_dependencies ( ) <EOL> ] <EOL> runtime_path = JDKManager ( ) . get_runtime_file ( "<STR_LIT>" ) <EOL> if runtime_path : <EOL> dependencies . append ( runtime_path ) <EOL> exclusion = Settings ( ) . get ( "<STR_LIT>" , [ ] ) <EOL> if exclusion : <EOL> exclusion = "<STR_LIT>" % ( shlex . quote ( os . pathsep . join ( exclusion ) ) ) <EOL> else : <EOL> exclusion = "<STR_LIT>" <EOL> if dependencies : <EOL> dependencies = "<STR_LIT>" % ( shlex . quote ( os . pathsep . join ( dependencies ) ) ) <EOL> else : <EOL> dependencies = "<STR_LIT>" <EOL> helper_script = "<STR_LIT>" % ( <EOL> shlex . quote ( executable ) , <EOL> shlex . quote ( helper_file ) , <EOL> exclusion , <EOL> dependencies , <EOL> query <EOL> ) <EOL> return GenericBlockShell ( ) . run ( helper_script ) <EOL> def get_packages ( self ) : <EOL> query = "<STR_LIT>" <EOL> output = self . query_data ( query ) <EOL> packages = [ ] <EOL> if output and output [ "<STR_LIT:data>" ] and output [ "<STR_LIT>" ] == <NUM_LIT:0> : <EOL> packages = output [ "<STR_LIT:data>" ] . strip ( ) . split ( "<STR_LIT:\n>" ) <EOL> return packages <EOL> def get_class_paths_for_classes ( self , class_names ) : <EOL> query = "<STR_LIT>" % ( os . pathsep . join ( class_names ) ) <EOL> output = self . query_data ( query ) <EOL> class_paths = { } <EOL> if output and output [ "<STR_LIT:data>" ] and output [ "<STR_LIT>" ] == <NUM_LIT:0> : <EOL> paths = output [ "<STR_LIT:data>" ] . strip ( ) . split ( "<STR_LIT:\n>" ) <EOL> for path in paths : <EOL> name , class_path = path . split ( "<STR_LIT:;>" ) <EOL> if name in class_paths : <EOL> class_paths [ name ] . append ( class_path ) <EOL> else : <EOL> class_paths [ name ] = [ class_path ] <EOL> return class_paths <EOL> def HelperService ( ) : <EOL> return _HelperService . instance ( ) </s>
