Search in sources :

Example 41 with XmlNode

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

the class SplitsProtoXmlBuilderTest method buildEmpty.

@Test
public void buildEmpty() {
    SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
    XmlNode rootNode = splitsProtoXmlBuilder.build();
    // Answer:
    // <splits>
    // </splits>
    XmlProtoElementBuilder actual = XmlProtoElementBuilder.create("splits");
    assertThat(rootNode).isEqualTo(getProto(actual));
}
Also used : XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) XmlNode(com.android.aapt.Resources.XmlNode) Test(org.junit.Test)

Example 42 with XmlNode

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

the class SplitsProtoXmlBuilderTest method buildManyModules.

@Test
public void buildManyModules() {
    SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
    splitsProtoXmlBuilder.addLanguageMapping(BASE_MODULE_NAME, /* language = */
    "ru", /* splitId = */
    "config.ru");
    splitsProtoXmlBuilder.addLanguageMapping(BundleModuleName.create("module"), /* language = */
    "en", /* splitId = */
    "module.config.en");
    XmlNode rootNode = splitsProtoXmlBuilder.build();
    // Answer:
    // <splits>
    // <module name="">
    // <language>
    // <entry key="ru" split="config.ru">
    // </language>
    // </module>
    // <module name="module">
    // <language>
    // <entry key="en" split="module.config.en">
    // </language>
    // </module>
    // </splits>
    assertThat(rootNode.getElement().getName()).isEqualTo("splits");
    assertThat(rootNode.getElement().getChildList()).containsExactly(getProto(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"))))), getProto(XmlProtoElementBuilder.create("module").addAttribute(createAttribute("name", "")).addChildElement(XmlProtoElementBuilder.create("language").addChildElement(XmlProtoElementBuilder.create("entry").addAttribute(createAttribute("key", "ru")).addAttribute(createAttribute("split", "config.ru"))))));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) Test(org.junit.Test)

Example 43 with XmlNode

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

the class LocaleConfigXmlInjectorTest method process_systemSplits.

@Test
public void process_systemSplits() throws Exception {
    ModuleSplit baseMasterSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    true, SYSTEM, /* languageTargeting= */
    null);
    ModuleSplit otherSplitA = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("ru-RU", "module ru-RU")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SYSTEM, languageTargeting("ru"));
    ModuleSplit otherSplitB = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("fr", "module fr")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SYSTEM, languageTargeting("fr"));
    ModuleSplit otherSplitC = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("en-AU", "module en-AU")).build(), "module", /* masterSplit= */
    false, SYSTEM, languageTargeting("en"));
    ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(otherSplitA, otherSplitB, otherSplitC);
    ImmutableList<ModuleSplit> processedSplits = localeConfigXmlInjector.process(VariantKey.create(baseMasterSplit), ImmutableList.<ModuleSplit>builder().add(baseMasterSplit).addAll(otherSplits).build());
    ModuleSplit processedBaseMasterSplit = processedSplits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    assertThat(processedBaseMasterSplit.getAndroidManifest().hasLocaleConfig()).isTrue();
    assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app.module:xml/locales_config").withFileReference("res/xml/locales_config.xml");
    XmlNode expectedLocaleConfigProtoXml = createLocalesXmlNode(new HashSet<>(Arrays.asList("ru-RU", "fr")));
    assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedLocaleConfigProtoXml);
    ImmutableList<ModuleSplit> processedOtherSplits = processedSplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    assertThat(processedOtherSplits).containsExactly(otherSplitA, otherSplitB, otherSplitC);
}
Also used : Arrays(java.util.Arrays) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) VariantKey(com.android.tools.build.bundletool.model.VariantKey) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) HashSet(java.util.HashSet) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Theories(org.junit.experimental.theories.Theories) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) SYSTEM(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Example 44 with XmlNode

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

the class LocaleConfigXmlInjectorTest method process_duplicateLocales.

@Test
public void process_duplicateLocales() throws Exception {
    ModuleSplit baseMasterSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    true, SPLIT, /* languageTargeting= */
    null);
    ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("ru-RU", "module ru-RU")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SPLIT, languageTargeting("ru")), createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("ru-RU", "module ru-RU")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SPLIT, languageTargeting("ru")), createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("fr", "module fr")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SPLIT, languageTargeting("fr")));
    ModuleSplit processedBaseMasterSplit = localeConfigXmlInjector.process(VariantKey.create(baseMasterSplit), ImmutableList.<ModuleSplit>builder().add(baseMasterSplit).addAll(otherSplits).build()).stream().filter(split -> split.isMasterSplit() && split.isBaseModuleSplit()).collect(onlyElement());
    XmlNode expectedLocaleConfigProtoXml = createLocalesXmlNode(new HashSet<>(Arrays.asList("ru-RU", "fr")));
    assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedLocaleConfigProtoXml);
}
Also used : Arrays(java.util.Arrays) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) VariantKey(com.android.tools.build.bundletool.model.VariantKey) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) HashSet(java.util.HashSet) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Theories(org.junit.experimental.theories.Theories) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) SYSTEM(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Example 45 with XmlNode

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

the class LocaleConfigXmlInjectorTest method process.

@Test
public void process() throws Exception {
    ModuleSplit baseMasterSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    true, SPLIT, /* languageTargeting= */
    null);
    ModuleSplit otherSplitA = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("ru-RU", "module ru-RU")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SPLIT, languageTargeting("ru"));
    ModuleSplit otherSplitB = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("fr", "module fr")).build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
    false, SPLIT, languageTargeting("fr"));
    ModuleSplit otherSplitC = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module", ImmutableMap.of("en-AU", "module en-AU")).build(), "module", /* masterSplit= */
    false, SPLIT, languageTargeting("en"));
    ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(otherSplitA, otherSplitB, otherSplitC);
    ImmutableList<ModuleSplit> processedSplits = localeConfigXmlInjector.process(VariantKey.create(baseMasterSplit), ImmutableList.<ModuleSplit>builder().add(baseMasterSplit).addAll(otherSplits).build());
    ModuleSplit processedBaseMasterSplit = processedSplits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    assertThat(processedBaseMasterSplit.getAndroidManifest().hasLocaleConfig()).isTrue();
    assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app.module:xml/locales_config").withFileReference("res/xml/locales_config.xml");
    XmlNode expectedLocaleConfigProtoXml = createLocalesXmlNode(new HashSet<>(Arrays.asList("ru-RU", "fr")));
    assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedLocaleConfigProtoXml);
    ImmutableList<ModuleSplit> processedOtherSplits = processedSplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    assertThat(processedOtherSplits).containsExactly(otherSplitA, otherSplitB, otherSplitC);
}
Also used : Arrays(java.util.Arrays) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) VariantKey(com.android.tools.build.bundletool.model.VariantKey) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) HashSet(java.util.HashSet) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Theories(org.junit.experimental.theories.Theories) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) SYSTEM(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

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