def list_submodule_status(self, recursive=True): """Lists the submodules in this git repository. Args: recursive: Whether to lists the submodules recursively. Yields: Tuples (git commit hash, submodule name, ref diff or None). """ args = ["submodule", "status"] if recursive: args.append("--recursive") cmd = self.command(*args) for line in cmd.output_lines: line = line.strip() if len(line) == 0: continue split = line.split() (commit_hash, module_name) = split[:2] if len(split) > 2: ref_diff = split[2] # ref_diff is formatted as "(<tag>-<commit-count>-g<short-hash>)" ref_diff = base.strip_prefix(ref_diff, "(") ref_diff = base.strip_suffix(ref_diff, ")") else: ref_diff = None yield (commit_hash, module_name, ref_diff)
def Run(self, args): assert (len(args) == 1), ("Specify a classpath to analyze.") classpath = args[0] cp_entries = classpath.split(":") cp_entries = list(normalize_classpath(cp_entries)) # Map: class name -> set of jar path class_map = collections.defaultdict(set) # Map: jar path -> set of class name jar_map = collections.defaultdict(set) for cp_entry in cp_entries: logging.debug("Processing classpath entry: %r", cp_entry) for zip_entry in list_jar_file_entries(cp_entry): if not zip_entry.endswith(".class"): continue class_name = base.strip_suffix(zip_entry, ".class").replace("/", ".") class_map[class_name].add(cp_entry) jar_map[cp_entry].add(class_name) for jar_paths in frozenset(map(frozenset, class_map.values())): if len(jar_paths) > 1: logging.info("-" * 80) logging.info( "Overlapping JARs: %s\n%s", ", ".join( sorted( frozenset( map(lambda k: os.path.basename(k), jar_paths)))), "\n".join(map(lambda k: "\t%s" % k, jar_paths))) union_classes = set() xsect_classes = None for jar_path in sorted(jar_paths): classes = jar_map[jar_path] union_classes.update(classes) if xsect_classes is None: xsect_classes = set(classes) else: xsect_classes.intersection_update(classes) logging.info("Union: %d classes - Intersection: %d classes.", len(union_classes), len(xsect_classes))
def Run(self, args): assert (len(args) == 1), ("Specify a classpath to analyze.") classpath = args[0] cp_entries = classpath.split(":") cp_entries = list(normalize_classpath(cp_entries)) # Map: class name -> set of jar path class_map = collections.defaultdict(set) # Map: jar path -> set of class name jar_map = collections.defaultdict(set) for cp_entry in cp_entries: logging.debug("Processing classpath entry: %r", cp_entry) for zip_entry in list_jar_file_entries(cp_entry): if not zip_entry.endswith(".class"): continue class_name = base.strip_suffix(zip_entry, ".class").replace("/", ".") class_map[class_name].add(cp_entry) jar_map[cp_entry].add(class_name) for jar_paths in frozenset(map(frozenset, class_map.values())): if len(jar_paths) > 1: logging.info("-" * 80) logging.info( "Overlapping JARs: %s\n%s", ", ".join(sorted(frozenset(map(lambda k: os.path.basename(k), jar_paths)))), "\n".join(map(lambda k: "\t%s" % k, jar_paths))) union_classes = set() xsect_classes = None for jar_path in sorted(jar_paths): classes = jar_map[jar_path] union_classes.update(classes) if xsect_classes is None: xsect_classes = set(classes) else: xsect_classes.intersection_update(classes) logging.info("Union: %d classes - Intersection: %d classes.", len(union_classes), len(xsect_classes))