Search in sources :

Example 46 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class SplitsXmlInjectorTest method process_standaloneSplitTypes.

@Test
public void process_standaloneSplitTypes() throws Exception {
    ModuleSplit standalone = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "", /* masterSplit= */
    true, STANDALONE, /* languageTargeting= */
    null);
    ResourceTable standaloneResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru-RU", "title ru-RU", "fr", "title fr")).build();
    standalone = standalone.toBuilder().setResourceTable(standaloneResourceTable).build();
    GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(standalone));
    ModuleSplit processedStandalone = xmlInjectorProcess(generatedApks).stream().collect(onlyElement());
    assertThat(processedStandalone.getAndroidManifest().getMetadataResourceId("com.android.vending.splits")).hasValue(0x7f020000);
    assertThat(processedStandalone.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
    XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").build();
    assertThat(XmlNode.parseFrom(processedStandalone.getEntries().get(0).getContent().read())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 47 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class XmlProtoElementTest method getChildrenText_noTextChildren.

@Test
public void getChildrenText_noTextChildren() {
    XmlNode childElement = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("element")).build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(childElement).build());
    assertThat(element.getChildrenText()).isEmpty();
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) Test(org.junit.Test)

Example 48 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class XmlProtoElementTest method getChildText.

@Test
public void getChildText() {
    XmlNode child = XmlNode.newBuilder().setText("child").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(child).build());
    assertThat(element.getChildText()).hasValue(new XmlProtoNode(child));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) Test(org.junit.Test)

Example 49 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class SplitsXmlInjector method processSplitApkVariant.

private static ImmutableList<ModuleSplit> processSplitApkVariant(Collection<ModuleSplit> splits) {
    boolean hasLanguageSplits = splits.stream().anyMatch(split -> split.getApkTargeting().hasLanguageTargeting());
    // If language splits are available we gather language mappings from these splits otherwise this
    // means that language splits are not generated and we need to gather all languages from
    // resource table of master splits.
    // We need to check splits targeting and can not rely on disabled language dimension because in
    // case of system variant it is possible to generate splits that don't have language targeting
    // for bundles with enabled language dimension.
    XmlNode splitsXmlContent = hasLanguageSplits ? getSplitsXmlContentFromLanguageTargeting(splits) : getSplitsXmlContentFromResourceTables(splits);
    ImmutableList.Builder<ModuleSplit> result = new ImmutableList.Builder<>();
    for (ModuleSplit split : splits) {
        if (split.isMasterSplit() && split.isBaseModuleSplit()) {
            result.add(injectSplitsXml(split, splitsXmlContent));
        } else {
            result.add(split);
        }
    }
    return result.build();
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit)

Example 50 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class LocaleConfigXmlInjector method createLocalesXmlNode.

public static XmlNode createLocalesXmlNode(ImmutableList<ModuleSplit> splits) {
    // Get all locales from the base module splits
    ImmutableSet<String> allLocales = getLocalesFromBaseModuleSplits(splits);
    XmlProtoElementBuilder localesConfigXml = XmlProtoElementBuilder.create(LOCALE_CONFIG_ELEMENT);
    allLocales.stream().filter(locale -> !locale.isEmpty()).forEach(locale -> localesConfigXml.addChildElement(createAttributes(locale)));
    return XmlProtoNode.createElementNode(localesConfigXml.build()).getProto();
}
Also used : XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) ImmutableSet(com.google.common.collect.ImmutableSet) ConfigValue(com.android.aapt.Resources.ConfigValue) Value(com.android.aapt.Resources.Value) ZipPath(com.android.tools.build.bundletool.model.ZipPath) VariantKey(com.android.tools.build.bundletool.model.VariantKey) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) Entry(com.android.aapt.Resources.Entry) Item(com.android.aapt.Resources.Item) FileReference(com.android.aapt.Resources.FileReference) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceId(com.android.tools.build.bundletool.model.ResourceId) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ResourceInjector(com.android.tools.build.bundletool.model.ResourceInjector) ByteSource(com.google.common.io.ByteSource) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder)

Aggregations

XmlNode (com.android.aapt.Resources.XmlNode)99 Test (org.junit.Test)91 XmlElement (com.android.aapt.Resources.XmlElement)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)27 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)23 Truth.assertThat (com.google.common.truth.Truth.assertThat)23 RunWith (org.junit.runner.RunWith)23 ResourceTable (com.android.aapt.Resources.ResourceTable)21 ImmutableList (com.google.common.collect.ImmutableList)21 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)16 Nullable (javax.annotation.Nullable)16 Theories (org.junit.experimental.theories.Theories)16 ZipFile (java.util.zip.ZipFile)12 FileReference (com.android.aapt.Resources.FileReference)10 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)9 Attribute (com.android.aapt.Resources.Attribute)9 Symbol (com.android.aapt.Resources.Attribute.Symbol)9 CompoundValue (com.android.aapt.Resources.CompoundValue)9 ConfigValue (com.android.aapt.Resources.ConfigValue)9