def add_target(self, target, recursive=False):
      products_added = False

      classpath_products = self._context.products.get_data('runtime_classpath')

      # TODO(John Sirois): Manifest handling is broken.  We should be tracking state and failing
      # fast if any duplicate entries are added; ie: if we get a second binary or a second agent.

      if isinstance(target, JvmBinary):
        self._add_manifest_entries(target, self._manifest)
        products_added = True
      elif isinstance(target, JavaAgent):
        self._add_agent_manifest(target, self._manifest)
        products_added = True
      elif recursive:
        agents = [t for t in target.closure() if isinstance(t, JavaAgent)]
        if len(agents) > 1:
          raise TaskError('Only 1 agent can be added to a jar, found {} for {}:\n\t{}'
                          .format(len(agents),
                                  target.address.reference(),
                                  '\n\t'.join(agent.address.reference() for agent in agents)))
        elif agents:
          self._add_agent_manifest(agents[0], self._manifest)
          products_added = True

      # In the transitive case we'll gather internal resources naturally as dependencies, but in the
      # non-transitive case we need to manually add these special (in the context of jarring)
      # dependencies.
      targets = target.closure(bfs=True) if recursive else [target]
      if not recursive and target.has_resources:
        targets += target.resources
      # We only gather internal classpath elements per our contract.
      target_classpath = ClasspathUtil.internal_classpath(targets,
                                                          classpath_products)
      for entry in target_classpath:
        if ClasspathUtil.is_jar(entry):
          self._jar.writejar(entry)
          products_added = True
        elif ClasspathUtil.is_dir(entry):
          for rel_file in ClasspathUtil.classpath_entries_contents([entry]):
            self._jar.write(os.path.join(entry, rel_file), rel_file)
            products_added = True
        else:
          # non-jar and non-directory classpath entries should be ignored
          pass

      return products_added
Adds the classes and resources for a target to an open jar.
dataset/ETHPy150Open pantsbuild/pants/src/python/pants/backend/jvm/tasks/jar_task.py/JarBuilderTask.JarBuilder.add_target