use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestEditorTest method setConfigForSplit.
@Test
public void setConfigForSplit() {
AndroidManifest androidManifest = createManifestWithApplicationElement();
AndroidManifest editedManifest = androidManifest.toEditor().setConfigForSplit("feature1").save();
XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
assertThat(manifestRoot.hasElement()).isTrue();
XmlElement manifestElement = manifestRoot.getElement();
assertThat(manifestElement.getName()).isEqualTo("manifest");
assertThat(manifestElement.getAttributeList()).containsExactly(xmlAttribute("configForSplit", "feature1"));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestEditorTest method copyPermissions.
@Test
public void copyPermissions() throws Exception {
XmlElement permisisonElement = xmlElement("permission", xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "SEND_SMS"));
AndroidManifest manifestWithPermissions = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(permisisonElement))));
AndroidManifest manifestToUpdate = AndroidManifest.create(androidManifest("com.test.app"));
AndroidManifest updatedManifest = manifestToUpdate.toEditor().copyPermissions(manifestWithPermissions).save();
ImmutableList<XmlElement> copiedPermissions = updatedManifest.getManifestRoot().getProto().getElement().getChildList().stream().map(XmlNode::getElement).filter(childElement -> childElement.getName().equals("permission")).collect(toImmutableList());
assertThat(copiedPermissions).containsExactly(permisisonElement);
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ModuleSplitTest method masterSplitGetsManifestForFeatureSplit.
@Test
public void masterSplitGetsManifestForFeatureSplit() throws Exception {
BundleModule module = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).build();
ModuleSplit split = ModuleSplit.forModule(module);
split = split.writeSplitIdInManifest(split.getSuffix());
XmlNode writtenManifest = split.getAndroidManifest().getManifestRoot().getProto();
assertThat(writtenManifest.getElement().getAttributeList()).containsExactly(xmlAttribute("package", "com.test.app"), xmlDecimalIntegerAttribute(ANDROID_NAMESPACE_URI, "versionCode", VERSION_CODE_RESOURCE_ID, 1), xmlAttribute("split", "testModule"), xmlBooleanAttribute(ANDROID_NAMESPACE_URI, "isFeatureSplit", IS_FEATURE_SPLIT_RESOURCE_ID, true));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class SplitsProtoXmlBuilderTest method buildOneModule.
@Test
public void buildOneModule() {
SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
splitsProtoXmlBuilder.addLanguageMapping(BundleModuleName.create("module"), /* language = */
"en", /* splitId = */
"module.config.en");
XmlNode rootNode = splitsProtoXmlBuilder.build();
// Answer:
// <splits>
// <module name="module">
// <language>
// <entry key="en" split="module.config.en">
// </language>
// </module>
// </splits>
XmlProtoElementBuilder actual = XmlProtoElementBuilder.create("splits").addChildElement(XmlProtoElementBuilder.create("module").addAttribute(createAttribute("name", "module")).addChildElement(XmlProtoElementBuilder.create("language").addChildElement(XmlProtoElementBuilder.create("entry").addAttribute(createAttribute("key", "en")).addAttribute(createAttribute("split", "module.config.en")))));
assertThat(rootNode).isEqualTo(getProto(actual));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class SplitsProtoXmlBuilderTest method buildManyEntries.
@Test
public void buildManyEntries() {
SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
splitsProtoXmlBuilder.addLanguageMapping(BASE_MODULE_NAME, /* language = */
"ru", /* splitId = */
"config.ru");
splitsProtoXmlBuilder.addLanguageMapping(BASE_MODULE_NAME, /* language = */
"en", /* splitId = */
"");
splitsProtoXmlBuilder.addLanguageMapping(BASE_MODULE_NAME, /* language = */
"fr", /* splitId = */
"config.fr");
XmlNode rootNode = splitsProtoXmlBuilder.build();
// Answer:
// <splits>
// <module name="">
// <language>
// <entry key="ru" split="config.ru">
// <entry key="en" split="">
// <entry key="fr" split="config.fr">
// </language>
// </module>
// </splits>
// Checking base structure.
assertThat(rootNode.getElement().getName()).isEqualTo("splits");
assertThat(rootNode.getElement().getChildCount()).isEqualTo(1);
assertThat(rootNode.getElement().getChild(0).getElement().getName()).isEqualTo("module");
assertThat(rootNode.getElement().getChild(0).getElement().getAttributeList()).containsExactly(createAttribute("name", "").getProto().build());
// Checking entries of splits[0][0] (splits -> module -> language).
assertThat(rootNode.getElement().getChild(0).getElement().getChild(0).getElement().getChildList()).containsExactly(getProto(XmlProtoElementBuilder.create("entry").addAttribute(createAttribute("key", "ru")).addAttribute(createAttribute("split", "config.ru"))), getProto(XmlProtoElementBuilder.create("entry").addAttribute(createAttribute("key", "en")).addAttribute(createAttribute("split", ""))), getProto(XmlProtoElementBuilder.create("entry").addAttribute(createAttribute("key", "fr")).addAttribute(createAttribute("split", "config.fr"))));
}
Aggregations