use of com.android.aapt.Resources.XmlElement in project bundletool by google.
the class ModuleSplitTest method removeUnknownSplits.
@Test
public void removeUnknownSplits() {
AndroidManifest manifest = AndroidManifest.create(androidManifest("com.test.app", withMainActivity("MainActivity"), withSplitNameActivity("FooActivity", "foo")));
ModuleSplit masterSplit = ModuleSplit.builder().setModuleName(BundleModuleName.create("base")).setApkTargeting(ApkTargeting.getDefaultInstance()).setVariantTargeting(lPlusVariantTargeting()).setMasterSplit(true).setAndroidManifest(manifest).build();
masterSplit = masterSplit.removeUnknownSplitComponents(ImmutableSet.of());
ImmutableList<XmlElement> activities = masterSplit.getAndroidManifest().getManifestElement().getChildElement("application").getChildrenElements(ACTIVITY_ELEMENT_NAME).map(XmlProtoElement::getProto).collect(toImmutableList());
assertThat(activities).hasSize(1);
XmlElement activityElement = activities.get(0);
assertThat(activityElement.getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "MainActivity"));
}
use of com.android.aapt.Resources.XmlElement in project bundletool by google.
the class StandaloneApksGeneratorTest method removeSplitNameFromShard.
@Test
public void removeSplitNameFromShard() throws Exception {
XmlNode manifest = androidManifest("com.test.app", withMainActivity("MainActivity"), withSplitNameActivity("FooActivity", "foo"));
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("res/drawable/image.jpg").addFile("res/drawable-mdpi/image.jpg").addFile("root/license.dat").setManifest(manifest).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), NO_DIMENSIONS);
assertThat(shards).hasSize(1);
ModuleSplit fatShard = shards.get(0);
ImmutableList<XmlElement> activities = fatShard.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"));
}
use of com.android.aapt.Resources.XmlElement in project bundletool by google.
the class XmlProtoElementBuilderTest method getAttributeIgnoringNamespace_duplicate.
@Test
public void getAttributeIgnoringNamespace_duplicate() {
XmlAttribute attribute = XmlAttribute.newBuilder().setName("attribute").build();
XmlElement protoElement = XmlElement.newBuilder().addAttribute(attribute).addAttribute(attribute).build();
XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
XmlProtoAttributeBuilder fetchedAttribute = element.getAttributeIgnoringNamespace("attribute").get();
assertThat(fetchedAttribute.getProto().build()).isEqualTo(attribute);
assertThat(element.getProto().build()).isEqualTo(protoElement);
}
use of com.android.aapt.Resources.XmlElement in project bundletool by google.
the class XmlProtoElementBuilderTest method removeAttribute_namespaceNotMatching.
@Test
public void removeAttribute_namespaceNotMatching() {
XmlElement protoElement = XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setName("attribute").setNamespaceUri("namespace")).build();
XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
element.removeAttribute("otherNamespace", "attribute");
assertThat(element.getProto().build()).isEqualTo(protoElement);
}
use of com.android.aapt.Resources.XmlElement in project bundletool by google.
the class XmlProtoElementBuilderTest method removeChildrenElementsIf.
@Test
public void removeChildrenElementsIf() {
XmlElement childElement = XmlElement.newBuilder().setName("hello").build();
XmlElement matchingElement = XmlElement.newBuilder().setName("foo").build();
XmlElement protoElement = XmlElement.newBuilder().addChild(XmlNode.newBuilder().setElement(childElement)).addChild(XmlNode.newBuilder().setElement(matchingElement)).build();
XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
element.removeChildrenElementsIf(node -> node.isElement() && node.getElement().getName().equals("foo"));
ImmutableList<XmlProtoElementBuilder> fetchedElements = element.getChildrenElements().collect(toImmutableList());
assertThat(fetchedElements).hasSize(1);
XmlProtoElementBuilder fetchedElement = fetchedElements.get(0);
assertThat(fetchedElement.getProto().build()).isEqualTo(childElement);
}
Aggregations