From deab8fb26f2ebeed906cb766e6ad253e772ec84c Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Sun, 3 Dec 2017 18:51:53 -0800 Subject: [PATCH] Implement new as-based API (#141) * WIP as() converters * Move kotlin to use the new APIs * Documentation pass * Create matching extension functions, deprecate old * Update kotlin tests with new extensions * Gradle 4.3.1 * Lower back to 4.2.1 due to error-prone plugin Compatibility issues * Make checkstyle happy about imports and lines * Update kotlin, error prone, nullaway, checker * Gradle 4.3.1 again, error prone and apt plugins to 0.0.13 --- .../build.gradle | 3 +- .../build.gradle | 3 +- android/autodispose-android/build.gradle | 4 +- .../uber/autodispose/kotlin/autodispose.kt | 261 +++++++++++++++--- .../kotlin/AutoDisposeKotlinTest.kt | 80 +++--- .../com/uber/autodispose/AutoDispose.java | 138 +++++++-- .../autodispose/AutoDisposeConverter.java | 36 +++ build.gradle | 2 +- gradle/dependencies.gradle | 14 +- gradle/wrapper/gradle-wrapper.jar | Bin 54708 -> 54712 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- 11 files changed, 436 insertions(+), 107 deletions(-) create mode 100644 autodispose/src/main/java/com/uber/autodispose/AutoDisposeConverter.java diff --git a/android/autodispose-android-archcomponents-test/build.gradle b/android/autodispose-android-archcomponents-test/build.gradle index 13e56f0c2..37ce95fbe 100644 --- a/android/autodispose-android-archcomponents-test/build.gradle +++ b/android/autodispose-android-archcomponents-test/build.gradle @@ -61,7 +61,8 @@ dependencies { tasks.withType(JavaCompile) { options.compilerArgs += ["-Xep:NullAway:ERROR", - "-XepOpt:NullAway:AnnotatedPackages=com.uber"] + "-XepOpt:NullAway:AnnotatedPackages=com.uber", + "-Xep:RestrictTo:OFF"] } apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/android/autodispose-android-archcomponents/build.gradle b/android/autodispose-android-archcomponents/build.gradle index db1526bba..2fad29674 100644 --- a/android/autodispose-android-archcomponents/build.gradle +++ b/android/autodispose-android-archcomponents/build.gradle @@ -71,7 +71,8 @@ dependencies { tasks.withType(JavaCompile) { options.compilerArgs += ["-Xep:NullAway:ERROR", - "-XepOpt:NullAway:AnnotatedPackages=com.uber"] + "-XepOpt:NullAway:AnnotatedPackages=com.uber", + "-Xep:RestrictTo:OFF"] } apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/android/autodispose-android/build.gradle b/android/autodispose-android/build.gradle index 69e934bd3..1a2de0b28 100755 --- a/android/autodispose-android/build.gradle +++ b/android/autodispose-android/build.gradle @@ -67,7 +67,9 @@ dependencies { } tasks.withType(JavaCompile) { - options.compilerArgs += ["-Xep:NullAway:ERROR", "-XepOpt:NullAway:AnnotatedPackages=com.uber"] + options.compilerArgs += ["-Xep:NullAway:ERROR", + "-XepOpt:NullAway:AnnotatedPackages=com.uber", + "-Xep:RestrictTo:OFF"] } apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/autodispose-kotlin/src/main/kotlin/com/uber/autodispose/kotlin/autodispose.kt b/autodispose-kotlin/src/main/kotlin/com/uber/autodispose/kotlin/autodispose.kt index c7b4e134b..680657baf 100644 --- a/autodispose-kotlin/src/main/kotlin/com/uber/autodispose/kotlin/autodispose.kt +++ b/autodispose-kotlin/src/main/kotlin/com/uber/autodispose/kotlin/autodispose.kt @@ -19,7 +19,6 @@ package com.uber.autodispose.kotlin import com.uber.autodispose.AutoDispose -import com.uber.autodispose.AutoDispose.ScopeHandler import com.uber.autodispose.CompletableSubscribeProxy import com.uber.autodispose.FlowableSubscribeProxy import com.uber.autodispose.LifecycleScopeProvider @@ -33,114 +32,314 @@ import io.reactivex.Maybe import io.reactivex.Observable import io.reactivex.Single import io.reactivex.annotations.CheckReturnValue +import kotlin.DeprecationLevel.WARNING /** - * Extension that proxies to [Flowable.to] + [AutoDispose.with] + [ScopeHandler.forFlowable] + * Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(scope)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Flowable.autoDisposeWith(scope: Maybe<*>): FlowableSubscribeProxy - = this.to(AutoDispose.with(scope).forFlowable()) + = this.`as`(AutoDispose.autoDisposable(scope)) /** - * Extension that proxies to [Observable.to] + [AutoDispose.with] + [ScopeHandler.forObservable] + * Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(scope)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Observable.autoDisposeWith(scope: Maybe<*>): ObservableSubscribeProxy - = this.to(AutoDispose.with(scope).forObservable()) + = this.`as`(AutoDispose.autoDisposable(scope)) /** - * Extension that proxies to [Single.to] + [AutoDispose.with] + [ScopeHandler.forSingle] + * Extension that proxies to [Single.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(scope)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Single.autoDisposeWith(scope: Maybe<*>): SingleSubscribeProxy - = this.to(AutoDispose.with(scope).forSingle()) + = this.`as`(AutoDispose.autoDisposable(scope)) /** - * Extension that proxies to [Maybe.to] + [AutoDispose.with] + [ScopeHandler.forMaybe] + * Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(scope)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Maybe.autoDisposeWith(scope: Maybe<*>): MaybeSubscribeProxy - = this.to(AutoDispose.with(scope).forMaybe()) + = this.`as`(AutoDispose.autoDisposable(scope)) /** - * Extension that proxies to [Completable.to] + [AutoDispose.with] + [ScopeHandler.forCompletable] + * Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(scope)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Completable.autoDisposeWith(scope: Maybe<*>): CompletableSubscribeProxy - = this.to(AutoDispose.with(scope).forCompletable()) + = this.`as`(AutoDispose.autoDisposable(scope)) /** - * Extension that proxies to [Flowable.to] + [AutoDispose.with] + [ScopeHandler.forFlowable] + * Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Flowable.autoDisposeWith(provider: ScopeProvider): FlowableSubscribeProxy - = this.to(AutoDispose.with(provider).forFlowable()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Observable.to] + [AutoDispose.with] + [ScopeHandler.forObservable] + * Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Observable.autoDisposeWith(provider: ScopeProvider): ObservableSubscribeProxy - = this.to(AutoDispose.with(provider).forObservable()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Single.to] + [AutoDispose.with] + [ScopeHandler.forSingle] + * Extension that proxies to [Single.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Single.autoDisposeWith(provider: ScopeProvider): SingleSubscribeProxy - = this.to(AutoDispose.with(provider).forSingle()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Maybe.to] + [AutoDispose.with] + [ScopeHandler.forMaybe] + * Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Maybe.autoDisposeWith(provider: ScopeProvider): MaybeSubscribeProxy - = this.to(AutoDispose.with(provider).forMaybe()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Completable.to] + [AutoDispose.with] + [ScopeHandler.forCompletable] + * Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Completable.autoDisposeWith(provider: ScopeProvider): CompletableSubscribeProxy - = this.to(AutoDispose.with(provider).forCompletable()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Flowable.to] + [AutoDispose.with]+ [ScopeHandler.forFlowable] + * Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable] * */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Flowable.autoDisposeWith( provider: LifecycleScopeProvider<*>): FlowableSubscribeProxy - = this.to(AutoDispose.with(provider).forFlowable()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Observable.to] + [AutoDispose.with] + [ScopeHandler.forObservable] + * Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Observable.autoDisposeWith( provider: LifecycleScopeProvider<*>): ObservableSubscribeProxy - = this.to(AutoDispose.with(provider).forObservable()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Single.to] + [AutoDispose.with] + [ScopeHandler.forSingle] + * Extension that proxies to [Single.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Single.autoDisposeWith( provider: LifecycleScopeProvider<*>): SingleSubscribeProxy - = this.to(AutoDispose.with(provider).forSingle()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Maybe.to] + [AutoDispose.with] + [ScopeHandler.forMaybe] + * Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Maybe.autoDisposeWith(provider: LifecycleScopeProvider<*>): MaybeSubscribeProxy - = this.to(AutoDispose.with(provider).forMaybe()) + = this.`as`(AutoDispose.autoDisposable(provider)) /** - * Extension that proxies to [Completable.to] + [AutoDispose.with]+ [ScopeHandler.forCompletable] + * Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable] */ +@Deprecated( + level = WARNING, + message = "Replaced with autoDisposable() to match top level APIs. This deprecation will become an ERROR in 0.6.0 and removed in 1.0.", + replaceWith = ReplaceWith("autoDisposable(provider)", + "com.uber.autodispose.kotlin.autoDisposable") +) @CheckReturnValue inline fun Completable.autoDisposeWith( provider: LifecycleScopeProvider<*>): CompletableSubscribeProxy - = this.to(AutoDispose.with(provider).forCompletable()) + = this.`as`(AutoDispose.autoDisposable(provider)) +/** + * Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Flowable.autoDisposable(scope: Maybe<*>): FlowableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(scope)) + +/** + * Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Observable.autoDisposable(scope: Maybe<*>): ObservableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(scope)) + +/** + * Extension that proxies to [Single.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Single.autoDisposable(scope: Maybe<*>): SingleSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(scope)) + +/** + * Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Maybe.autoDisposable(scope: Maybe<*>): MaybeSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(scope)) + +/** + * Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Completable.autoDisposable(scope: Maybe<*>): CompletableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(scope)) + +/** + * Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Flowable.autoDisposable(provider: ScopeProvider): FlowableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Observable.autoDisposable(provider: ScopeProvider): ObservableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Single.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Single.autoDisposable(provider: ScopeProvider): SingleSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Maybe.autoDisposable(provider: ScopeProvider): MaybeSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Completable.autoDisposable(provider: ScopeProvider): CompletableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Flowable.to] + [AutoDispose.autoDisposable] + * + */ +@CheckReturnValue +inline fun Flowable.autoDisposable( + provider: LifecycleScopeProvider<*>): FlowableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Observable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Observable.autoDisposable( + provider: LifecycleScopeProvider<*>): ObservableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Single.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Single.autoDisposable( + provider: LifecycleScopeProvider<*>): SingleSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Maybe.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Maybe.autoDisposable(provider: LifecycleScopeProvider<*>): MaybeSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) + +/** + * Extension that proxies to [Completable.to] + [AutoDispose.autoDisposable] + */ +@CheckReturnValue +inline fun Completable.autoDisposable( + provider: LifecycleScopeProvider<*>): CompletableSubscribeProxy + = this.`as`(AutoDispose.autoDisposable(provider)) diff --git a/autodispose-kotlin/src/test/kotlin/com/uber/autodispose/kotlin/AutoDisposeKotlinTest.kt b/autodispose-kotlin/src/test/kotlin/com/uber/autodispose/kotlin/AutoDisposeKotlinTest.kt index 689c1cfe0..eb2781ccf 100644 --- a/autodispose-kotlin/src/test/kotlin/com/uber/autodispose/kotlin/AutoDisposeKotlinTest.kt +++ b/autodispose-kotlin/src/test/kotlin/com/uber/autodispose/kotlin/AutoDisposeKotlinTest.kt @@ -44,7 +44,7 @@ class AutoDisposeKotlinTest { @Test fun observable_maybeNormalCompletion() { Observable.just("Hello") - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) o.assertValue { it == "Hello" } @@ -54,7 +54,7 @@ class AutoDisposeKotlinTest { @Test fun observable_maybeNormalInterrupted() { val subject = PublishSubject.create() subject - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) subject.onNext("Hello") @@ -70,7 +70,7 @@ class AutoDisposeKotlinTest { @Test fun observable_scopeProviderNormalCompletion() { Observable.just("Hello") - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) o.assertValue { it == "Hello" } @@ -80,7 +80,7 @@ class AutoDisposeKotlinTest { @Test fun observable_scopeProviderNormalInterrupted() { val subject = PublishSubject.create() subject - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) subject.onNext("Hello") @@ -96,7 +96,7 @@ class AutoDisposeKotlinTest { @Test fun observable_lifecycleNotStarted() { Observable.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleNotStartedException } @@ -105,7 +105,7 @@ class AutoDisposeKotlinTest { @Test fun observable_lifecycleNormalCompletion() { lifecycleScopeProvider.start() Observable.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertValue { it == "Hello" } @@ -116,7 +116,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() val subject = PublishSubject.create() subject - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) subject.onNext("Hello") @@ -134,7 +134,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() Observable.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleEndedException } @@ -142,7 +142,7 @@ class AutoDisposeKotlinTest { @Test fun flowable_maybeNormalCompletion() { Flowable.just("Hello") - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(s) s.assertValue { it == "Hello" } @@ -152,7 +152,7 @@ class AutoDisposeKotlinTest { @Test fun flowable_maybeNormalInterrupted() { val subject = PublishSubject.create() subject.toFlowable(ERROR) - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(s) subject.onNext("Hello") @@ -168,7 +168,7 @@ class AutoDisposeKotlinTest { @Test fun flowable_scopeProviderNormalCompletion() { Flowable.just("Hello") - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(s) s.assertValue { it == "Hello" } @@ -178,7 +178,7 @@ class AutoDisposeKotlinTest { @Test fun flowable_scopeProviderNormalInterrupted() { val subject = PublishSubject.create() subject.toFlowable(ERROR) - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(s) subject.onNext("Hello") @@ -194,7 +194,7 @@ class AutoDisposeKotlinTest { @Test fun flowable_lifecycleNotStarted() { Flowable.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(s) s.assertError { it is LifecycleNotStartedException } @@ -203,7 +203,7 @@ class AutoDisposeKotlinTest { @Test fun flowable_lifecycleNormalCompletion() { lifecycleScopeProvider.start() Flowable.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(s) s.assertValue { it == "Hello" } @@ -214,7 +214,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() val subject = PublishSubject.create() subject.toFlowable(ERROR) - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(s) subject.onNext("Hello") @@ -232,7 +232,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() Flowable.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(s) s.assertError { it is LifecycleEndedException } @@ -240,7 +240,7 @@ class AutoDisposeKotlinTest { @Test fun maybe_maybeNormalCompletion() { Maybe.just("Hello") - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) o.assertValue { it == "Hello" } @@ -250,7 +250,7 @@ class AutoDisposeKotlinTest { @Test fun maybe_maybeNormalInterrupted() { val subject = MaybeSubject.create() subject - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) subject.onSuccess("Hello") @@ -266,7 +266,7 @@ class AutoDisposeKotlinTest { @Test fun maybe_scopeProviderNormalCompletion() { Maybe.just("Hello") - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) o.assertValue { it == "Hello" } @@ -276,7 +276,7 @@ class AutoDisposeKotlinTest { @Test fun maybe_scopeProviderNormalInterrupted() { val subject = MaybeSubject.create() subject - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) scopeProvider.emit() @@ -292,7 +292,7 @@ class AutoDisposeKotlinTest { @Test fun maybe_lifecycleNotStarted() { Maybe.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleNotStartedException } @@ -301,7 +301,7 @@ class AutoDisposeKotlinTest { @Test fun maybe_lifecycleNormalCompletion() { lifecycleScopeProvider.start() Maybe.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertValue { it == "Hello" } @@ -312,7 +312,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() val subject = PublishSubject.create() subject - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) lifecycleScopeProvider.stop() @@ -326,7 +326,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() Maybe.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleEndedException } @@ -334,7 +334,7 @@ class AutoDisposeKotlinTest { @Test fun single_maybeNormalCompletion() { Single.just("Hello") - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) o.assertValue { it == "Hello" } @@ -344,7 +344,7 @@ class AutoDisposeKotlinTest { @Test fun single_maybeNormalInterrupted() { val subject = SingleSubject.create() subject - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) subject.onSuccess("Hello") @@ -360,7 +360,7 @@ class AutoDisposeKotlinTest { @Test fun single_scopeProviderNormalCompletion() { Single.just("Hello") - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) o.assertValue { it == "Hello" } @@ -370,7 +370,7 @@ class AutoDisposeKotlinTest { @Test fun single_scopeProviderNormalInterrupted() { val subject = SingleSubject.create() subject - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) subject.onSuccess("Hello") @@ -386,7 +386,7 @@ class AutoDisposeKotlinTest { @Test fun single_lifecycleNotStarted() { Single.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleNotStartedException } @@ -395,7 +395,7 @@ class AutoDisposeKotlinTest { @Test fun single_lifecycleNormalCompletion() { lifecycleScopeProvider.start() Single.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertValue { it == "Hello" } @@ -406,7 +406,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() val subject = PublishSubject.create() subject - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) lifecycleScopeProvider.stop() @@ -420,7 +420,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() Single.just("Hello") - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleEndedException } @@ -428,7 +428,7 @@ class AutoDisposeKotlinTest { @Test fun completable_maybeNormalCompletion() { Completable.complete() - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) o.assertComplete() @@ -437,7 +437,7 @@ class AutoDisposeKotlinTest { @Test fun completable_maybeNormalInterrupted() { val subject = PublishSubject.create() subject - .autoDisposeWith(scopeMaybe) + .autoDisposable(scopeMaybe) .subscribe(o) subject.onNext("Hello") @@ -453,7 +453,7 @@ class AutoDisposeKotlinTest { @Test fun completable_scopeProviderNormalCompletion() { Completable.complete() - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) o.assertComplete() @@ -462,7 +462,7 @@ class AutoDisposeKotlinTest { @Test fun completable_scopeProviderNormalInterrupted() { val subject = CompletableSubject.create() subject - .autoDisposeWith(scopeProvider) + .autoDisposable(scopeProvider) .subscribe(o) subject.onComplete() @@ -476,7 +476,7 @@ class AutoDisposeKotlinTest { @Test fun completable_lifecycleNotStarted() { Completable.complete() - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleNotStartedException } @@ -485,7 +485,7 @@ class AutoDisposeKotlinTest { @Test fun completable_lifecycleNormalCompletion() { lifecycleScopeProvider.start() Completable.complete() - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertComplete() @@ -495,7 +495,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() val subject = CompletableSubject.create() subject - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) lifecycleScopeProvider.stop() @@ -509,7 +509,7 @@ class AutoDisposeKotlinTest { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() Completable.complete() - .autoDisposeWith(lifecycleScopeProvider) + .autoDisposable(lifecycleScopeProvider) .subscribe(o) o.assertError { it is LifecycleEndedException } diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDispose.java b/autodispose/src/main/java/com/uber/autodispose/AutoDispose.java index bfec1253d..28ab87d33 100644 --- a/autodispose/src/main/java/com/uber/autodispose/AutoDispose.java +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDispose.java @@ -19,35 +19,35 @@ import io.reactivex.Completable; import io.reactivex.Flowable; import io.reactivex.Maybe; +import io.reactivex.MaybeSource; import io.reactivex.Observable; +import io.reactivex.ObservableConverter; import io.reactivex.Single; import io.reactivex.annotations.CheckReturnValue; import io.reactivex.functions.Function; +import java.util.concurrent.Callable; + +import static com.uber.autodispose.AutoDisposeUtil.checkNotNull; +import static com.uber.autodispose.ScopeUtil.deferredResolvedLifecycle; /** - * Factories for autodispose transformation {@link Function}s that can be used with RxJava types' - * corresponding {@code to(...)} methods to transform them into auto-disposing streams. + * Factories for autodispose converters that can be used with RxJava types' corresponding + * {@code as(...)} methods to transform them into auto-disposing streams. *

- * There are several static {@code with(...)} entry points, with the most basic being a simple - * {@link #with(Maybe)}. The provided {@link Maybe} is ultimately what every scope resolves to - * under the hood, and AutoDispose has some built-in understanding for predefined types. The scope - * is considered ended upon onSuccess emission of this {@link Maybe}. + * There are several static {@code autoDisposable(...)} entry points, with the most basic being a + * simple {@link #autoDisposable(Maybe)}. The provided {@link Maybe} is ultimately what every scope + * resolves to under the hood, and AutoDispose has some built-in understanding for predefined types. + * The scope is considered ended upon onSuccess emission of this {@link Maybe}. *

- * Every factory method returns an instance of a {@link ScopeHandler} that serves as an indirection - * to route to the corresponding RxJava types. This is structured in such a way to be friendly to - * autocompletion in IDEs, where the no-parameter generic method will autocomplete with the - * appropriate generic parameters in Java <7, or implicitly in >=8. + * This is structured in such a way to be friendly to autocompletion in IDEs, where the no-parameter + * generic method will autocomplete with the appropriate generic parameters in Java <7, or + * implicitly in >=8. * - * @see Flowable#to(Function) - * @see Observable#to(Function) - * @see Maybe#to(Function) - * @see Single#to(Function) - * @see Completable#to(Function) - * @see ScopeHandler#forFlowable() - * @see ScopeHandler#forObservable() - * @see ScopeHandler#forMaybe() - * @see ScopeHandler#forSingle() - * @see ScopeHandler#forCompletable() + * @see Flowable#as(io.reactivex.FlowableConverter) + * @see Observable#as(io.reactivex.ObservableConverter) + * @see Maybe#as(io.reactivex.MaybeConverter) + * @see Single#as(io.reactivex.SingleConverter) + * @see Completable#as(io.reactivex.CompletableConverter) */ @SuppressWarnings("deprecation") // Temporary until we remove and inline the Scoper classes public final class AutoDispose { @@ -56,7 +56,7 @@ public final class AutoDispose { * The intermediary return type of the {@code with(...)} factories in {@link AutoDispose}. See the * documentation on {@link AutoDispose} for more information on why this interface exists. */ - public interface ScopeHandler { + @Deprecated public interface ScopeHandler { /** * Entry point for auto-disposing {@link Flowable}s. *

@@ -139,8 +139,10 @@ public interface ScopeHandler { * @param scope the target scope * @return a {@link ScopeHandler} for this scope to create AutoDisposing transformation * {@link Function}s + * @deprecated This will be removed in AutoDispose 1.0. Please use the {@code autoDisposable()} + * APIs. */ - @CheckReturnValue public static ScopeHandler with(Maybe scope) { + @Deprecated @CheckReturnValue public static ScopeHandler with(Maybe scope) { return new MaybeScopeHandlerImpl(scope); } @@ -150,8 +152,10 @@ public interface ScopeHandler { * @param scope the target scope * @return a {@link ScopeHandler} for this scope to create AutoDisposing transformation * {@link Function}s + * @deprecated This will be removed in AutoDispose 1.0. Please use the {@code autoDisposable()} + * APIs. */ - @CheckReturnValue public static ScopeHandler with(ScopeProvider scope) { + @Deprecated @CheckReturnValue public static ScopeHandler with(ScopeProvider scope) { return new ScopeProviderHandlerImpl(scope); } @@ -161,8 +165,10 @@ public interface ScopeHandler { * @param scope the target scope * @return a {@link ScopeHandler} for this scope to create AutoDisposing transformation * {@link Function}s + * @deprecated This will be removed in AutoDispose 1.0. Please use the {@code autoDisposable()} + * APIs. */ - @CheckReturnValue public static ScopeHandler with(LifecycleScopeProvider scope) { + @Deprecated @CheckReturnValue public static ScopeHandler with(LifecycleScopeProvider scope) { return new LifecycleScopeProviderHandlerImpl(scope); } @@ -256,6 +262,90 @@ public Function, ObservableSubscribeProxy> forObs } } + /** + * Entry point for auto-disposing streams from a {@link ScopeProvider}. + *

+ * Example usage: + *


+   *   Observable.just(1)
+   *        .to(AutoDispose.autoDisposable(scope))
+   *        .subscribe(...)
+   * 
+ * + * @param provider the target scope provider + * @param the stream type. + * @return an {@link AutoDisposeConverter} to transform with operators like + * {@link Observable#as(ObservableConverter)} + */ + public static AutoDisposeConverter autoDisposable(final ScopeProvider provider) { + checkNotNull(provider, "provider == null"); + return autoDisposable(Maybe.defer(new Callable>() { + @Override public MaybeSource call() { + return provider.requestScope(); + } + })); + } + + /** + * Entry point for auto-disposing streams from a {@link LifecycleScopeProvider}. + *

+ * Example usage: + *


+   *   Observable.just(1)
+   *        .to(AutoDispose.autoDisposable(scope))
+   *        .subscribe(...)
+   * 
+ * + * @param provider the target lifecycle scope provider + * @param the stream type. + * @return an {@link AutoDisposeConverter} to transform with operators like + * {@link Observable#as(ObservableConverter)} + */ + public static AutoDisposeConverter autoDisposable( + final LifecycleScopeProvider provider) { + return autoDisposable(deferredResolvedLifecycle(checkNotNull(provider, "provider == null"))); + } + + /** + * Entry point for auto-disposing streams from a {@link Maybe}. + *

+ * Example usage: + *


+   *   Observable.just(1)
+   *        .to(AutoDispose.autoDisposable(scope))
+   *        .subscribe(...)
+   * 
+ * + * @param scope the target scope + * @param the stream type. + * @return an {@link AutoDisposeConverter} to transform with operators like + * {@link Observable#as(ObservableConverter)} + */ + public static AutoDisposeConverter autoDisposable(final Maybe scope) { + checkNotNull(scope, "scope == null"); + return new AutoDisposeConverter() { + @Override public CompletableSubscribeProxy apply(Completable upstream) { + return upstream.to(new CompletableScoper(scope)); + } + + @Override public FlowableSubscribeProxy apply(Flowable upstream) { + return upstream.to(new FlowableScoper(scope)); + } + + @Override public MaybeSubscribeProxy apply(Maybe upstream) { + return upstream.to(new MaybeScoper(scope)); + } + + @Override public ObservableSubscribeProxy apply(Observable upstream) { + return upstream.to(new ObservableScoper(scope)); + } + + @Override public SingleSubscribeProxy apply(Single upstream) { + return upstream.to(new SingleScoper(scope)); + } + }; + } + private AutoDispose() { throw new AssertionError("No instances"); } diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDisposeConverter.java b/autodispose/src/main/java/com/uber/autodispose/AutoDisposeConverter.java new file mode 100644 index 000000000..3f1af9502 --- /dev/null +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDisposeConverter.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.uber.autodispose; + +import io.reactivex.CompletableConverter; +import io.reactivex.FlowableConverter; +import io.reactivex.MaybeConverter; +import io.reactivex.ObservableConverter; +import io.reactivex.SingleConverter; + +/** + * A custom converter that implements all the RxJava types converters, for use with the {@code as()} + * operator. + * + * @param the type. + */ +public interface AutoDisposeConverter extends FlowableConverter>, + ObservableConverter>, + MaybeConverter>, + SingleConverter>, + CompletableConverter { +} diff --git a/build.gradle b/build.gradle index c8ca5b708..ce8b87a2d 100755 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ */ task wrapper(type: Wrapper) { - gradleVersion = '4.2.1' + gradleVersion = '4.3.1' distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 3f611f990..4af5a9d4a 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -19,8 +19,8 @@ def versions = [ archComponents: '1.0.0', archRuntime: '1.0.3', dokka: '0.9.15', - errorProne: '2.1.1', - kotlin: '1.1.51', + errorProne: '2.1.3', + kotlin: '1.2.0', support: '26.1.0' ] @@ -31,9 +31,9 @@ def build = [ minSdkVersion: 14, targetSdkVersion: 26, - checkerFramework: 'org.checkerframework:dataflow:2.1.14', + checkerFramework: 'org.checkerframework:dataflow:2.3.0', errorProne: "com.google.errorprone:error_prone_core:${versions.errorProne}", - nullAway: 'com.uber.nullaway:nullaway:0.1.4', + nullAway: 'com.uber.nullaway:nullaway:0.2.0', repositories: [ plugins: 'https://plugins.gradle.org/m2/' @@ -41,10 +41,10 @@ def build = [ gradlePlugins: [ android: 'com.android.tools.build:gradle:2.3.0', - apt: 'net.ltgt.gradle:gradle-apt-plugin:0.11', + apt: 'net.ltgt.gradle:gradle-apt-plugin:0.13', dokka: "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}", dokkaAndroid: "org.jetbrains.dokka:dokka-android-gradle-plugin:${versions.dokka}", - errorProne: 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.11', + errorProne: 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.13', kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" ] ] @@ -62,7 +62,7 @@ def misc = [ def rx = [ android: 'io.reactivex.rxjava2:rxandroid:2.0.1', - java: 'io.reactivex.rxjava2:rxjava:2.1.0' + java: 'io.reactivex.rxjava2:rxjava:2.1.7' ] def support = [ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7a3265ee94c0ab25cf079ac8ccdf87f41d455d42..ed88a042a287c140a32e1639edfc91b2a233da8c 100755 GIT binary patch delta 795 zcmYk4T}YEr7{}l9IOewecvrq|zRp&Pu)Rae%932Deb8trl2#f~U1)|>mXMGjAzer% z&iqrBDUui62!${~D9~`z+FbKvc2ief^yN(!L>FCjJZkP-{r}JJd7g95bB=#FVQe^| zd!KQ6Puiz4Ns><8FReCw%lO&6+{~nIb;N&j(mcOgCsleA4KI|~35Dlufje+)qXND_ zm7$-C zNCU=IXTZy;owQ_Gcc$r5`e0pgFlB6mGbH1oT~6Y=uC2Rv0WW0hF>X)8$7ziUve!Zu zJc`J0<;CaQ^8~EOOGO87rsT&%W4?ez`K!=b7!R`w1w3AuEGqAL;^8fifX_WiXnL#B zW-qtdsPJ0F5gg_6ru73$lC39HMV@L=&=@*Oj#?q#gbtJLtdKe35;E7rRiBGHVU1mb zKkR0MSPq|K8Y*WlQS>sNw%G7~ri|*Z3i&r?M|DJ{V3V+&k-hZf2A4Vb5-FgL7A_Cq z^gE5RTDf%Kd}}hsxHY$lq>8poajRWXl}@&cP)~a=Cl~ zP~a;;g!9j{Dl>u2)sgi94?593S4>K;kTtzYqOGnkepr7V3s~Hj&Nt9#zF)LW9We8L z8aW4rwJmt4VF>L*4siH;&A#wR+e7Y%>Eil69rB*$v$$2d$AZgkDa@W)gZKs0ud hdM7b5xg9l&a_0Yk%%8%#@f=)z#qC9x{!m~g_z#MO4vPQ) delta 660 zcmYL{T}V@59LCT4H#Q?>XANaLQ<7DtN0!d8mPQ(d#Y~%QMV3|&tMxU>NJ!X)MC3)G z_AvS;@^)P$R0w^LIgf76wz=)XuIk3JAY2z+_x7^#T>XB}bDkFt@0kb}ya*SJ>{#m@ zU2-)`lH?t2@#=o{<@%U3qKv<~Hf2~Nx!d%GuJFnw6Yq^^iMUqZ1|lBz0AC{x_70Y5 zCoN0JX(jMat5n7W9%2fr<1)_Z=GD{?PCPv++i~KVE1jt z?KzbNFfq4_9{cdxw+)7@jGb|Xs{C9nIO*RcqA?!LU&LUb44>kA=yZT%jcAU}D>T)M zFTGW0$;f!d_5M{{9^8l@^A5VvFHq}OaQvf6)&Zg21MBgIt05@V9klXR#`c85Jm^eZ zq1<&*EGJr-33bVHR5A?5-D-3XmtuEX#`mN`g?B_$n`)%ekiedhQM4~p3ZErYr`T^e z7S2=hkvQ%BLKAIyBCsNTfP7;dZMc=LV=~^RJ?tBdnJ)Gd7cyt*!z4aWHt`QsSqP2U Zdh7q6h+m|6^)fjv;byi**Btp9{sG{o{Gk8< diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c583957d2..702c4b68b 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip