def _render_jar_tool_args(self): args = [] with temporary_dir() as manifest_stage_dir: classpath = self._classpath or [] def as_cli_entry(entry): src = entry.materialize(manifest_stage_dir) return '{}={}'.format(src, entry.dest) if entry.dest else src files = map(as_cli_entry, self._entries) if self._entries else [] jars = self._jars or [] with safe_args(classpath, delimiter=',') as classpath_args: with safe_args(files, delimiter=',') as files_args: with safe_args(jars, delimiter=',') as jars_args: if self._main: args.append('-main={}'.format(self._main)) if classpath_args: args.append('-classpath={}'.format(','.join(classpath_args))) if self._manifest: args.append('-manifest={}'.format(self._manifest.materialize(manifest_stage_dir))) if files_args: args.append('-files={}'.format(','.join(files_args))) if jars_args: args.append('-jars={}'.format(','.join(jars_args))) yield args
def _render_jar_tool_args(self, options): """Format the arguments to jar-tool. :param Options options: """ args = [] with temporary_dir() as manifest_stage_dir: classpath = self._classpath or [] def as_cli_entry(entry): src = entry.materialize(manifest_stage_dir) return '{}={}'.format(src, entry.dest) if entry.dest else src files = map(as_cli_entry, self._entries) if self._entries else [] jars = self._jars or [] with safe_args(classpath, options, delimiter=',') as classpath_args: with safe_args(files, options, delimiter=',') as files_args: with safe_args(jars, options, delimiter=',') as jars_args: # If you specify --manifest to jar-tool you cannot specify --main. if self._manifest_entry: manifest_file = self._manifest_entry.materialize( manifest_stage_dir) else: manifest_file = None if self._main and manifest_file: main_arg = None with open(manifest_file, 'a') as f: f.write("Main-Class: {}\n".format(self._main)) else: main_arg = self._main if main_arg: args.append('-main={}'.format(self._main)) if classpath_args: args.append('-classpath={}'.format( ','.join(classpath_args))) if manifest_file: args.append('-manifest={}'.format(manifest_file)) if files_args: args.append('-files={}'.format( ','.join(files_args))) if jars_args: args.append('-jars={}'.format(','.join(jars_args))) yield args
def _render_jar_tool_args(self, options): """Format the arguments to jar-tool. :param Options options: """ args = [] with temporary_dir() as manifest_stage_dir: classpath = self._classpath or [] def as_cli_entry(entry): src = entry.materialize(manifest_stage_dir) return '{}={}'.format(src, entry.dest) if entry.dest else src files = map(as_cli_entry, self._entries) if self._entries else [] jars = self._jars or [] with safe_args(classpath, options, delimiter=',') as classpath_args: with safe_args(files, options, delimiter=',') as files_args: with safe_args(jars, options, delimiter=',') as jars_args: # If you specify --manifest to jar-tool you cannot specify --main. if self._manifest_entry: manifest_file = self._manifest_entry.materialize(manifest_stage_dir) else: manifest_file = None if self._main and manifest_file: main_arg = None with open(manifest_file, 'a') as f: f.write("Main-Class: {}\n".format(self._main)) else: main_arg = self._main if main_arg: args.append('-main={}'.format(self._main)) if classpath_args: args.append('-classpath={}'.format(','.join(classpath_args))) if manifest_file: args.append('-manifest={}'.format(manifest_file)) if files_args: args.append('-files={}'.format(','.join(files_args))) if jars_args: args.append('-jars={}'.format(','.join(jars_args))) yield args
def execute(self, targets): if not self.skip: def run_tests(tests): args = ["--color"] if self.color else [] args.append("--specs=%s" % ",".join(tests)) specs_runner_main = "com.twitter.common.testing.ExplicitSpecsRunnerMain" bootstrapped_cp = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(self._specs_bootstrap_key) classpath = self.classpath( bootstrapped_cp, confs=self.confs, exclusives_classpath=self.get_base_classpath_for_target(targets[0]), ) result = execute_java( classpath=classpath, main=specs_runner_main, jvm_options=self._jvm_options, args=args, workunit_factory=self.context.new_workunit, workunit_name="specs", workunit_labels=[WorkUnit.TEST], ) if result != 0: raise TaskError("java %s ... exited non-zero (%i)" % (specs_runner_main, result)) if self.tests: run_tests(self.tests) else: with safe_args(self.calculate_tests(targets)) as tests: if tests: run_tests(tests)
def execute(self): if not self.skip: targets = self.context.targets() def run_tests(tests): args = ['--color'] if self.get_options().colors else [] args.append('--specs={}'.format(','.join(tests))) specs_runner_main = 'com.twitter.common.testing.ExplicitSpecsRunnerMain' bootstrapped_cp = self.tool_classpath('specs') classpath = self.classpath(targets, cp=bootstrapped_cp) result = execute_java( classpath=classpath, main=specs_runner_main, jvm_options=self.jvm_options, args=self.args + args, workunit_factory=self.context.new_workunit, workunit_name='specs', workunit_labels=[WorkUnit.TEST] ) if result != 0: raise TaskError('java {} ... exited non-zero ({})'.format(specs_runner_main, result)) if self.tests: run_tests(self.tests) else: with safe_args(self.calculate_tests(targets), self.get_options()) as tests: if tests: run_tests(tests)
def _run_tests(self, tests_and_targets, classpath, main, extra_jvm_options=None): extra_jvm_options = extra_jvm_options or [] result = 0 for batch in self._partition(tests_and_targets.keys()): with binary_util.safe_args(batch, self._task_exports.task_options) as batch_tests: result += abs(execute_java( classpath=classpath, main=main, jvm_options=self._task_exports.jvm_options + extra_jvm_options, args=self._args + batch_tests + [u'-xmlreport'], workunit_factory=self._context.new_workunit, workunit_name='run', workunit_labels=[WorkUnit.TEST], cwd=self._working_dir )) if result != 0 and self._fail_fast: break if result != 0: failed_targets = self._get_failed_targets(tests_and_targets) raise TestFailedTaskError( 'java {0} ... exited non-zero ({1})'.format(main, result), failed_targets=failed_targets )
def _run_tests(self, tests, classpath, main, extra_jvm_options=None, cwd=None): # TODO(John Sirois): Integrated batching with the test runner. As things stand we get # results summaries for example for each batch but no overall summary. # http://jira.local.twitter.com/browse/AWESOME-1114 extra_jvm_options = extra_jvm_options or [] result = 0 cwd = cwd or get_buildroot() for batch in self._partition(tests): with binary_util.safe_args(batch) as batch_tests: result += abs( execute_java(classpath=classpath, main=main, jvm_options=self._task_exports.jvm_options + extra_jvm_options, args=self._args + batch_tests, workunit_factory=self._context.new_workunit, workunit_name='run', workunit_labels=[WorkUnit.TEST], cwd=cwd)) if result != 0 and self._fail_fast: break if result != 0: raise TaskError('java %s ... exited non-zero (%i)' % (main, result))
def execute(self): if not self.skip: targets = self.context.targets() def run_tests(tests): args = ['--color'] if self.color else [] args.append('--specs=%s' % ','.join(tests)) specs_runner_main = 'com.twitter.common.testing.ExplicitSpecsRunnerMain' bootstrapped_cp = self.tool_classpath(self._specs_bootstrap_key) classpath = self.classpath( bootstrapped_cp, confs=self.confs, exclusives_classpath=self.get_base_classpath_for_target(targets[0])) result = execute_java( classpath=classpath, main=specs_runner_main, jvm_options=self.jvm_options, args=self.args + args, workunit_factory=self.context.new_workunit, workunit_name='specs', workunit_labels=[WorkUnit.TEST] ) if result != 0: raise TaskError('java %s ... exited non-zero (%i)' % (specs_runner_main, result)) if self.tests: run_tests(self.tests) else: with safe_args(self.calculate_tests(targets)) as tests: if tests: run_tests(tests)
def execute(self): if not self.skip: targets = self.context.targets() def run_tests(tests): args = ['--color'] if self.color else [] args.append('--specs=%s' % ','.join(tests)) specs_runner_main = 'com.twitter.common.testing.ExplicitSpecsRunnerMain' bootstrapped_cp = self.tool_classpath( self._specs_bootstrap_key) classpath = self.classpath( bootstrapped_cp, confs=self.confs, exclusives_classpath=self.get_base_classpath_for_target( targets[0])) result = execute_java( classpath=classpath, main=specs_runner_main, jvm_options=self.jvm_options, args=self.args + args, workunit_factory=self.context.new_workunit, workunit_name='specs', workunit_labels=[WorkUnit.TEST]) if result != 0: raise TaskError('java %s ... exited non-zero (%i)' % (specs_runner_main, result)) if self.tests: run_tests(self.tests) else: with safe_args(self.calculate_tests(targets)) as tests: if tests: run_tests(tests)
def _render_jar_tool_args(self): args = [] with temporary_dir() as manifest_stage_dir: classpath = self._classpath or [] def as_cli_entry(entry): src = entry.materialize(manifest_stage_dir) return '{}={}'.format(src, entry.dest) if entry.dest else src files = map(as_cli_entry, self._entries) if self._entries else [] jars = self._jars or [] with safe_args(classpath, delimiter=',') as classpath_args: with safe_args(files, delimiter=',') as files_args: with safe_args(jars, delimiter=',') as jars_args: if self._main: args.append('-main={}'.format(self._main)) if classpath_args: args.append('-classpath={}'.format( ','.join(classpath_args))) if self._manifest: args.append('-manifest={}'.format( self._manifest.materialize( manifest_stage_dir))) if files_args: args.append('-files={}'.format( ','.join(files_args))) if jars_args: args.append('-jars={}'.format(','.join(jars_args))) yield args
def _run_tests(self, tests_to_targets, main, extra_jvm_options=None, classpath_prepend=(), classpath_append=()): extra_jvm_options = extra_jvm_options or [] result = 0 for workdir, tests in self._tests_by_workdir(tests_to_targets).items(): for batch in self._partition(tests): classpath = self._task_exports.classpath( map(tests_to_targets.get, batch), cp=self._task_exports.tool_classpath('junit')) complete_classpath = OrderedSet() complete_classpath.update(classpath_prepend) complete_classpath.update(classpath) complete_classpath.update(classpath_append) with binary_util.safe_args( batch, self._task_exports.task_options) as batch_tests: self._context.log.debug('CWD = {}'.format(workdir)) result += abs( execute_java( classpath=complete_classpath, main=main, jvm_options=self._task_exports.jvm_options + extra_jvm_options, args=self._args + batch_tests + [u'-xmlreport'], workunit_factory=self._context.new_workunit, workunit_name='run', workunit_labels=[WorkUnit.TEST], cwd=workdir, )) if result != 0 and self._fail_fast: break if result != 0: failed_targets = self._get_failed_targets(tests_to_targets) raise TestFailedTaskError( 'java {0} ... exited non-zero ({1}); {2} failed targets.'. format(main, result, len(failed_targets)), failed_targets=failed_targets)
def instrument_code(): safe_mkdir(self.coverage_instrument_dir, clean=True) with binary_util.safe_args(self.get_coverage_patterns(targets)) as patterns: args = [ 'instr', '-out', self.coverage_metadata_file, '-d', self.coverage_instrument_dir, '-cp', os.pathsep.join(junit_classpath), '-exit' ] for pattern in patterns: args.extend(['-filter', pattern]) main = 'emma' result = execute_java(classpath=emma_classpath, main=main, args=args, workunit_factory=self.context.new_workunit, workunit_name='emma-instrument') if result != 0: raise TaskError("java %s ... exited non-zero (%i)" " 'failed to instrument'" % (main, result))
def _run_tests(self, tests, classpath, main, jvm_args=None): # TODO(John Sirois): Integrated batching with the test runner. As things stand we get # results summaries for example for each batch but no overall summary. # http://jira.local.twitter.com/browse/AWESOME-1114 result = 0 for batch in self._partition(tests): with binary_util.safe_args(batch) as batch_tests: result += abs(execute_java( classpath=classpath, main=main, jvm_options=(jvm_args or []) + self._jvm_args, args=self._opts + batch_tests, workunit_factory=self._context.new_workunit, workunit_name='run', workunit_labels=[WorkUnit.TEST] )) if result != 0 and self._fail_fast: break if result != 0: raise TaskError('java %s ... exited non-zero (%i)' % (main, result))
def instrument(self, targets, tests, junit_classpath): safe_mkdir(self._coverage_instrument_dir, clean=True) self._emma_classpath = self._task_exports.tool_classpath('emma') with binary_util.safe_args(self.get_coverage_patterns(targets)) as patterns: args = [ 'instr', '-out', self._coverage_metadata_file, '-d', self._coverage_instrument_dir, '-cp', os.pathsep.join(junit_classpath), '-exit' ] for pattern in patterns: args.extend(['-filter', pattern]) main = 'emma' result = execute_java(classpath=self._emma_classpath, main=main, args=args, workunit_factory=self._context.new_workunit, workunit_name='emma-instrument') if result != 0: raise TaskError("java {0} ... exited non-zero ({1})" " 'failed to instrument'".format(main, result))
def execute(self): # TODO(Eric Ayers) Remove this logic after 0.0.30 along with the option itself. if self.get_options().color is False: print( "--no-color is obsolete and will be removed. Specify --no-colors instead.", file=sys.stderr) self.colors = self.get_options().color if not self.skip: targets = self.context.targets() def run_tests(tests): args = ['--color'] if self.colors else [] args.append('--specs=%s' % ','.join(tests)) specs_runner_main = 'com.twitter.common.testing.ExplicitSpecsRunnerMain' bootstrapped_cp = self.tool_classpath('specs') classpath = self.classpath(targets, cp=bootstrapped_cp, confs=self.confs) result = execute_java( classpath=classpath, main=specs_runner_main, jvm_options=self.jvm_options, args=self.args + args, workunit_factory=self.context.new_workunit, workunit_name='specs', workunit_labels=[WorkUnit.TEST]) if result != 0: raise TaskError('java %s ... exited non-zero (%i)' % (specs_runner_main, result)) if self.tests: run_tests(self.tests) else: with safe_args(self.calculate_tests(targets)) as tests: if tests: run_tests(tests)
def _run_tests(self, tests, classpath, main, extra_jvm_options=None, cwd=None): # TODO(John Sirois): Integrated batching with the test runner. As things stand we get # results summaries for example for each batch but no overall summary. # http://jira.local.twitter.com/browse/AWESOME-1114 extra_jvm_options = extra_jvm_options or [] result = 0 cwd = cwd or get_buildroot() for batch in self._partition(tests): with binary_util.safe_args(batch) as batch_tests: result += abs(execute_java( classpath=classpath, main=main, jvm_options=self._task_exports.jvm_options + extra_jvm_options, args=self._args + batch_tests, workunit_factory=self._context.new_workunit, workunit_name='run', workunit_labels=[WorkUnit.TEST], cwd=cwd )) if result != 0 and self._fail_fast: break if result != 0: raise TaskError('java {0} ... exited non-zero ({1})'.format(main, result))
def execute(self): # TODO(Eric Ayers) Remove this logic after 0.0.30 along with the option itself. if self.get_options().color is False: print("--no-color is obsolete and will be removed. Specify --no-colors instead.", file=sys.stderr) self.colors = self.get_options().color if not self.skip: targets = self.context.targets() def run_tests(tests): args = ['--color'] if self.colors else [] args.append('--specs=%s' % ','.join(tests)) specs_runner_main = 'com.twitter.common.testing.ExplicitSpecsRunnerMain' bootstrapped_cp = self.tool_classpath('specs') classpath = self.classpath(targets, cp=bootstrapped_cp, confs=self.confs) result = execute_java( classpath=classpath, main=specs_runner_main, jvm_options=self.jvm_options, args=self.args + args, workunit_factory=self.context.new_workunit, workunit_name='specs', workunit_labels=[WorkUnit.TEST] ) if result != 0: raise TaskError('java %s ... exited non-zero (%i)' % (specs_runner_main, result)) if self.tests: run_tests(self.tests) else: with safe_args(self.calculate_tests(targets)) as tests: if tests: run_tests(tests)
def _run_tests(self, tests_to_targets, main, extra_jvm_options=None, classpath_prepend=(), classpath_append=()): extra_jvm_options = extra_jvm_options or [] result = 0 for workdir, tests in self._tests_by_workdir(tests_to_targets).items(): for batch in self._partition(tests): classpath = self._task_exports.classpath(map(tests_to_targets.get, batch), cp=self._task_exports.tool_classpath('junit')) complete_classpath = OrderedSet() complete_classpath.update(classpath_prepend) complete_classpath.update(classpath) complete_classpath.update(classpath_append) with binary_util.safe_args(batch, self._task_exports.task_options) as batch_tests: self._context.log.debug('CWD = {}'.format(workdir)) result += abs(execute_java( classpath=complete_classpath, main=main, jvm_options=self._task_exports.jvm_options + extra_jvm_options, args=self._args + batch_tests + [u'-xmlreport'], workunit_factory=self._context.new_workunit, workunit_name='run', workunit_labels=[WorkUnit.TEST], cwd=workdir, )) if result != 0 and self._fail_fast: break if result != 0: failed_targets = self._get_failed_targets(tests_to_targets) raise TestFailedTaskError( 'java {0} ... exited non-zero ({1}); {2} failed targets.' .format(main, result, len(failed_targets)), failed_targets=failed_targets )
def instrument(self, targets, tests, junit_classpath): safe_mkdir(self._coverage_instrument_dir, clean=True) self._emma_classpath = self._task_exports.tool_classpath('emma') with binary_util.safe_args(self.get_coverage_patterns(targets), self._task_exports.task_options) as patterns: args = [ 'instr', '-out', self._coverage_metadata_file, '-d', self._coverage_instrument_dir, '-cp', os.pathsep.join(junit_classpath), '-exit' ] for pattern in patterns: args.extend(['-filter', pattern]) main = 'emma' result = execute_java(classpath=self._emma_classpath, main=main, jvm_options=self._coverage_jvm_options, args=args, workunit_factory=self._context.new_workunit, workunit_name='emma-instrument') if result != 0: raise TaskError("java {0} ... exited non-zero ({1})" " 'failed to instrument'".format(main, result))