use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.
the class AndroidManifestTest method configSplit_noExtraElementsFromModuleSplit.
@Test
public void configSplit_noExtraElementsFromModuleSplit() throws Exception {
XmlNode.Builder xmlNodeBuilder = XmlNode.newBuilder();
TextFormat.merge(TestData.openReader("testdata/manifest/manifest1.textpb"), xmlNodeBuilder);
AndroidManifest androidManifest = AndroidManifest.create(xmlNodeBuilder.build());
XmlNode.Builder expectedXmlNodeBuilder = XmlNode.newBuilder();
TextFormat.merge(TestData.openReader("testdata/manifest/config_split_manifest1.textpb"), expectedXmlNodeBuilder);
AndroidManifest configManifest = AndroidManifest.createForConfigSplit(androidManifest.getPackageName(), androidManifest.getVersionCode(), "testModule.config.hdpi", "testModule", Optional.empty());
XmlProtoNode generatedManifest = configManifest.getManifestRoot();
assertThat(generatedManifest.getProto()).ignoringRepeatedFieldOrder().isEqualTo(expectedXmlNodeBuilder.build());
}
use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.
the class WearApkLocator method extractWearApkName.
/**
* Parses the XML description file for the name of the wear APK.
*
* <p>According to
* https://developer.android.com/training/wearables/apps/packaging#PackageManually, it is the
* value inside the tag <rawPathResId>.
*/
private static Optional<String> extractWearApkName(ModuleEntry wearApkDescriptionXmlEntry) {
XmlProtoNode root;
try (InputStream content = wearApkDescriptionXmlEntry.getContent().openStream()) {
root = new XmlProtoNode(XmlNode.parseFrom(content));
} catch (InvalidProtocolBufferException e) {
throw InvalidBundleException.builder().withCause(e).withUserMessage("The wear APK description file '%s' could not be parsed.", wearApkDescriptionXmlEntry.getPath()).build();
} catch (IOException e) {
throw new UncheckedIOException(String.format("An unexpected error occurred while reading APK description file '%s'.", wearApkDescriptionXmlEntry.getPath()), e);
}
// If the Wear APK is unbundled, there is nothing to find.
if (root.getElement().getOptionalChildElement("unbundled").isPresent()) {
return Optional.empty();
}
// If 'unbundled' is not present, then 'rawPathResId' must be.
Optional<XmlProtoElement> rawPathResId = root.getElement().getOptionalChildElement("rawPathResId");
if (!rawPathResId.isPresent()) {
throw InvalidBundleException.builder().withUserMessage("The wear APK description file '%s' does not contain 'unbundled' or 'rawPathResId'.", wearApkDescriptionXmlEntry.getPath()).build();
}
return Optional.of(rawPathResId.get().getChildText().get().getText());
}
use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.
the class XmlProtoToXmlConverterTest method testNoNamespaceDeclaration_doesNotCrash.
@Test
public void testNoNamespaceDeclaration_doesNotCrash() {
XmlProtoNode proto = XmlProtoNode.createElementNode(XmlProtoElementBuilder.create("root").addAttribute(XmlProtoAttributeBuilder.create("http://uri", "key").setValueAsString("value")).addAttribute(XmlProtoAttributeBuilder.create("http://uri", "key2").setValueAsString("value2")).addAttribute(XmlProtoAttributeBuilder.create("http://other-uri", "other-key").setValueAsString("other-value")).build());
Document document = XmlProtoToXmlConverter.convert(proto);
String xmlString = XmlUtils.documentToString(document);
assertThat(xmlString).isEqualTo(String.format("<root xmlns:_unknown0_=\"http://uri\" " + "_unknown0_:key=\"value\" " + "_unknown0_:key2=\"value2\" " + "xmlns:_unknown1_=\"http://other-uri\" " + "_unknown1_:other-key=\"other-value\"/>%n"));
}
use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.
the class XmlProtoToXmlConverterTest method testNameAndNamespaceOfAndroidAttributeRemoved.
@Test
public void testNameAndNamespaceOfAndroidAttributeRemoved() {
XmlProtoNode proto = XmlProtoNode.createElementNode(XmlProtoElementBuilder.create("manifest").addAttribute(XmlProtoAttributeBuilder.create("").setResourceId(0x0101021b).setValueAsDecimalInteger(123)).build());
Document document = XmlProtoToXmlConverter.convert(proto);
String xmlString = XmlUtils.documentToString(document);
assertThat(xmlString).isEqualTo(String.format("<manifest _0x0101021b_=\"123\"/>%n"));
}
use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.
the class XmlProtoToXmlConverterTest method testNoNamespaceDeclarationWithNestedElementsWithCommonUris.
@Test
public void testNoNamespaceDeclarationWithNestedElementsWithCommonUris() {
XmlProtoNode proto = XmlProtoNode.createElementNode(XmlProtoElementBuilder.create("root").addChildElement(XmlProtoElementBuilder.create("http://schemas.android.com/apk/res/android", "android-element").addChildElement(XmlProtoElementBuilder.create("http://schemas.android.com/apk/res/android", "android-element2"))).build());
Document document = XmlProtoToXmlConverter.convert(proto);
String xmlString = XmlUtils.documentToString(document);
assertThat(xmlString).isEqualTo(String.format("<root>%n" + " <android:android-element " + "xmlns:android=\"http://schemas.android.com/apk/res/android\">%n" + " <android:android-element2/>%n" + " </android:android-element>%n" + "</root>%n"));
}
Aggregations