Search in sources :

Example 81 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class DumpManagerTest method dumpManifest.

@Test
public void dumpManifest() throws Exception {
    XmlNode manifest = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").build()).build();
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifest)).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setModuleName("base").setOutputStream(new PrintStream(outputStream)).build().execute();
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("<manifest/>%n"));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ManifestProtoUtils.withMetadataValue(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) XmlAttribute(com.android.aapt.Resources.XmlAttribute) DumpTarget(com.android.tools.build.bundletool.commands.DumpCommand.DumpTarget) Bundletool(com.android.bundle.Config.Bundletool) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) Path(java.nio.file.Path) ResourceTable(com.android.aapt.Resources.ResourceTable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) PrintStream(java.io.PrintStream) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) BundleConfig(com.android.bundle.Config.BundleConfig) ManifestProtoUtils.withDebuggableAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDebuggableAttribute) XmlElement(com.android.aapt.Resources.XmlElement) Compression(com.android.bundle.Config.Compression) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) PrintStream(java.io.PrintStream) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 82 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BundleModuleMergerTest method testDoNotMergeIfNotInstallTime.

@Test
public void testDoNotMergeIfNotInstallTime() throws Exception {
    XmlNode onDemandModuleManifest = androidManifestForFeature("com.test.app.detail", withOnDemandDelivery());
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), onDemandModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false);
        assertThat(appBundle.getFeatureModules().keySet()).comparingElementsUsing(equalsBundleModuleName()).containsExactly("base", "detail");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 83 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_mergingOptedOut.

@Test
public void testMultipleModulesWithInstallTime_mergingOptedOut() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeRemovableElement(true));
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false);
        assertThat(appBundle.getFeatureModules().keySet()).comparingElementsUsing(equalsBundleModuleName()).containsExactly("base", "detail");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 84 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_implicitMerging_duplicateModuleEntries.

@Test
public void testMultipleModulesWithInstallTime_implicitMerging_duplicateModuleEntries() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery());
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail1/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail1/assets/detailsAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail2/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail2/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("detail2/assets/detailsAssetfile.txt"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false);
        assertThat(appBundle.getFeatureModules().keySet()).comparingElementsUsing(equalsBundleModuleName()).containsExactly("base");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 85 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_bundleToolVersionOverride.

@Test
public void testMultipleModulesWithInstallTime_bundleToolVersionOverride() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery());
    createBasicZipBuilder(BUNDLE_CONFIG_0_14_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        true);
        assertThat(appBundle.getFeatureModules().keySet()).comparingElementsUsing(equalsBundleModuleName()).containsExactly("base");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Aggregations

XmlNode (com.android.aapt.Resources.XmlNode)99 Test (org.junit.Test)91 XmlElement (com.android.aapt.Resources.XmlElement)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)27 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)23 Truth.assertThat (com.google.common.truth.Truth.assertThat)23 RunWith (org.junit.runner.RunWith)23 ResourceTable (com.android.aapt.Resources.ResourceTable)21 ImmutableList (com.google.common.collect.ImmutableList)21 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)16 Nullable (javax.annotation.Nullable)16 Theories (org.junit.experimental.theories.Theories)16 ZipFile (java.util.zip.ZipFile)12 FileReference (com.android.aapt.Resources.FileReference)10 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)9 Attribute (com.android.aapt.Resources.Attribute)9 Symbol (com.android.aapt.Resources.Attribute.Symbol)9 CompoundValue (com.android.aapt.Resources.CompoundValue)9 ConfigValue (com.android.aapt.Resources.ConfigValue)9