Search in sources :

Example 26 with BundleModuleName

use of com.android.tools.build.bundletool.model.BundleModuleName in project bundletool by google.

the class SameTargetingMerger method mergeSplits.

private ModuleSplit mergeSplits(ImmutableCollection<ModuleSplit> splits) {
    ModuleSplit.Builder builder = ModuleSplit.builder();
    ImmutableList.Builder<ModuleEntry> entries = ImmutableList.builder();
    AndroidManifest mergedManifest = null;
    ResourceTable mergedResourceTable = null;
    NativeLibraries mergedNativeConfig = null;
    Map<String, TargetedAssetsDirectory> mergedAssetsConfig = new HashMap<>();
    ApexImages mergedApexConfig = null;
    ImmutableList<ApexEmbeddedApkConfig> mergedApexEmbeddedApkConfigs = null;
    BundleModuleName mergedModuleName = null;
    Boolean mergedIsMasterSplit = null;
    VariantTargeting mergedVariantTargeting = null;
    for (ModuleSplit split : splits) {
        mergedManifest = getSameValueOrNonNull(mergedManifest, split.getAndroidManifest()).orElseThrow(() -> new IllegalStateException("Encountered two distinct manifests while merging."));
        if (split.getResourceTable().isPresent()) {
            mergedResourceTable = getSameValueOrNonNull(mergedResourceTable, split.getResourceTable().get()).orElseThrow(() -> new IllegalStateException("Unsupported case: encountered two distinct resource tables while " + "merging."));
        }
        if (split.getNativeConfig().isPresent()) {
            mergedNativeConfig = getSameValueOrNonNull(mergedNativeConfig, split.getNativeConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct native configs while merging."));
        }
        if (split.getApexConfig().isPresent()) {
            mergedApexConfig = getSameValueOrNonNull(mergedApexConfig, split.getApexConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex configs while merging."));
        }
        mergedApexEmbeddedApkConfigs = getSameValueOrNonNull(mergedApexEmbeddedApkConfigs, split.getApexEmbeddedApkConfigs()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex embedded apk configs while merging."));
        mergedModuleName = getSameValueOrNonNull(mergedModuleName, split.getModuleName()).orElseThrow(() -> new IllegalStateException("Encountered two distinct module names while merging."));
        mergedIsMasterSplit = getSameValueOrNonNull(mergedIsMasterSplit, Boolean.valueOf(split.isMasterSplit())).orElseThrow(() -> new IllegalStateException("Encountered conflicting isMasterSplit flag values while merging."));
        mergedVariantTargeting = getSameValueOrNonNull(mergedVariantTargeting, split.getVariantTargeting()).orElseThrow(() -> new IllegalStateException("Encountered conflicting variant targeting values while merging."));
        entries.addAll(split.getEntries());
        builder.setApkTargeting(split.getApkTargeting());
        split.getAssetsConfig().ifPresent(assetsConfig -> {
            mergeTargetedAssetsDirectories(mergedAssetsConfig, assetsConfig.getDirectoryList());
        });
    }
    if (mergedManifest != null) {
        builder.setAndroidManifest(mergedManifest);
    }
    if (mergedResourceTable != null) {
        builder.setResourceTable(mergedResourceTable);
    }
    if (mergedNativeConfig != null) {
        builder.setNativeConfig(mergedNativeConfig);
    }
    if (!mergedAssetsConfig.isEmpty()) {
        builder.setAssetsConfig(Assets.newBuilder().addAllDirectory(mergedAssetsConfig.values()).build());
    }
    if (mergedApexConfig != null) {
        builder.setApexConfig(mergedApexConfig);
    }
    if (mergedApexEmbeddedApkConfigs != null) {
        builder.setApexEmbeddedApkConfigs(mergedApexEmbeddedApkConfigs);
    }
    if (mergedModuleName != null) {
        builder.setModuleName(mergedModuleName);
    }
    if (mergedIsMasterSplit != null) {
        builder.setMasterSplit(mergedIsMasterSplit);
    }
    builder.setVariantTargeting(mergedVariantTargeting);
    builder.setEntries(entries.build());
    return builder.build();
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) TargetedAssetsDirectory(com.android.bundle.Files.TargetedAssetsDirectory) NativeLibraries(com.android.bundle.Files.NativeLibraries) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ApexEmbeddedApkConfig(com.android.bundle.Config.ApexEmbeddedApkConfig) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ResourceTable(com.android.aapt.Resources.ResourceTable)

Aggregations

BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)26 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)19 Test (org.junit.Test)14 ZipPath (com.android.tools.build.bundletool.model.ZipPath)6 BundleModule (com.android.tools.build.bundletool.model.BundleModule)5 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)5 ImmutableList (com.google.common.collect.ImmutableList)5 AppBundle (com.android.tools.build.bundletool.model.AppBundle)4 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)4 HashMap (java.util.HashMap)4 BundleConfig (com.android.bundle.Config.BundleConfig)3 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)3 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ResourceTable (com.android.aapt.Resources.ResourceTable)2 DeviceSpec (com.android.bundle.Devices.DeviceSpec)2 TargetedAssetsDirectory (com.android.bundle.Files.TargetedAssetsDirectory)2 Predicates.not (com.google.common.base.Predicates.not)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2