@contextmanager
  def open_jar(self, path, overwrite=False, compressed=True, jar_rules=None):
    jar = Jar(path)
    try:
      yield jar
    except jar.Error as e:
      raise TaskError('Failed to write to jar at {}: {}'.format(path, e))

    with jar._render_jar_tool_args(self.get_options()) as args:
      if args:  # Don't build an empty jar
        args.append('-update={}'.format(self._flag(not overwrite)))
        args.append('-compress={}'.format(self._flag(compressed)))

        jar_rules = jar_rules or JarRules.default()
        args.append('-default_action={}'.format(self._action_name(jar_rules.default_dup_action)))

        skip_patterns = []
        duplicate_actions = []

        for rule in jar_rules.rules:
          if isinstance(rule, Skip):
            skip_patterns.append(rule.apply_pattern)
          elif isinstance(rule, Duplicate):
            duplicate_actions.append('{}={}'.format(
              rule.apply_pattern.pattern, self._action_name(rule.action)))
          else:
            raise ValueError('Unrecognized rule: {}'.format(rule))

        if skip_patterns:
          args.append('-skip={}'.format(','.join(p.pattern for p in skip_patterns)))

        if duplicate_actions:
          args.append('-policies={}'.format(','.join(duplicate_actions)))

        args.append(path)

        if JarTool.global_instance().run(context=self.context, runjava=self.runjava, args=args):
          raise TaskError('jar-tool failed')
Report an error that occurred while running the given test.
dataset/ETHPy150Open pantsbuild/pants/src/python/pants/backend/jvm/tasks/jar_task.py/JarTask.open_jar--crossover with--dataset/ETHPy150Open twisted/twisted/twisted/trial/reporter.py/TestResult.addError