Search in sources :

Example 1 with SplitsProtoXmlBuilder

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

the class SplitsXmlInjector method processStandaloneVariant.

private static ModuleSplit processStandaloneVariant(ModuleSplit split) {
    if (!split.getResourceTable().isPresent()) {
        return split;
    }
    SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
    addLanguageSplitsFromResourceTable(splitsProtoXmlBuilder, split);
    return injectSplitsXml(split, splitsProtoXmlBuilder.build());
}
Also used : SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder)

Example 2 with SplitsProtoXmlBuilder

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

the class SplitsXmlInjector method getSplitsXmlContentFromResourceTables.

private static XmlNode getSplitsXmlContentFromResourceTables(Collection<ModuleSplit> splits) {
    SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
    splits.stream().filter(ModuleSplit::isMasterSplit).forEach(split -> addLanguageSplitsFromResourceTable(splitsProtoXmlBuilder, split));
    return splitsProtoXmlBuilder.build();
}
Also used : SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder)

Example 3 with SplitsProtoXmlBuilder

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

the class SplitsXmlInjectorTest method process_standaloneSplitTypes.

@Test
public void process_standaloneSplitTypes() throws Exception {
    ModuleSplit standalone = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "", /* masterSplit= */
    true, STANDALONE, /* languageTargeting= */
    null);
    ResourceTable standaloneResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru-RU", "title ru-RU", "fr", "title fr")).build();
    standalone = standalone.toBuilder().setResourceTable(standaloneResourceTable).build();
    GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(standalone));
    ModuleSplit processedStandalone = xmlInjectorProcess(generatedApks).stream().collect(onlyElement());
    assertThat(processedStandalone.getAndroidManifest().getMetadataResourceId("com.android.vending.splits")).hasValue(0x7f020000);
    assertThat(processedStandalone.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
    XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").build();
    assertThat(XmlNode.parseFrom(processedStandalone.getEntries().get(0).getContent().read())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 4 with SplitsProtoXmlBuilder

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

the class SplitsXmlInjectorTest method process_noLanguageTargeting.

@Test
public void process_noLanguageTargeting() throws Exception {
    ResourceTable baseResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru", "title ru-RU", "fr", "title fr", "es", "title es")).build();
    ModuleSplit baseModule = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "", /* masterSplit= */
    true, SPLIT, /* languageTargeting= */
    null).toBuilder().setResourceTable(baseResourceTable).build();
    ResourceTable featureResourceTable = new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module_str", ImmutableMap.of("ru", "module ru-RU")).build();
    ModuleSplit featureModule = createModuleSplit("module", /* splitId= */
    "module", /* masterSplit= */
    true, SPLIT, /* languageTargeting= */
    null).toBuilder().setResourceTable(featureResourceTable).build();
    GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(baseModule, featureModule));
    ModuleSplit processedBaseMasterSplit = xmlInjectorProcess(generatedApks).stream().filter(module -> module.isMasterSplit() && module.isBaseModuleSplit()).collect(onlyElement());
    assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
    XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BundleModuleName.create("module"), "ru", "module").addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").addLanguageMapping(BASE_MODULE_NAME, "es", "").build();
    Optional<ModuleEntry> splitsXml = processedBaseMasterSplit.findEntry("res/xml/splits0.xml");
    assertThat(splitsXml).isPresent();
    assertThat(XmlNode.parseFrom(splitsXml.get().getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Also used : ARCHIVE(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.ARCHIVE) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Theories(org.junit.experimental.theories.Theories) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) SYSTEM(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM) STANDALONE(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.STANDALONE) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) INSTANT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.INSTANT) ImmutableMap(com.google.common.collect.ImmutableMap) TestUtils.createModuleEntryForFile(com.android.tools.build.bundletool.testing.TestUtils.createModuleEntryForFile) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Optional(java.util.Optional) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) XmlNode(com.android.aapt.Resources.XmlNode) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 5 with SplitsProtoXmlBuilder

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

the class SplitsXmlInjectorTest method process_systemSplits.

@Test
public void process_systemSplits() throws Exception {
    ModuleSplit baseMasterSplit = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "", /* masterSplit= */
    true, SYSTEM, languageTargeting("es"));
    ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "config.ru", /* masterSplit= */
    false, SYSTEM, languageTargeting("ru")), createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "config.fr", /* masterSplit= */
    false, SYSTEM, languageTargeting("fr")), createModuleSplit("module", /* splitId= */
    "module.config.ru", /* masterSplit= */
    false, SYSTEM, languageTargeting("ru")));
    GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.<ModuleSplit>builder().add(baseMasterSplit).addAll(otherSplits).build());
    assertThat(generatedApks.getAllApksStream()).containsAtLeastElementsIn(otherSplits);
    ModuleSplit processedBaseMasterSplit = xmlInjectorProcess(generatedApks).stream().filter(module -> module.isMasterSplit() && module.isBaseModuleSplit()).collect(onlyElement());
    assertThat(processedBaseMasterSplit.getAndroidManifest().getMetadataResourceId("com.android.vending.splits")).hasValue(0x7f010000);
    assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
    XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BundleModuleName.create("module"), "ru", "module.config.ru").addLanguageMapping(BASE_MODULE_NAME, "ru", "config.ru").addLanguageMapping(BASE_MODULE_NAME, "fr", "config.fr").addLanguageMapping(BASE_MODULE_NAME, "es", "").build();
    assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Also used : ARCHIVE(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.ARCHIVE) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Theories(org.junit.experimental.theories.Theories) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) SYSTEM(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM) STANDALONE(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.STANDALONE) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) INSTANT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.INSTANT) ImmutableMap(com.google.common.collect.ImmutableMap) TestUtils.createModuleEntryForFile(com.android.tools.build.bundletool.testing.TestUtils.createModuleEntryForFile) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Optional(java.util.Optional) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) XmlNode(com.android.aapt.Resources.XmlNode) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Aggregations

SplitsProtoXmlBuilder (com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder)6 ResourceTable (com.android.aapt.Resources.ResourceTable)4 XmlNode (com.android.aapt.Resources.XmlNode)4 GeneratedApks (com.android.tools.build.bundletool.model.GeneratedApks)4 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)4 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)4 Test (org.junit.Test)4 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)3 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)3 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)3 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)3 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)3 BASE_MODULE_NAME (com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME)3 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)3 SplitType (com.android.tools.build.bundletool.model.ModuleSplit.SplitType)3 ARCHIVE (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.ARCHIVE)3 INSTANT (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.INSTANT)3 SPLIT (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT)3 STANDALONE (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.STANDALONE)3 SYSTEM (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM)3