Class APKModuleGraph

  • All Implemented Interfaces:
    AddsToRuleKey

    public class APKModuleGraph
    extends Object
    implements AddsToRuleKey
    Utility class for grouping sets of targets and their dependencies into APK Modules containing their exclusive dependencies. Targets that are dependencies of the root target are included in the root. Targets that have dependencies in two are more groups are put the APKModule that represents the dependent modules minimal cover based on the declared dependencies given. If the minimal cover contains more than one APKModule, the target will belong to a new shared APKModule that is a dependency of all APKModules in the minimal cover.
    • Constructor Detail

      • APKModuleGraph

        public APKModuleGraph​(TargetGraph targetGraph,
                              BuildTarget target)
        Constructor for the APKModule graph generator object that produces a graph with only a root module.
      • APKModuleGraph

        public APKModuleGraph​(Optional<com.google.common.collect.ImmutableMap<String,​com.google.common.collect.ImmutableList<BuildTarget>>> seedConfigMap,
                              Optional<com.google.common.collect.ImmutableMap<String,​com.google.common.collect.ImmutableList<String>>> appModuleDependencies,
                              Optional<List<BuildTarget>> blacklistedModules,
                              Set<String> modulesWithResources,
                              Set<String> modulesWithManifest,
                              TargetGraph targetGraph,
                              BuildTarget target)
        Constructor for the APKModule graph generator object
        Parameters:
        seedConfigMap - A map of names to seed targets to use for creating APKModule.
        appModuleDependencies -

        a mapping of declared dependencies between module names. If a APKModule m1 depends on m2, it implies to buck that in order for m1 to be available for execution m2 must be available for use as well. Because of this, we can say that including a buck target in m2 effectively includes the buck-target in m2's dependent m1. In other words, m2 covers m1. Therefore, if a buck target is required by both these modules, we can safely place it in the minimal cover which is the APKModule m2.

        blacklistedModules - A list of targets that will NOT be included in any module.
        modulesWithResources - A list of modules with resources
        modulesWithManifest - A list of modules with manifests. This parameter will be later used to fetch Manifest information for each module.
        targetGraph - The full target graph of the build
        target - The root target to use to traverse the graph
      • APKModuleGraph

        public APKModuleGraph​(TargetGraph targetGraph,
                              BuildTarget target,
                              Optional<Set<BuildTarget>> seedTargets)
        Constructor for the APKModule graph generator object
        Parameters:
        targetGraph - The full target graph of the build
        target - The root target to use to traverse the graph
        seedTargets - The set of seed targets to use for creating APKModule.
    • Method Detail

      • toOutgoingEdgesMap

        public com.google.common.collect.ImmutableSortedMap<APKModule,​com.google.common.collect.ImmutableSortedSet<APKModule>> toOutgoingEdgesMap()
      • extractTargetsFromQueries

        public static Optional<List<BuildTarget>> extractTargetsFromQueries​(Optional<List<Query>> queries)
        Utility method for flattening a list of queries into the a list of the build targets they resolve to.
        Parameters:
        queries - list of queries, they are expected to have already been resolved
        Returns:
        list of build targets queries resolve to joined together
      • getGraph

        public DirectedAcyclicGraph<APKModule> getGraph()
        Lazy generate the graph on first use
        Returns:
        the DAG representing APKModules and their dependency relationships
      • getRootAPKModule

        public APKModule getRootAPKModule()
        Get the APKModule representing the core application that is always included in the apk
        Returns:
        the root APK Module
      • getAPKModules

        public com.google.common.collect.ImmutableSet<APKModule> getAPKModules()
      • getSeedConfigMap

        public Optional<com.google.common.collect.ImmutableMap<String,​com.google.common.collect.ImmutableList<BuildTarget>>> getSeedConfigMap()
      • findModuleForTarget

        public APKModule findModuleForTarget​(BuildTarget target)
        Get the Module that contains the given target
        Parameters:
        target - target to serach for in modules
        Returns:
        the module that contains the target
      • findResourceModuleForTarget

        public APKModule findResourceModuleForTarget​(BuildTarget target)
        Get the Module that should contain the resources for the given target
        Parameters:
        target - target to serach for in modules
        Returns:
        the module that contains the target
      • findManifestModuleForTarget

        public APKModule findManifestModuleForTarget​(BuildTarget target)
        Get the Module that should contain the manifest for the given target or else fallback to the same logic of findResourceModuleForTarget.
        Parameters:
        target - target to search for in modules
        Returns:
        the module that contains the target
      • getAPKModuleToClassesMap

        public static com.google.common.collect.ImmutableMultimap<APKModule,​String> getAPKModuleToClassesMap​(com.google.common.collect.ImmutableMultimap<APKModule,​Path> apkModuleToJarPathMap,
                                                                                                                   java.util.function.Function<String,​String> translatorFunction,
                                                                                                                   ProjectFilesystem filesystem)
                                                                                                            throws IOException
        Group the classes in the input jars into a multimap based on the APKModule they belong to
        Parameters:
        apkModuleToJarPathMap - the mapping of APKModules to the path for the jar files
        translatorFunction - function used to translate the class names to obfuscated names
        filesystem - filesystem representation for resolving paths
        Returns:
        The mapping of APKModules to the class names they contain
        Throws:
        IOException