aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java
diff options
context:
space:
mode:
authorGravatar asteinb <asteinb@google.com>2018-04-03 07:08:09 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-03 07:09:21 -0700
commit81dbe79d09b4fa98d7803018b5d6d026e2e52a2e (patch)
treefdfcf9f2286b215ce7e23366d83dbead470f99e6 /src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java
parentd9b1082fd2a0e9500dd0a510dc8da6c3dc87fbd2 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResources.java28
1 files changed, 27 insertions, 1 deletions
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;
* <p>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<Artifact> resources;
private final ImmutableList<PathFragment> resourceRoots;
+ AndroidResources(AndroidResources other) {
+ this(other.resources, other.resourceRoots);
+ }
+
@VisibleForTesting
public AndroidResources(
ImmutableList<Artifact> resources, ImmutableList<PathFragment> 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);
+ }
}