<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from pants . backend . jvm . targets . jar_dependency import JarDependency <EOL> from pants . backend . jvm . tasks . jvm_tool_task_mixin import JvmToolTaskMixin <EOL> from pants . base . exceptions import TaskError <EOL> from pants . java import util <EOL> from pants . java . distribution . distribution import DistributionLocator <EOL> from pants . java . executor import SubprocessExecutor <EOL> from pants . java . nailgun_executor import NailgunExecutor , NailgunProcessGroup <EOL> from pants . task . task import Task , TaskBase <EOL> class NailgunTaskBase ( JvmToolTaskMixin , TaskBase ) : <EOL> ID_PREFIX = '<STR_LIT>' <EOL> @ classmethod <EOL> def register_options ( cls , register ) : <EOL> super ( NailgunTaskBase , cls ) . register_options ( register ) <EOL> register ( '<STR_LIT>' , type = bool , default = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , advanced = True , default = <NUM_LIT:10> , type = float , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , advanced = True , default = <NUM_LIT:5> , type = int , <EOL> help = '<STR_LIT>' ) <EOL> cls . register_jvm_tool ( register , <EOL> '<STR_LIT>' , <EOL> classpath = [ <EOL> JarDependency ( org = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> rev = '<STR_LIT>' ) , <EOL> ] ) <EOL> @ classmethod <EOL> def global_subsystems ( cls ) : <EOL> return super ( NailgunTaskBase , cls ) . global_subsystems ( ) + ( DistributionLocator , ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( NailgunTaskBase , self ) . __init__ ( * args , ** kwargs ) <EOL> id_tuple = ( self . ID_PREFIX , self . __class__ . __name__ ) <EOL> self . _identity = '<STR_LIT:_>' . join ( id_tuple ) <EOL> self . _executor_workdir = os . path . join ( self . context . options . for_global_scope ( ) . pants_workdir , <EOL> * id_tuple ) <EOL> self . set_distribution ( ) <EOL> def set_distribution ( self , minimum_version = None , maximum_version = None , jdk = False ) : <EOL> try : <EOL> self . _dist = DistributionLocator . cached ( minimum_version = minimum_version , <EOL> maximum_version = maximum_version , jdk = jdk ) <EOL> except DistributionLocator . Error as e : <EOL> raise TaskError ( e ) <EOL> @ property <EOL> def dist ( self ) : <EOL> return self . _dist <EOL> def create_java_executor ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . get_options ( ) . use_nailgun : <EOL> classpath = os . pathsep . join ( self . tool_classpath ( '<STR_LIT>' ) ) <EOL> return NailgunExecutor ( self . _identity , <EOL> self . _executor_workdir , <EOL> classpath , <EOL> self . _dist , <EOL> connect_timeout = self . get_options ( ) . nailgun_timeout_seconds , <EOL> connect_attempts = self . get_options ( ) . nailgun_connect_attempts ) <EOL> else : <EOL> return SubprocessExecutor ( self . _dist ) <EOL> def runjava ( self , classpath , main , jvm_options = None , args = None , workunit_name = None , <EOL> workunit_labels = None , workunit_log_config = None ) : <EOL> """<STR_LIT>""" <EOL> executor = self . create_java_executor ( ) <EOL> create_synthetic_jar = not self . get_options ( ) . use_nailgun <EOL> try : <EOL> return util . execute_java ( classpath = classpath , <EOL> main = main , <EOL> jvm_options = jvm_options , <EOL> args = args , <EOL> executor = executor , <EOL> workunit_factory = self . context . new_workunit , <EOL> workunit_name = workunit_name , <EOL> workunit_labels = workunit_labels , <EOL> workunit_log_config = workunit_log_config , <EOL> create_synthetic_jar = create_synthetic_jar , <EOL> synthetic_jar_dir = self . _executor_workdir ) <EOL> except executor . Error as e : <EOL> raise TaskError ( e ) <EOL> class NailgunTask ( NailgunTaskBase , Task ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class NailgunKillall ( Task ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def register_options ( cls , register ) : <EOL> super ( NailgunKillall , cls ) . register_options ( register ) <EOL> register ( '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' ) <EOL> def execute ( self ) : <EOL> NailgunProcessGroup ( ) . killall ( everywhere = self . get_options ( ) . everywhere ) </s>
