use of com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT 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);
}
use of com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT in project bundletool by google.
the class LocaleConfigXmlInjectorTest method process_duplicateLocales.
@Test
public void process_duplicateLocales() throws Exception {
ModuleSplit baseMasterSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null);
ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("ru-RU", "module ru-RU")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
false, SPLIT, languageTargeting("ru")), createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("ru-RU", "module ru-RU")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
false, SPLIT, languageTargeting("ru")), createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("fr", "module fr")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
false, SPLIT, languageTargeting("fr")));
ModuleSplit processedBaseMasterSplit = localeConfigXmlInjector.process(VariantKey.create(baseMasterSplit), ImmutableList.<ModuleSplit>builder().add(baseMasterSplit).addAll(otherSplits).build()).stream().filter(split -> split.isMasterSplit() && split.isBaseModuleSplit()).collect(onlyElement());
XmlNode expectedLocaleConfigProtoXml = createLocalesXmlNode(new HashSet<>(Arrays.asList("ru-RU", "fr")));
assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedLocaleConfigProtoXml);
}
use of com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT in project bundletool by google.
the class LocaleConfigXmlInjectorTest method process.
@Test
public void process() throws Exception {
ModuleSplit baseMasterSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
true, SPLIT, /* 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, SPLIT, 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, SPLIT, 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, SPLIT, 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);
}
use of com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT 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);
}
use of com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT in project bundletool by google.
the class SplitsXmlInjectorTest method process.
@Test
public void process() throws Exception {
ModuleSplit baseMasterSplit = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null);
ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"config.ru", /* masterSplit= */
false, SPLIT, languageTargeting("ru")), createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"config.fr", /* masterSplit= */
false, SPLIT, languageTargeting("fr")), createModuleSplit("module", /* splitId= */
"module", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null), createModuleSplit("module", /* splitId= */
"module.config.ru", /* masterSplit= */
false, SPLIT, 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").build();
assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Aggregations