<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> import shutil <EOL> from abc import abstractmethod , abstractproperty <EOL> from pants . util . dirutil import safe_mkdir <EOL> from pants . util . meta import AbstractClass <EOL> from pants . util . strutil import safe_shlex_split <EOL> class CoverageTaskSettings ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , options , context , workdir , tool_classpath , confs , log ) : <EOL> self . options = options <EOL> self . context = context <EOL> self . workdir = workdir <EOL> self . tool_classpath = tool_classpath <EOL> self . confs = confs <EOL> self . log = log <EOL> self . coverage_dir = os . path . join ( self . workdir , '<STR_LIT>' ) <EOL> self . coverage_instrument_dir = os . path . join ( self . coverage_dir , '<STR_LIT>' ) <EOL> self . coverage_console_file = os . path . join ( self . coverage_dir , '<STR_LIT>' ) <EOL> self . coverage_xml_file = os . path . join ( self . coverage_dir , '<STR_LIT>' ) <EOL> self . coverage_html_file = os . path . join ( self . coverage_dir , '<STR_LIT:html>' , '<STR_LIT>' ) <EOL> @ classmethod <EOL> def from_task ( cls , task ) : <EOL> return cls ( <EOL> options = task . get_options ( ) , <EOL> context = task . context , <EOL> workdir = task . workdir , <EOL> tool_classpath = task . tool_classpath , <EOL> confs = task . confs , <EOL> log = task . context . log ) <EOL> class Coverage ( AbstractClass ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def register_options ( cls , register , register_jvm_tool ) : <EOL> register ( '<STR_LIT>' , type = bool , help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , advanced = True , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , advanced = True , type = list , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' . format ( flag = '<STR_LIT>' ) ) <EOL> register ( '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , advanced = True , type = bool , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def __init__ ( self , settings , copy2 = shutil . copy2 , copytree = shutil . copytree , is_file = os . path . isfile , <EOL> safe_md = safe_mkdir ) : <EOL> self . _settings = settings <EOL> options = settings . options <EOL> self . _context = settings . context <EOL> self . _coverage = options . coverage <EOL> self . _coverage_jvm_options = [ ] <EOL> for jvm_option in options . coverage_jvm_options : <EOL> self . _coverage_jvm_options . extend ( safe_shlex_split ( jvm_option ) ) <EOL> self . _coverage_open = options . coverage_open <EOL> self . _coverage_force = options . coverage_force <EOL> self . _copy2 = copy2 <EOL> self . _copytree = copytree <EOL> self . _is_file = is_file <EOL> self . _safe_makedir = safe_md <EOL> @ abstractmethod <EOL> def instrument ( self , targets , tests , compute_junit_classpath , execute_java_for_targets ) : <EOL> pass <EOL> @ abstractmethod <EOL> def report ( self , targets , tests , execute_java_for_targets , tests_failed_exception ) : <EOL> pass <EOL> @ abstractproperty <EOL> def classpath_prepend ( self ) : <EOL> pass <EOL> @ abstractproperty <EOL> def classpath_append ( self ) : <EOL> pass <EOL> @ abstractproperty <EOL> def extra_jvm_options ( self ) : <EOL> pass <EOL> def is_coverage_target ( self , tgt ) : <EOL> return ( tgt . is_java or tgt . is_scala ) and not tgt . is_test and not tgt . is_codegen <EOL> def initialize_instrument_classpath ( self , targets , instrumentation_classpath ) : <EOL> """<STR_LIT>""" <EOL> self . _safe_makedir ( self . _settings . coverage_instrument_dir , clean = True ) <EOL> for target in targets : <EOL> if not self . is_coverage_target ( target ) : <EOL> continue <EOL> paths = instrumentation_classpath . get_for_target ( target ) <EOL> target_instrumentation_path = os . path . join ( self . _settings . coverage_instrument_dir , target . id ) <EOL> for ( index , ( config , path ) ) in enumerate ( paths ) : <EOL> entry_instrumentation_path = os . path . join ( target_instrumentation_path , str ( index ) ) <EOL> if self . _is_file ( path ) : <EOL> self . _safe_makedir ( entry_instrumentation_path , clean = True ) <EOL> self . _copy2 ( path , entry_instrumentation_path ) <EOL> new_path = os . path . join ( entry_instrumentation_path , os . path . basename ( path ) ) <EOL> else : <EOL> self . _copytree ( path , entry_instrumentation_path ) <EOL> new_path = entry_instrumentation_path <EOL> instrumentation_classpath . remove_for_target ( target , [ ( config , path ) ] ) <EOL> instrumentation_classpath . add_for_target ( target , [ ( config , new_path ) ] ) <EOL> self . _settings . log . debug ( <EOL> "<STR_LIT>" . format ( path , new_path ) ) </s>
