Search in sources :

Example 1 with CompoundValue

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

the class ResourceAnalyzer method transitiveClosure.

private ImmutableSet<ResourceId> transitiveClosure(ImmutableSet<ResourceId> anchorResources) throws IOException {
    Set<ResourceId> referencedResources = new HashSet<>();
    Queue<ResourceId> resourcesToInspect = new ArrayDeque<>();
    resourcesToInspect.addAll(anchorResources);
    while (!resourcesToInspect.isEmpty()) {
        ResourceId resourceId = resourcesToInspect.remove();
        if (referencedResources.contains(resourceId) || !baseModuleResourcesById.containsKey(resourceId)) {
            continue;
        }
        referencedResources.add(resourceId);
        ResourceTableEntry resourceEntry = baseModuleResourcesById.get(resourceId);
        for (ConfigValue configValue : resourceEntry.getEntry().getConfigValueList()) {
            switch(configValue.getValue().getValueCase()) {
                case ITEM:
                    Item item = configValue.getValue().getItem();
                    resourcesToInspect.addAll(findAllReferencedAppResources(item));
                    break;
                case COMPOUND_VALUE:
                    CompoundValue compoundValue = configValue.getValue().getCompoundValue();
                    resourcesToInspect.addAll(findAllReferencedAppResources(compoundValue));
                    break;
                case VALUE_NOT_SET:
            }
        }
    }
    return ImmutableSet.copyOf(referencedResources);
}
Also used : Item(com.android.aapt.Resources.Item) ConfigValue(com.android.aapt.Resources.ConfigValue) CompoundValue(com.android.aapt.Resources.CompoundValue) ResourceTableEntry(com.android.tools.build.bundletool.model.ResourceTableEntry) ResourceId(com.android.tools.build.bundletool.model.ResourceId) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 2 with CompoundValue

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

the class ResourceTableMergerTest method stripSourceReferences_inOneofField_strips.

@Test
public void stripSourceReferences_inOneofField_strips() throws Exception {
    CompoundValue withoutSource = CompoundValue.newBuilder().setStyle(Style.newBuilder().setParent(Reference.newBuilder().setName("dad")).addEntry(Style.Entry.newBuilder().setComment("comment"))).build();
    CompoundValue.Builder withSourceBuilder = withoutSource.toBuilder();
    withSourceBuilder.getStyleBuilder().setParentSource(Source.newBuilder().setPathIdx(42));
    CompoundValue withSource = withSourceBuilder.build();
    assertThat(withSource).isNotEqualTo(withoutSource);
    CompoundValue.Builder stripped = withSource.toBuilder();
    ResourceTableMerger.stripSourceReferences(stripped);
    assertThat(stripped.build()).isEqualTo(withoutSource);
}
Also used : CompoundValue(com.android.aapt.Resources.CompoundValue) Test(org.junit.Test)

Example 3 with CompoundValue

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

the class XmlProtoPrintUtilsTest method getCompoundValueAsString_style.

@Test
public void getCompoundValueAsString_style() {
    CompoundValue compoundValue = CompoundValue.newBuilder().setStyle(Style.newBuilder().addEntry(Style.Entry.newBuilder().setItem(createItem("name1"))).addEntry(Style.Entry.newBuilder().setItem(createItem("name2")))).build();
    assertThat(XmlProtoPrintUtils.getCompoundValueAsString(compoundValue)).isEqualTo("[\"name1\", \"name2\"]");
}
Also used : CompoundValue(com.android.aapt.Resources.CompoundValue) Test(org.junit.Test)

Example 4 with CompoundValue

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

the class XmlProtoPrintUtilsTest method getCompoundValueAsString_array.

@Test
public void getCompoundValueAsString_array() {
    CompoundValue compoundValue = CompoundValue.newBuilder().setArray(Array.newBuilder().addElement(Element.newBuilder().setItem(createItem("name1"))).addElement(Element.newBuilder().setItem(createItem("name2")))).build();
    assertThat(XmlProtoPrintUtils.getCompoundValueAsString(compoundValue)).isEqualTo("[\"name1\", \"name2\"]");
}
Also used : CompoundValue(com.android.aapt.Resources.CompoundValue) Test(org.junit.Test)

Example 5 with CompoundValue

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

the class XmlProtoPrintUtilsTest method getCompoundValueAsString_styleable.

@Test
public void getCompoundValueAsString_styleable() {
    CompoundValue compoundValue = CompoundValue.newBuilder().setStyleable(Styleable.newBuilder().addEntry(Styleable.Entry.newBuilder().setAttr(createReference("name1"))).addEntry(Styleable.Entry.newBuilder().setAttr(createReference("name2")))).build();
    assertThat(XmlProtoPrintUtils.getCompoundValueAsString(compoundValue)).isEqualTo("[@name1, @name2]");
}
Also used : CompoundValue(com.android.aapt.Resources.CompoundValue) Test(org.junit.Test)

Aggregations

CompoundValue (com.android.aapt.Resources.CompoundValue)7 Test (org.junit.Test)6 ConfigValue (com.android.aapt.Resources.ConfigValue)1 Item (com.android.aapt.Resources.Item)1 ResourceId (com.android.tools.build.bundletool.model.ResourceId)1 ResourceTableEntry (com.android.tools.build.bundletool.model.ResourceTableEntry)1 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1