Search in sources :

Example 16 with BundleModuleName

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

the class BundleModuleMergerTest method testRealBundle.

@Test
public void testRealBundle() throws Exception {
    File file = tmp.newFile();
    try (FileOutputStream os = new FileOutputStream(file)) {
        // This bundle has a base module and 3 feature modules: java, assets and initialInstall.
        // initialInstall should be merged into base.
        os.write(TestData.readBytes("testdata/bundle/install-time-permanent-modules.aab"));
    }
    Path bundleFile = file.toPath();
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundlePreMerge = AppBundle.buildFromZip(appBundleZip);
        AppBundle appBundlePostMerge = BundleModuleMerger.mergeNonRemovableInstallTimeModules(appBundlePreMerge, /* overrideBundleToolVersion = */
        false);
        assertThat(appBundlePostMerge.getModules().keySet().stream().map(BundleModuleName::getName)).containsExactly("base", "java", "assets");
        assertEntriesPreserved(appBundlePreMerge, appBundlePostMerge);
        assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes.dex"))).isPresent();
        assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes2.dex"))).isPresent();
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 17 with BundleModuleName

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

the class FusingAndroidManifestMergerTest method mergeChildrenMode_onlyOneMetadataPerName.

@Test
public void mergeChildrenMode_onlyOneMetadataPerName() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of(), /* metadata= */
    ImmutableList.of("sharedMeta", "baseMeta"))), androidManifestForFeature("com.testapp.feature1", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of(), /* metadata= */
    ImmutableList.of("sharedMeta"))));
    AndroidManifest merged = createMerger(Mode.MERGE_CHILDREN).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of(), /* metadata= */
    ImmutableList.of("sharedMeta", "baseMeta"))));
    assertThat(merged).isEqualTo(expected);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Example 18 with BundleModuleName

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

the class FusingAndroidManifestMergerTest method mergeChildrenMode_nonIntentFilterOrMetadataElements_notMerged.

@Test
public void mergeChildrenMode_nonIntentFilterOrMetadataElements_notMerged() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("elementBase")))), androidManifestForFeature("com.testapp.feature1", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("elementFeature")))));
    AndroidManifest merged = createMerger(Mode.MERGE_CHILDREN).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("elementFeature")))));
    assertThat(merged).isEqualTo(expected);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Example 19 with BundleModuleName

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

the class FusingAndroidManifestMergerTest method mergeChildrenMode_keepTextNodesInsideElement.

@Test
public void mergeChildrenMode_keepTextNodesInsideElement() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addAttribute(XmlProtoAttributeBuilder.createAndroidAttribute(NAME_ATTRIBUTE_NAME, NAME_RESOURCE_ID).setValueAsString("meta"))))), androidManifestForFeature("com.testapp.feature1", withActivity("myActivity", activity -> activity.addChildText("text"))));
    AndroidManifest merged = createMerger(Mode.MERGE_CHILDREN).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildText("text").addChildElement(XmlProtoElementBuilder.create("meta-data").addAttribute(XmlProtoAttributeBuilder.createAndroidAttribute(NAME_ATTRIBUTE_NAME, NAME_RESOURCE_ID).setValueAsString("meta"))))));
    assertThat(merged).isEqualTo(expected);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Example 20 with BundleModuleName

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

the class FusingAndroidManifestMergerTest method mergeChildrenMode_gatherAllMetadataAndIntentFilters.

@Test
public void mergeChildrenMode_gatherAllMetadataAndIntentFilters() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("baseAction", "baseAction2"), /* metadata= */
    ImmutableList.of("baseMeta"))), androidManifestForFeature("com.testapp.feature1", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("feature1Action"), /* metadata= */
    ImmutableList.of("feature1Meta"))), androidManifestForFeature("com.testapp.feature2", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("feature2Action"), /* metadata= */
    ImmutableList.of())));
    AndroidManifest merged = createMerger(Mode.MERGE_CHILDREN).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("feature1Action", "feature2Action", "baseAction", "baseAction2"), /* metadata= */
    ImmutableList.of("feature1Meta", "baseMeta"))));
    assertThat(merged).isEqualTo(expected);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

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