From 81dbe79d09b4fa98d7803018b5d6d026e2e52a2e Mon Sep 17 00:00:00 2001 From: asteinb Date: Tue, 3 Apr 2018 07:08:09 -0700 Subject: Add methods to parse resources without assets - Add ParsedAndroidResources to wrap AndroidResources and resource parsing output. - Implement parse() method in AndroidResources, and support for it elsewhere - Move some supporting methods to the right place (setting up an aapt2 sdk for tests goes to the base test rule, and creating a dummy DataBinding zip goes to the DataBinding class). - Tests for new parse() method, including support for getting a test RuleContext instance RELNOTES: none PiperOrigin-RevId: 191436027 --- .../build/lib/rules/android/AndroidResources.java | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java index 0402d62ba8..d4e11efe15 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java @@ -31,6 +31,7 @@ import com.google.devtools.build.lib.vfs.PathFragment; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; @@ -41,7 +42,7 @@ import javax.annotation.Nullable; *

This is used to encapsulate the logic and the data associated with the resources derived from * an appropriate android rule in a reusable instance. */ -public final class AndroidResources { +public class AndroidResources { private static final String DEFAULT_RESOURCES_ATTR = "resource_files"; public static final String[] RESOURCES_ATTRIBUTES = @@ -293,6 +294,10 @@ public final class AndroidResources { private final ImmutableList resources; private final ImmutableList resourceRoots; + AndroidResources(AndroidResources other) { + this(other.resources, other.resourceRoots); + } + @VisibleForTesting public AndroidResources( ImmutableList resources, ImmutableList resourceRoots) { @@ -385,4 +390,25 @@ public final class AndroidResources { return Optional.of(new AndroidResources(filtered.get(), filteredResourcesRootsBuilder.build())); } + + public ParsedAndroidResources parse( + RuleContext ruleContext, + StampedAndroidManifest manifest) throws InterruptedException, RuleErrorException { + return ParsedAndroidResources.parseFrom(ruleContext, this, manifest); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof AndroidResources)) { + return false; + } + + AndroidResources other = (AndroidResources) object; + return resources.equals(other.resources) && resourceRoots.equals(other.resourceRoots); + } + + @Override + public int hashCode() { + return Objects.hash(resources, resourceRoots); + } } -- cgit v1.2.3