Search in sources :

Example 1 with SYSTEM

use of com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM in project bundletool by google.

the class LocaleConfigXmlInjectorTest method process_systemSplits.

@Test
public void process_systemSplits() throws Exception {
    ModuleSplit baseMasterSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    true, SYSTEM, /* languageTargeting= */
    null);
    ModuleSplit otherSplitA = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("ru-RU", "module ru-RU")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SYSTEM, languageTargeting("ru"));
    ModuleSplit otherSplitB = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("fr", "module fr")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SYSTEM, languageTargeting("fr"));
    ModuleSplit otherSplitC = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("en-AU", "module en-AU")).build(), "module", /* masterSplit= */
    false, SYSTEM, languageTargeting("en"));
    ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(otherSplitA, otherSplitB, otherSplitC);
    ImmutableList<ModuleSplit> processedSplits = localeConfigXmlInjector.process(VariantKey.create(baseMasterSplit), ImmutableList.<ModuleSplit>builder().add(baseMasterSplit).addAll(otherSplits).build());
    ModuleSplit processedBaseMasterSplit = processedSplits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    assertThat(processedBaseMasterSplit.getAndroidManifest().hasLocaleConfig()).isTrue();
    assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app.module:xml/locales_config").withFileReference("res/xml/locales_config.xml");
    XmlNode expectedLocaleConfigProtoXml = createLocalesXmlNode(new HashSet<>(Arrays.asList("ru-RU", "fr")));
    assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedLocaleConfigProtoXml);
    ImmutableList<ModuleSplit> processedOtherSplits = processedSplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    assertThat(processedOtherSplits).containsExactly(otherSplitA, otherSplitB, otherSplitC);
}
Also used : Arrays(java.util.Arrays) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) VariantKey(com.android.tools.build.bundletool.model.VariantKey) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) 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) HashSet(java.util.HashSet) 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) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) 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) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Example 2 with SYSTEM

use of com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM 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

ResourceTable (com.android.aapt.Resources.ResourceTable)2 XmlNode (com.android.aapt.Resources.XmlNode)2 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)2 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)2 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)2 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)2 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)2 BASE_MODULE_NAME (com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME)2 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)2 SplitType (com.android.tools.build.bundletool.model.ModuleSplit.SplitType)2 SPLIT (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT)2 SYSTEM (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM)2 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)2 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)2 TargetingUtils.languageTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting)2 TruthResourceTable.assertThat (com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)2