use of com.android.aapt.Resources.XmlNode 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.aapt.Resources.XmlNode 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);
}
use of com.android.aapt.Resources.XmlNode 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);
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class XmlProtoElementTest method getChildrenText.
@Test
public void getChildrenText() {
XmlNode childText1 = XmlNode.newBuilder().setText("child1").build();
XmlNode childText2 = XmlNode.newBuilder().setText("child2").build();
XmlNode childElement3 = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("element")).build();
XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(childText1).addChild(childText2).addChild(childElement3).build());
assertThat(element.getChildrenText()).containsExactly(new XmlProtoNode(childText1), new XmlProtoNode(childText2));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ModuleSplitterTest method splitNameNotRemovedForInstantSplit.
@Test
public void splitNameNotRemovedForInstantSplit() throws Exception {
XmlNode manifest = androidManifest("com.test.app", withMainActivity("MainActivity"), withSplitNameActivity("FooActivity", "testModule"));
BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(manifest).build();
ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createNoStamp(bundleModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setForInstantAppVariants(true).build(), lPlusVariantTargeting(), ImmutableSet.of("testModule")).splitModule();
assertThat(moduleSplits).hasSize(1);
ModuleSplit masterSplit = moduleSplits.get(0);
ImmutableList<XmlElement> activities = masterSplit.getAndroidManifest().getManifestRoot().getElement().getChildElement("application").getChildrenElements(ACTIVITY_ELEMENT_NAME).map(XmlProtoElement::getProto).collect(toImmutableList());
assertThat(activities).hasSize(2);
XmlElement activityElement = activities.get(1);
assertThat(activityElement.getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "FooActivity"), xmlAttribute(ANDROID_NAMESPACE_URI, "splitName", SPLIT_NAME_RESOURCE_ID, "testModule"));
}
Aggregations