tools/android/dependency_analysis/print_class_dependencies.py
def main():
    """Prints class-level dependencies for one or more input classes."""
    arg_parser = argparse.ArgumentParser(
        description='Given a JSON dependency graph, output '
        'the class-level dependencies for a given list of classes.')
    required_arg_group = arg_parser.add_argument_group('required arguments')
    required_arg_group.add_argument(
        '-f',
        '--file',
        required=True,
        help='Path to the JSON file containing the dependency graph. '
        'See the README on how to generate this file.')
    required_arg_group_either = arg_parser.add_argument_group(
        'required arguments (at least one)')
    required_arg_group_either.add_argument(
        '-c',
        '--classes',
        dest='class_names',
        help='Case-sensitive name of the classes to print dependencies for. '
        'Matches either the simple class name without package or the fully '
        'qualified class name. For example, `AppHooks` matches '
        '`org.chromium.browser.AppHooks`. Specify multiple classes with a '
        'comma-separated list, for example '
        '`ChromeActivity,ChromeTabbedActivity`')
    required_arg_group_either.add_argument(
        '-p',
        '--packages',
        dest='package_names',
        help='Case-sensitive name of the packages to print dependencies for, '
        'such as `org.chromium.browser`. Specify multiple packages with a '
        'comma-separated list.`')
    direction_arg_group = arg_parser.add_mutually_exclusive_group()
    direction_arg_group.add_argument('--inbound',
                                     dest='inbound_only',
                                     action='store_true',
                                     help='Print inbound dependencies only.')
    direction_arg_group.add_argument('--outbound',
                                     dest='outbound_only',
                                     action='store_true',
                                     help='Print outbound dependencies only.')
    arg_parser.add_argument('--fully-qualified',
                            action='store_true',
                            help='Use fully qualified class names instead of '
                            'shortened ones.')
    arg_parser.add_argument('--ignore-modularized',
                            action='store_true',
                            help='Do not print outbound dependencies on '
                            'allowed (modules, components, base, etc.) '
                            'dependencies.')
    arg_parser.add_argument('--ignore-audited-here',
                            action='store_true',
                            help='Do not print outbound dependencies on '
                            'other classes being audited in this run.')
    arg_parser.add_argument('--ignore-same-package',
                            action='store_true',
                            help='Do not print outbound dependencies on '
                            'classes in the same package.')
    arguments = arg_parser.parse_args()

    if not arguments.class_names and not arguments.package_names:
        raise ValueError('Either -c/--classes or -p/--packages need to be '
                         'specified.')

    print_mode = PrintMode(inbound=not arguments.outbound_only,
                           outbound=not arguments.inbound_only,
                           ignore_modularized=arguments.ignore_modularized,
                           ignore_audited_here=arguments.ignore_audited_here,
                           ignore_same_package=arguments.ignore_same_package,
                           fully_qualified=arguments.fully_qualified)

    class_graph, package_graph, _ = \
        serialization.load_class_and_package_graphs_from_file(arguments.file)

    valid_class_names = []
    if arguments.class_names:
        valid_class_names.extend(
            print_dependencies_helper.get_valid_classes_from_class_input(
                class_graph, arguments.class_names))
    if arguments.package_names:
        valid_class_names.extend(
            print_dependencies_helper.get_valid_classes_from_package_input(
                package_graph, arguments.package_names))

    target_dependencies = TargetDependencies()
    for i, fully_qualified_class_name in enumerate(valid_class_names):
        if i > 0:
            print()

        new_target_deps = print_class_dependencies_for_key(
            class_graph, fully_qualified_class_name, print_mode,
            set(valid_class_names))
        target_dependencies.merge(new_target_deps)

    target_dependencies.print()
Prints class-level dependencies for one or more input classes.
Prints class-level dependencies for one or more input classes.
Prints class - level dependencies for one or more input classes .
def main():
    arg_parser = argparse.ArgumentParser(
        description='Given a JSON dependency graph, output '
        'the class-level dependencies for a given list of classes.')
    required_arg_group = arg_parser.add_argument_group('required arguments')
    required_arg_group.add_argument(
        '-f',
        '--file',
        required=True,
        help='Path to the JSON file containing the dependency graph. '
        'See the README on how to generate this file.')
    required_arg_group_either = arg_parser.add_argument_group(
        'required arguments (at least one)')
    required_arg_group_either.add_argument(
        '-c',
        '--classes',
        dest='class_names',
        help='Case-sensitive name of the classes to print dependencies for. '
        'Matches either the simple class name without package or the fully '
        'qualified class name. For example, `AppHooks` matches '
        '`org.chromium.browser.AppHooks`. Specify multiple classes with a '
        'comma-separated list, for example '
        '`ChromeActivity,ChromeTabbedActivity`')
    required_arg_group_either.add_argument(
        '-p',
        '--packages',
        dest='package_names',
        help='Case-sensitive name of the packages to print dependencies for, '
        'such as `org.chromium.browser`. Specify multiple packages with a '
        'comma-separated list.`')
    direction_arg_group = arg_parser.add_mutually_exclusive_group()
    direction_arg_group.add_argument('--inbound',
                                     dest='inbound_only',
                                     action='store_true',
                                     help='Print inbound dependencies only.')
    direction_arg_group.add_argument('--outbound',
                                     dest='outbound_only',
                                     action='store_true',
                                     help='Print outbound dependencies only.')
    arg_parser.add_argument('--fully-qualified',
                            action='store_true',
                            help='Use fully qualified class names instead of '
                            'shortened ones.')
    arg_parser.add_argument('--ignore-modularized',
                            action='store_true',
                            help='Do not print outbound dependencies on '
                            'allowed (modules, components, base, etc.) '
                            'dependencies.')
    arg_parser.add_argument('--ignore-audited-here',
                            action='store_true',
                            help='Do not print outbound dependencies on '
                            'other classes being audited in this run.')
    arg_parser.add_argument('--ignore-same-package',
                            action='store_true',
                            help='Do not print outbound dependencies on '
                            'classes in the same package.')
    arguments = arg_parser.parse_args()
    if not arguments.class_names and not arguments.package_names:
        raise ValueError('Either -c/--classes or -p/--packages need to be '
                         'specified.')
    print_mode = PrintMode(inbound=not arguments.outbound_only,
                           outbound=not arguments.inbound_only,
                           ignore_modularized=arguments.ignore_modularized,
                           ignore_audited_here=arguments.ignore_audited_here,
                           ignore_same_package=arguments.ignore_same_package,
                           fully_qualified=arguments.fully_qualified)
    class_graph, package_graph, _ = \
        serialization.load_class_and_package_graphs_from_file(arguments.file)
    valid_class_names = []
    if arguments.class_names:
        valid_class_names.extend(
            print_dependencies_helper.get_valid_classes_from_class_input(
                class_graph, arguments.class_names))
    if arguments.package_names:
        valid_class_names.extend(
            print_dependencies_helper.get_valid_classes_from_package_input(
                package_graph, arguments.package_names))
    target_dependencies = TargetDependencies()
    for i, fully_qualified_class_name in enumerate(valid_class_names):
        if i > 0:
            print()
        new_target_deps = print_class_dependencies_for_key(
            class_graph, fully_qualified_class_name, print_mode,
            set(valid_class_names))
        target_dependencies.merge(new_target_deps)
    target_dependencies.print()
def main ( ) : arg_parser = argparse . ArgumentParser ( description = 'Given a JSON dependency graph, output ' 'the class-level dependencies for a given list of classes.' ) required_arg_group = arg_parser . add_argument_group ( 'required arguments' ) required_arg_group . add_argument ( '-f' , '--file' , required = True , help = 'Path to the JSON file containing the dependency graph. ' 'See the README on how to generate this file.' ) required_arg_group_either = arg_parser . add_argument_group ( 'required arguments (at least one)' ) required_arg_group_either . add_argument ( '-c' , '--classes' , dest = 'class_names' , help = 'Case-sensitive name of the classes to print dependencies for. ' 'Matches either the simple class name without package or the fully ' 'qualified class name. For example, `AppHooks` matches ' '`org.chromium.browser.AppHooks`. Specify multiple classes with a ' 'comma-separated list, for example ' '`ChromeActivity,ChromeTabbedActivity`' ) required_arg_group_either . add_argument ( '-p' , '--packages' , dest = 'package_names' , help = 'Case-sensitive name of the packages to print dependencies for, ' 'such as `org.chromium.browser`. Specify multiple packages with a ' 'comma-separated list.`' ) direction_arg_group = arg_parser . add_mutually_exclusive_group ( ) direction_arg_group . add_argument ( '--inbound' , dest = 'inbound_only' , action = 'store_true' , help = 'Print inbound dependencies only.' ) direction_arg_group . add_argument ( '--outbound' , dest = 'outbound_only' , action = 'store_true' , help = 'Print outbound dependencies only.' ) arg_parser . add_argument ( '--fully-qualified' , action = 'store_true' , help = 'Use fully qualified class names instead of ' 'shortened ones.' ) arg_parser . add_argument ( '--ignore-modularized' , action = 'store_true' , help = 'Do not print outbound dependencies on ' 'allowed (modules, components, base, etc.) ' 'dependencies.' ) arg_parser . add_argument ( '--ignore-audited-here' , action = 'store_true' , help = 'Do not print outbound dependencies on ' 'other classes being audited in this run.' ) arg_parser . add_argument ( '--ignore-same-package' , action = 'store_true' , help = 'Do not print outbound dependencies on ' 'classes in the same package.' ) arguments = arg_parser . parse_args ( ) if not arguments . class_names and not arguments . package_names : raise ValueError ( 'Either -c/--classes or -p/--packages need to be ' 'specified.' ) print_mode = PrintMode ( inbound = not arguments . outbound_only , outbound = not arguments . inbound_only , ignore_modularized = arguments . ignore_modularized , ignore_audited_here = arguments . ignore_audited_here , ignore_same_package = arguments . ignore_same_package , fully_qualified = arguments . fully_qualified ) class_graph , package_graph , _ = serialization . load_class_and_package_graphs_from_file ( arguments . file ) valid_class_names = [ ] if arguments . class_names : valid_class_names . extend ( print_dependencies_helper . get_valid_classes_from_class_input ( class_graph , arguments . class_names ) ) if arguments . package_names : valid_class_names . extend ( print_dependencies_helper . get_valid_classes_from_package_input ( package_graph , arguments . package_names ) ) target_dependencies = TargetDependencies ( ) for i , fully_qualified_class_name in enumerate ( valid_class_names ) : if i > 0 : print ( ) new_target_deps = print_class_dependencies_for_key ( class_graph , fully_qualified_class_name , print_mode , set ( valid_class_names ) ) target_dependencies . merge ( new_target_deps ) target_dependencies . print ( )
Prints class-level dependencies for one or more input classes.
Prints class - level dependencies for one or more input classes .
"""Prints class-level dependencies for one or more input classes."""