def _consolidate_classpath(self, targets, classpath_products):
    """Convert loose directories in classpath_products into jars. """
    # TODO: find a way to not process classpath entries for valid VTs.

    # NB: It is very expensive to call to get entries for each target one at a time.
    # For performance reasons we look them all up at once.
    entries_map = defaultdict(list)
    for (cp, target) in classpath_products.get_product_target_mappings_for_targets(targets, True):
      entries_map[target].append(cp)

    with self.invalidated(targets=targets, invalidate_dependents=True) as invalidation:
      for vt in invalidation.all_vts:
        entries = entries_map.get(vt.target, [])
        for index, (conf, entry) in enumerate(entries):
          if ClasspathUtil.is_dir(entry.path):
            jarpath = os.path.join(vt.results_dir, 'output-{}.jar'.format(index))

            # Regenerate artifact for invalid vts.
            if not vt.valid:
              with self.open_jar(jarpath, overwrite=True, compressed=False) as jar:
                jar.write(entry.path)

            # Replace directory classpath entry with its jarpath.
            classpath_products.remove_for_target(vt.target, [(conf, entry.path)])
            classpath_products.add_for_target(vt.target, [(conf, jarpath)])
def _consolidate_classpath ( self , targets , classpath_products ) : entries_map = defaultdict ( list ) for ( cp , target ) in classpath_products . get_product_target_mappings_for_targets ( targets , True ) : entries_map [ target ] . append ( cp ) with self . invalidated ( targets = targets , invalidate_dependents = True ) as invalidation : for vt in invalidation . all_vts : entries = entries_map . get ( vt . target , [ ] ) for index , ( conf , entry ) in enumerate ( entries ) : if ClasspathUtil . is_dir ( entry . path ) : jarpath = os . path . join ( vt . results_dir , 'output-{}.jar' . format ( index ) ) if not vt . valid : with self . open_jar ( jarpath , overwrite = True , compressed = False ) as jar : jar . write ( entry . path ) classpath_products . remove_for_target ( vt . target , [ ( conf , entry . path ) ] ) classpath_products . add_for_target ( vt . target , [ ( conf , jarpath ) ] )
Convert loose directories in classpath_products into jars.