From 157b917a453ae8ce610accbbad2e292ad649557b Mon Sep 17 00:00:00 2001 From: corysmith Date: Mon, 6 Aug 2018 12:53:14 -0700 Subject: Add configuration for android data binding v2. RELNOTES: None PiperOrigin-RevId: 207592136 --- .../build/lib/rules/android/DataBinding.java | 42 +++++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/DataBinding.java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/DataBinding.java b/src/main/java/com/google/devtools/build/lib/rules/android/DataBinding.java index 9564643e8e..a5c4c33624 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/DataBinding.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/DataBinding.java @@ -148,11 +148,11 @@ public final class DataBinding { } } - private static final class EnabledDataBindingContext implements DataBindingContext { + private static final class EnabledDataBindingV1Context implements DataBindingContext { private final ActionConstructionContext actionConstructionContext; - private EnabledDataBindingContext(ActionConstructionContext actionConstructionContext) { + private EnabledDataBindingV1Context(ActionConstructionContext actionConstructionContext) { this.actionConstructionContext = actionConstructionContext; } @@ -269,7 +269,7 @@ public final class DataBinding { if (o == null || getClass() != o.getClass()) { return false; } - EnabledDataBindingContext that = (EnabledDataBindingContext) o; + EnabledDataBindingV1Context that = (EnabledDataBindingV1Context) o; return Objects.equals(actionConstructionContext, that.actionConstructionContext); } @@ -284,28 +284,52 @@ public final class DataBinding { } } + private static class EnabledDataBindingV2Context implements DataBindingContext { + + private final ActionConstructionContext actionContext; + + private EnabledDataBindingV2Context(ActionConstructionContext actionContext) { + this.actionContext = actionContext; + throw new UnsupportedOperationException("V2 not implemented yet."); + } + // TODO(b/112038432): Enable databinding v2. + } + private static final DataBindingContext DISABLED_CONTEXT = new DataBindingContext() {}; /** Supplies a databinding context from a rulecontext. */ - public static DataBindingContext contextFrom(RuleContext ruleContext) { + public static DataBindingContext contextFrom( + RuleContext ruleContext, AndroidConfiguration androidConfig) { if (isEnabled(ruleContext)) { - return asEnabledDataBindingContextFrom(ruleContext); + if (androidConfig.useDataBindingV2()) { + return asEnabledDataBindingV2ContextFrom(ruleContext); + } + return asEnabledDataBindingV1ContextFrom(ruleContext); } return asDisabledDataBindingContext(); } /** Supplies a databinding context from an action context. */ - public static DataBindingContext contextFrom(boolean enabled, ActionConstructionContext context) { + public static DataBindingContext contextFrom( + boolean enabled, ActionConstructionContext context, AndroidConfiguration androidConfig) { if (enabled) { - return asEnabledDataBindingContextFrom(context); + if (androidConfig.useDataBindingV2()) { + return asEnabledDataBindingV2ContextFrom(context); + } + return asEnabledDataBindingV1ContextFrom(context); } return asDisabledDataBindingContext(); } /** Supplies an enabled DataBindingContext from the action context. */ - public static DataBindingContext asEnabledDataBindingContextFrom( + private static DataBindingContext asEnabledDataBindingV1ContextFrom( + ActionConstructionContext actionContext) { + return new EnabledDataBindingV1Context(actionContext); + } + + private static DataBindingContext asEnabledDataBindingV2ContextFrom( ActionConstructionContext actionContext) { - return new EnabledDataBindingContext(actionContext); + return new EnabledDataBindingV2Context(actionContext); } /** Supplies a disabled (no-op) DataBindingContext. */ -- cgit v1.2.3