<s> from pybuilder . core import task , use_plugin <EOL> from pybuilder . errors import BuildFailedException <EOL> from subprocess import PIPE , Popen <EOL> import sys <EOL> use_plugin ( "<STR_LIT>" ) <EOL> @ task <EOL> def run_unit_tests ( project , logger ) : <EOL> run_command ( '<STR_LIT>' , project , logger ) <EOL> @ task <EOL> def run_integration_tests ( project , logger ) : <EOL> run_command ( '<STR_LIT>' , project , logger ) <EOL> @ task <EOL> def analyze ( project , logger ) : <EOL> run_command ( '<STR_LIT>' , project , logger ) <EOL> @ task <EOL> def package ( project , logger ) : <EOL> run_command ( '<STR_LIT>' , project , logger ) <EOL> @ task <EOL> def publish ( project , logger ) : <EOL> run_command ( '<STR_LIT>' , project , logger ) <EOL> def _write_command_report ( project , stdout , stderr , command_line , phase , process_return_code ) : <EOL> project . write_report ( '<STR_LIT>' % phase , stdout ) <EOL> project . write_report ( '<STR_LIT>' % phase , stderr ) <EOL> def _log_quoted_output ( logger , output_type , output , phase ) : <EOL> separator = '<STR_LIT:->' * <NUM_LIT:5> <EOL> logger . info ( '<STR_LIT>' . format ( separator , output_type , phase ) ) <EOL> for line in output . split ( '<STR_LIT:\n>' ) : <EOL> logger . info ( line ) <EOL> logger . info ( '<STR_LIT>' . format ( separator , output_type ) ) <EOL> def run_command ( phase , project , logger ) : <EOL> command_line = project . get_property ( '<STR_LIT>' % phase ) <EOL> if not command_line : <EOL> return <EOL> process_handle = Popen ( command_line , stdout = PIPE , stderr = PIPE , shell = True ) <EOL> stdout , stderr = process_handle . communicate ( ) <EOL> stdout , stderr = stdout . decode ( sys . stdout . encoding or '<STR_LIT:utf-8>' ) , stderr . decode ( sys . stderr . encoding or '<STR_LIT:utf-8>' ) <EOL> process_return_code = process_handle . returncode <EOL> _write_command_report ( project , <EOL> stdout , <EOL> stderr , <EOL> command_line , <EOL> phase , <EOL> process_return_code ) <EOL> if project . get_property ( '<STR_LIT>' % phase ) and stdout : <EOL> _log_quoted_output ( logger , '<STR_LIT>' , stdout , phase ) <EOL> if project . get_property ( '<STR_LIT>' % phase ) and stderr : <EOL> _log_quoted_output ( logger , '<STR_LIT:error>' , stderr , phase ) <EOL> if process_return_code != <NUM_LIT:0> : <EOL> raise BuildFailedException ( <EOL> '<STR_LIT>' . format ( command_line , <EOL> phase , <EOL> process_return_code ) ) </s>
