diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b444dcd5..71acf12a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,65 +1,85 @@ name: CI -on: [push, pull_request] +on: + # Only run push on main + push: + branches: + - main + paths-ignore: + - '**/*.md' + # Always run on PRs + pull_request: + branches: [ main ] + merge_group: + +concurrency: + group: 'ci-${{ github.event.merge_group.head_ref || github.head_ref }}-${{ github.workflow }}' + cancel-in-progress: true jobs: build: - name: JDK ${{ matrix.java_version }} runs-on: macOS-latest - strategy: - fail-fast: false - matrix: - java_version: [11] + env: + api-level: "18" steps: - name: Checkout uses: actions/checkout@v1 + - name: Gradle Wrapper Validation uses: gradle/wrapper-validation-action@v1 - - name: Install JDK ${{ matrix.java_version }} + + - name: Install JDK uses: actions/setup-java@v2 with: distribution: 'zulu' - java-version: ${{ matrix.java_version }} - - name: Install Android SDK - uses: malinskiy/action-android/install-sdk@release/0.1.2 - - run: sdkmanager platform-tools - # TODO Caching disabled for now due to the size of Gradle's cache rendering this super slow -# - name: Cache build .gradle dir -# uses: actions/cache@v1.0.1 -# with: -# path: .gradle -# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} -# restore-keys: | -# ${{ runner.os }}-gradle- -# - name: Cache user .gradle dir -# uses: actions/cache@v1.0.1 -# with: -# path: ~/.gradle -# key: ${{ runner.os }}-gradleuser-${{ hashFiles('**/*.gradle') }} -# restore-keys: | -# ${{ runner.os }}-gradleuser- - - name: Configure Gradle - # Initial gradle configuration, install dependencies, etc - run: ./gradlew help - - name: Spot check - # Run spotless first to fail fast on spotless issues - run: ./gradlew spotlessCheck --stacktrace - - name: Build project - run: ./gradlew assemble --stacktrace + java-version: '17' + + - name: Gradle cache + uses: gradle/gradle-build-action@v2 + # TODO split test and instrumentation into parallel builds - - name: Run tests - run: ./gradlew test --stacktrace + - name: Build and run unit tests + id: gradle + uses: gradle/gradle-build-action@v2 + with: + arguments: check + + - name: AVD cache + uses: actions/cache@v3 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-${{ env.api-level }} + + - name: Create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ env.api-level }} + force-avd-creation: false + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: false + script: echo "Generated AVD snapshot for caching." + - name: Run instrumentation tests - uses: malinskiy/action-android/emulator-run-cmd@release/0.1.2 + uses: reactivecircus/android-emulator-runner@v2 with: - cmd: ./gradlew connectedCheck --stacktrace - api: 18 - tag: default - abi: x86 - - name: Reclaim memory - run: ./gradlew --stop && jps|grep -E 'KotlinCompileDaemon|GradleDaemon'| awk '{print $1}'| xargs kill -9 - - name: Final checks - run: ./gradlew check --stacktrace + api-level: ${{ env.api-level }} + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: true + script: ./gradlew connectedCheck + + - name: (Fail-only) Upload build reports + if: failure() + uses: actions/upload-artifact@v3 + with: + name: reports + path: | + **/build/reports/** + - name: Upload snapshot (main only) + if: success() && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' run: ./gradlew publish -PmavenCentralUsername="${{ secrets.SonatypeUsername }}" -PmavenCentralPassword="${{ secrets.SonatypePassword }}" - if: success() && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && matrix.java_version == '11' diff --git a/.gitignore b/.gitignore index ca505c381..d12627111 100644 --- a/.gitignore +++ b/.gitignore @@ -60,7 +60,7 @@ lint_result.txt *.war *.ear -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +# virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* @@ -107,7 +107,7 @@ annotations/ # Mkdocs docs/1.x/* -docs/2.x/* +docs/api/2.x/* docs/changelog.md docs/contributing.md docs/code-of-conduct.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 26e6a152d..b43781413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,15 +115,15 @@ _2019-09-18_ ### Kotlin `CoroutineScope` interop [#374](https://github.com/uber/AutoDispose/pull/374) Interop functions for `CoroutineScope` to `ScopeProvider`/`Completable` (and vice versa) are now available -in a new `autodispose-coroutines-interop` artifact. This is not intended to allow AutoDispose's -scoping machinery be a competitor for it, but rather just a tool for interop-ing codebases that use +in a new `autodispose-coroutines-interop` artifact. This is not intended to allow AutoDispose's +scoping machinery be a competitor for it, but rather just a tool for interop-ing codebases that use both or aid in migrations. ### Kotlin API naming improvements [#372](https://github.com/uber/AutoDispose/pull/372) [#377](https://github.com/uber/AutoDispose/pull/377) -To better differentiate between the `AutoDispose` classes's `autoDisposable()` methods (which return -Rx converter types), the Kotlin `autoDisposable()` extensions have been deprecated in favor of a more -idiomatic `autoDispose()` verb form name. The old extensions have been annotated with `@Deprecated` +To better differentiate between the `AutoDispose` classes's `autoDisposable()` methods (which return +Rx converter types), the Kotlin `autoDisposable()` extensions have been deprecated in favor of a more +idiomatic `autoDispose()` verb form name. The old extensions have been annotated with `@Deprecated` and replacements, so this should be an easy one time migration. ```kotlin @@ -134,10 +134,10 @@ myObservable ### Fused proxy types [#376](https://github.com/uber/AutoDispose/pull/376) -AutoDispose's analogous Rx types (`AutoDisposeObservable`, etc) have been updated to implement -their `*SubscribeProxy` interfaces directly. The current behavior of subscribe proxies is best -thought of as similar to `hide()`. Subscribe proxies have always wrapped the AutoDispose's -analogous Rx types to prevent upcasting. If your team are good citizens though, you can now disable +AutoDispose's analogous Rx types (`AutoDisposeObservable`, etc) have been updated to implement +their `*SubscribeProxy` interfaces directly. The current behavior of subscribe proxies is best +thought of as similar to `hide()`. Subscribe proxies have always wrapped the AutoDispose's +analogous Rx types to prevent upcasting. If your team are good citizens though, you can now disable proxy hiding via `AutoDisposePlugins` to save that extra allocation. ### New `withScope()` API [#375](https://github.com/uber/AutoDispose/pull/375) [#378](https://github.com/uber/AutoDispose/pull/378) @@ -170,7 +170,7 @@ _2019-05-15_ ### Unified Kotlin extensions -Starting with 1.3.0, all the `-ktx` artifacts and their kotlin extensions have been merged into the main artifacts they extended. This means that extensions in an artifact like `autodispose-android-ktx` are now available directly in the corresponding `autodispose-android`. +Starting with 1.3.0, all the `-ktx` artifacts and their kotlin extensions have been merged into the main artifacts they extended. This means that extensions in an artifact like `autodispose-android-ktx` are now available directly in the corresponding `autodispose-android`. This is a binary-compatible change because the extensions file name has changed while the extensions themselves have remained in the same package. So in essence, `import com.uber.autodispose.autoDisposable` still works as-is. Just remove the ktx artifact dependencies and everything will still link as-is! @@ -352,17 +352,17 @@ This is the first release candidate of AutoDispose 1.0! _Note: we say `Completable` for semantic convenience, but in code it's almost always referred to via `CompletableSource` for flexibility_ -This is a significant API change, but a good one we want to clean up before releasing 1.0. Since its inception, AutoDispose has always coerced +This is a significant API change, but a good one we want to clean up before releasing 1.0. Since its inception, AutoDispose has always coerced scopes into a `Maybe` representation. Now, scopes are coerced to a `CompletableSource`. -`Maybe` seemed like the right idea for something that "may or may not emit", but in our case we actually don't -care about the difference between onSuccess or onComplete. We did have a notion of "UNBOUND", but that doesn't offer anything other -than a severed lifecycle scope disposal in an atomic reference (no other cleanups would happen for gc, etc). This brings us to a `Single`. -The thing is though, we don't care about the object/element type. A `Single` where the type doesn't matter is semantically a `Completable`, +`Maybe` seemed like the right idea for something that "may or may not emit", but in our case we actually don't +care about the difference between onSuccess or onComplete. We did have a notion of "UNBOUND", but that doesn't offer anything other +than a severed lifecycle scope disposal in an atomic reference (no other cleanups would happen for gc, etc). This brings us to a `Single`. +The thing is though, we don't care about the object/element type. A `Single` where the type doesn't matter is semantically a `Completable`, and thus this change. -Note that semantics are slightly different for anyone that sourced scope via emissions from an `Observable`, `Maybe`, `Completable`, -or `Flowable`, where before a completion event would not trigger disposal. Now it would. In the lifecycle artifact, completion +Note that semantics are slightly different for anyone that sourced scope via emissions from an `Observable`, `Maybe`, `Completable`, +or `Flowable`, where before a completion event would not trigger disposal. Now it would. In the lifecycle artifact, completion of the lifecycle or emission of the target event (via `takeUntil()`) will signal disposal. If there's a strong desire for it, we could look at adding top-level `autoDisposable` overrides that accept other RxJava types (and coerce them to `Completable`). @@ -375,7 +375,7 @@ supports corresponding-events-type lifecycles for use with lifecycle components Dan Lew excellently discusses this subject in his "[Why Not RxLifecycle?](https://blog.danlew.net/2017/08/02/why-not-rxlifecycle/)" blog post. This does come with the caveat that one must implement `requestScope()` in implementations now. To smoothen this usage, a `autodispose-lifecycle-jdk8` -artifact exists with a `DefaultLifecycleScopeProvider` that has a `default` implementation of this on Java 8+ that matches the existing behavior. A +artifact exists with a `DefaultLifecycleScopeProvider` that has a `default` implementation of this on Java 8+ that matches the existing behavior. A similar default behavior was added for the `autodispose-lifecycle-ktx` artifact. These behaviors can be further tuned via factory helpers in `LifecycleScopes`. Other notable changes in this: @@ -391,7 +391,7 @@ throwing `OutsideScopeException. * Kotlin artifacts with `.ktx` or `.kotlin` package name entries have had them removed to match convention with other ktx-style artifacts. * i.e. Instead of `com.uber.autodispose.kotlin`, it would just be `com.uber.autodispose`. * `ViewScopeProvider` now uses a custom `MainThreadDisposable` that respects any main thread checks set via `AutoDisposeAndroidPlugins`. ([#232](https://github.com/uber/AutoDispose/pull/232)) -* Jetbrains annotations have been removed in favor of just using RxJava's `@Nullable` annotation directly. Saves some proguard rules and dependencies, and also makes annotation usage consistent. +* Jetbrains annotations have been removed in favor of just using RxJava's `@Nullable` annotation directly. Saves some proguard rules and dependencies, and also makes annotation usage consistent. * The following dependencies have been updated: * RxJava 2.2.0 (`as()` and `ParallelFlowable` are now stable APIs) * Kotlin 1.2.60 @@ -404,7 +404,7 @@ throwing `OutsideScopeException. * [Architecture components sample](https://github.com/uber/AutoDispose/pull/223), including `ViewModel` and using a repository pattern * [General structure cleanup](https://github.com/uber/AutoDispose/pull/226) -This is an RC1. We won't release 1.0 final until the AndroidX artifacts are stable to save ourselves from having to release a 2.0 immediately after this. +This is an RC1. We won't release 1.0 final until the AndroidX artifacts are stable to save ourselves from having to release a 2.0 immediately after this. These are a lot of breaking changes, so please let us know if you see any issues. Thanks to the following contributors for this release: [@shaishavgandhi05](https://github.com/shaishavgandhi05) and [@remcomokveld](https://github.com/remcomokveld) @@ -416,55 +416,55 @@ _2018-5-7_ ### Deprecated Scoper APIs now use the converter API under the hood ([#188](https://github.com/uber/AutoDispose/issues/188)) -Up to this point, the new `as()`-based converter APIs just delegated to the existing deprecated -`to()` APIs. In this release, they have been flipped, such that the `to()` APIs now just point to -the `as()`-based APIs. This should be no visible user change, but please let us know if you see any +Up to this point, the new `as()`-based converter APIs just delegated to the existing deprecated +`to()` APIs. In this release, they have been flipped, such that the `to()` APIs now just point to +the `as()`-based APIs. This should be no visible user change, but please let us know if you see any issues. ### ViewScopeProvider now implements ScopeProvider instead of LifecycleScopeProvider ([#196](https://github.com/uber/AutoDispose/issues/196)) -We believe this makes more sense, as there's no beginning boundary check for Views that we can -check and the general attach state is quite simple. This also avoids leaking an unnecessary +We believe this makes more sense, as there's no beginning boundary check for Views that we can +check and the general attach state is quite simple. This also avoids leaking an unnecessary internal API. ### Defer to `Comparable` checks if `LifecycleScopeProvider` types implement it ([#196](https://github.com/uber/AutoDispose/issues/196)) -For better flexibility, if a type for `LifecycleScopeProvider` implements `Comparable`, we will -defer to it rather than `equals()`. This allows for consumers to better convey event *ordering* to -the scope provider, and allow AutoDispose to catch events *after* a target event as a fallback. -This covers cases where the targeted "end" event is missed but a later event comes through, -allowing AutoDispose to dispose anyway. Note that this may result in a behavior change if your +For better flexibility, if a type for `LifecycleScopeProvider` implements `Comparable`, we will +defer to it rather than `equals()`. This allows for consumers to better convey event *ordering* to +the scope provider, and allow AutoDispose to catch events *after* a target event as a fallback. +This covers cases where the targeted "end" event is missed but a later event comes through, +allowing AutoDispose to dispose anyway. Note that this may result in a behavior change if your lifecycle types implemented `Comparable` before. ### Removed Error-Prone annotations ([#208](https://github.com/uber/AutoDispose/issues/208)) -As of Error-Prone 2.3.1, `@DoNotMock` was removed. We've switched to an internal copy of this -annotation for documentation purposes and for any external checkers to still check this usage on +As of Error-Prone 2.3.1, `@DoNotMock` was removed. We've switched to an internal copy of this +annotation for documentation purposes and for any external checkers to still check this usage on their own (by name). ### Switch from JSR305 to Jetbrains annotations for nullability ([#208](https://github.com/uber/AutoDispose/issues/208)) -To be compatible with the Java 9 module system, we've switched away from the JSR 305 -annotations/javax-extras on packages and now use the Jetbrains annotations for nullability instead. -We still abide by a nonnull-by-default implementation, and only annotate nullable elements with +To be compatible with the Java 9 module system, we've switched away from the JSR 305 +annotations/javax-extras on packages and now use the Jetbrains annotations for nullability instead. +We still abide by a nonnull-by-default implementation, and only annotate nullable elements with `@Nullable`. This dependency, like JSR305/javax-extras, is `compileOnly`. ### Misc changes * A few miscellaneous IDE warnings ([#208](https://github.com/uber/AutoDispose/issues/208)) * We are now building against Android Gradle Plugin 3.1.x (latest stable) ([#190](https://github.com/uber/AutoDispose/issues/190)) - * Due to ongoing Dokka issues and update latency, we've had to disable it on Kotlin artifacts for + * Due to ongoing Dokka issues and update latency, we've had to disable it on Kotlin artifacts for now. We plan to re-enable on the next release, which should add compatibility for AGP 3.x+. ### Call for input on next steps -We have two major design proposals that we want community feedback on that would take shape in the +We have two major design proposals that we want community feedback on that would take shape in the next couple of releases. Please let us know if you have any thoughts! * **Kotlin rewrite:** [#198](https://github.com/uber/AutoDispose/issues/198) * **Extract LifecycleScopeProvider to separate artifact, make it extend ScopeProvider:** [#197](https://github.com/uber/AutoDispose/issues/197) -Thanks to the following contributors for this release: [@tbsandee](https://github.com/tbsandee), +Thanks to the following contributors for this release: [@tbsandee](https://github.com/tbsandee), [@atexannamedbob](https://github.com/atexannamedbob) Version 0.7.0 @@ -474,14 +474,14 @@ _2018-3-26_ ### AutoDisposeAndroidPlugins ([#183](https://github.com/uber/AutoDispose/pull/183)) -New API! `AutoDisposeAndroidPlugins` API for plugin hooks to AutoDispose's android behavior at runtime. +New API! `AutoDisposeAndroidPlugins` API for plugin hooks to AutoDispose's android behavior at runtime. The first plugin supported here is `MainThreadChecker`. -This plugin allows for supplying a custom `BooleanSupplier` that can customize how main thread checks -work. The conventional use case of this is Android JUnit tests, where the `Looper` class is not +This plugin allows for supplying a custom `BooleanSupplier` that can customize how main thread checks +work. The conventional use case of this is Android JUnit tests, where the `Looper` class is not stubbed in the mock android.jar and fails explosively when touched. -Another potential use of this at runtime to customize checks for more fine-grained main thread +Another potential use of this at runtime to customize checks for more fine-grained main thread checks behavior. Example @@ -492,7 +492,7 @@ AutoDisposeAndroidPlugins.setOnCheckMainThread(() -> { }) ``` -This is available in the `autodispose-android` artifact, and all mainthread-checking APIs in android +This is available in the `autodispose-android` artifact, and all mainthread-checking APIs in android artifacts will delegate to this plugin hook. ### Misc @@ -547,7 +547,7 @@ These are to match the convenience `test()` methods in regular RxJava types. - Android artifacts now compiled against SDK 27 - Android support annotations updated to 27.0.2 -Thanks to the following contributors! [@VisheshVadhera](https://github.com/VisheshVadhera) [@bangarharshit](https://github.com/bangarharshit) [@mmallozzi](https://github.com/mmallozzi) [@0legg](https://github.com/0legg) [@shaunkawano](https://github.com/shaunkawano) +Thanks to the following contributors! [@VisheshVadhera](https://github.com/VisheshVadhera) [@bangarharshit](https://github.com/bangarharshit) [@mmallozzi](https://github.com/mmallozzi) [@0legg](https://github.com/0legg) [@shaunkawano](https://github.com/shaunkawano) Version 0.5.1 ---------------------------- @@ -667,7 +667,7 @@ A new `autodispose-rxlifecycle` interop module was added, adding support for sco - Removed synthetic accessors ([#103](https://github.com/uber/AutoDispose/issues/103)) - Updated to Kotlin 1.1.51 ([#116](https://github.com/uber/AutoDispose/issues/116)) -Thanks to the following contributors! [@rubengees](https://github.com/rubengees) [@bangarharshit](https://github.com/bangarharshit) +Thanks to the following contributors! [@rubengees](https://github.com/rubengees) [@bangarharshit](https://github.com/bangarharshit) #### Updated dependencies: ``` @@ -688,17 +688,17 @@ compile 'com.uber.autodispose:autodispose-android-archcomponents-test:x.y.z' compile 'com.uber.autodispose:autodispose-rxlifecycle:x.y.z' ``` -[![Maven Central](https://img.shields.io/maven-central/v/com.uber.autodispose/autodispose-android-kotlin.svg)](https://mvnrepository.com/artifact/com.uber.autodispose/autodispose-android-kotlin) +[![Maven Central](https://img.shields.io/maven-central/v/com.uber.autodispose/autodispose-android-kotlin.svg)](https://mvnrepository.com/artifact/com.uber.autodispose/autodispose-android-kotlin) ```gradle compile 'com.uber.autodispose:autodispose-android-kotlin:x.y.z' ``` -[![Maven Central](https://img.shields.io/maven-central/v/com.uber.autodispose/autodispose-android-archcomponents-kotlin.svg)](https://mvnrepository.com/artifact/com.uber.autodispose/autodispose-android-archcomponents-kotlin) +[![Maven Central](https://img.shields.io/maven-central/v/com.uber.autodispose/autodispose-android-archcomponents-kotlin.svg)](https://mvnrepository.com/artifact/com.uber.autodispose/autodispose-android-archcomponents-kotlin) ```gradle compile 'com.uber.autodispose:autodispose-android-archcomponents-kotlin:x.y.z' ``` -[![Maven Central](https://img.shields.io/maven-central/v/com.uber.autodispose/autodispose-android-archcomponents-test-kotlin.svg)](https://mvnrepository.com/artifact/com.uber.autodispose/autodispose-android-archcomponents-test-kotlin) +[![Maven Central](https://img.shields.io/maven-central/v/com.uber.autodispose/autodispose-android-archcomponents-test-kotlin.svg)](https://mvnrepository.com/artifact/com.uber.autodispose/autodispose-android-archcomponents-test-kotlin) ```gradle compile 'com.uber.autodispose:autodispose-android-archcomponents-test-kotlin:x.y.z' ``` @@ -728,12 +728,12 @@ Observable(1) an intermediary `ScopeHandler`, which in turn has 5 generic `for___()` methods that correspond to the 5 RxJava types (`Observable`, `Flowable`, `Single`, `Maybe`, and `Completable`). -The old `Scoper` class are now **deprecated**, and will be removed in AutoDispose 1.0. Fortunately, +The old `Scoper` class are now **deprecated**, and will be removed in AutoDispose 1.0. Fortunately, this is easy to migrate via IntelliJ's structural replace. Information can be found [here](https://github.com/uber/AutoDispose/wiki/Migrating-from-0.2.0-to-0.3.0). * **New: Support for Android Architecture Components! ([#71](https://github.com/uber/AutoDispose/pull/71))** -With the beta release of architecture components, they are now supported in the `autodispose-android-archcomponents` +With the beta release of architecture components, they are now supported in the `autodispose-android-archcomponents` artifact. ```java @@ -763,7 +763,7 @@ The reason for this is that there may be conditions where you want to handle fun on information from that Observer. As of RxJava 2.1.4, one such case could be to read information from a `LambdaConsumerIntrospection` ([relevant PR](https://github.com/ReactiveX/RxJava/pull/5590)). -In the future, this will likely be narrowed to return a `@Nullable lambdaConsumerIntrospection()`, but +In the future, this will likely be narrowed to return a `@Nullable lambdaConsumerIntrospection()`, but we're open to feedback if others think this should remain the high level `Observer` type. Thanks to [@mswysocki](https://github.com/mswysocki) for his contribution on this! @@ -786,20 +786,20 @@ iterate on this over time. * **Improved: EndConsumerHelper ([#77](https://github.com/uber/AutoDispose/pull/77))** -AutoDispose uses the same disposal-helper utilities as RxJava. This updates to RxJava's new +AutoDispose uses the same disposal-helper utilities as RxJava. This updates to RxJava's new `EndConsumerHelper`, which should hopefully help produce more helpful error messages in disposal error conditions. * **Other** Updated various dependencies: - + Android Arch Components: 1.0.0-beta1 Android Support Library: 26.1.0 (to match arch components) - Kotlin: 1.1.50 - -As always, we welcome any and all discussions/feedback/PRs! We're marching toward a 1.0 release Real -Soon Now, so now is the time. There are a few outstanding discussion issues in the issue tracker about + Kotlin: 1.1.50 + +As always, we welcome any and all discussions/feedback/PRs! We're marching toward a 1.0 release Real +Soon Now, so now is the time. There are a few outstanding discussion issues in the issue tracker about 1.0 final design decisions. Version 0.2.0 @@ -844,7 +844,7 @@ For testing with just the `Maybe` scope, we recommend using RxJava's built-in * **Fix**: Add missing `@CheckReturnValue` annotations to `subscribeWith` methods. (#53) **Other tidbits:** -- Removed `@NonNull` annotations. Everything is `@NonNull` by default, and only elements +- Removed `@NonNull` annotations. Everything is `@NonNull` by default, and only elements annotated with `@Nullable` are not. - Use of the new `java-library` plugin for gradle (#64). The RxJava dependencies are marked as `api`. - Error prone has been integrated. Currently the annotations are just marked as `compileOnly`, but if a need arises/community wants them - we can compile them in a future version. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 735ce1331..29f96d9e4 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -40,7 +40,7 @@ Project maintainers who do not follow or enforce the Code of Conduct in good fai ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version] -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +[homepage]: https://contributor-covenant.org +[version]: https://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f3f75b7c5..b5cd5a058 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,17 +11,17 @@ We love GitHub issues! For small feature requests, an issue first proposing it for discussion or demo implementation in a PR suffice. -For big features, please open an issue so that we can agree on the direction, and hopefully avoid +For big features, please open an issue so that we can agree on the direction, and hopefully avoid investing a lot of time on a feature that might need reworking. Small pull requests for things like typos, bugfixes, etc are always welcome. ### Code style -This project uses [ktlint](https://github.com/pinterest/ktlint) and [GJF](https://github.com/google/google-java-format), +This project uses [ktlint](https://github.com/pinterest/ktlint) and [GJF](https://github.com/google/google-java-format), provided via the [spotless](https://github.com/diffplug/spotless) gradle plugin. -If you find that one of your pull reviews does not pass the CI server check due to a code style +If you find that one of your pull reviews does not pass the CI server check due to a code style conflict, you can easily fix it by running: ./gradlew spotlessApply. Generally speaking - we use vanilla ktlint + 2space indents, and vanilla GJF. You can integrate both of diff --git a/LICENSE.txt b/LICENSE.txt index 75b52484e..a082ed219 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,7 +1,7 @@ Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/ + https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -193,7 +193,7 @@ 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 + https://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, diff --git a/MAINTAINING_WEBSITE.md b/MAINTAINING_WEBSITE.md index ecbb50a84..3a4100454 100644 --- a/MAINTAINING_WEBSITE.md +++ b/MAINTAINING_WEBSITE.md @@ -1,6 +1,6 @@ # Maintaining Documentation Website -The [documentation website](https://uber.github.io/AutoDispose/) is built using [MkDocs](https://squidfunk.github.io/mkdocs-material/). This requires you to install python to deploy the website. MkDocs supports Python versions 2.7, 3.4, 3.5, 3.6, 3.7. +The [documentation website](https://uber.github.io/AutoDispose/) is built using [MkDocs](https://squidfunk.github.io/mkdocs-material/). This requires you to install python to deploy the website. MkDocs supports Python versions 2.7, 3.4, 3.5, 3.6, 3.7. ## Overview @@ -15,27 +15,26 @@ nav: - 'Nested Page': nested_page.md -- 'Top Level Page': top_level_page.md ``` - + ## Editing a Page - + You can find the markdown file corresponding to the page that you want to edit by checking the `mkdocs.yml` file and finding the `nav` section. This should have the markdown file name. You can then find that file in the `docs` directory. After you've made changes to that file, get them merged in and [deploy the website](#deploying-the-website) - + ## Adding Custom CSS - + You can add your own CSS in the [app.css](https://github.com/uber/AutoDispose/blob/main/docs/css/app.css) file. - + ## Deploying the website - + The website can be deployed by executing the `deploy_website.sh` script like so: ```bash ./deploy_website.sh -``` +``` The script does the following: * Creates a temporary folder. * Clones the repository. * Runs Dokka. - * Copies over the files like `README.md`, `CHANGELOG.md`, `CONTRIBUTING.md` etc into the `docs` folder. This is done because these markdown files are required to be in the GitHub repo and we copy it over so that we don't create duplicates. + * Copies over the files like `README.md`, `CHANGELOG.md`, `CONTRIBUTING.md` etc into the `docs` folder. This is done because these markdown files are required to be in the GitHub repo and we copy it over so that we don't create duplicates. * Deploys mkdocs on gh-pages. * Deletes the temporary folder. - diff --git a/README.md b/README.md index 50b9e9d26..c832d4884 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -AutoDispose -=========== +# AutoDispose Automatic binding+disposal of RxJava streams. @@ -14,7 +13,7 @@ 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 + https://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, diff --git a/RELEASING.md b/RELEASING.md index 201ec295e..c389ee939 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -5,11 +5,8 @@ Releasing 2. Update the `CHANGELOG.md` for the impending release. 3. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) 4. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version) - 5. `./gradlew clean publish --no-daemon --no-parallel && ./gradlew closeAndReleaseRepository` + 5. `./gradlew publish` 6. Update the `gradle.properties` to the next SNAPSHOT version. 7. `git commit -am "Prepare next development version."` 8. `git push && git push --tags` - 9. After release propagates (wait ~30 minutes), update Javadocs/KDocs via [Osstrich](https://github.com/square/osstrich) - - Make sure you have push access - - `./gradlew publishDocs` - 10. Deploy the updated website with the new docs. This can be done by running the script `./deploy_website.sh` + 9. Deploy the updated website with the new docs. This can be done by running the script `./deploy_website.sh` diff --git a/android/autodispose-android/build.gradle b/android/autodispose-android/build.gradle deleted file mode 100644 index 5c08c95f1..000000000 --- a/android/autodispose-android/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ - -plugins { - id "com.vanniktech.maven.publish" -} - -dependencies { - api project(':autodispose') - api deps.rx.java - api deps.androidx.annotations - implementation deps.rx.android - - lintPublish project(':static-analysis:autodispose-lint') - - testImplementation project(':test-utils') - testImplementation deps.test.junit - testImplementation deps.test.truth - androidTestImplementation project(':test-utils') - androidTestImplementation deps.androidx.annotations - androidTestImplementation deps.test.androidExtJunit - androidTestImplementation deps.test.androidRunner - androidTestImplementation deps.test.androidRules - androidTestUtil deps.test.androidOrchestrator -} diff --git a/android/autodispose-android/build.gradle.kts b/android/autodispose-android/build.gradle.kts new file mode 100644 index 000000000..283aa852e --- /dev/null +++ b/android/autodispose-android/build.gradle.kts @@ -0,0 +1,41 @@ +/* + * 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 + * + * https://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. + */ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.mavenPublish) +} + +android { namespace = "autodispose2.android" } + +dependencies { + api(project(":autodispose")) + api(libs.rx.java) + api(libs.androidx.annotations) + implementation(libs.rx.android) + + lintPublish(project(":static-analysis:autodispose-lint")) + + testImplementation(project(":test-utils")) + testImplementation(libs.test.junit) + testImplementation(libs.test.truth) + androidTestImplementation(project(":test-utils")) + androidTestImplementation(libs.androidx.annotations) + androidTestImplementation(libs.test.androidExtJunit) + androidTestImplementation(libs.test.androidRunner) + androidTestImplementation(libs.test.androidRules) + androidTestUtil(libs.test.androidOrchestrator) +} diff --git a/android/autodispose-android/gradle.properties b/android/autodispose-android/gradle.properties index 751bbb43a..2f5e982f5 100644 --- a/android/autodispose-android/gradle.properties +++ b/android/autodispose-android/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, diff --git a/android/autodispose-android/src/androidTest/AndroidManifest.xml b/android/autodispose-android/src/androidTest/AndroidManifest.xml index 8c4f9bd0c..97efad847 100644 --- a/android/autodispose-android/src/androidTest/AndroidManifest.xml +++ b/android/autodispose-android/src/androidTest/AndroidManifest.xml @@ -5,7 +5,7 @@ ~ 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 + ~ https://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, @@ -15,14 +15,13 @@ --> + xmlns:tools="http://schemas.android.com/tools"> - + diff --git a/android/autodispose-android/src/androidTest/java/autodispose2/android/AutoDisposeTestActivity.java b/android/autodispose-android/src/androidTest/java/autodispose2/android/AutoDisposeTestActivity.java index aa01d580e..60af99a83 100644 --- a/android/autodispose-android/src/androidTest/java/autodispose2/android/AutoDisposeTestActivity.java +++ b/android/autodispose-android/src/androidTest/java/autodispose2/android/AutoDisposeTestActivity.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/androidTest/java/autodispose2/android/ViewScopeProviderTest.java b/android/autodispose-android/src/androidTest/java/autodispose2/android/ViewScopeProviderTest.java index e5ac184d5..cf0e56918 100644 --- a/android/autodispose-android/src/androidTest/java/autodispose2/android/ViewScopeProviderTest.java +++ b/android/autodispose-android/src/androidTest/java/autodispose2/android/ViewScopeProviderTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/main/AndroidManifest.xml b/android/autodispose-android/src/main/AndroidManifest.xml deleted file mode 100644 index 7212ebfe3..000000000 --- a/android/autodispose-android/src/main/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - diff --git a/android/autodispose-android/src/main/java/autodispose2/android/AutoDisposeAndroidPlugins.java b/android/autodispose-android/src/main/java/autodispose2/android/AutoDisposeAndroidPlugins.java index 6ea2de32f..a858ef15e 100644 --- a/android/autodispose-android/src/main/java/autodispose2/android/AutoDisposeAndroidPlugins.java +++ b/android/autodispose-android/src/main/java/autodispose2/android/AutoDisposeAndroidPlugins.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/main/java/autodispose2/android/DetachEventCompletable.java b/android/autodispose-android/src/main/java/autodispose2/android/DetachEventCompletable.java index a7a5cbd76..187dedebe 100644 --- a/android/autodispose-android/src/main/java/autodispose2/android/DetachEventCompletable.java +++ b/android/autodispose-android/src/main/java/autodispose2/android/DetachEventCompletable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/main/java/autodispose2/android/KotlinExtensions.kt b/android/autodispose-android/src/main/java/autodispose2/android/KotlinExtensions.kt index 2dfeaeb87..b38badcd2 100644 --- a/android/autodispose-android/src/main/java/autodispose2/android/KotlinExtensions.kt +++ b/android/autodispose-android/src/main/java/autodispose2/android/KotlinExtensions.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -34,62 +34,37 @@ import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.parallel.ParallelFlowable -/** - * Extension that returns a [ScopeProvider] for this [View]. - */ -@CheckReturnValue -inline fun View.scope(): ScopeProvider = ViewScopeProvider.from(this) +/** Extension that returns a [ScopeProvider] for this [View]. */ +@CheckReturnValue public inline fun View.scope(): ScopeProvider = ViewScopeProvider.from(this) -/** - * Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -inline fun Flowable.autoDispose( - view: View -): FlowableSubscribeProxy = +public inline fun Flowable.autoDispose(view: View): FlowableSubscribeProxy = this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view))) -/** - * Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -inline fun Observable.autoDispose( - view: View -): ObservableSubscribeProxy = +public inline fun Observable.autoDispose(view: View): ObservableSubscribeProxy = this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view))) -/** - * Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -inline fun Single.autoDispose( - view: View -): SingleSubscribeProxy = +public inline fun Single.autoDispose(view: View): SingleSubscribeProxy = this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view))) -/** - * Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -inline fun Maybe.autoDispose( - view: View -): MaybeSubscribeProxy = +public inline fun Maybe.autoDispose(view: View): MaybeSubscribeProxy = this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view))) -/** - * Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -inline fun Completable.autoDispose( - view: View -): CompletableSubscribeProxy = +public inline fun Completable.autoDispose(view: View): CompletableSubscribeProxy = this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view))) -/** - * Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -inline fun ParallelFlowable.autoDispose( +public inline fun ParallelFlowable.autoDispose( view: View ): ParallelFlowableSubscribeProxy = this.to(AutoDispose.autoDisposable(ViewScopeProvider.from(view))) diff --git a/android/autodispose-android/src/main/java/autodispose2/android/ViewScopeProvider.java b/android/autodispose-android/src/main/java/autodispose2/android/ViewScopeProvider.java index f40886f07..caa1d3493 100644 --- a/android/autodispose-android/src/main/java/autodispose2/android/ViewScopeProvider.java +++ b/android/autodispose-android/src/main/java/autodispose2/android/ViewScopeProvider.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/main/java/autodispose2/android/internal/AutoDisposeAndroidUtil.java b/android/autodispose-android/src/main/java/autodispose2/android/internal/AutoDisposeAndroidUtil.java index 698b8eb45..6093a38b7 100644 --- a/android/autodispose-android/src/main/java/autodispose2/android/internal/AutoDisposeAndroidUtil.java +++ b/android/autodispose-android/src/main/java/autodispose2/android/internal/AutoDisposeAndroidUtil.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/main/java/autodispose2/android/internal/MainThreadDisposable.java b/android/autodispose-android/src/main/java/autodispose2/android/internal/MainThreadDisposable.java index ee3aba8d4..15f99f101 100644 --- a/android/autodispose-android/src/main/java/autodispose2/android/internal/MainThreadDisposable.java +++ b/android/autodispose-android/src/main/java/autodispose2/android/internal/MainThreadDisposable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/main/java/autodispose2/android/package-info.java b/android/autodispose-android/src/main/java/autodispose2/android/package-info.java index 1af0357bf..82109be96 100644 --- a/android/autodispose-android/src/main/java/autodispose2/android/package-info.java +++ b/android/autodispose-android/src/main/java/autodispose2/android/package-info.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/test/java/autodispose2/android/AutoDisposeAndroidPluginsTest.java b/android/autodispose-android/src/test/java/autodispose2/android/AutoDisposeAndroidPluginsTest.java index 2426ffbc9..82b3ee6bf 100644 --- a/android/autodispose-android/src/test/java/autodispose2/android/AutoDisposeAndroidPluginsTest.java +++ b/android/autodispose-android/src/test/java/autodispose2/android/AutoDisposeAndroidPluginsTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-android/src/test/java/autodispose2/android/internal/MainThreadDisposableTest.java b/android/autodispose-android/src/test/java/autodispose2/android/internal/MainThreadDisposableTest.java index c6c14a578..182101b46 100644 --- a/android/autodispose-android/src/test/java/autodispose2/android/internal/MainThreadDisposableTest.java +++ b/android/autodispose-android/src/test/java/autodispose2/android/internal/MainThreadDisposableTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-androidx-lifecycle-test/build.gradle b/android/autodispose-androidx-lifecycle-test/build.gradle deleted file mode 100644 index 0dff73a87..000000000 --- a/android/autodispose-androidx-lifecycle-test/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ - -plugins { - id "com.vanniktech.maven.publish" -} - -dependencies { - api project(':autodispose') - api deps.androidx.annotations - api deps.androidx.lifecycle.common - api deps.androidx.lifecycle.runtime -} diff --git a/autodispose/build.gradle b/android/autodispose-androidx-lifecycle-test/build.gradle.kts similarity index 58% rename from autodispose/build.gradle rename to android/autodispose-androidx-lifecycle-test/build.gradle.kts index 04d0437e5..9203ed4e4 100644 --- a/autodispose/build.gradle +++ b/android/autodispose-androidx-lifecycle-test/build.gradle.kts @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -13,24 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - plugins { - id 'com.android.lint' - id 'ru.vyarus.animalsniffer' - id "com.vanniktech.maven.publish" + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.mavenPublish) } -lintOptions { - abortOnError true - warningsAsErrors true -} +android { namespace = "autodispose2.androidx.lifecycle.test" } dependencies { - api deps.rx.java - compileOnly deps.build.errorProneAnnotations - - signature deps.build.animalSniffer - lintChecks project(':static-analysis:autodispose-lint') - - testImplementation project(':test-utils') + api(project(":autodispose")) + api(libs.androidx.annotations) + api(libs.androidx.lifecycle.common) + api(libs.androidx.lifecycle.runtime) } diff --git a/android/autodispose-androidx-lifecycle-test/gradle.properties b/android/autodispose-androidx-lifecycle-test/gradle.properties index 7dd2fca39..9dfce69a5 100644 --- a/android/autodispose-androidx-lifecycle-test/gradle.properties +++ b/android/autodispose-androidx-lifecycle-test/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, diff --git a/android/autodispose-androidx-lifecycle-test/src/main/AndroidManifest.xml b/android/autodispose-androidx-lifecycle-test/src/main/AndroidManifest.xml deleted file mode 100644 index 7380b750e..000000000 --- a/android/autodispose-androidx-lifecycle-test/src/main/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - diff --git a/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/KotlinExtensions.kt b/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/KotlinExtensions.kt index 657b3ac33..4ae238287 100644 --- a/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/KotlinExtensions.kt +++ b/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/KotlinExtensions.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -21,11 +21,9 @@ import android.annotation.SuppressLint import androidx.lifecycle.LifecycleRegistry import io.reactivex.rxjava3.annotations.CheckReturnValue -/** - * Extension that returns a [TestLifecycleOwner] for this [LifecycleRegistry]. - */ +/** Extension that returns a [TestLifecycleOwner] for this [LifecycleRegistry]. */ @Suppress("DEPRECATION") @SuppressLint("RestrictedApi") @CheckReturnValue @Deprecated("Switch to androidx.lifecycle.testing.TestLifecycleOwner") -inline fun LifecycleRegistry.test(): TestLifecycleOwner = TestLifecycleOwner.create(this) +public inline fun LifecycleRegistry.test(): TestLifecycleOwner = TestLifecycleOwner.create(this) diff --git a/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/TestLifecycleOwner.java b/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/TestLifecycleOwner.java index 2b902f2e9..8900ef73a 100644 --- a/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/TestLifecycleOwner.java +++ b/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/TestLifecycleOwner.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/package-info.java b/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/package-info.java index 205829101..907a38cf2 100644 --- a/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/package-info.java +++ b/android/autodispose-androidx-lifecycle-test/src/main/java/autodispose2/androidx/lifecycle/test/package-info.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-androidx-lifecycle/build.gradle b/android/autodispose-androidx-lifecycle/build.gradle deleted file mode 100644 index 31791ff40..000000000 --- a/android/autodispose-androidx-lifecycle/build.gradle +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ - -plugins { - id "com.vanniktech.maven.publish" -} - -dependencies { - annotationProcessor deps.androidx.lifecycle.compiler - - api project(':autodispose') - api project(':autodispose-lifecycle') - api deps.androidx.annotations - api deps.androidx.lifecycle.runtime - - implementation project(':android:autodispose-android') - implementation deps.rx.android - - lintPublish project(':static-analysis:autodispose-lint') - - androidTestImplementation project(':android:autodispose-androidx-lifecycle-test') - androidTestImplementation project(':test-utils') - androidTestImplementation deps.androidx.lifecycle.runtimeTest - androidTestImplementation deps.test.androidExtJunit - androidTestImplementation deps.test.androidRunner - androidTestImplementation deps.test.androidRules - androidTestUtil deps.test.androidOrchestrator -} diff --git a/android/autodispose-androidx-lifecycle/build.gradle.kts b/android/autodispose-androidx-lifecycle/build.gradle.kts new file mode 100644 index 000000000..74d6eed67 --- /dev/null +++ b/android/autodispose-androidx-lifecycle/build.gradle.kts @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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. + */ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.mavenPublish) +} + +android { namespace = "autodispose2.androidx.lifecycle" } + +dependencies { + annotationProcessor(libs.androidx.lifecycle.compiler) + + api(project(":autodispose")) + api(project(":autodispose-lifecycle")) + api(libs.androidx.annotations) + api(libs.androidx.lifecycle.runtime) + + implementation(project(":android:autodispose-android")) + implementation(libs.rx.android) + + lintPublish(project(":static-analysis:autodispose-lint")) + + androidTestImplementation(project(":android:autodispose-androidx-lifecycle-test")) + androidTestImplementation(project(":test-utils")) + androidTestImplementation(libs.androidx.lifecycle.runtimeTest) + androidTestImplementation(libs.test.androidExtJunit) + androidTestImplementation(libs.test.androidRunner) + androidTestImplementation(libs.test.androidRules) + androidTestUtil(libs.test.androidOrchestrator) +} diff --git a/android/autodispose-androidx-lifecycle/gradle.properties b/android/autodispose-androidx-lifecycle/gradle.properties index 55a54bae6..a313d38c9 100644 --- a/android/autodispose-androidx-lifecycle/gradle.properties +++ b/android/autodispose-androidx-lifecycle/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, diff --git a/android/autodispose-androidx-lifecycle/lint.xml b/android/autodispose-androidx-lifecycle/lint.xml index 42d0afee1..38451e3f1 100644 --- a/android/autodispose-androidx-lifecycle/lint.xml +++ b/android/autodispose-androidx-lifecycle/lint.xml @@ -6,7 +6,7 @@ ~ 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 + ~ https://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, diff --git a/android/autodispose-androidx-lifecycle/src/androidTest/AndroidManifest.xml b/android/autodispose-androidx-lifecycle/src/androidTest/AndroidManifest.xml deleted file mode 100644 index a8a49920c..000000000 --- a/android/autodispose-androidx-lifecycle/src/androidTest/AndroidManifest.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - diff --git a/android/autodispose-androidx-lifecycle/src/androidTest/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProviderTest.java b/android/autodispose-androidx-lifecycle/src/androidTest/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProviderTest.java index af5eab1e1..1b24c4a73 100644 --- a/android/autodispose-androidx-lifecycle/src/androidTest/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProviderTest.java +++ b/android/autodispose-androidx-lifecycle/src/androidTest/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProviderTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-androidx-lifecycle/src/main/AndroidManifest.xml b/android/autodispose-androidx-lifecycle/src/main/AndroidManifest.xml deleted file mode 100644 index 1c132c244..000000000 --- a/android/autodispose-androidx-lifecycle/src/main/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - diff --git a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProvider.java b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProvider.java index 4c57cc822..2eb33ddea 100644 --- a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProvider.java +++ b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/AndroidLifecycleScopeProvider.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/KotlinExtensions.kt b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/KotlinExtensions.kt index 6f7d63c83..28f8fe17e 100644 --- a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/KotlinExtensions.kt +++ b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/KotlinExtensions.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -37,13 +37,9 @@ import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.parallel.ParallelFlowable -/** - * Extension that returns a [ScopeProvider] for this [LifecycleOwner]. - */ +/** Extension that returns a [ScopeProvider] for this [LifecycleOwner]. */ @CheckReturnValue -inline fun LifecycleOwner.scope(): ScopeProvider = AndroidLifecycleScopeProvider.from( - this -) +public inline fun LifecycleOwner.scope(): ScopeProvider = AndroidLifecycleScopeProvider.from(this) /** * Extension that returns a [ScopeProvider] for this [LifecycleOwner]. @@ -51,12 +47,8 @@ inline fun LifecycleOwner.scope(): ScopeProvider = AndroidLifecycleScopeProvider * @param untilEvent the event until the scope is valid. */ @CheckReturnValue -inline fun LifecycleOwner.scope( - untilEvent: Lifecycle.Event -): ScopeProvider = AndroidLifecycleScopeProvider.from( - this, - untilEvent -) +public inline fun LifecycleOwner.scope(untilEvent: Event): ScopeProvider = + AndroidLifecycleScopeProvider.from(this, untilEvent) /** * Extension that returns a [ScopeProvider] for this [LifecycleOwner]. @@ -64,20 +56,13 @@ inline fun LifecycleOwner.scope( * @param boundaryResolver function that resolves the event boundary. */ @CheckReturnValue -inline fun LifecycleOwner.scope( +public inline fun LifecycleOwner.scope( boundaryResolver: CorrespondingEventsFunction -): ScopeProvider = AndroidLifecycleScopeProvider.from( - this, - boundaryResolver -) +): ScopeProvider = AndroidLifecycleScopeProvider.from(this, boundaryResolver) -/** - * Extension that returns a [ScopeProvider] for this [Lifecycle]. - */ +/** Extension that returns a [ScopeProvider] for this [Lifecycle]. */ @CheckReturnValue -inline fun Lifecycle.scope(): ScopeProvider = AndroidLifecycleScopeProvider.from( - this -) +public inline fun Lifecycle.scope(): ScopeProvider = AndroidLifecycleScopeProvider.from(this) /** * Extension that returns a [ScopeProvider] for this [Lifecycle]. @@ -85,11 +70,8 @@ inline fun Lifecycle.scope(): ScopeProvider = AndroidLifecycleScopeProvider.from * @param untilEvent the event until the scope is valid. */ @CheckReturnValue -inline fun Lifecycle.scope( - untilEvent: Lifecycle.Event -): ScopeProvider = AndroidLifecycleScopeProvider.from( - this, untilEvent -) +public inline fun Lifecycle.scope(untilEvent: Event): ScopeProvider = + AndroidLifecycleScopeProvider.from(this, untilEvent) /** * Extension that returns a [ScopeProvider] for this [Lifecycle]. @@ -97,166 +79,134 @@ inline fun Lifecycle.scope( * @param boundaryResolver function that resolves the event boundary. */ @CheckReturnValue -inline fun Lifecycle.scope( +public inline fun Lifecycle.scope( boundaryResolver: CorrespondingEventsFunction -): ScopeProvider = AndroidLifecycleScopeProvider.from( - this, boundaryResolver -) +): ScopeProvider = AndroidLifecycleScopeProvider.from(this, boundaryResolver) /** - * Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] when - * subscription will be disposed. + * Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] + * when subscription will be disposed. * * @param lifecycleOwner The lifecycle owner. * @param untilEvent Optional lifecycle event when subscription will be disposed. */ @CheckReturnValue -inline fun Flowable.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): FlowableSubscribeProxy { +public inline fun Flowable.autoDispose( + lifecycleOwner: LifecycleOwner, + untilEvent: Event? = null +): FlowableSubscribeProxy { return if (untilEvent == null) { this.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner))) } else { this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from( - lifecycleOwner, - untilEvent - ) - ) + AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner, untilEvent)) ) } } /** - * Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] when - * subscription will be disposed. + * Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] and takes an + * [untilEvent] when subscription will be disposed. * * @param lifecycleOwner The lifecycle owner. * @param untilEvent Optional lifecycle event when subscription will be disposed. */ @CheckReturnValue -inline fun Observable.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): ObservableSubscribeProxy { +public inline fun Observable.autoDispose( + lifecycleOwner: LifecycleOwner, + untilEvent: Event? = null +): ObservableSubscribeProxy { return if (untilEvent == null) { - this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from(lifecycleOwner) - ) - ) + this.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner))) } else { this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from( - lifecycleOwner, - untilEvent - ) - ) + AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner, untilEvent)) ) } } /** - * Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] when - * subscription will be disposed. + * Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] + * when subscription will be disposed. * * @param lifecycleOwner The lifecycle owner. * @param untilEvent Optional lifecycle event when subscription will be disposed. */ @CheckReturnValue -inline fun Single.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): SingleSubscribeProxy { +public inline fun Single.autoDispose( + lifecycleOwner: LifecycleOwner, + untilEvent: Event? = null +): SingleSubscribeProxy { return if (untilEvent == null) { - this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from(lifecycleOwner) - ) - ) + this.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner))) } else { this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from( - lifecycleOwner, - untilEvent - ) - ) + AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner, untilEvent)) ) } } /** - * Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] when - * subscription will be disposed. + * Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] + * when subscription will be disposed. * * @param lifecycleOwner The lifecycle owner. * @param untilEvent Optional lifecycle event when subscription will be disposed. */ @CheckReturnValue -inline fun Maybe.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): MaybeSubscribeProxy { +public inline fun Maybe.autoDispose( + lifecycleOwner: LifecycleOwner, + untilEvent: Event? = null +): MaybeSubscribeProxy { return if (untilEvent == null) { - this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from(lifecycleOwner) - ) - ) + this.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner))) } else { this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from( - lifecycleOwner, - untilEvent - ) - ) + AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner, untilEvent)) ) } } /** - * Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] when - * subscription will be disposed. + * Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] and takes an + * [untilEvent] when subscription will be disposed. * * @param lifecycleOwner The lifecycle owner. * @param untilEvent Optional lifecycle event when subscription will be disposed. */ @CheckReturnValue -inline fun Completable.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): CompletableSubscribeProxy { +public inline fun Completable.autoDispose( + lifecycleOwner: LifecycleOwner, + untilEvent: Event? = null +): CompletableSubscribeProxy { return if (untilEvent == null) { - this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from(lifecycleOwner) - ) - ) + this.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner))) } else { this.to( AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from( - lifecycleOwner, - untilEvent - ) + AndroidLifecycleScopeProvider.from(lifecycleOwner, untilEvent) ) ) } } /** - * Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] and takes an [untilEvent] when - * subscription will be disposed. + * Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] and takes an + * [untilEvent] when subscription will be disposed. * * @param lifecycleOwner The lifecycle owner. * @param untilEvent Optional lifecycle event when subscription will be disposed. */ @CheckReturnValue -inline fun ParallelFlowable.autoDispose(lifecycleOwner: LifecycleOwner, untilEvent: Event? = null): ParallelFlowableSubscribeProxy { +public inline fun ParallelFlowable.autoDispose( + lifecycleOwner: LifecycleOwner, + untilEvent: Event? = null +): ParallelFlowableSubscribeProxy { return if (untilEvent == null) { - this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from(lifecycleOwner) - ) - ) + this.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner))) } else { this.to( - AutoDispose.autoDisposable( - AndroidLifecycleScopeProvider.from( - lifecycleOwner, - untilEvent - ) - ) + AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycleOwner, untilEvent)) ) } } diff --git a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/LifecycleEventsObservable.java b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/LifecycleEventsObservable.java index c3076d91e..31698cf24 100644 --- a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/LifecycleEventsObservable.java +++ b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/LifecycleEventsObservable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/package-info.java b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/package-info.java index d62b1ee8c..249f34090 100644 --- a/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/package-info.java +++ b/android/autodispose-androidx-lifecycle/src/main/java/autodispose2/androidx/lifecycle/package-info.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-interop/coroutines/build.gradle b/autodispose-interop/coroutines/build.gradle.kts similarity index 59% rename from autodispose-interop/coroutines/build.gradle rename to autodispose-interop/coroutines/build.gradle.kts index 1e4ec3e98..97301f35d 100644 --- a/autodispose-interop/coroutines/build.gradle +++ b/autodispose-interop/coroutines/build.gradle.kts @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -13,16 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - plugins { - id 'ru.vyarus.animalsniffer' - id "com.vanniktech.maven.publish" + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.animalSniffer) + alias(libs.plugins.mavenPublish) } dependencies { - api deps.rx.java - api project(':autodispose') - api deps.kotlin.coroutines + api(libs.rx.java) + api(project(":autodispose")) + api(libs.kotlin.coroutines) + + signature(libs.build.animalSniffer) { + artifact { + name = "java17" + type = "signature" + } + } - testImplementation project(':test-utils') + testImplementation(project(":test-utils")) } diff --git a/autodispose-interop/coroutines/gradle.properties b/autodispose-interop/coroutines/gradle.properties index 0c2719bc1..64792698c 100644 --- a/autodispose-interop/coroutines/gradle.properties +++ b/autodispose-interop/coroutines/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, diff --git a/autodispose-interop/coroutines/src/main/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInterop.kt b/autodispose-interop/coroutines/src/main/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInterop.kt index 8c7a2dd9d..c1f58980f 100644 --- a/autodispose-interop/coroutines/src/main/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInterop.kt +++ b/autodispose-interop/coroutines/src/main/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInterop.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -30,20 +30,24 @@ import io.reactivex.rxjava3.core.Flowable import io.reactivex.rxjava3.core.Maybe import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.core.Single +import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel -import kotlin.coroutines.CoroutineContext /** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */ -public inline fun Flowable.autoDispose(scope: CoroutineScope): FlowableSubscribeProxy { +public inline fun Flowable.autoDispose( + scope: CoroutineScope +): FlowableSubscribeProxy { return autoDispose(scope.asScopeProvider()) } /** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */ -public inline fun Observable.autoDispose(scope: CoroutineScope): ObservableSubscribeProxy { +public inline fun Observable.autoDispose( + scope: CoroutineScope +): ObservableSubscribeProxy { return autoDispose(scope.asScopeProvider()) } @@ -64,13 +68,15 @@ public inline fun Completable.autoDispose(scope: CoroutineScope): CompletableSub /** * @return a [ScopeProvider] representation of this [CoroutineScope]. This scope will complete when - * [this] coroutine scope completes. + * [this] coroutine scope completes. */ -public fun CoroutineScope.asScopeProvider(): ScopeProvider = ScopeProvider { asUndeferredCompletable() } +public fun CoroutineScope.asScopeProvider(): ScopeProvider = ScopeProvider { + asUndeferredCompletable() +} /** * @return a [Completable] representation of this [CoroutineScope]. This will complete when [this] - * coroutine scope completes. Note that the returned [Completable] is deferred. + * coroutine scope completes. Note that the returned [Completable] is deferred. */ public fun CoroutineScope.asCompletable(): Completable { return Completable.defer { asUndeferredCompletable() } @@ -78,43 +84,51 @@ public fun CoroutineScope.asCompletable(): Completable { private fun CoroutineScope.asUndeferredCompletable(): Completable { return Completable.create { emitter -> - val job = coroutineContext[Job] ?: error( - "Scope cannot be created because it does not have a job: ${this@asUndeferredCompletable}" - ) - val handle = job.invokeOnCompletion { - when (it) { - null, is CancellationException -> emitter.onComplete() - else -> emitter.onError(it) + val job = + coroutineContext[Job] + ?: error( + "Scope cannot be created because it does not have a job: ${this@asUndeferredCompletable}" + ) + val handle = + job.invokeOnCompletion { + when (it) { + null, + is CancellationException -> emitter.onComplete() + else -> emitter.onError(it) + } } - } emitter.setCancellable(handle::dispose) } } /** * @param context an optional [CoroutineContext] to use for this scope. Default is a new - * [SupervisorJob]. + * [SupervisorJob]. * @return a [CoroutineScope] representation of this [ScopeProvider]. This scope will cancel when - * [this] scope provider completes. + * [this] scope provider completes. */ -public fun ScopeProvider.asCoroutineScope(context: CoroutineContext = SupervisorJob()): CoroutineScope { +public fun ScopeProvider.asCoroutineScope( + context: CoroutineContext = SupervisorJob() +): CoroutineScope { return requestScope().asCoroutineScope(context) } /** * @param context an optional [CoroutineContext] to use for this scope. Default is a new - * [SupervisorJob]. + * [SupervisorJob]. * @return a [CoroutineScope] representation of this [CompletableSource]. This scope will cancel - * when [this] scope provider completes. + * when [this] scope provider completes. */ -public fun CompletableSource.asCoroutineScope(context: CoroutineContext = SupervisorJob()): CoroutineScope { +public fun CompletableSource.asCoroutineScope( + context: CoroutineContext = SupervisorJob() +): CoroutineScope { val scope = CoroutineScope(context) // Bind to the scope, so if the scope is manually canceled before our scope provider emits, we // clean up here. - Completable.wrap(this) - .autoDispose(scope) - .subscribe({ scope.cancel() }) { e -> scope.cancel("OnError", e) } + Completable.wrap(this).autoDispose(scope).subscribe({ scope.cancel() }) { e -> + scope.cancel("OnError", e) + } return scope } diff --git a/autodispose-interop/coroutines/src/test/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInteropTest.kt b/autodispose-interop/coroutines/src/test/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInteropTest.kt index c4bc865f0..1eadea240 100644 --- a/autodispose-interop/coroutines/src/test/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInteropTest.kt +++ b/autodispose-interop/coroutines/src/test/kotlin/autodispose2/interop/coroutines/AutoDisposeCoroutinesInteropTest.kt @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/build.gradle b/autodispose-lifecycle/build.gradle.kts similarity index 60% rename from autodispose-lifecycle/build.gradle rename to autodispose-lifecycle/build.gradle.kts index f76b40d5e..cd66d68e7 100644 --- a/autodispose-lifecycle/build.gradle +++ b/autodispose-lifecycle/build.gradle.kts @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -13,18 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - plugins { - id 'ru.vyarus.animalsniffer' - id "com.vanniktech.maven.publish" + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.animalSniffer) + alias(libs.plugins.mavenPublish) } dependencies { - api project(":autodispose") - compileOnly deps.build.errorProneAnnotations + api(project(":autodispose")) + compileOnly(libs.build.errorProneAnnotations) - signature deps.build.animalSniffer + signature(libs.build.animalSniffer) { + artifact { + name = "java17" + type = "signature" + } + } - testImplementation project(':test-utils') - testImplementation deps.kotlin.stdlib + testImplementation(project(":test-utils")) } diff --git a/autodispose-lifecycle/gradle.properties b/autodispose-lifecycle/gradle.properties index 6d9634781..d13792830 100644 --- a/autodispose-lifecycle/gradle.properties +++ b/autodispose-lifecycle/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, diff --git a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/CorrespondingEventsFunction.java b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/CorrespondingEventsFunction.java index 09f54f0c4..5146a7107 100644 --- a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/CorrespondingEventsFunction.java +++ b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/CorrespondingEventsFunction.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleEndedException.java b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleEndedException.java index 5427ccc91..12302825a 100644 --- a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleEndedException.java +++ b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleEndedException.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleNotStartedException.java b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleNotStartedException.java index 2cd258250..6397065c0 100644 --- a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleNotStartedException.java +++ b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleNotStartedException.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopeProvider.java b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopeProvider.java index 875aa9328..a40ff172a 100644 --- a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopeProvider.java +++ b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopeProvider.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopes.java b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopes.java index 0bdce4af0..e4a7b2d12 100644 --- a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopes.java +++ b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopes.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/TestLifecycleScopeProvider.java b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/TestLifecycleScopeProvider.java index d1eb91b89..679e0d717 100644 --- a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/TestLifecycleScopeProvider.java +++ b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/TestLifecycleScopeProvider.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/package-info.java b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/package-info.java index 244892a00..4c5600f34 100644 --- a/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/package-info.java +++ b/autodispose-lifecycle/src/main/java/autodispose2/lifecycle/package-info.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/AutoDisposeLifecycleTest.kt b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/AutoDisposeLifecycleTest.kt index 2babf30ba..79449c2e8 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/AutoDisposeLifecycleTest.kt +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/AutoDisposeLifecycleTest.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -39,30 +39,27 @@ class AutoDisposeLifecycleTest { private val s = TestSubscriber() private val lifecycleScopeProvider = TestLifecycleScopeProvider.create() - @Test fun observable_lifecycleNotStarted() { - Observable.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + @Test + fun observable_lifecycleNotStarted() { + Observable.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleNotStartedException } } - @Test fun observable_lifecycleNormalCompletion() { + @Test + fun observable_lifecycleNormalCompletion() { lifecycleScopeProvider.start() - Observable.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Observable.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun observable_lifecycleNormalInterrupted() { + @Test + fun observable_lifecycleNormalInterrupted() { lifecycleScopeProvider.start() val subject = PublishSubject.create() - subject - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + subject.autoDispose(lifecycleScopeProvider).subscribe(o) subject.onNext("Hello") @@ -75,40 +72,36 @@ class AutoDisposeLifecycleTest { // o.assertNotSubscribed() } - @Test fun observable_lifecycleEnded() { + @Test + fun observable_lifecycleEnded() { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() - Observable.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Observable.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleEndedException } } - @Test fun flowable_lifecycleNotStarted() { - Flowable.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(s) + @Test + fun flowable_lifecycleNotStarted() { + Flowable.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(s) s.assertError { it is LifecycleNotStartedException } } - @Test fun flowable_lifecycleNormalCompletion() { + @Test + fun flowable_lifecycleNormalCompletion() { lifecycleScopeProvider.start() - Flowable.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(s) + Flowable.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(s) s.assertValue { it == "Hello" } s.assertComplete() } - @Test fun flowable_lifecycleNormalInterrupted() { + @Test + fun flowable_lifecycleNormalInterrupted() { lifecycleScopeProvider.start() val subject = PublishSubject.create() - subject.toFlowable(ERROR) - .autoDispose(lifecycleScopeProvider) - .subscribe(s) + subject.toFlowable(ERROR).autoDispose(lifecycleScopeProvider).subscribe(s) subject.onNext("Hello") @@ -121,40 +114,36 @@ class AutoDisposeLifecycleTest { // s.assertNotSubscribed() } - @Test fun flowable_lifecycleEnded() { + @Test + fun flowable_lifecycleEnded() { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() - Flowable.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(s) + Flowable.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(s) s.assertError { it is LifecycleEndedException } } - @Test fun maybe_lifecycleNotStarted() { - Maybe.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + @Test + fun maybe_lifecycleNotStarted() { + Maybe.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleNotStartedException } } - @Test fun maybe_lifecycleNormalCompletion() { + @Test + fun maybe_lifecycleNormalCompletion() { lifecycleScopeProvider.start() - Maybe.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Maybe.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun maybe_lifecycleNormalInterrupted() { + @Test + fun maybe_lifecycleNormalInterrupted() { lifecycleScopeProvider.start() val subject = PublishSubject.create() - subject - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + subject.autoDispose(lifecycleScopeProvider).subscribe(o) lifecycleScopeProvider.stop() @@ -163,40 +152,36 @@ class AutoDisposeLifecycleTest { // o.assertNotSubscribed() } - @Test fun maybe_lifecycleEnded() { + @Test + fun maybe_lifecycleEnded() { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() - Maybe.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Maybe.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleEndedException } } - @Test fun single_lifecycleNotStarted() { - Single.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + @Test + fun single_lifecycleNotStarted() { + Single.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleNotStartedException } } - @Test fun single_lifecycleNormalCompletion() { + @Test + fun single_lifecycleNormalCompletion() { lifecycleScopeProvider.start() - Single.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Single.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun single_lifecycleNormalInterrupted() { + @Test + fun single_lifecycleNormalInterrupted() { lifecycleScopeProvider.start() val subject = PublishSubject.create() - subject - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + subject.autoDispose(lifecycleScopeProvider).subscribe(o) lifecycleScopeProvider.stop() @@ -205,39 +190,35 @@ class AutoDisposeLifecycleTest { // o.assertNotSubscribed() } - @Test fun single_lifecycleEnded() { + @Test + fun single_lifecycleEnded() { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() - Single.just("Hello") - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Single.just("Hello").autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleEndedException } } - @Test fun completable_lifecycleNotStarted() { - Completable.complete() - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + @Test + fun completable_lifecycleNotStarted() { + Completable.complete().autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleNotStartedException } } - @Test fun completable_lifecycleNormalCompletion() { + @Test + fun completable_lifecycleNormalCompletion() { lifecycleScopeProvider.start() - Completable.complete() - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Completable.complete().autoDispose(lifecycleScopeProvider).subscribe(o) o.assertComplete() } - @Test fun completable_lifecycleNormalInterrupted() { + @Test + fun completable_lifecycleNormalInterrupted() { lifecycleScopeProvider.start() val subject = CompletableSubject.create() - subject - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + subject.autoDispose(lifecycleScopeProvider).subscribe(o) lifecycleScopeProvider.stop() @@ -246,17 +227,17 @@ class AutoDisposeLifecycleTest { // o.assertNotSubscribed() } - @Test fun completable_lifecycleEnded() { + @Test + fun completable_lifecycleEnded() { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() - Completable.complete() - .autoDispose(lifecycleScopeProvider) - .subscribe(o) + Completable.complete().autoDispose(lifecycleScopeProvider).subscribe(o) o.assertError { it is LifecycleEndedException } } - @Test fun parallelFlowable_lifecycleNotStarted() { + @Test + fun parallelFlowable_lifecycleNotStarted() { val s2 = TestSubscriber() Flowable.just("Hello", "World") .parallel(DEFAULT_PARALLELISM) @@ -267,7 +248,8 @@ class AutoDisposeLifecycleTest { s2.assertError { it is LifecycleNotStartedException } } - @Test fun parallelFlowable_lifecycleNormalCompletion() { + @Test + fun parallelFlowable_lifecycleNormalCompletion() { lifecycleScopeProvider.start() val s2 = TestSubscriber() Flowable.just("Hello", "World") @@ -281,11 +263,13 @@ class AutoDisposeLifecycleTest { s2.assertComplete() } - @Test fun parallelFlowable_lifecycleNormalInterrupted() { + @Test + fun parallelFlowable_lifecycleNormalInterrupted() { lifecycleScopeProvider.start() val subject = PublishSubject.create() val s2 = TestSubscriber() - subject.toFlowable(ERROR) + subject + .toFlowable(ERROR) .parallel(DEFAULT_PARALLELISM) .autoDispose(lifecycleScopeProvider) .subscribe(arrayOf(s, s2)) @@ -302,7 +286,8 @@ class AutoDisposeLifecycleTest { // s.assertNotSubscribed() } - @Test fun parallelFlowable_lifecycleEnded() { + @Test + fun parallelFlowable_lifecycleEnded() { lifecycleScopeProvider.start() lifecycleScopeProvider.stop() val s2 = TestSubscriber() diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderCompletableTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderCompletableTest.java index 6db6e8a36..d0b283cf1 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderCompletableTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderCompletableTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderMaybeTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderMaybeTest.java index 6021b0ef2..070b4b406 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderMaybeTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderMaybeTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderObservableTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderObservableTest.java index a066f1484..707accf0c 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderObservableTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderObservableTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderParallelFlowableTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderParallelFlowableTest.java index e5ff2e74a..07031b66d 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderParallelFlowableTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderParallelFlowableTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSingleTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSingleTest.java index ffe7c7ad4..5a0ccc998 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSingleTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSingleTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSubscriberTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSubscriberTest.java index d91ccafdf..f3ce44959 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSubscriberTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopeProviderSubscriberTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopesTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopesTest.java index 1ade0efdc..e78d35490 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopesTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/LifecycleScopesTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestLifecycleScopeProviderTest.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestLifecycleScopeProviderTest.java index 34337aae2..bfaa54b02 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestLifecycleScopeProviderTest.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestLifecycleScopeProviderTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestUtil.java b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestUtil.java index ac6d807a5..075a2add4 100644 --- a/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestUtil.java +++ b/autodispose-lifecycle/src/test/java/autodispose2/lifecycle/TestUtil.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/Module.md b/autodispose/Module.md index 7bdd06f36..02a219104 100644 --- a/autodispose/Module.md +++ b/autodispose/Module.md @@ -9,9 +9,9 @@ usually looks like this: ``` myObservable - .doStuff() - .as(autoDisposable(this)) // <-- AutoDispose - .subscribe(s -> ...); + .doStuff() + .as(autoDisposable(this)) // <-- AutoDispose + .subscribe(s -> ...); ``` By doing this, you will automatically unsubscribe from `myObservable` as indicated by your scope diff --git a/autodispose/build.gradle.kts b/autodispose/build.gradle.kts new file mode 100644 index 000000000..5845035a3 --- /dev/null +++ b/autodispose/build.gradle.kts @@ -0,0 +1,41 @@ +/* + * 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 + * + * https://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. + */ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.android.lint) + alias(libs.plugins.animalSniffer) + alias(libs.plugins.mavenPublish) +} + +lint { + abortOnError = true + warningsAsErrors = true +} + +dependencies { + api(libs.rx.java) + compileOnly(libs.build.errorProneAnnotations) + + signature(libs.build.animalSniffer) { + artifact { + name = "java17" + type = "signature" + } + } + lintChecks(project(":static-analysis:autodispose-lint")) + + testImplementation(project(":test-utils")) +} diff --git a/autodispose/gradle.properties b/autodispose/gradle.properties index 54dfc463d..c1fb9ef4d 100644 --- a/autodispose/gradle.properties +++ b/autodispose/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, diff --git a/autodispose/src/main/java/autodispose2/AtomicThrowable.java b/autodispose/src/main/java/autodispose2/AtomicThrowable.java index c6eb02585..b6169499a 100644 --- a/autodispose/src/main/java/autodispose2/AtomicThrowable.java +++ b/autodispose/src/main/java/autodispose2/AtomicThrowable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposableHelper.java b/autodispose/src/main/java/autodispose2/AutoDisposableHelper.java index 8a35757db..98c1c1169 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposableHelper.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposableHelper.java @@ -5,7 +5,7 @@ * in * compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is diff --git a/autodispose/src/main/java/autodispose2/AutoDispose.java b/autodispose/src/main/java/autodispose2/AutoDispose.java index ddf899dbc..3c43fa42f 100644 --- a/autodispose/src/main/java/autodispose2/AutoDispose.java +++ b/autodispose/src/main/java/autodispose2/AutoDispose.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -360,6 +360,7 @@ public Disposable subscribe(Consumer onSuccess) { return new AutoDisposeSingle<>(upstream, scope).subscribe(onSuccess); } + @SuppressWarnings("NullAway") // False positive @Override public Disposable subscribe( BiConsumer<@Nullable ? super T, @Nullable ? super Throwable> biConsumer) { diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeBackpressureHelper.java b/autodispose/src/main/java/autodispose2/AutoDisposeBackpressureHelper.java index 4b446753f..edd07c556 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeBackpressureHelper.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeBackpressureHelper.java @@ -5,7 +5,7 @@ * in * compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeCompletable.java b/autodispose/src/main/java/autodispose2/AutoDisposeCompletable.java index fab17591f..8c81c8012 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeCompletable.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeCompletable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeConverter.java b/autodispose/src/main/java/autodispose2/AutoDisposeConverter.java index 69cba9b34..75006dfbb 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeConverter.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeConverter.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeEndConsumerHelper.java b/autodispose/src/main/java/autodispose2/AutoDisposeEndConsumerHelper.java index 06cebe55b..c270156d2 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeEndConsumerHelper.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeEndConsumerHelper.java @@ -4,7 +4,7 @@ * 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 + * https://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 diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeFlowable.java b/autodispose/src/main/java/autodispose2/AutoDisposeFlowable.java index 205ad6d27..768ed3e4b 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeFlowable.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeFlowable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeMaybe.java b/autodispose/src/main/java/autodispose2/AutoDisposeMaybe.java index 9674b9e8d..14f24a7a4 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeMaybe.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeMaybe.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeObservable.java b/autodispose/src/main/java/autodispose2/AutoDisposeObservable.java index 1c76e058f..96db085a7 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeObservable.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeObservable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeParallelFlowable.java b/autodispose/src/main/java/autodispose2/AutoDisposeParallelFlowable.java index efb3c84bd..1e60e43a0 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeParallelFlowable.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeParallelFlowable.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposePlugins.java b/autodispose/src/main/java/autodispose2/AutoDisposePlugins.java index 783d01753..13f2a7da6 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposePlugins.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposePlugins.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -72,7 +72,7 @@ public static Consumer getOutsideScopeHandler() { return outsideScopeHandler; } - /** @param handler the consumer for handling {@link OutsideScopeException} to set, null allowed */ + /** Sets a consumer for handling {@link OutsideScopeException} to set, null allowed */ public static void setOutsideScopeHandler( @Nullable Consumer handler) { if (lockdown) { @@ -82,9 +82,9 @@ public static void setOutsideScopeHandler( } /** - * @param fillInStacktrace {@code true} to fill in stacktraces in {@link OutsideScopeException}s. - * {@code false} to disable them (and use them as signals only). Disabling them, if you don't - * care about the stacktraces, can result in some minor performance improvements. + * Sets whether to fill in stacktraces in {@link OutsideScopeException}s. {@code false} to disable + * them (and use them as signals only). Disabling them, if you don't care about the stacktraces, + * can result in some minor performance improvements. */ public static void setFillInOutsideScopeExceptionStacktraces(boolean fillInStacktrace) { if (lockdown) { @@ -94,9 +94,9 @@ public static void setFillInOutsideScopeExceptionStacktraces(boolean fillInStack } /** - * @param hideProxies {@code true} hide proxy interfaces. This wraps all proxy interfaces in - * {@link autodispose2} at runtime in an anonymous instance to prevent introspection, similar - * to {@link Observable#hide()}. The default is {@code true}. + * Sets whether to hide proxy interfaces. This wraps all proxy interfaces in {@link autodispose2} + * at runtime in an anonymous instance to prevent introspection, similar to {@link + * Observable#hide()}. The default is {@code true}. */ public static void setHideProxies(boolean hideProxies) { if (lockdown) { diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeSingle.java b/autodispose/src/main/java/autodispose2/AutoDisposeSingle.java index e842b7b66..640c892be 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeSingle.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeSingle.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposeUtil.java b/autodispose/src/main/java/autodispose2/AutoDisposeUtil.java index 2c70d8fbf..ea1220245 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposeUtil.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposeUtil.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposingCompletableObserverImpl.java b/autodispose/src/main/java/autodispose2/AutoDisposingCompletableObserverImpl.java index d171d1134..ecc4371cd 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposingCompletableObserverImpl.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposingCompletableObserverImpl.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposingMaybeObserverImpl.java b/autodispose/src/main/java/autodispose2/AutoDisposingMaybeObserverImpl.java index c21508ab3..1869dc235 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposingMaybeObserverImpl.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposingMaybeObserverImpl.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposingObserverImpl.java b/autodispose/src/main/java/autodispose2/AutoDisposingObserverImpl.java index 8defca317..7c3f4999e 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposingObserverImpl.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposingObserverImpl.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposingSingleObserverImpl.java b/autodispose/src/main/java/autodispose2/AutoDisposingSingleObserverImpl.java index 93e6e705b..282c8eac5 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposingSingleObserverImpl.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposingSingleObserverImpl.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoDisposingSubscriberImpl.java b/autodispose/src/main/java/autodispose2/AutoDisposingSubscriberImpl.java index b21539b47..6f0f5e21e 100644 --- a/autodispose/src/main/java/autodispose2/AutoDisposingSubscriberImpl.java +++ b/autodispose/src/main/java/autodispose2/AutoDisposingSubscriberImpl.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/AutoSubscriptionHelper.java b/autodispose/src/main/java/autodispose2/AutoSubscriptionHelper.java index 3c8adc951..51572f05c 100644 --- a/autodispose/src/main/java/autodispose2/AutoSubscriptionHelper.java +++ b/autodispose/src/main/java/autodispose2/AutoSubscriptionHelper.java @@ -5,7 +5,7 @@ * in * compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is diff --git a/autodispose/src/main/java/autodispose2/CompletableSubscribeProxy.java b/autodispose/src/main/java/autodispose2/CompletableSubscribeProxy.java index 442ca398c..5b144908f 100644 --- a/autodispose/src/main/java/autodispose2/CompletableSubscribeProxy.java +++ b/autodispose/src/main/java/autodispose2/CompletableSubscribeProxy.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/ExceptionHelper.java b/autodispose/src/main/java/autodispose2/ExceptionHelper.java index 9f69e3d3b..c65528a06 100644 --- a/autodispose/src/main/java/autodispose2/ExceptionHelper.java +++ b/autodispose/src/main/java/autodispose2/ExceptionHelper.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -35,6 +35,7 @@ private ExceptionHelper() { * A singleton instance of a Throwable indicating a terminal state for exceptions, * don't leak this. */ + @SuppressWarnings("StaticAssignmentOfThrowable") private static final Throwable TERMINATED = new Termination(); static boolean addThrowable(AtomicReference field, Throwable exception) { diff --git a/autodispose/src/main/java/autodispose2/FlowableSubscribeProxy.java b/autodispose/src/main/java/autodispose2/FlowableSubscribeProxy.java index d3c9b2d10..669f1a032 100644 --- a/autodispose/src/main/java/autodispose2/FlowableSubscribeProxy.java +++ b/autodispose/src/main/java/autodispose2/FlowableSubscribeProxy.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/HalfSerializer.java b/autodispose/src/main/java/autodispose2/HalfSerializer.java index 0d8b3730b..bafcbafcf 100644 --- a/autodispose/src/main/java/autodispose2/HalfSerializer.java +++ b/autodispose/src/main/java/autodispose2/HalfSerializer.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/KotlinExtensions.kt b/autodispose/src/main/java/autodispose2/KotlinExtensions.kt index b7df6cdc3..11865a149 100644 --- a/autodispose/src/main/java/autodispose2/KotlinExtensions.kt +++ b/autodispose/src/main/java/autodispose2/KotlinExtensions.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -27,89 +27,71 @@ import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.parallel.ParallelFlowable -/** - * Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue public inline fun Flowable.autoDispose(scope: Completable): FlowableSubscribeProxy = this.to(AutoDispose.autoDisposable(scope)) -/** - * Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -public inline fun Observable.autoDispose(scope: Completable): ObservableSubscribeProxy = - this.to(AutoDispose.autoDisposable(scope)) +public inline fun Observable.autoDispose( + scope: Completable +): ObservableSubscribeProxy = this.to(AutoDispose.autoDisposable(scope)) -/** - * Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue public inline fun Single.autoDispose(scope: Completable): SingleSubscribeProxy = this.to(AutoDispose.autoDisposable(scope)) -/** - * Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue public inline fun Maybe.autoDispose(scope: Completable): MaybeSubscribeProxy = this.to(AutoDispose.autoDisposable(scope)) -/** - * Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue public inline fun Completable.autoDispose(scope: Completable): CompletableSubscribeProxy = this.to(AutoDispose.autoDisposable(scope)) -/** - * Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -public inline fun ParallelFlowable.autoDispose(scope: Completable): ParallelFlowableSubscribeProxy = - this.to(AutoDispose.autoDisposable(scope)) +public inline fun ParallelFlowable.autoDispose( + scope: Completable +): ParallelFlowableSubscribeProxy = this.to(AutoDispose.autoDisposable(scope)) -/** - * Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Flowable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -public inline fun Flowable.autoDispose(provider: ScopeProvider): FlowableSubscribeProxy = - this.to(AutoDispose.autoDisposable(provider)) +public inline fun Flowable.autoDispose( + provider: ScopeProvider +): FlowableSubscribeProxy = this.to(AutoDispose.autoDisposable(provider)) -/** - * Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Observable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -public inline fun Observable.autoDispose(provider: ScopeProvider): ObservableSubscribeProxy = - this.to(AutoDispose.autoDisposable(provider)) +public inline fun Observable.autoDispose( + provider: ScopeProvider +): ObservableSubscribeProxy = this.to(AutoDispose.autoDisposable(provider)) -/** - * Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Single.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -public inline fun Single.autoDispose(provider: ScopeProvider): SingleSubscribeProxy = - this.to(AutoDispose.autoDisposable(provider)) +public inline fun Single.autoDispose( + provider: ScopeProvider +): SingleSubscribeProxy = this.to(AutoDispose.autoDisposable(provider)) -/** - * Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Maybe.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue public inline fun Maybe.autoDispose(provider: ScopeProvider): MaybeSubscribeProxy = this.to(AutoDispose.autoDisposable(provider)) -/** - * Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [Completable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue public inline fun Completable.autoDispose(provider: ScopeProvider): CompletableSubscribeProxy = this.to(AutoDispose.autoDisposable(provider)) -/** - * Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] - */ +/** Extension that proxies to [ParallelFlowable.as] + [AutoDispose.autoDisposable] */ @CheckReturnValue -public inline fun ParallelFlowable.autoDispose(provider: ScopeProvider): ParallelFlowableSubscribeProxy = - this.to(AutoDispose.autoDisposable(provider)) +public inline fun ParallelFlowable.autoDispose( + provider: ScopeProvider +): ParallelFlowableSubscribeProxy = this.to(AutoDispose.autoDisposable(provider)) /** Executes a [body] with an [AutoDisposeContext] backed by the given [scope]. */ public inline fun withScope(scope: ScopeProvider, body: AutoDisposeContext.() -> Unit) { @@ -123,8 +105,8 @@ public inline fun withScope(completableScope: Completable, body: AutoDisposeCont } /** - * A context intended for use as `AutoDisposeContext.() -> Unit` function body parameters - * where zero-arg [autoDispose] functions can be called. This should be backed by an underlying + * A context intended for use as `AutoDisposeContext.() -> Unit` function body parameters where + * zero-arg [autoDispose] functions can be called. This should be backed by an underlying * [Completable] or [ScopeProvider]. */ public interface AutoDisposeContext { @@ -150,9 +132,14 @@ public interface AutoDisposeContext { @PublishedApi internal class RealAutoDisposeContext(private val scope: Completable) : AutoDisposeContext { override fun ParallelFlowable.autoDispose() = autoDispose(scope) + override fun Flowable.autoDispose() = autoDispose(scope) + override fun Observable.autoDispose() = autoDispose(scope) + override fun Single.autoDispose() = autoDispose(scope) + override fun Maybe.autoDispose() = autoDispose(scope) + override fun Completable.autoDispose() = autoDispose(scope) } diff --git a/autodispose/src/main/java/autodispose2/MaybeSubscribeProxy.java b/autodispose/src/main/java/autodispose2/MaybeSubscribeProxy.java index cd22d0e1f..6b7193241 100644 --- a/autodispose/src/main/java/autodispose2/MaybeSubscribeProxy.java +++ b/autodispose/src/main/java/autodispose2/MaybeSubscribeProxy.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/ObservableSubscribeProxy.java b/autodispose/src/main/java/autodispose2/ObservableSubscribeProxy.java index e0a0be51e..274563f5a 100644 --- a/autodispose/src/main/java/autodispose2/ObservableSubscribeProxy.java +++ b/autodispose/src/main/java/autodispose2/ObservableSubscribeProxy.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/OutsideScopeException.java b/autodispose/src/main/java/autodispose2/OutsideScopeException.java index cab24b2d0..fc7601184 100644 --- a/autodispose/src/main/java/autodispose2/OutsideScopeException.java +++ b/autodispose/src/main/java/autodispose2/OutsideScopeException.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/ParallelFlowableSubscribeProxy.java b/autodispose/src/main/java/autodispose2/ParallelFlowableSubscribeProxy.java index cc31ea427..0b69e7cbc 100644 --- a/autodispose/src/main/java/autodispose2/ParallelFlowableSubscribeProxy.java +++ b/autodispose/src/main/java/autodispose2/ParallelFlowableSubscribeProxy.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/ScopeProvider.java b/autodispose/src/main/java/autodispose2/ScopeProvider.java index 5c78a8a11..3b5d2ac1f 100644 --- a/autodispose/src/main/java/autodispose2/ScopeProvider.java +++ b/autodispose/src/main/java/autodispose2/ScopeProvider.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/Scopes.java b/autodispose/src/main/java/autodispose2/Scopes.java index b718a6ca6..79644287e 100644 --- a/autodispose/src/main/java/autodispose2/Scopes.java +++ b/autodispose/src/main/java/autodispose2/Scopes.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/SingleSubscribeProxy.java b/autodispose/src/main/java/autodispose2/SingleSubscribeProxy.java index e0fd9dee5..e4b047b49 100644 --- a/autodispose/src/main/java/autodispose2/SingleSubscribeProxy.java +++ b/autodispose/src/main/java/autodispose2/SingleSubscribeProxy.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/TestScopeProvider.java b/autodispose/src/main/java/autodispose2/TestScopeProvider.java index 8c9eca0c8..1b323060c 100644 --- a/autodispose/src/main/java/autodispose2/TestScopeProvider.java +++ b/autodispose/src/main/java/autodispose2/TestScopeProvider.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/observers/AutoDisposingCompletableObserver.java b/autodispose/src/main/java/autodispose2/observers/AutoDisposingCompletableObserver.java index d44638c31..f636539d2 100644 --- a/autodispose/src/main/java/autodispose2/observers/AutoDisposingCompletableObserver.java +++ b/autodispose/src/main/java/autodispose2/observers/AutoDisposingCompletableObserver.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/observers/AutoDisposingMaybeObserver.java b/autodispose/src/main/java/autodispose2/observers/AutoDisposingMaybeObserver.java index d4bc7db3a..fe9af691e 100644 --- a/autodispose/src/main/java/autodispose2/observers/AutoDisposingMaybeObserver.java +++ b/autodispose/src/main/java/autodispose2/observers/AutoDisposingMaybeObserver.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/observers/AutoDisposingObserver.java b/autodispose/src/main/java/autodispose2/observers/AutoDisposingObserver.java index ba0695955..c1d985972 100644 --- a/autodispose/src/main/java/autodispose2/observers/AutoDisposingObserver.java +++ b/autodispose/src/main/java/autodispose2/observers/AutoDisposingObserver.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/observers/AutoDisposingSingleObserver.java b/autodispose/src/main/java/autodispose2/observers/AutoDisposingSingleObserver.java index 84269bd4f..cf3183c29 100644 --- a/autodispose/src/main/java/autodispose2/observers/AutoDisposingSingleObserver.java +++ b/autodispose/src/main/java/autodispose2/observers/AutoDisposingSingleObserver.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/observers/AutoDisposingSubscriber.java b/autodispose/src/main/java/autodispose2/observers/AutoDisposingSubscriber.java index fda2bae46..106d95a30 100644 --- a/autodispose/src/main/java/autodispose2/observers/AutoDisposingSubscriber.java +++ b/autodispose/src/main/java/autodispose2/observers/AutoDisposingSubscriber.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/observers/package-info.java b/autodispose/src/main/java/autodispose2/observers/package-info.java index 132f389b5..82f1f764f 100644 --- a/autodispose/src/main/java/autodispose2/observers/package-info.java +++ b/autodispose/src/main/java/autodispose2/observers/package-info.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/main/java/autodispose2/package-info.java b/autodispose/src/main/java/autodispose2/package-info.java index 687796b83..d269ea1f4 100644 --- a/autodispose/src/main/java/autodispose2/package-info.java +++ b/autodispose/src/main/java/autodispose2/package-info.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/test/java/autodispose2/AClass.java b/autodispose/src/test/java/autodispose2/AClass.java index 789604afc..fbaf1bd93 100644 --- a/autodispose/src/test/java/autodispose2/AClass.java +++ b/autodispose/src/test/java/autodispose2/AClass.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/test/java/autodispose2/AutoDisposeCompletableObserverTest.java b/autodispose/src/test/java/autodispose2/AutoDisposeCompletableObserverTest.java index a499e4dba..daa91dac3 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposeCompletableObserverTest.java +++ b/autodispose/src/test/java/autodispose2/AutoDisposeCompletableObserverTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -131,6 +131,7 @@ public void autoDispose_withProvider_interrupted() { o.assertNoMoreEvents(); } + @SuppressWarnings("NullAway") @Test public void verifyObserverDelegate() { final AtomicReference atomicObserver = new AtomicReference<>(); diff --git a/autodispose/src/test/java/autodispose2/AutoDisposeKotlinTest.kt b/autodispose/src/test/java/autodispose2/AutoDisposeKotlinTest.kt index 24780faca..6f9820145 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposeKotlinTest.kt +++ b/autodispose/src/test/java/autodispose2/AutoDisposeKotlinTest.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -46,20 +46,18 @@ class AutoDisposeKotlinTest { private val scope = CompletableSubject.create() private val scopeProvider = TestScopeProvider.create() - @Test fun observable_maybeNormalCompletion() { - Observable.just("Hello") - .autoDispose(scope) - .subscribe(o) + @Test + fun observable_maybeNormalCompletion() { + Observable.just("Hello").autoDispose(scope).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun observable_maybeNormalInterrupted() { + @Test + fun observable_maybeNormalInterrupted() { val subject = PublishSubject.create() - subject - .autoDispose(scope) - .subscribe(o) + subject.autoDispose(scope).subscribe(o) subject.onNext("Hello") @@ -68,24 +66,22 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun observable_scopeProviderNormalCompletion() { - Observable.just("Hello") - .autoDispose(scopeProvider) - .subscribe(o) + @Test + fun observable_scopeProviderNormalCompletion() { + Observable.just("Hello").autoDispose(scopeProvider).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun observable_scopeProviderNormalInterrupted() { + @Test + fun observable_scopeProviderNormalInterrupted() { val subject = PublishSubject.create() - subject - .autoDispose(scopeProvider) - .subscribe(o) + subject.autoDispose(scopeProvider).subscribe(o) subject.onNext("Hello") @@ -94,24 +90,22 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun flowable_maybeNormalCompletion() { - Flowable.just("Hello") - .autoDispose(scope) - .subscribe(s) + @Test + fun flowable_maybeNormalCompletion() { + Flowable.just("Hello").autoDispose(scope).subscribe(s) s.assertValue { it == "Hello" } s.assertComplete() } - @Test fun flowable_maybeNormalInterrupted() { + @Test + fun flowable_maybeNormalInterrupted() { val subject = PublishSubject.create() - subject.toFlowable(ERROR) - .autoDispose(scope) - .subscribe(s) + subject.toFlowable(ERROR).autoDispose(scope).subscribe(s) subject.onNext("Hello") @@ -120,24 +114,22 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(s.isDisposed).isTrue() -// s.assertNotSubscribed() + // assertThat(s.isDisposed).isTrue() + // s.assertNotSubscribed() } - @Test fun flowable_scopeProviderNormalCompletion() { - Flowable.just("Hello") - .autoDispose(scopeProvider) - .subscribe(s) + @Test + fun flowable_scopeProviderNormalCompletion() { + Flowable.just("Hello").autoDispose(scopeProvider).subscribe(s) s.assertValue { it == "Hello" } s.assertComplete() } - @Test fun flowable_scopeProviderNormalInterrupted() { + @Test + fun flowable_scopeProviderNormalInterrupted() { val subject = PublishSubject.create() - subject.toFlowable(ERROR) - .autoDispose(scopeProvider) - .subscribe(s) + subject.toFlowable(ERROR).autoDispose(scopeProvider).subscribe(s) subject.onNext("Hello") @@ -146,24 +138,22 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(s.isDisposed).isTrue() -// s.assertNotSubscribed() + // assertThat(s.isDisposed).isTrue() + // s.assertNotSubscribed() } - @Test fun maybe_maybeNormalCompletion() { - Maybe.just("Hello") - .autoDispose(scope) - .subscribe(o) + @Test + fun maybe_maybeNormalCompletion() { + Maybe.just("Hello").autoDispose(scope).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun maybe_maybeNormalInterrupted() { + @Test + fun maybe_maybeNormalInterrupted() { val subject = MaybeSubject.create() - subject - .autoDispose(scope) - .subscribe(o) + subject.autoDispose(scope).subscribe(o) subject.onSuccess("Hello") @@ -172,24 +162,22 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun maybe_scopeProviderNormalCompletion() { - Maybe.just("Hello") - .autoDispose(scopeProvider) - .subscribe(o) + @Test + fun maybe_scopeProviderNormalCompletion() { + Maybe.just("Hello").autoDispose(scopeProvider).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun maybe_scopeProviderNormalInterrupted() { + @Test + fun maybe_scopeProviderNormalInterrupted() { val subject = MaybeSubject.create() - subject - .autoDispose(scopeProvider) - .subscribe(o) + subject.autoDispose(scopeProvider).subscribe(o) scopeProvider.emit() @@ -198,24 +186,22 @@ class AutoDisposeKotlinTest { o.assertNoValues() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun single_maybeNormalCompletion() { - Single.just("Hello") - .autoDispose(scope) - .subscribe(o) + @Test + fun single_maybeNormalCompletion() { + Single.just("Hello").autoDispose(scope).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun single_maybeNormalInterrupted() { + @Test + fun single_maybeNormalInterrupted() { val subject = SingleSubject.create() - subject - .autoDispose(scope) - .subscribe(o) + subject.autoDispose(scope).subscribe(o) subject.onSuccess("Hello") @@ -224,24 +210,22 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun single_scopeProviderNormalCompletion() { - Single.just("Hello") - .autoDispose(scopeProvider) - .subscribe(o) + @Test + fun single_scopeProviderNormalCompletion() { + Single.just("Hello").autoDispose(scopeProvider).subscribe(o) o.assertValue { it == "Hello" } o.assertComplete() } - @Test fun single_scopeProviderNormalInterrupted() { + @Test + fun single_scopeProviderNormalInterrupted() { val subject = SingleSubject.create() - subject - .autoDispose(scopeProvider) - .subscribe(o) + subject.autoDispose(scopeProvider).subscribe(o) subject.onSuccess("Hello") @@ -250,23 +234,21 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun completable_maybeNormalCompletion() { - Completable.complete() - .autoDispose(scope) - .subscribe(o) + @Test + fun completable_maybeNormalCompletion() { + Completable.complete().autoDispose(scope).subscribe(o) o.assertComplete() } - @Test fun completable_maybeNormalInterrupted() { + @Test + fun completable_maybeNormalInterrupted() { val subject = PublishSubject.create() - subject - .autoDispose(scope) - .subscribe(o) + subject.autoDispose(scope).subscribe(o) subject.onNext("Hello") @@ -275,34 +257,33 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun completable_scopeProviderNormalCompletion() { - Completable.complete() - .autoDispose(scopeProvider) - .subscribe(o) + @Test + fun completable_scopeProviderNormalCompletion() { + Completable.complete().autoDispose(scopeProvider).subscribe(o) o.assertComplete() } - @Test fun completable_scopeProviderNormalInterrupted() { + @Test + fun completable_scopeProviderNormalInterrupted() { val subject = CompletableSubject.create() - subject - .autoDispose(scopeProvider) - .subscribe(o) + subject.autoDispose(scopeProvider).subscribe(o) subject.onComplete() scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(o.isDisposed).isTrue() -// o.assertNotSubscribed() + // assertThat(o.isDisposed).isTrue() + // o.assertNotSubscribed() } - @Test fun parallelFlowable_maybeNormalCompletion() { + @Test + fun parallelFlowable_maybeNormalCompletion() { val s2 = TestSubscriber() Flowable.just("Hello", "World") .parallel(DEFAULT_PARALLELISM) @@ -315,10 +296,12 @@ class AutoDisposeKotlinTest { s2.assertComplete() } - @Test fun parallelFlowable_maybeNormalInterrupted() { + @Test + fun parallelFlowable_maybeNormalInterrupted() { val subject = PublishSubject.create() val s2 = TestSubscriber() - subject.toFlowable(ERROR) + subject + .toFlowable(ERROR) .parallel(DEFAULT_PARALLELISM) .autoDispose(scope) .subscribe(arrayOf(s, s2)) @@ -332,11 +315,12 @@ class AutoDisposeKotlinTest { scope.onComplete() // https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(s.isDisposed).isTrue() -// s.assertNotSubscribed() + // assertThat(s.isDisposed).isTrue() + // s.assertNotSubscribed() } - @Test fun parallelFlowable_scopeProviderNormalCompletion() { + @Test + fun parallelFlowable_scopeProviderNormalCompletion() { val s2 = TestSubscriber() Flowable.just("Hello", "World") .parallel(DEFAULT_PARALLELISM) @@ -349,10 +333,12 @@ class AutoDisposeKotlinTest { s2.assertComplete() } - @Test fun parallelFlowable_scopeProviderNormalInterrupted() { + @Test + fun parallelFlowable_scopeProviderNormalInterrupted() { val subject = PublishSubject.create() val s2 = TestSubscriber() - subject.toFlowable(ERROR) + subject + .toFlowable(ERROR) .parallel(DEFAULT_PARALLELISM) .autoDispose(scopeProvider) .subscribe(arrayOf(s, s2)) @@ -365,12 +351,13 @@ class AutoDisposeKotlinTest { scope.onComplete() -// https://github.com/ReactiveX/RxJava/issues/5178 -// assertThat(s.isDisposed).isTrue() -// s.assertNotSubscribed() + // https://github.com/ReactiveX/RxJava/issues/5178 + // assertThat(s.isDisposed).isTrue() + // s.assertNotSubscribed() } - @Test fun withScope_parallelFlowable() { + @Test + fun withScope_parallelFlowable() { val scopeSource = CompletableSubject.create() val source = PublishProcessor.create() withScope(scopeSource) { diff --git a/autodispose/src/test/java/autodispose2/AutoDisposeMaybeObserverTest.java b/autodispose/src/test/java/autodispose2/AutoDisposeMaybeObserverTest.java index 5daf1bd9c..8c13458f9 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposeMaybeObserverTest.java +++ b/autodispose/src/test/java/autodispose2/AutoDisposeMaybeObserverTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -161,6 +161,7 @@ public void autoDispose_withProvider_interrupted() { o.assertNoMoreEvents(); } + @SuppressWarnings("NullAway") @Test public void verifyObserverDelegate() { final AtomicReference atomicObserver = new AtomicReference<>(); diff --git a/autodispose/src/test/java/autodispose2/AutoDisposeObserverTest.java b/autodispose/src/test/java/autodispose2/AutoDisposeObserverTest.java index 192658778..20efcdf7f 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposeObserverTest.java +++ b/autodispose/src/test/java/autodispose2/AutoDisposeObserverTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -127,6 +127,7 @@ public void autoDispose_withProvider() { assertThat(scope.hasObservers()).isFalse(); } + @SuppressWarnings("NullAway") @Test public void verifyObserverDelegate() { final AtomicReference atomicObserver = new AtomicReference<>(); diff --git a/autodispose/src/test/java/autodispose2/AutoDisposeParallelFlowableTest.java b/autodispose/src/test/java/autodispose2/AutoDisposeParallelFlowableTest.java index d3f982ac0..fb68a45d1 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposeParallelFlowableTest.java +++ b/autodispose/src/test/java/autodispose2/AutoDisposeParallelFlowableTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/test/java/autodispose2/AutoDisposePluginsTest.java b/autodispose/src/test/java/autodispose2/AutoDisposePluginsTest.java index 8f950b278..f9d0fcfa6 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposePluginsTest.java +++ b/autodispose/src/test/java/autodispose2/AutoDisposePluginsTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/test/java/autodispose2/AutoDisposeSingleObserverTest.java b/autodispose/src/test/java/autodispose2/AutoDisposeSingleObserverTest.java index 7cdf33c08..73886f30e 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposeSingleObserverTest.java +++ b/autodispose/src/test/java/autodispose2/AutoDisposeSingleObserverTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -139,6 +139,7 @@ public void autoDispose_withProvider_interrupted() { o.assertNoMoreEvents(); } + @SuppressWarnings("NullAway") @Test public void verifyObserverDelegate() { final AtomicReference atomicObserver = new AtomicReference<>(); diff --git a/autodispose/src/test/java/autodispose2/AutoDisposeSubscriberTest.java b/autodispose/src/test/java/autodispose2/AutoDisposeSubscriberTest.java index eafdd2d24..eb4a37d66 100644 --- a/autodispose/src/test/java/autodispose2/AutoDisposeSubscriberTest.java +++ b/autodispose/src/test/java/autodispose2/AutoDisposeSubscriberTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -128,6 +128,7 @@ public void autoDispose_withProvider() { assertThat(scope.hasObservers()).isFalse(); } + @SuppressWarnings("NullAway") @Test public void verifySubscriberDelegate() { final AtomicReference atomicSubscriber = new AtomicReference<>(); diff --git a/autodispose/src/test/java/autodispose2/BClass.java b/autodispose/src/test/java/autodispose2/BClass.java index 35bc44bad..322d1b934 100644 --- a/autodispose/src/test/java/autodispose2/BClass.java +++ b/autodispose/src/test/java/autodispose2/BClass.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/test/java/autodispose2/PluginsMatrixTest.java b/autodispose/src/test/java/autodispose2/PluginsMatrixTest.java index a71d0729b..43dcd6581 100644 --- a/autodispose/src/test/java/autodispose2/PluginsMatrixTest.java +++ b/autodispose/src/test/java/autodispose2/PluginsMatrixTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/test/java/autodispose2/TestScopeProviderTest.java b/autodispose/src/test/java/autodispose2/TestScopeProviderTest.java index c308d11d8..b78bd0c0d 100644 --- a/autodispose/src/test/java/autodispose2/TestScopeProviderTest.java +++ b/autodispose/src/test/java/autodispose2/TestScopeProviderTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/autodispose/src/test/java/autodispose2/TestUtil.java b/autodispose/src/test/java/autodispose2/TestUtil.java index 33311a6e6..a2e2bba3d 100644 --- a/autodispose/src/test/java/autodispose2/TestUtil.java +++ b/autodispose/src/test/java/autodispose2/TestUtil.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/build.gradle b/build.gradle deleted file mode 100644 index d399a8d42..000000000 --- a/build.gradle +++ /dev/null @@ -1,288 +0,0 @@ -/* - * 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. - */ -import net.ltgt.gradle.errorprone.CheckSeverity -buildscript { - apply from: rootProject.file('gradle/dependencies.gradle') - buildscript { - repositories { - google() - mavenCentral() - gradlePluginPortal() - } - dependencies { - classpath deps.build.gradlePlugins.android - classpath deps.build.gradlePlugins.kotlin - classpath "net.ltgt.gradle:gradle-errorprone-plugin:${deps.versions.errorPronePlugin}" - classpath "net.ltgt.gradle:gradle-nullaway-plugin:${deps.versions.nullawayPlugin}" - classpath "org.jetbrains.dokka:dokka-gradle-plugin:${deps.versions.dokka}" - classpath "ru.vyarus:gradle-animalsniffer-plugin:${deps.versions.animalSniffer}" - classpath "com.diffplug.spotless:spotless-plugin-gradle:${deps.versions.spotless}" - classpath "com.vanniktech:gradle-maven-publish-plugin:0.17.0" - classpath "org.jetbrains.kotlinx:binary-compatibility-validator:0.6.0" - } - } -} - -apply plugin: "binary-compatibility-validator" - -apiValidation { - ignoredProjects += ["sample", "test-utils"] -} - -Set mixedSourcesArtifacts = [ - "autodispose", - "autodispose-android", - "autodispose-androidx-lifecycle", - "autodispose-androidx-lifecycle-test", - "autodispose-lifecycle" -] -// These are files with different copyright headers that should not be modified automatically. -String[] copiedFiles = [ - "AtomicThrowable", - "AutoDisposableHelper", - "AutoDisposeBackpressureHelper", - "AutoDisposeEndConsumerHelper", - "AutoSubscriptionHelper", - "ExceptionHelper", - "HalfSerializer", -].collect { "**/*${it}.java" } as String[] -subprojects { - repositories { - google() - mavenCentral() - } - - apply from: rootProject.file('gradle/dependencies.gradle') - apply plugin: 'com.diffplug.spotless' - spotless { - format 'misc', { - target '**/*.md', '**/.gitignore' - - indentWithTabs() - trimTrailingWhitespace() - endWithNewline() - } - kotlin { - target "**/*.kt" - ktlint(deps.versions.ktlint).userData(['indent_size': '2', 'continuation_indent_size' : '2']) - licenseHeaderFile rootProject.file('spotless/copyright.kt') - trimTrailingWhitespace() - endWithNewline() - } - java { - target "**/*.java" - targetExclude(copiedFiles) - googleJavaFormat(deps.versions.gjf) - licenseHeaderFile rootProject.file('spotless/copyright.java') - removeUnusedImports() - trimTrailingWhitespace() - endWithNewline() - } - groovyGradle { - target '**/*.gradle' - trimTrailingWhitespace() - endWithNewline() - } - } - - boolean isMixedSourceSet = project.name in mixedSourcesArtifacts - boolean isAndroidLibrary = project.path.startsWith(":android:") - boolean isLint = project.path.endsWith("-lint") - boolean isKotlin = project.path.endsWith("-ktx") || isLint || isMixedSourceSet || project.path.contains("coroutines") - boolean isSample = project.name == "sample" - boolean isJavaLibrary = !isAndroidLibrary && !isKotlin && !isSample || (isMixedSourceSet && !isAndroidLibrary) - boolean usesErrorProne = !isKotlin && !isSample || isMixedSourceSet - project.pluginManager.withPlugin("java") { - java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } - } - } - if (isAndroidLibrary) { - project.apply plugin: 'com.android.library' - project.android { - compileSdkVersion deps.build.compileSdkVersion - - defaultConfig { - minSdkVersion deps.build.minSdkVersion - targetSdkVersion deps.build.targetSdkVersion - consumerProguardFiles 'consumer-proguard-rules.txt' - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - testApplicationId "autodispose2.android.lifecycle.androidTest" - } - compileOptions { - sourceCompatibility deps.build.javaVersion - targetCompatibility deps.build.javaVersion - } - lintOptions { - lintConfig file('lint.xml') - } - testOptions { - execution 'ANDROIDX_TEST_ORCHESTRATOR' - } - } - } else if (!isSample) { - project.tasks.withType(JavaCompile).configureEach { - // Cannot set JavaCompile's release flag in android projects - options.release.set(8) - } - } - if (isKotlin) { - if (isAndroidLibrary) { - project.apply plugin: 'org.jetbrains.kotlin.android' - project.apply plugin: 'org.jetbrains.dokka' - - project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - kotlinOptions { - freeCompilerArgs = [ - "-Xjsr305=strict", - "-progressive" - ] - jvmTarget = "1.8" - } - } - - project.kotlin { - explicitApi() - } - } else { - project.apply plugin: 'org.jetbrains.kotlin.jvm' - project.apply plugin: 'org.jetbrains.dokka' - - project.compileKotlin { - kotlinOptions { - freeCompilerArgs = [ - "-Xjsr305=strict", - "-progressive" - ] - jvmTarget = "1.8" - } - } - project.compileTestKotlin { - kotlinOptions { - freeCompilerArgs = [ - "-Xjsr305=strict", - "-progressive" - ] - jvmTarget = "1.8" - } - } - project.kotlin { - explicitApi() - } - } - project.pluginManager.withPlugin("org.jetbrains.dokka") { - tasks.named("dokkaGfm") { - outputDirectory.set(rootProject.file("docs/2.x")) - moduleName.set(project.property("POM_ARTIFACT_ID")) - moduleVersion.set(project.property("VERSION_NAME")) - dokkaSourceSets.configureEach { - skipDeprecated.set(true) - includes.from("Module.md") - suppressGeneratedFiles.set(true) - suppressInheritedMembers.set(true) - externalDocumentationLink { - url.set(new URL("http://reactivex.io/RxJava/3.x/javadoc/")) - } - externalDocumentationLink { - url.set(new URL("https://kotlin.github.io/kotlinx.coroutines/index.html")) - } - perPackageOption { - matchingRegex.set(/.*\.internal.*/) - suppress.set(true) - } - } - } - } - // Lint must be compileOnly, mixed source sets (for now) must manually specify depending on needs - if (!(isLint || isMixedSourceSet)) { - project.dependencies { - api deps.kotlin.stdlib - } - } else { - // Lint or mixed source set - project.dependencies { - compileOnly deps.kotlin.stdlib - testImplementation deps.kotlin.stdlib - if (isAndroidLibrary) { - androidTestImplementation deps.kotlin.stdlib - } - } - } - } - if (isJavaLibrary) { - project.apply plugin: 'java-library' - project.sourceCompatibility = deps.build.javaVersion - project.targetCompatibility = deps.build.javaVersion - project.test { - testLogging.showStandardStreams = true - } - } - if (usesErrorProne) { - project.apply plugin: 'net.ltgt.errorprone' - project.apply plugin: 'net.ltgt.nullaway' - project.dependencies { - if (!JavaVersion.current().isJava9Compatible()) { - errorproneJavac deps.build.errorProneJavac - } - errorprone deps.build.nullAway - errorprone deps.build.errorProne - } - if (isJavaLibrary) { - project.tasks.withType(JavaCompile).configureEach { - options.errorprone.nullaway { - severity = CheckSeverity.ERROR - annotatedPackages.add("autodispose2") - } - } - project.tasks.withType(Test) { - setMaxParallelForks(Runtime.runtime.availableProcessors().intdiv(2) ?: 1) - } - } - } - afterEvaluate { - if (isAndroidLibrary && usesErrorProne) { - def configurer = { variant -> - variant.getJavaCompileProvider().configure { - options.errorprone.nullaway { - severity = CheckSeverity.ERROR - annotatedPackages.add("autodispose2") - } - } - } - project.android.libraryVariants.configureEach(configurer) - project.android.testVariants.configureEach(configurer) - project.android.unitTestVariants.configureEach(configurer) - } - if (isAndroidLibrary) { - project.android { - variantFilter { variant -> - if (variant.buildType.name == 'debug') { - variant.setIgnore(true) - } - } - } - } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -apply from: 'gradle/dependencies.gradle' -apply from: 'gradle/publish-docs.gradle' diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..52dc65572 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,287 @@ +/* + * 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 + * + * https://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. + */ +import com.android.build.api.dsl.ApplicationExtension +import com.android.build.api.dsl.CommonExtension +import com.android.build.api.variant.ApplicationAndroidComponentsExtension +import com.android.build.api.variant.LibraryAndroidComponentsExtension +import com.android.build.gradle.LibraryExtension +import com.diffplug.gradle.spotless.SpotlessExtension +import com.diffplug.gradle.spotless.SpotlessExtensionPredeclare +import com.diffplug.spotless.LineEnding +import com.vanniktech.maven.publish.MavenPublishBaseExtension +import java.net.URI +import net.ltgt.gradle.errorprone.CheckSeverity +import net.ltgt.gradle.errorprone.errorprone +import net.ltgt.gradle.nullaway.nullaway +import org.jetbrains.dokka.gradle.DokkaTaskPartial +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension + +plugins { + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.android.application) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.android.lint) apply false + alias(libs.plugins.errorProne) apply false + alias(libs.plugins.nullAway) apply false + alias(libs.plugins.dokka) + alias(libs.plugins.animalSniffer) apply false + alias(libs.plugins.mavenPublish) apply false + alias(libs.plugins.ksp) apply false + alias(libs.plugins.spotless) + alias(libs.plugins.binaryCompatibilityValidator) +} + +apiValidation { ignoredProjects += listOf("sample", "test-utils") } + +val mixedSourcesArtifacts = + setOf( + "autodispose", + "autodispose-android", + "autodispose-androidx-lifecycle", + "autodispose-androidx-lifecycle-test", + "autodispose-lifecycle" + ) +// These are files with different copyright headers that should not be modified automatically. +val copiedFiles = + listOf( + "AtomicThrowable", + "AutoDisposableHelper", + "AutoDisposeBackpressureHelper", + "AutoDisposeEndConsumerHelper", + "AutoSubscriptionHelper", + "ExceptionHelper", + "HalfSerializer", + ) + .map { "**/*${it}.java" } + .toTypedArray() + +tasks.dokkaHtmlMultiModule { + outputDirectory.set(rootDir.resolve("docs/api/2.x")) + includes.from(project.layout.projectDirectory.file("README.md")) +} + +val ktfmtVersion = libs.versions.ktfmt.get() + +allprojects { + apply(plugin = "com.diffplug.spotless") + val spotlessFormatters: SpotlessExtension.() -> Unit = { + lineEndings = LineEnding.PLATFORM_NATIVE + + format("misc") { + target("**/*.md", "**/.gitignore") + indentWithSpaces(2) + trimTrailingWhitespace() + endWithNewline() + } + kotlin { + target("**/src/**/*.kt") + targetExclude("spotless/copyright.kt") + ktfmt(ktfmtVersion).googleStyle() + licenseHeaderFile(rootProject.file("spotless/copyright.kt")) + trimTrailingWhitespace() + endWithNewline() + } + kotlinGradle { + target("*.kts") + targetExclude("spotless/copyright.kt") + ktfmt(ktfmtVersion).googleStyle() + trimTrailingWhitespace() + endWithNewline() + licenseHeaderFile( + rootProject.file("spotless/copyright.kt"), + "(import|plugins|buildscript|dependencies|pluginManagement|dependencyResolutionManagement)" + ) + } + + java { + target("**/*.java") + targetExclude(*copiedFiles, "spotless/copyright.java") + googleJavaFormat(libs.versions.gjf.get()) + licenseHeaderFile(rootProject.file("spotless/copyright.java")) + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + } + } + configure { + spotlessFormatters() + if (project.rootProject == project) { + predeclareDeps() + } + } + if (project.rootProject == project) { + configure { spotlessFormatters() } + } +} + +val compileSdkVersionInt: Int = libs.versions.compileSdkVersion.get().toInt() +val targetSdkVersion: Int = libs.versions.targetSdkVersion.get().toInt() +val minSdkVersion: Int = libs.versions.minSdkVersion.get().toInt() +val defaultJvmTargetVersion = libs.versions.jvmTarget +val lintJvmTargetVersion = libs.versions.lintJvmTarget +val nullAwayDep = libs.build.nullAway +val errorProneDep = libs.build.errorProne + +subprojects { + val isSample = project.name == "sample" + val isLint = project.path.contains("static-analysis") + val isAndroid = project.path.startsWith(":android:") || isSample + val jvmTargetVersion = + if (isLint) { + lintJvmTargetVersion + } else { + defaultJvmTargetVersion + } + + pluginManager.withPlugin("java") { + configure { + toolchain { + languageVersion.set( + JavaLanguageVersion.of(libs.versions.jdk.get().removeSuffix("-ea").toInt()) + ) + } + } + + if (!isAndroid && !isLint) { + tasks.withType().configureEach { + options.release.set(jvmTargetVersion.map { it.removePrefix("1.") }.map(String::toInt)) + } + } + } + + val configureKotlin = + Action { + configure { + if (!isSample) { + explicitApi() + } + val jvmCompilerOptions: KotlinJvmCompilerOptions.() -> Unit = { + jvmTarget.set(jvmTargetVersion.map(JvmTarget::fromTarget)) + freeCompilerArgs.addAll("-Xjsr305=strict") + if (!isLint) { + progressiveMode.set(true) + } + } + when (this) { + is KotlinJvmProjectExtension -> compilerOptions(jvmCompilerOptions) + is KotlinAndroidProjectExtension -> compilerOptions(jvmCompilerOptions) + } + } + } + pluginManager.withPlugin("org.jetbrains.kotlin.jvm", configureKotlin) + pluginManager.withPlugin("org.jetbrains.kotlin.android", configureKotlin) + + pluginManager.withPlugin("com.vanniktech.maven.publish") { + project.apply(plugin = "org.jetbrains.dokka") + + tasks.withType().configureEach { + outputDirectory.set(buildDir.resolve("docs/partial")) + moduleName.set(project.property("POM_ARTIFACT_ID").toString()) + moduleVersion.set(project.property("VERSION_NAME").toString()) + dokkaSourceSets.configureEach { + skipDeprecated.set(true) + includes.from("Module.md") + suppressGeneratedFiles.set(true) + suppressInheritedMembers.set(true) + externalDocumentationLink { + url.set(URI("https://reactivex.io/RxJava/3.x/javadoc/").toURL()) + } + externalDocumentationLink { + url.set(URI("https://kotlin.github.io/kotlinx.coroutines/index.html").toURL()) + } + perPackageOption { + matchingRegex.set("/.*\\.internal.*/") + suppress.set(true) + } + val moduleMd = project.layout.projectDirectory.file("Module.md") + if (moduleMd.asFile.exists()) { + includes.from(moduleMd) + } + } + } + + configure { + publishToMavenCentral(automaticRelease = true) + signAllPublications() + } + } + + // Common android config + val commonAndroidConfig: CommonExtension<*, *, *, *>.() -> Unit = { + compileSdk = compileSdkVersionInt + + defaultConfig { + minSdk = minSdkVersion + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + testApplicationId = "autodispose2.androidTest" + } + compileOptions { + sourceCompatibility = JavaVersion.toVersion(jvmTargetVersion.get()) + targetCompatibility = JavaVersion.toVersion(jvmTargetVersion.get()) + } + lint { + checkTestSources = true + val lintXml = file("lint.xml") + if (lintXml.exists()) { + lintConfig = lintXml + } + } + testOptions { execution = "ANDROIDX_TEST_ORCHESTRATOR" } + } + + pluginManager.withPlugin("com.android.library") { + project.configure { + commonAndroidConfig() + defaultConfig { consumerProguardFiles("consumer-proguard-rules.txt") } + testBuildType = "release" + configure { + beforeVariants(selector().withBuildType("debug")) { builder -> builder.enable = false } + } + } + } + + pluginManager.withPlugin("com.android.application") { + project.configure { + commonAndroidConfig() + configure { + // Only debug enabled for this one + beforeVariants { builder -> + builder.enable = builder.buildType != "release" + builder.enableAndroidTest = false + builder.enableUnitTest = false + } + } + } + } + + project.apply(plugin = "net.ltgt.errorprone") + project.apply(plugin = "net.ltgt.nullaway") + project.dependencies { + add("errorprone", nullAwayDep) + add("errorprone", errorProneDep) + } + project.tasks.withType().configureEach { + options.errorprone.nullaway { + severity = CheckSeverity.ERROR + annotatedPackages.add("autodispose2") + } + } +} diff --git a/deploy_website.sh b/deploy_website.sh index 0de40b282..069df4667 100755 --- a/deploy_website.sh +++ b/deploy_website.sh @@ -4,28 +4,27 @@ # https://squidfunk.github.io/mkdocs-material/ # It requires Python to run. # Install the packages with the following command: -# pip install mkdocs mkdocs-material +# pip install mkdocs mkdocs-material mdx_truly_sane_lists -if [ "$1" = "--local" ]; then local=true; fi -if ! [ $local ]; then +if [[ "$1" = "--local" ]]; then local=true; fi + +if ! [[ ${local} ]]; then set -ex REPO="git@github.com:uber/AutoDispose.git" DIR=temp-clone # Delete any existing temporary website clone - rm -rf $DIR + rm -rf ${DIR} # Clone the current repo into temp folder - git clone $REPO $DIR + git clone ${REPO} ${DIR} # Move working directory into temp folder - cd $DIR - - git checkout main + cd ${DIR} - # Generate the API docs for 2.x - ./gradlew dokkaGfm + # Generate the API docs + ./gradlew dokkaHtmlMultiModule --no-configuration-cache fi # Copy in special files that GitHub wants in the project root. @@ -34,14 +33,14 @@ cp CONTRIBUTING.md docs/contributing.md cp CODE_OF_CONDUCT.md docs/code-of-conduct.md # Build the site and push the new files up to GitHub -if ! [ $local ]; then +if ! [[ ${local} ]]; then mkdocs gh-deploy else mkdocs serve fi # Delete our temp folder -if ! [ $local ]; then +if ! [[ ${local} ]]; then cd .. - rm -rf $DIR -fi + rm -rf ${DIR} +fi \ No newline at end of file diff --git a/docs/error-prone.md b/docs/error-prone.md index 396ebbf28..ce8f1fe39 100644 --- a/docs/error-prone.md +++ b/docs/error-prone.md @@ -105,7 +105,7 @@ afterEvaluate { error_prone_core 2.3.2 - + ``` @@ -152,7 +152,7 @@ By default the checker is applied to AutoDispose interfaces and standard Android 5. [ScopeProvider](https://uber.github.io/AutoDispose/1.x/autodispose/com/uber/autodispose/ScopeProvider.html) 6. [LifecycleOwner](https://developer.android.com/reference/android/arch/lifecycle/LifecycleOwner.html) -This can be configured by [Error-Prone's command line flags](http://errorprone.info/docs/flags). The following flag is supported and takes input in a form of comma separated list of fully qualified class names of classes with scopes: +This can be configured by [Error-Prone's command line flags](https://errorprone.info/docs/flags). The following flag is supported and takes input in a form of comma separated list of fully qualified class names of classes with scopes: ``` -XepOpt:AutoDispose:TypesWithScope=com.bluelinelabs.conductor.Controller,android.app.Activity @@ -171,7 +171,7 @@ If you only want the error prone check to run on your custom scopes and not the `Lenient` is a mode to ask the checker to be lenient when capturing returned `Disposable` types. What this means is that if an rx `subscribe` method is called and its returned `Disposable` is captured, AutoDispose this code is manually managing the subscription and show ignore it. The same applies for capturing the returned value of `subscribeWith` if the input type implements `Disposable`. -This can be configured by [Error-Prone's command line flags](http://errorprone.info/docs/flags). The following flag is supported and takes input in a form of a boolean `true` or `false`: +This can be configured by [Error-Prone's command line flags](https://errorprone.info/docs/flags). The following flag is supported and takes input in a form of a boolean `true` or `false`: ``` -XepOpt:AutoDispose:Lenient=true diff --git a/docs/index.md b/docs/index.md index beb56e8a5..5b23e000f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,19 +3,19 @@ AutoDispose ![](https://github.com/uber/AutoDispose/workflows/ci.yml/badge.svg?branch=master) -**AutoDispose** is an RxJava 2+ tool for automatically binding the execution of RxJava streams to a +**AutoDispose** is an RxJava 2+ tool for automatically binding the execution of RxJava streams to a provided scope via disposal/cancellation. Overview -------- -Often (especially in mobile applications), Rx subscriptions need to stop in response to some event -(for instance, when Activity#onStop() executes in an Android app). In order to support this common +Often (especially in mobile applications), Rx subscriptions need to stop in response to some event +(for instance, when Activity#onStop() executes in an Android app). In order to support this common scenario in RxJava 2, we built AutoDispose. The idea is simple: construct your chain like any other, and then at subscription you simply drop in -the relevant factory call + method for that type as a converter. In everyday use, it - usually looks like this: +the relevant factory call + method for that type as a converter. In everyday use, it + usually looks like this: ```java myObservable @@ -24,23 +24,23 @@ myObservable .subscribe(s -> ...); ``` -By doing this, you will automatically unsubscribe from `myObservable` as indicated by your -scope - this helps prevent many classes of errors when an observable emits an item, but the actions +By doing this, you will automatically unsubscribe from `myObservable` as indicated by your +scope - this helps prevent many classes of errors when an observable emits an item, but the actions taken in the subscription are no longer valid. For instance, if a network request comes back after a UI has already been torn down, the UI can't be updated - this pattern prevents this type of bug. ### `autoDisposable()` -The main entry point is via static factory `autoDisposable()` methods in the `AutoDispose` class. -There are two overloads: `Completable` and `ScopeProvider`. They return an +The main entry point is via static factory `autoDisposable()` methods in the `AutoDispose` class. +There are two overloads: `Completable` and `ScopeProvider`. They return an `AutoDisposeConverter` object that implements all the RxJava `Converter` interfaces for use with the `as()` operator in RxJava types. #### Completable (as a scope) -The `Completable` semantic is modeled after the `takeUntil()` operator, which accepts an `Observable` -whose first emission is used as a notification to signal completion. This is logically the -behavior of a `Single`, so we choose to make that explicit. Since the type doesn't matter, we +The `Completable` semantic is modeled after the `takeUntil()` operator, which accepts an `Observable` +whose first emission is used as a notification to signal completion. This is logically the +behavior of a `Single`, so we choose to make that explicit. Since the type doesn't matter, we simplify this further to just be a `Completable`, where the scope-end emission is just a completion event. All scopes in AutoDispose eventually resolve to a `Completable` that emits the end-of-scope notification in `onComplete`. `onError` will pass through to the underlying subscription. @@ -68,8 +68,8 @@ Modeled after RxJava's plugins, this allows you to customize the behavior of Aut #### OutsideScopeHandler When a scope is bound to outside of its allowable boundary, `AutoDispose` will send an error event with an - `OutsideScopeException` to downstream consumers. If you want to customize this behavior, you can use - `AutoDisposePlugins#setOutsideScopeHandler` to intercept these exceptions and rethrow something + `OutsideScopeException` to downstream consumers. If you want to customize this behavior, you can use + `AutoDisposePlugins#setOutsideScopeHandler` to intercept these exceptions and rethrow something else or nothing at all. Example @@ -84,9 +84,9 @@ A good use case of this is, say, just silently disposing/logging observers outsi The supported mechanism to throw this is in `ScopeProvider#requestScope()` implementations. #### FillInOutsideScopeExceptionStacktraces - + If you have your own handling of exceptions in scope boundary events, you can optionally set -`AutoDisposePlugins#setFillInOutsideScopeExceptionStacktraces` to `false`. This will result in +`AutoDisposePlugins#setFillInOutsideScopeExceptionStacktraces` to `false`. This will result in AutoDispose `not` filling in stacktraces for exceptions, for a potential minor performance boost. ### AutoDisposeAndroidPlugins @@ -95,11 +95,11 @@ Similar to `AutoDisposePlugins`, this allows you to customize the behavior of Au #### MainThreadChecker -This plugin allows for supplying a custom `BooleanSupplier` that can customize how main thread -checks work. The conventional use case of this is Android JUnit tests, where the `Looper` class is +This plugin allows for supplying a custom `BooleanSupplier` that can customize how main thread +checks work. The conventional use case of this is Android JUnit tests, where the `Looper` class is not stubbed in the mock android.jar and fails explosively when touched. -Another potential use of this at runtime to customize checks for more fine-grained main thread +Another potential use of this at runtime to customize checks for more fine-grained main thread checks behavior. Example @@ -112,12 +112,12 @@ AutoDisposeAndroidPlugins.setOnCheckMainThread(() -> { ### Behavior Under the hood, AutoDispose decorates RxJava's real observer with a custom *AutoDisposing* observer. -This custom observer leverages the scope to create a disposable, auto-disposing observer that acts -as a lambda observer (pass-through) unless the underlying scope `CompletableSource` emits `onComplete`. Both +This custom observer leverages the scope to create a disposable, auto-disposing observer that acts +as a lambda observer (pass-through) unless the underlying scope `CompletableSource` emits `onComplete`. Both scope emission and upstream termination result in immediate disposable of both the underlying scope subscription and upstream disposable. -These custom `AutoDisposing` observers are considered public read-only API, and can be found under the +These custom `AutoDisposing` observers are considered public read-only API, and can be found under the `observers` package. They also support retrieval of the underlying observer via `delegateObserver()` methods. Read-only API means that the public signatures will follow semantic versioning, but we may add new methods in the future (which would break compilation if you make custom implementations!). @@ -143,13 +143,13 @@ public interface LifecycleScopeProvider extends ScopeProvider { Function correspondingEvents(); E peekLifecycle(); - + // Inherited from ScopeProvider CompletableSource requestScope(); } ``` -A common use case for this is objects that have implicit lifecycles, such as Android's `Activity`, +A common use case for this is objects that have implicit lifecycles, such as Android's `Activity`, `Fragment`, and `View` classes. Internally at subscription-time, `AutoDispose` will resolve a `CompletableSource` representation of the target `end` event in the lifecycle, and exposes an API to dictate what corresponding events are for the current lifecycle state (e.g. `ATTACH` -> `DETACH`). This also allows @@ -163,13 +163,13 @@ as follows: - `correspondingEvents()` - a mapping of events to corresponding ones, i.e. Attach -> Detach. - `peekLifecycle()` - returns the current lifecycle state of the object. -In `requestScope()`, the implementation expects to these pieces to construct a `CompletableSource` representation -of the proper end scope, while also doing precondition checks for lifecycle boundaries. If a -lifecycle has not started, it will send you to `onError` with a `LifecycleNotStartedException`. If -the lifecycle as ended, it is recommended to throw a `LifecycleEndedException` in your +In `requestScope()`, the implementation expects to these pieces to construct a `CompletableSource` representation +of the proper end scope, while also doing precondition checks for lifecycle boundaries. If a +lifecycle has not started, it will send you to `onError` with a `LifecycleNotStartedException`. If +the lifecycle as ended, it is recommended to throw a `LifecycleEndedException` in your `correspondingEvents()` mapping, but it is up to the user. -To simplify implementations, there's an included `LifecycleScopes` utility class with factories +To simplify implementations, there's an included `LifecycleScopes` utility class with factories for generating `CompletableSource` representations from `LifecycleScopeProvider` instances. `autodispose-lifecycle` contains the core `LifecycleScopeProvider` and `LifecycleScopes` APIs as well as a convenience test helper. @@ -197,11 +197,11 @@ with [RxLifecycle](https://github.com/trello/RxLifecycle)'s `LifecycleProvider` ### Philosophy -Each factory returns a subscribe proxies upon application that just proxy to real subscribe calls under -the hood to "AutoDisposing" implementations of the types. These types decorate the actual observer +Each factory returns a subscribe proxies upon application that just proxy to real subscribe calls under +the hood to "AutoDisposing" implementations of the types. These types decorate the actual observer at subscribe-time to achieve autodispose behavior. The types are *not* exposed directly because autodisposing has *ordering* requirements; specifically, it has to be done at the end of a chain to properly -wrap all the upstream behavior. Lint could catch this too, but we have seen no use cases for disposing +wrap all the upstream behavior. Lint could catch this too, but we have seen no use cases for disposing upstream (which can cause a lot of unexpected behavior). Thus, we optimize for the common case, and the API is designed to prevent ordering issues while still being a drop-in one-liner. @@ -216,14 +216,14 @@ Two common patterns for binding execution in RxJava that we used prior to this w given observable to `takeUntil()` that event is emitted. Both implementations are elegant and work well, but came with caveats that we sought to revisit and solve -in AutoDispose. +in AutoDispose. `CompositeSubscription` requires manual capture of the return value of `subscribe` calls, and gets tedious to reason about with regards to binding subscription until different events. [`RxLifecycle`][rxlifecycle] solves the caveats of `CompositeSubscription` use by working in a dead-simple API and handling -resolution of corresponding events. It works great for `Observable` types, but due to the nature of -how `takeUntil()` works, we found that `Single` and `Completable` usage was risky to use (particularly in a +resolution of corresponding events. It works great for `Observable` types, but due to the nature of +how `takeUntil()` works, we found that `Single` and `Completable` usage was risky to use (particularly in a large team with varying levels of RxJava experience) considering lifecycle interruption would result in a downstream `CancellationException` every time. It's the contract of those types, but induced a lot of ceremony for what would otherwise likely be our most commonly used type (`Single`). Even with `Observable`, @@ -231,18 +231,18 @@ we were still burned occasionally by the completion event still coming through t Another caveat we often ran into (and later aggressively linted against) was that the `compose()` call had ordering implications, and needed to be as close to the `subscribe()` call as possible to properly wrap upstream. If binding to views, there were also threading requirements on the observable chain in order to work properly. - + At the end of the day, we wanted true disposal/unsubscription-based behavior, but with RxLifecycle-esque semantics around scope resolution. RxJava 2's `Observer` interfaces provide the perfect mechanism for this via their `onSubscribe()` callbacks. The result is de-risked `Single`/`Completable` usage, no ordering concerns, no threading concerns (fingers crossed), and true disposal with no further events of any kind upon scope end. We're quite happy with it, and hope the community finds it useful as well. - -Special thanks go to [Dan Lew][dan] (creator of RxLifecycle), who helped pioneer this area for RxJava - in android and humored many of the discussions around lifecycle handling over the past couple years - that we've learned from. Much of the internal scope resolution mechanics of `AutoDispose` are + +Special thanks go to [Dan Lew][dan] (creator of RxLifecycle), who helped pioneer this area for RxJava + in android and humored many of the discussions around lifecycle handling over the past couple years + that we've learned from. Much of the internal scope resolution mechanics of `AutoDispose` are inspired by RxLifecycle. - + ## RxJava versions support | RxJava version | AutoDispose version | diff --git a/docs/lint-check.md b/docs/lint-check.md index f10259a57..688e5913f 100644 --- a/docs/lint-check.md +++ b/docs/lint-check.md @@ -1,8 +1,8 @@ -`AutoDisposeDetector` is a lint check to detect missing AutoDispose scope within defined scoped elements. +`AutoDisposeDetector` is a lint check to detect missing AutoDispose scope within defined scoped elements. ## Installation -For Android Java/Kotlin projects, no configuration is required as the AutoDispose lint check is run by default with the existing lint checks. +For Android Java/Kotlin projects, no configuration is required as the AutoDispose lint check is run by default with the existing lint checks. For pure JVM projects, apply the `com.android.lint` plugin and add the lint dependency to the `lintChecks` configuration. @@ -22,7 +22,7 @@ dependencies { The following code snippet: ```kotlin class ComponentWithLifecycle : Activity { - + fun observeOnSomething() { Observable .interval(1, TimeUnit.SECONDS) @@ -54,7 +54,7 @@ You can add your own custom scopes that you want the lint check applied to. In y ```groovy autodispose.typesWithScope=com.bluelinelabs.conductor.Controller,com.sample.app.BasePresenter ``` -The types supplied are then added to the default types listed above. +The types supplied are then added to the default types listed above. ### Overriding Scopes @@ -67,12 +67,12 @@ autodispose.overrideScopes=true `Lenient` is a mode to ask the checker to be lenient when capturing returned Disposable types. What this means is that if an rx subscribe method is called and its returned Disposable is captured, AutoDispose this code is manually managing the subscription and show ignore it. The same applies for capturing the returned value of subscribeWith if the input type implements Disposable. -This can be configured by adding the following flag to the **app-level** `gradle.properties` file. +This can be configured by adding the following flag to the **app-level** `gradle.properties` file. ```groovy autodispose.lenient=true ``` -The default value of this is `false`. +The default value of this is `false`. ### Kotlin Extension diff --git a/gradle.properties b/gradle.properties index 0caed712a..76ad8af12 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, @@ -21,7 +21,7 @@ POM_SCM_URL=https://github.com/uber/AutoDispose/ POM_SCM_CONNECTION=scm:git:git://github.com/uber/AutoDispose.git POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/uber/AutoDispose.git POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo POM_DEVELOPER_ID=uber POM_DEVELOPER_NAME=Uber Technologies @@ -35,9 +35,6 @@ android.defaults.buildfeatures.renderscript=false android.defaults.buildfeatures.resvalues=false android.defaults.buildfeatures.shaders=false android.library.defaults.buildfeatures.androidresources=false -android.disableAutomaticComponentCreation=true - -kapt.include.compile.classpath=false # For GJF and error prone and kapt and AGP org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 \ diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle deleted file mode 100644 index 66acbdd8d..000000000 --- a/gradle/dependencies.gradle +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - */ - -def versions = [ - androidTest: '1.4.0', - animalSniffer: '1.5.0', - androidxLifecycle: '2.3.1', - dokka: '1.6.10', - errorProne: '2.9.0', - errorPronePlugin: '2.0.1', - gjf: '1.11.0', - nullawayPlugin: '1.1.0', - kotlin: '1.6.10', - lint: '30.1.0', - ktlint: '0.42.1', - spotless: '6.2.1' -] - -def apt = [ - autoService: "com.google.auto.service:auto-service:1.0" -] - -def build = [ - compileSdkVersion: 31, - ci: 'true' == System.getenv('CI'), - minSdkVersion: 14, - targetSdkVersion: 31, - javaVersion: JavaVersion.VERSION_1_8, - - errorProne: "com.google.errorprone:error_prone_core:${versions.errorProne}", - errorProneAnnotations: "com.google.errorprone:error_prone_annotations:${versions.errorProne}", - errorProneJavac: "com.google.errorprone:javac:9+181-r4173-1", - errorProneCheckApi: "com.google.errorprone:error_prone_check_api:${versions.errorProne}", - errorProneTestHelpers: "com.google.errorprone:error_prone_test_helpers:${versions.errorProne}", - nullAway: 'com.uber.nullaway:nullaway:0.9.2', - animalSniffer: 'org.codehaus.mojo.signature:java17:1.0@signature', - - gradlePlugins: [ - android: 'com.android.tools.build:gradle:7.1.0', - dokka: "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}", - dokkaAndroid: "org.jetbrains.dokka:dokka-android-gradle-plugin:${versions.dokka}", - kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" - ], - - lint: [ - api: "com.android.tools.lint:lint-api:${versions.lint}", - core: "com.android.tools.lint:lint:${versions.lint}", - tests: "com.android.tools.lint:lint-tests:${versions.lint}" - ] -] - -def kotlin = [ - coroutines: "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1", - stdlib: "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" -] - -def misc = [ - rxlifecycle2 : 'com.trello.rxlifecycle2:rxlifecycle:2.2.2', - rxlifecycle3 : 'com.trello.rxlifecycle3:rxlifecycle:3.0.0' -] - -def rx = [ - android: 'io.reactivex.rxjava3:rxandroid:3.0.0', - java: 'io.reactivex.rxjava3:rxjava:3.1.0' -] - -def androidx = [ - annotations: "androidx.annotation:annotation:1.2.0", - activityKtx: 'androidx.activity:activity-ktx:1.2.3', - lifecycle: [ - compiler: "androidx.lifecycle:lifecycle-compiler:${versions.androidxLifecycle}", - common: "androidx.lifecycle:lifecycle-common:${versions.androidxLifecycle}", - runtime: "androidx.lifecycle:lifecycle-runtime:${versions.androidxLifecycle}", - runtimeKtx: "androidx.lifecycle:lifecycle-runtime-ktx:${versions.androidxLifecycle}", - runtimeTest: "androidx.lifecycle:lifecycle-runtime-testing:${versions.androidxLifecycle}", - vmKtx: "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.androidxLifecycle}" - ] -] - -def test = [ - androidExtJunit: "androidx.test.ext:junit:1.1.3", - androidRunner: "androidx.test:runner:${versions.androidTest}", - androidRules: "androidx.test:rules:${versions.androidTest}", - androidOrchestrator: "androidx.test:orchestrator:${versions.androidTest}", - junit: 'junit:junit:4.13.2', - truth: 'com.google.truth:truth:1.1.3' -] - -ext.deps = [ - "androidx": androidx, - "apt": apt, - "build": build, - "kotlin": kotlin, - "misc": misc, - "rx": rx, - "test": test, - "versions": versions -] diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..8f38157bb --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,92 @@ +[versions] +agp = "8.0.2" +androidTest = "1.6.0-alpha03" +androidxLifecycle = "2.6.1" +animalSniffer = "1.7.1" +appcompat = "1.6.1" +compileSdkVersion = "33" +constraintlayout = "2.1.4" +dokka = "1.8.20" +errorProne = "2.20.0" +errorPronePlugin = "3.1.0" +fragmentKtx = "1.6.0" +gjf = "1.17.0" +jdk = "17" +jvmTarget = "1.8" +kotlin = "1.9.0" +ktfmt = "0.44" +leakcanaryAndroid = "2.12" +lifecycleExtensions = "2.2.0" +lint = "31.0.2" +lintJvmTarget = "17" +material = "1.9.0" +mavenPublish = "0.25.3" +minSdkVersion = "14" +multidex = "2.0.1" +nullawayPlugin = "1.6.0" +replayingShareKotlin = "2.0.1" +rxjava3Bridge = "3.0.0" +rxrelay = "2.1.1" +spotless = "6.20.0" +targetSdkVersion = "33" + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +android-library = { id = "com.android.library", version.ref = "agp" } +android-lint = { id = "com.android.lint", version.ref = "agp" } +animalSniffer = { id = "ru.vyarus.animalsniffer", version.ref = "animalSniffer" } +binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" } +dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } +errorProne = { id = "net.ltgt.errorprone", version.ref = "errorPronePlugin" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +ksp = { id = "com.google.devtools.ksp", version = "1.9.0-1.0.12" } +mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } +nullAway = { id = "net.ltgt.nullaway", version.ref = "nullawayPlugin" } +spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } + +[libraries] +androidx-activityKtx = "androidx.activity:activity-ktx:1.7.2" +androidx-annotations = "androidx.annotation:annotation:1.6.0" +androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" } +androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" } +androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "fragmentKtx" } +androidx-lifecycle-common = { module = "androidx.lifecycle:lifecycle-common", version.ref = "androidxLifecycle" } +androidx-lifecycle-compiler = { module = "androidx.lifecycle:lifecycle-compiler", version.ref = "androidxLifecycle" } +androidx-lifecycle-extensions = { module = "androidx.lifecycle:lifecycle-extensions", version.ref = "lifecycleExtensions" } +androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime", version.ref = "androidxLifecycle" } +androidx-lifecycle-runtimeKtx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidxLifecycle" } +androidx-lifecycle-runtimeTest = { module = "androidx.lifecycle:lifecycle-runtime-testing", version.ref = "androidxLifecycle" } +androidx-lifecycle-vmKtx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidxLifecycle" } +autoService-annotations = "com.google.auto.service:auto-service-annotations:1.1.1" +autoService-ksp = "dev.zacsweers.autoservice:auto-service-ksp:1.1.0" +build-animalSniffer = "org.codehaus.mojo.signature:java17:1.0" +build-errorProne = { module = "com.google.errorprone:error_prone_core", version.ref = "errorProne" } +build-errorProneAnnotations = { module = "com.google.errorprone:error_prone_annotations", version.ref = "errorProne" } +build-errorProneCheckApi = { module = "com.google.errorprone:error_prone_check_api", version.ref = "errorProne" } +build-errorProneTestHelpers = { module = "com.google.errorprone:error_prone_test_helpers", version.ref = "errorProne" } +build-lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "lint" } +build-lint-core = { module = "com.android.tools.lint:lint", version.ref = "lint" } +build-lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref = "lint" } +build-nullAway = "com.uber.nullaway:nullaway:0.10.11" +kotlin-coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2" +leakcanary-android = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakcanaryAndroid" } +material = { module = "com.google.android.material:material", version.ref = "material" } +multidex = { module = "com.android.support:multidex", version.ref = "multidex" } + + +# Only present to trigger automatic renovate updates +renovateTrigger-ktfmt = { module = "com.facebook:ktfmt", version.ref = "ktfmt" } +renovateTrigger-gjf = { module = "com.google.googlejavaformat:google-java-format", version.ref = "gjf" } + +replaying-share-kotlin = { module = "com.jakewharton.rx2:replaying-share-kotlin", version.ref = "replayingShareKotlin" } +rx-android = "io.reactivex.rxjava3:rxandroid:3.0.2" +rx-java = "io.reactivex.rxjava3:rxjava:3.1.6" +rxjava3-bridge = { module = "com.github.akarnokd:rxjava3-bridge", version.ref = "rxjava3Bridge" } +rxrelay = { module = "com.jakewharton.rxrelay2:rxrelay", version.ref = "rxrelay" } +test-androidExtJunit = "androidx.test.ext:junit:1.2.0-alpha01" +test-androidOrchestrator = { module = "androidx.test:orchestrator", version = "1.5.0-alpha01" } +test-androidRules = { module = "androidx.test:rules", version = "1.6.0-alpha01" } +test-androidRunner = { module = "androidx.test:runner", version.ref = "androidTest" } +test-junit = "junit:junit:4.13.2" +test-truth = "com.google.truth:truth:1.1.5" diff --git a/gradle/publish-docs.gradle b/gradle/publish-docs.gradle deleted file mode 100644 index d25867276..000000000 --- a/gradle/publish-docs.gradle +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2018. 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. - */ - -configurations { - osstrich -} - -repositories { - mavenCentral() -} - -dependencies { - osstrich 'com.squareup.osstrich:osstrich:1.4.0' -} - -task publishDocs(type: JavaExec) { - classpath = configurations.osstrich - main = 'com.squareup.osstrich.JavadocPublisher' - args = ['build/javadoc', - 'https://github.com/uber/autodispose', - 'autodispose2'] -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927a4..033e24c4c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb8790..9f4197d5f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c78733..fcb6fca14 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +130,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +213,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f93..6689b85be 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/mkdocs.yml b/mkdocs.yml index cae3f4d2b..31d6d6d06 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -38,12 +38,13 @@ markdown_extensions: nav: - 'Overview': index.md - '2.X API': - - 'autodispose': 2.x/autodispose/autodispose2/index.md - - 'autodispose-android': 2.x/autodispose-android/autodispose2.android/index.md - - 'autodispose-androidx-lifecycle': 2.x/autodispose-androidx-lifecycle/autodispose2.androidx.lifecycle/index.md - - 'autodispose-interop-coroutines': 2.x/autodispose-interop-coroutines/autodispose2.interop.coroutines/index.md - - 'autodispose-lifecycle': 2.x/autodispose-lifecycle/autodispose2.lifecycle/index.md - - 'autodispose-observers': 2.x/autodispose/autodispose2.observers/index.md + - 'Overview': api/2.x/index.html + - 'autodispose': api/2.x/autodispose/index.html + - 'autodispose-android': api/2.x/android/autodispose-android/index.html + - 'autodispose-androidx-lifecycle': api/2.x/android/autodispose-androidx-lifecycle/index.html + - 'autodispose-interop-coroutines': api/2.x/autodispose-interop/coroutines/index.html + - 'autodispose-lifecycle': api/2.x/autodispose-lifecycle/index.html + - 'autodispose-observers': api/2.x/autodispose/autodispose2.observers/index.html - 'Error Prone': error-prone.md - 'Lint Check': lint-check.md - 'Changelog' : changelog.md diff --git a/sample/build.gradle b/sample/build.gradle deleted file mode 100644 index 9bb1fb580..000000000 --- a/sample/build.gradle +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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. - */ -//import com.android.build.gradle.api.BaseVariant -//import net.ltgt.gradle.errorprone.CheckSeverity - -plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' -// id 'net.ltgt.errorprone' -// id 'net.ltgt.nullaway' -} - -android { - compileSdkVersion deps.build.compileSdkVersion - - defaultConfig { - minSdkVersion deps.build.minSdkVersion - targetSdkVersion deps.build.targetSdkVersion - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - testApplicationId "autodispose2.android.lifecycle.androidTest" - multiDexEnabled true - } - compileOptions { - sourceCompatibility deps.build.javaVersion - targetCompatibility deps.build.javaVersion - } - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - } - lintOptions { - checkDependencies true - } - variantFilter { variant -> - if (variant.buildType.name == "release") { - variant.setIgnore(true) - } - } - buildTypes { - debug { - matchingFallbacks = ['release'] - } - } - testOptions { - execution 'ANDROIDX_TEST_ORCHESTRATOR' - } - -// def classesWithScope = [ -// "android.app.Activity", -// "android.app.Fragment", -// "androidx.lifecycle.LifecycleOwner", -// "autodispose2.ScopeProvider", -// "autodispose2.sample.CustomScope" -// ] -// DomainObjectSet variants = getApplicationVariants() -// variants.addAll(getTestVariants()) -// variants.addAll(getUnitTestVariants()) -// variants.configureEach { variant -> -// variant.getJavaCompileProvider().configure { -// options.errorprone { -// nullaway { -// severity = CheckSeverity.ERROR -// annotatedPackages.add("com.uber") -// } -// check("AutoDispose", CheckSeverity.ERROR) -// option("AutoDispose:TypesWithScope", classesWithScope.join(",")) -// } -// } -// } -} - -project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - kotlinOptions { - freeCompilerArgs = [ - "-Xjsr305=strict", - "-progressive" - ] - jvmTarget = "1.8" - } -} - -dependencies { - implementation project(':android:autodispose-android') - implementation project(':android:autodispose-androidx-lifecycle') - implementation project(':autodispose') - implementation project(':autodispose-lifecycle') -// implementation project(":autodispose-rxlifecycle3") - implementation 'com.android.support:multidex:2.0.1' - implementation 'androidx.appcompat:appcompat:1.3.1' - implementation 'androidx.constraintlayout:constraintlayout:2.1.0' - implementation 'com.google.android.material:material:1.4.0' - implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" - implementation "androidx.fragment:fragment:1.3.6" - implementation deps.androidx.activityKtx - implementation deps.androidx.lifecycle.runtimeKtx - implementation deps.androidx.lifecycle.vmKtx - implementation deps.kotlin.stdlib - implementation deps.rx.android - implementation 'com.jakewharton.rx2:replaying-share-kotlin:2.0.1' - implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.1' - implementation 'com.github.akarnokd:rxjava3-bridge:3.0.0' - -// errorproneJavac deps.build.errorProneJavac -// errorprone deps.build.errorProne -// errorprone deps.build.nullAway -// errorprone project(':static-analysis:autodispose-error-prone') - - debugImplementation "com.squareup.leakcanary:leakcanary-android:2.7" - - androidTestImplementation project(':test-utils') - androidTestImplementation deps.test.androidRunner - androidTestImplementation deps.test.androidRules - androidTestUtil deps.test.androidOrchestrator - androidTestImplementation deps.test.androidExtJunit -} diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts new file mode 100644 index 000000000..8ebf719a1 --- /dev/null +++ b/sample/build.gradle.kts @@ -0,0 +1,109 @@ +/* + * 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 + * + * https://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. + */ +import net.ltgt.gradle.errorprone.CheckSeverity +import net.ltgt.gradle.errorprone.errorprone +import net.ltgt.gradle.nullaway.nullaway +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.errorProne) + alias(libs.plugins.nullAway) +} + +android { + namespace = "autodispose2.sample" + + defaultConfig { + targetSdk = libs.versions.targetSdkVersion.get().toInt() + multiDexEnabled = true + } + sourceSets { getByName("main") { java.srcDirs("src/main/kotlin") } } + lint { checkDependencies = true } + buildTypes { getByName("debug") { matchingFallbacks += listOf("release") } } + testOptions { execution = "ANDROIDX_TEST_ORCHESTRATOR" } +} + +val classesWithScope = + listOf( + "android.app.Activity", + "android.app.Fragment", + "androidx.lifecycle.LifecycleOwner", + "autodispose2.ScopeProvider", + "autodispose2.sample.CustomScope" + ) + +tasks.withType().configureEach { + options.errorprone { + nullaway { + severity = CheckSeverity.ERROR + annotatedPackages.add("com.uber") + } + check("AutoDispose", CheckSeverity.ERROR) + option("AutoDispose:TypesWithScope", classesWithScope.joinToString(",")) + } +} + +androidComponents { + beforeVariants { builder -> + if (builder.buildType == "release") { + builder.enable = false + } + } +} + +project.tasks.withType().configureEach { + compilerOptions { + freeCompilerArgs.addAll("-Xjsr305=strict") + progressiveMode.set(true) + jvmTarget.set(JvmTarget.JVM_1_8) + } +} + +dependencies { + implementation(project(":android:autodispose-android")) + implementation(project(":android:autodispose-androidx-lifecycle")) + implementation(project(":autodispose")) + implementation(project(":autodispose-lifecycle")) + // implementation project(":autodispose-rxlifecycle3") + implementation(libs.multidex) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.constraintlayout) + implementation(libs.material) + implementation(libs.androidx.lifecycle.extensions) + implementation(libs.androidx.fragment.ktx) + implementation(libs.androidx.activityKtx) + implementation(libs.androidx.lifecycle.runtimeKtx) + implementation(libs.androidx.lifecycle.vmKtx) + implementation(libs.rx.android) + implementation(libs.replaying.share.kotlin) + implementation(libs.rxrelay) + implementation(libs.rxjava3.bridge) + + errorprone(libs.build.errorProne) + errorprone(libs.build.nullAway) + errorprone(project(":static-analysis:autodispose-error-prone")) + + debugImplementation(libs.leakcanary.android) + + androidTestImplementation(project(":test-utils")) + androidTestImplementation(libs.test.androidRunner) + androidTestImplementation(libs.test.androidRules) + androidTestUtil(libs.test.androidOrchestrator) + androidTestImplementation(libs.test.androidExtJunit) +} diff --git a/sample/src/androidTest/java/autodispose2/TestKotlinActivity.kt b/sample/src/androidTest/java/autodispose2/TestKotlinActivity.kt index 8cf7022d7..e1ec29e46 100644 --- a/sample/src/androidTest/java/autodispose2/TestKotlinActivity.kt +++ b/sample/src/androidTest/java/autodispose2/TestKotlinActivity.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -29,12 +29,10 @@ import io.reactivex.rxjava3.core.Flowable import io.reactivex.rxjava3.core.Maybe import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.core.Single -import org.junit.Ignore import java.util.concurrent.TimeUnit +import org.junit.Ignore -/** - * Test Activity class to verify compilation of various extension functions. - */ +/** Test Activity class to verify compilation of various extension functions. */ @Ignore("Since it's only used to verify compilation of the extension functions") class TestKotlinActivity : AppCompatActivity(), ScopeProvider { @@ -42,9 +40,7 @@ class TestKotlinActivity : AppCompatActivity(), ScopeProvider { super.onCreate(savedInstanceState) // With extension function that overloads LifecycleOwner - Observable.interval(1, TimeUnit.SECONDS) - .autoDispose(this) - .subscribe() + Observable.interval(1, TimeUnit.SECONDS).autoDispose(this).subscribe() // With extension function that overloads LifecycleOwner and until Event Observable.interval(1, TimeUnit.SECONDS) @@ -61,78 +57,60 @@ class TestKotlinActivity : AppCompatActivity(), ScopeProvider { .autoDispose(AndroidLifecycleScopeProvider.from(this)) .subscribe() - Maybe.just(1) - .autoDispose(this) - .subscribe() + Maybe.just(1).autoDispose(this).subscribe() - Maybe.just(1) - .autoDispose(this, Lifecycle.Event.ON_DESTROY) - .subscribe() + Maybe.just(1).autoDispose(this, Lifecycle.Event.ON_DESTROY).subscribe() - Flowable.just(1) - .autoDispose(this) - .subscribe() + Flowable.just(1).autoDispose(this).subscribe() - Flowable.just(1) - .autoDispose(this, Lifecycle.Event.ON_DESTROY) - .subscribe() + Flowable.just(1).autoDispose(this, Lifecycle.Event.ON_DESTROY).subscribe() - Single.just(1) - .autoDispose(this) - .subscribe() + Single.just(1).autoDispose(this).subscribe() - Single.just(1) - .autoDispose(this, Lifecycle.Event.ON_DESTROY) - .subscribe() + Single.just(1).autoDispose(this, Lifecycle.Event.ON_DESTROY).subscribe() - Completable.never() - .autoDispose(this) - .subscribe() + Completable.never().autoDispose(this).subscribe() - Completable.never() - .autoDispose(this, Lifecycle.Event.ON_DESTROY) - .subscribe() + Completable.never().autoDispose(this, Lifecycle.Event.ON_DESTROY).subscribe() val rootView = findViewById(android.R.id.content) // Taking scope of a View - Observable.interval(1, TimeUnit.DAYS) - .autoDispose(rootView) - .subscribe() + Observable.interval(1, TimeUnit.DAYS).autoDispose(rootView).subscribe() // TODO re-enable with rxlifecycle interop // RxLifecycle -// val lifecycleProvider = TestLifecycleProvider() -// Observable.interval(1, TimeUnit.SECONDS) -// .autoDispose(lifecycleProvider) -// .subscribe() -// -// Observable.interval(1, TimeUnit.SECONDS) -// .autoDispose(lifecycleProvider, TestLifecycleProvider.Event.CREATE) -// .subscribe() + // val lifecycleProvider = TestLifecycleProvider() + // Observable.interval(1, TimeUnit.SECONDS) + // .autoDispose(lifecycleProvider) + // .subscribe() + // + // Observable.interval(1, TimeUnit.SECONDS) + // .autoDispose(lifecycleProvider, TestLifecycleProvider.Event.CREATE) + // .subscribe() } override fun requestScope(): CompletableSource { return Completable.complete() } -// /** Stub implementation for [LifecycleProvider] for compilation testing */ -// class TestLifecycleProvider : LifecycleProvider { -// override fun lifecycle(): Observable { -// return Observable.empty() -// } -// -// override fun bindUntilEvent(event: Event): LifecycleTransformer { -// TODO("Stub to test compilation of extensions that use LifecycleProvider") -// } -// -// override fun bindToLifecycle(): LifecycleTransformer { -// TODO("Stub to test compilation of extensions that use LifecycleProvider") -// } -// -// enum class Event { -// CREATE, -// DESTROY -// } -// } + // /** Stub implementation for [LifecycleProvider] for compilation testing */ + // class TestLifecycleProvider : LifecycleProvider { + // override fun lifecycle(): Observable { + // return Observable.empty() + // } + // + // override fun bindUntilEvent(event: Event): LifecycleTransformer { + // TODO("Stub to test compilation of extensions that use LifecycleProvider") + // } + // + // override fun bindToLifecycle(): LifecycleTransformer { + // TODO("Stub to test compilation of extensions that use LifecycleProvider") + // } + // + // enum class Event { + // CREATE, + // DESTROY + // } + // } } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index dee46e34b..794a90f2a 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ ~ 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 + ~ https://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, @@ -15,8 +15,7 @@ ~ limitations under the License. --> + xmlns:tools="http://schemas.android.com/tools"> { private val lifecycleEvents = BehaviorSubject.create() enum class ActivityEvent { - CREATE, START, RESUME, PAUSE, STOP, DESTROY + CREATE, + START, + RESUME, + PAUSE, + STOP, + DESTROY } override fun lifecycle(): Observable { @@ -93,17 +98,16 @@ abstract class AutoDisposeActivityKotlin : Activity(), LifecycleScopeProvider { activityEvent -> - when (activityEvent) { - CREATE -> DESTROY - START -> STOP - RESUME -> PAUSE - PAUSE -> STOP - STOP -> DESTROY - else -> throw LifecycleEndedException( - "Cannot bind to Activity lifecycle after destroy." - ) + private val CORRESPONDING_EVENTS = + CorrespondingEventsFunction { activityEvent -> + when (activityEvent) { + CREATE -> DESTROY + START -> STOP + RESUME -> PAUSE + PAUSE -> STOP + STOP -> DESTROY + else -> throw LifecycleEndedException("Cannot bind to Activity lifecycle after destroy.") + } } - } } } diff --git a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeFragmentKotlin.kt b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeFragmentKotlin.kt index 1150b11ba..4199661b5 100644 --- a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeFragmentKotlin.kt +++ b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeFragmentKotlin.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -45,7 +45,16 @@ abstract class AutoDisposeFragmentKotlin : Fragment(), LifecycleScopeProvider() enum class FragmentEvent { - ATTACH, CREATE, CREATE_VIEW, START, RESUME, PAUSE, STOP, DESTROY_VIEW, DESTROY, DETACH + ATTACH, + CREATE, + CREATE_VIEW, + START, + RESUME, + PAUSE, + STOP, + DESTROY_VIEW, + DESTROY, + DETACH } override fun lifecycle(): Observable { @@ -119,21 +128,20 @@ abstract class AutoDisposeFragmentKotlin : Fragment(), LifecycleScopeProvider { event -> - when (event) { - ATTACH -> DETACH - CREATE -> DESTROY - CREATE_VIEW -> DESTROY_VIEW - START -> STOP - RESUME -> PAUSE - PAUSE -> STOP - STOP -> DESTROY_VIEW - DESTROY_VIEW -> DESTROY - DESTROY -> DETACH - else -> throw LifecycleEndedException( - "Cannot bind to Fragment lifecycle after detach." - ) + private val CORRESPONDING_EVENTS = + CorrespondingEventsFunction { event -> + when (event) { + ATTACH -> DETACH + CREATE -> DESTROY + CREATE_VIEW -> DESTROY_VIEW + START -> STOP + RESUME -> PAUSE + PAUSE -> STOP + STOP -> DESTROY_VIEW + DESTROY_VIEW -> DESTROY + DESTROY -> DETACH + else -> throw LifecycleEndedException("Cannot bind to Fragment lifecycle after detach.") + } } - } } } diff --git a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewHolderKotlin.kt b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewHolderKotlin.kt index abfd53570..0dfb845e2 100644 --- a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewHolderKotlin.kt +++ b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewHolderKotlin.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -27,9 +27,9 @@ import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.subjects.BehaviorSubject /** - * Example implementation of a [ViewHolder] implementation that implements - * [LifecycleScopeProvider]. This could be useful for cases where you have subscriptions that should be - * disposed upon unbinding or otherwise aren't overwritten in future binds. + * Example implementation of a [ViewHolder] implementation that implements [LifecycleScopeProvider]. + * This could be useful for cases where you have subscriptions that should be disposed upon + * unbinding or otherwise aren't overwritten in future binds. */ abstract class AutoDisposeViewHolderKotlin(itemView: View) : BindAwareViewHolder(itemView), LifecycleScopeProvider { @@ -37,7 +37,8 @@ abstract class AutoDisposeViewHolderKotlin(itemView: View) : private val lifecycleEvents by lazy { BehaviorSubject.create() } enum class ViewHolderEvent { - BIND, UNBIND + BIND, + UNBIND } override fun onBind() = lifecycleEvents.onNext(BIND) @@ -46,19 +47,19 @@ abstract class AutoDisposeViewHolderKotlin(itemView: View) : override fun lifecycle(): Observable = lifecycleEvents.hide() - override fun correspondingEvents(): CorrespondingEventsFunction = CORRESPONDING_EVENTS + override fun correspondingEvents(): CorrespondingEventsFunction = + CORRESPONDING_EVENTS override fun peekLifecycle(): ViewHolderEvent? = lifecycleEvents.value companion object { - private val CORRESPONDING_EVENTS = CorrespondingEventsFunction { viewHolderEvent -> - when (viewHolderEvent) { - BIND -> UNBIND - else -> throw LifecycleEndedException( - "Cannot use ViewHolder lifecycle after unbind." - ) + private val CORRESPONDING_EVENTS = + CorrespondingEventsFunction { viewHolderEvent -> + when (viewHolderEvent) { + BIND -> UNBIND + else -> throw LifecycleEndedException("Cannot use ViewHolder lifecycle after unbind.") + } } - } } } diff --git a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewKotlin.kt b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewKotlin.kt index 81c5a8332..33ff2ca3b 100644 --- a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewKotlin.kt +++ b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewKotlin.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -38,21 +38,26 @@ import io.reactivex.rxjava3.subjects.BehaviorSubject abstract class AutoDisposeViewKotlin : View, LifecycleScopeProvider { enum class ViewEvent { - ATTACH, DETACH + ATTACH, + DETACH } private val lifecycleEvents by lazy { BehaviorSubject.create() } - @JvmOverloads constructor( + @JvmOverloads + constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = View.NO_ID - ) : - super(context, attrs, defStyleAttr) + ) : super(context, attrs, defStyleAttr) @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : - super(context, attrs, defStyleAttr, defStyleRes) + constructor( + context: Context, + attrs: AttributeSet, + defStyleAttr: Int, + defStyleRes: Int + ) : super(context, attrs, defStyleAttr, defStyleRes) override fun onAttachedToWindow() { super.onAttachedToWindow() @@ -81,13 +86,12 @@ abstract class AutoDisposeViewKotlin : View, LifecycleScopeProvider { * "Attach" returns "Detach", then any stream subscribed to during Attach will autodispose on * Detach. */ - private val CORRESPONDING_EVENTS = CorrespondingEventsFunction { viewEvent -> - when (viewEvent) { - ATTACH -> DETACH - else -> throw LifecycleEndedException( - "Cannot bind to View lifecycle after detach." - ) + private val CORRESPONDING_EVENTS = + CorrespondingEventsFunction { viewEvent -> + when (viewEvent) { + ATTACH -> DETACH + else -> throw LifecycleEndedException("Cannot bind to View lifecycle after detach.") + } } - } } } diff --git a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewModel.kt b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewModel.kt index 69ef0f7b3..a9ead9bcc 100644 --- a/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewModel.kt +++ b/sample/src/main/kotlin/autodispose2/recipes/AutoDisposeViewModel.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -24,9 +24,7 @@ import autodispose2.recipes.AutoDisposeViewModel.ViewModelEvent.CREATED import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.subjects.BehaviorSubject -/** - * Demo base [ViewModel] that can automatically dispose itself in [onCleared]. - */ +/** Demo base [ViewModel] that can automatically dispose itself in [onCleared]. */ abstract class AutoDisposeViewModel : ViewModel(), LifecycleScopeProvider { // Subject backing the auto disposing of subscriptions. @@ -35,12 +33,12 @@ abstract class AutoDisposeViewModel : ViewModel(), LifecycleScopeProvider target disposal event. + * Returns a [CorrespondingEventsFunction] that maps the current event -> target disposal event. * * @return function mapping the current event to terminal event. */ @@ -66,10 +63,7 @@ abstract class AutoDisposeViewModel : ViewModel(), LifecycleScopeProvider target disposal event. ViewModel has a very simple lifecycle. - * It is created and then later on cleared. So we only have two events and all subscriptions - * will only be disposed at [ViewModelEvent.CLEARED]. + * Function of current event -> target disposal event. ViewModel has a very simple lifecycle. It + * is created and then later on cleared. So we only have two events and all subscriptions will + * only be disposed at [ViewModelEvent.CLEARED]. */ - private val CORRESPONDING_EVENTS = CorrespondingEventsFunction { event -> - when (event) { - ViewModelEvent.CREATED -> ViewModelEvent.CLEARED - else -> throw LifecycleEndedException( - "Cannot bind to ViewModel lifecycle after onCleared." - ) + private val CORRESPONDING_EVENTS = + CorrespondingEventsFunction { event -> + when (event) { + ViewModelEvent.CREATED -> ViewModelEvent.CLEARED + else -> + throw LifecycleEndedException("Cannot bind to ViewModel lifecycle after onCleared.") + } } - } } } diff --git a/sample/src/main/kotlin/autodispose2/recipes/subscriberproxies.kt b/sample/src/main/kotlin/autodispose2/recipes/subscriberproxies.kt index 2bdddea4b..e198db182 100644 --- a/sample/src/main/kotlin/autodispose2/recipes/subscriberproxies.kt +++ b/sample/src/main/kotlin/autodispose2/recipes/subscriberproxies.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -41,12 +41,12 @@ import io.reactivex.rxjava3.plugins.RxJavaPlugins */ private val onNextStub: (Any) -> Unit = {} -private val onErrorStub: (Throwable) -> Unit = { RxJavaPlugins.onError(OnErrorNotImplementedException(it)) } +private val onErrorStub: (Throwable) -> Unit = { + RxJavaPlugins.onError(OnErrorNotImplementedException(it)) +} private val onCompleteStub: () -> Unit = {} -/** - * Overloaded subscribe function that allows passing named parameters - */ +/** Overloaded subscribe function that allows passing named parameters */ fun ObservableSubscribeProxy.subscribeBy( onError: (Throwable) -> Unit = onErrorStub, onComplete: () -> Unit = onCompleteStub, @@ -59,9 +59,7 @@ fun ObservableSubscribeProxy.subscribeBy( } } -/** - * Overloaded subscribe function that allows passing named parameters - */ +/** Overloaded subscribe function that allows passing named parameters */ fun FlowableSubscribeProxy.subscribeBy( onError: (Throwable) -> Unit = onErrorStub, onComplete: () -> Unit = onCompleteStub, @@ -74,9 +72,7 @@ fun FlowableSubscribeProxy.subscribeBy( } } -/** - * Overloaded subscribe function that allows passing named parameters - */ +/** Overloaded subscribe function that allows passing named parameters */ fun SingleSubscribeProxy.subscribeBy( onError: (Throwable) -> Unit = onErrorStub, onSuccess: (T) -> Unit = onNextStub @@ -88,9 +84,7 @@ fun SingleSubscribeProxy.subscribeBy( } } -/** - * Overloaded subscribe function that allows passing named parameters - */ +/** Overloaded subscribe function that allows passing named parameters */ fun MaybeSubscribeProxy.subscribeBy( onError: (Throwable) -> Unit = onErrorStub, onComplete: () -> Unit = onCompleteStub, @@ -103,9 +97,7 @@ fun MaybeSubscribeProxy.subscribeBy( } } -/** - * Overloaded subscribe function that allows passing named parameters - */ +/** Overloaded subscribe function that allows passing named parameters */ fun CompletableSubscribeProxy.subscribeBy( onError: (Throwable) -> Unit = onErrorStub, onComplete: () -> Unit = onCompleteStub diff --git a/sample/src/main/kotlin/autodispose2/sample/ArchComponentActivity.kt b/sample/src/main/kotlin/autodispose2/sample/ArchComponentActivity.kt index bdb777998..d82ef49f9 100644 --- a/sample/src/main/kotlin/autodispose2/sample/ArchComponentActivity.kt +++ b/sample/src/main/kotlin/autodispose2/sample/ArchComponentActivity.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -19,8 +19,8 @@ import android.os.Bundle import android.util.Log import android.widget.Button import android.widget.ImageView +import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.ViewModelProviders import autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider import autodispose2.autoDispose import autodispose2.sample.repository.ImageRepository @@ -35,11 +35,11 @@ class ArchComponentActivity : AppCompatActivity() { private val scopeProvider by lazy { AndroidLifecycleScopeProvider.from(this) } - // Custom view model factory - private val viewModelFactory by lazy { ArchComponentViewModel.Factory(ImageRepository(resources)) } - // ViewModel for given Activity - private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get(ArchComponentViewModel::class.java) } + private val viewModel by + viewModels { + ArchComponentViewModel.Factory(ImageRepository(resources)) + } lateinit var imageView: ImageView lateinit var button: Button @@ -54,7 +54,8 @@ class ArchComponentActivity : AppCompatActivity() { // Using automatic disposal, this should determine that the correct time to // dispose is onDestroy (the opposite of onCreate). - viewModel.image() + viewModel + .image() .doOnDispose { Log.i(TAG, "Disposing ViewModel observer from onCreate()") } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -65,9 +66,7 @@ class ArchComponentActivity : AppCompatActivity() { } // Set listener to load the image. - button.setOnClickListener { - viewModel.loadBitmap(R.raw.sunset) - } + button.setOnClickListener { viewModel.loadBitmap(R.raw.sunset) } } override fun onStart() { diff --git a/sample/src/main/kotlin/autodispose2/sample/ArchComponentViewModel.kt b/sample/src/main/kotlin/autodispose2/sample/ArchComponentViewModel.kt index 4e169544c..eeb331f93 100644 --- a/sample/src/main/kotlin/autodispose2/sample/ArchComponentViewModel.kt +++ b/sample/src/main/kotlin/autodispose2/sample/ArchComponentViewModel.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -22,33 +22,28 @@ import autodispose2.sample.repository.ImageRepository import io.reactivex.rxjava3.core.Observable /** - * Demo Architecture Component ViewModel. The ViewModel - * will expose your Rx stream which should be observed - * by the view. + * Demo Architecture Component ViewModel. The ViewModel will expose your Rx stream which should be + * observed by the view. */ class ArchComponentViewModel(private val imageRepository: ImageRepository) : ViewModel() { /** - * Calls the repository to get a subscription of the Bitmap. - * The repository caches the last value of the Observable so that - * things like orientation changes don't trigger "reloading" of the + * Calls the repository to get a subscription of the Bitmap. The repository caches the last value + * of the Observable so that things like orientation changes don't trigger "reloading" of the * Bitmap from the raw resource. */ fun image(): Observable { return imageRepository.image() } - /** - * Load the given [imageId] from resources. - */ + /** Load the given [imageId] from resources. */ fun loadBitmap(imageId: Int) { imageRepository.loadImage(imageId) } class Factory(private val imageRepository: ImageRepository) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { - @Suppress("UNCHECKED_CAST") - return ArchComponentViewModel(imageRepository) as T + @Suppress("UNCHECKED_CAST") return ArchComponentViewModel(imageRepository) as T } } } diff --git a/sample/src/main/kotlin/autodispose2/sample/DisposingViewModel.kt b/sample/src/main/kotlin/autodispose2/sample/DisposingViewModel.kt index a5210137f..91ba7e45a 100644 --- a/sample/src/main/kotlin/autodispose2/sample/DisposingViewModel.kt +++ b/sample/src/main/kotlin/autodispose2/sample/DisposingViewModel.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -30,78 +30,64 @@ import io.reactivex.rxjava3.schedulers.Schedulers /** * Demo AutoDisposing ViewModel. * - * This ViewModel will subscribe to Rx streams for you and pass along - * the values through the [viewRelay]. + * This ViewModel will subscribe to Rx streams for you and pass along the values through the + * [viewRelay]. * - * Often times, like in the case of network calls, we want our network - * requests to go on even if there are orientation changes. If you subscribe - * to your network Rx stream in the view, the request will be cancelled on - * orientation change (since your streams are disposed) and you will likely - * have to make a new network call. + * Often times, like in the case of network calls, we want our network requests to go on even if + * there are orientation changes. If you subscribe to your network Rx stream in the view, the + * request will be cancelled on orientation change (since your streams are disposed) and you will + * likely have to make a new network call. * - * Since the ViewModel survives configuration changes, it is an ideal place - * to subscribe to network Rx streams and then pass it along to the UI - * using a [BehaviorRelay] or LiveData. Since both of them cache the last - * emitted value, as soon as your Activity/Fragment comes back and resubscribes - * to the [viewRelay] after orientation change, it will safely get the most - * updated value. + * Since the ViewModel survives configuration changes, it is an ideal place to subscribe to network + * Rx streams and then pass it along to the UI using a [BehaviorRelay] or LiveData. Since both of + * them cache the last emitted value, as soon as your Activity/Fragment comes back and resubscribes + * to the [viewRelay] after orientation change, it will safely get the most updated value. * - * AutoDispose will automatically dispose any pending subscriptions when - * the [onCleared] method is called since it extends from [AutoDisposeViewModel]. + * AutoDispose will automatically dispose any pending subscriptions when the [onCleared] method is + * called since it extends from [AutoDisposeViewModel]. */ class DisposingViewModel(private val repository: NetworkRepository) : AutoDisposeViewModel() { /** * The relay to communicate state to the UI. * - * This should be subscribed by the UI to get the latest - * state updates unaffected by config changes. - * This could easily be substituted by a LiveData instance - * since both of them cache the last emitted value. + * This should be subscribed by the UI to get the latest state updates unaffected by config + * changes. This could easily be substituted by a LiveData instance since both of them cache the + * last emitted value. */ private val viewRelay = BehaviorRelay.create() /** * Downloads a large image over the network. * - * This could take some time and we wish to show - * a progress indicator to the user. We setup a - * [DownloadState] which we will pass to the UI to - * show our state. + * This could take some time and we wish to show a progress indicator to the user. We setup a + * [DownloadState] which we will pass to the UI to show our state. * - * We subscribe in ViewModel to survive configuration - * changes and keep the download request going. As the - * view will resubscribe to the [viewRelay], it will get - * the most updated [DownloadState]. + * We subscribe in ViewModel to survive configuration changes and keep the download request going. + * As the view will resubscribe to the [viewRelay], it will get the most updated [DownloadState]. * * @see repository */ fun downloadLargeImage() { // Notify UI that we're loading network viewRelay.accept(DownloadState.Started) - repository.downloadProgress() + repository + .downloadProgress() .subscribeOn(Schedulers.io()) .doOnDispose { Log.i(TAG, "Disposing subscription from the ViewModel") } .autoDispose(this) .subscribe( - { progress -> - viewRelay.accept(DownloadState.InProgress(progress)) - }, - { error -> - error.printStackTrace() - }, - { - viewRelay.accept(DownloadState.Completed) - } + { progress -> viewRelay.accept(DownloadState.InProgress(progress)) }, + { error -> error.printStackTrace() }, + { viewRelay.accept(DownloadState.Completed) } ) } /** * State representation for our current activity. * - * For the purposes of this demo, we'll use a [String] - * but you can model your own ViewState with a sealed class - * and expose that. + * For the purposes of this demo, we'll use a [String] but you can model your own ViewState with a + * sealed class and expose that. */ fun downloadState(): Observable { return RxJavaBridge.toV3Observable(viewRelay) @@ -113,8 +99,7 @@ class DisposingViewModel(private val repository: NetworkRepository) : AutoDispos class Factory(private val networkRepository: NetworkRepository) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { - @Suppress("UNCHECKED_CAST") - return DisposingViewModel(networkRepository) as T + @Suppress("UNCHECKED_CAST") return DisposingViewModel(networkRepository) as T } } } diff --git a/sample/src/main/kotlin/autodispose2/sample/DisposingViewModelActivity.kt b/sample/src/main/kotlin/autodispose2/sample/DisposingViewModelActivity.kt index ca6e06f87..a8c1dff63 100644 --- a/sample/src/main/kotlin/autodispose2/sample/DisposingViewModelActivity.kt +++ b/sample/src/main/kotlin/autodispose2/sample/DisposingViewModelActivity.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -18,8 +18,8 @@ package autodispose2.sample import android.os.Bundle import android.widget.ProgressBar import android.widget.TextView +import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.ViewModelProviders import autodispose2.ScopeProvider import autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider import autodispose2.autoDispose @@ -31,10 +31,9 @@ class DisposingViewModelActivity : AppCompatActivity() { // Network repository. Can be substituted by DI private val networkRepository: NetworkRepository by lazy { NetworkRepository() } - // The view model factory - private val viewModelFactory by lazy { DisposingViewModel.Factory(networkRepository) } // The ViewModel for this Activity. - private val viewModel: DisposingViewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get(DisposingViewModel::class.java) } + private val viewModel: DisposingViewModel by + viewModels { DisposingViewModel.Factory(networkRepository) } private val scope: ScopeProvider by lazy { AndroidLifecycleScopeProvider.from(this) } @@ -56,15 +55,11 @@ class DisposingViewModelActivity : AppCompatActivity() { } // Get latest value from ViewModel unaffected by any config changes. - viewModel.downloadState() + viewModel + .downloadState() .observeOn(AndroidSchedulers.mainThread()) .autoDispose(scope) - .subscribe( - { state -> - resolveState(state) - }, - {} - ) + .subscribe({ state -> resolveState(state) }, {}) } /** diff --git a/sample/src/main/kotlin/autodispose2/sample/HomeActivity.kt b/sample/src/main/kotlin/autodispose2/sample/HomeActivity.kt index de82319a1..b0c345f43 100644 --- a/sample/src/main/kotlin/autodispose2/sample/HomeActivity.kt +++ b/sample/src/main/kotlin/autodispose2/sample/HomeActivity.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -21,9 +21,7 @@ import android.widget.Button import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar -/** - * Central activity that opens up other activities. - */ +/** Central activity that opens up other activities. */ class HomeActivity : AppCompatActivity() { lateinit var toolbar: Toolbar @@ -34,24 +32,16 @@ class HomeActivity : AppCompatActivity() { toolbar = findViewById(R.id.toolbar) setSupportActionBar(toolbar) - supportActionBar?.let { - setTitle(R.string.app_name) - } + supportActionBar?.let { setTitle(R.string.app_name) } val mainActivityButton: Button = findViewById(R.id.javaActivityButton) - mainActivityButton.setOnClickListener { - startActivity(JavaActivity::class.java) - } + mainActivityButton.setOnClickListener { startActivity(JavaActivity::class.java) } val archComponentsButton: Button = findViewById(R.id.archComponentsActivityButton) - archComponentsButton.setOnClickListener { - startActivity(ArchComponentActivity::class.java) - } + archComponentsButton.setOnClickListener { startActivity(ArchComponentActivity::class.java) } val kotlinActivityButton: Button = findViewById(R.id.kotlinActivityButton) - kotlinActivityButton.setOnClickListener { - startActivity(KotlinActivity::class.java) - } + kotlinActivityButton.setOnClickListener { startActivity(KotlinActivity::class.java) } val disposingActivityButton: Button = findViewById(R.id.disposingActivity) disposingActivityButton.setOnClickListener { diff --git a/sample/src/main/kotlin/autodispose2/sample/KotlinActivity.kt b/sample/src/main/kotlin/autodispose2/sample/KotlinActivity.kt index 4abd32739..140cbe620 100644 --- a/sample/src/main/kotlin/autodispose2/sample/KotlinActivity.kt +++ b/sample/src/main/kotlin/autodispose2/sample/KotlinActivity.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -47,7 +47,8 @@ class KotlinActivity : AppCompatActivity() { .autoDispose(scopeProvider) .subscribeBy { num -> Log.i(TAG, "Started in onCreate(), running until onDestroy(): $num") } - supportFragmentManager.beginTransaction() + supportFragmentManager + .beginTransaction() .add(R.id.fragment_container, KotlinFragment()) .commitNow() } @@ -82,10 +83,10 @@ class KotlinActivity : AppCompatActivity() { .doOnDispose { Log.i(TAG, "Disposing subscription from onResume() with untilEvent ON_DESTROY") } - .autoDispose( - AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY) - ) - .subscribeBy { num -> Log.i(TAG, "Started in onResume(), running until in onDestroy(): $num") } + .autoDispose(AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY)) + .subscribeBy { num -> + Log.i(TAG, "Started in onResume(), running until in onDestroy(): $num") + } } override fun onPause() { diff --git a/sample/src/main/kotlin/autodispose2/sample/KotlinFragment.kt b/sample/src/main/kotlin/autodispose2/sample/KotlinFragment.kt index d6474c5ab..04299ce28 100644 --- a/sample/src/main/kotlin/autodispose2/sample/KotlinFragment.kt +++ b/sample/src/main/kotlin/autodispose2/sample/KotlinFragment.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -97,18 +97,14 @@ class KotlinFragment : Fragment() { Observable.interval(1, TimeUnit.SECONDS) .doOnDispose { Log.i(TAG, "Disposing subscription from onResume()") } .autoDispose(scopeProvider) - .subscribeBy { num -> - Log.i(TAG, "Started in onResume(), running until in onPause(): $num") - } + .subscribeBy { num -> Log.i(TAG, "Started in onResume(), running until in onPause(): $num") } // Setting a specific untilEvent, this should dispose in onDestroy. Observable.interval(1, TimeUnit.SECONDS) .doOnDispose { Log.i(TAG, "Disposing subscription from onResume() with untilEvent ON_DESTROY") } - .autoDispose( - AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY) - ) + .autoDispose(AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY)) .subscribeBy { num -> Log.i(TAG, "Started in onResume(), running until in onDestroy(): $num") } diff --git a/sample/src/main/kotlin/autodispose2/sample/repository/ImageRepository.kt b/sample/src/main/kotlin/autodispose2/sample/repository/ImageRepository.kt index 6ea4dcdac..69b81e44c 100644 --- a/sample/src/main/kotlin/autodispose2/sample/repository/ImageRepository.kt +++ b/sample/src/main/kotlin/autodispose2/sample/repository/ImageRepository.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -25,10 +25,8 @@ import hu.akarnokd.rxjava3.bridge.RxJavaBridge import io.reactivex.rxjava3.core.Observable /** - * Repository layer for loading a Bitmap from res/raw. - * If you're using DI, this should be a singleton class, - * so that [imageObservable] can be reused across - * activities/fragments. + * Repository layer for loading a Bitmap from res/raw. If you're using DI, this should be a + * singleton class, so that [imageObservable] can be reused across activities/fragments. * * @param resources */ @@ -38,24 +36,24 @@ class ImageRepository(private val resources: Resources) { private val relay = PublishRelay.create() /** - * The Observable returned to the UI. This will map each given - * resourceId to a Bitmap and cache it using [replayingShare]. + * The Observable returned to the UI. This will map each given resourceId to a Bitmap and cache it + * using [replayingShare]. * - * The caching is necessary since this is an expensive operation - * and should not be triggered every time someone subscribes to it. - * [replayingShare] helps with that. + * The caching is necessary since this is an expensive operation and should not be triggered every + * time someone subscribes to it. [replayingShare] helps with that. */ - private val imageObservable = RxJavaBridge.toV3Observable( - relay - .map { - return@map BitmapFactory.decodeStream(resources.openRawResource(it)) - } - .replayingShare() - ) + private val imageObservable = + RxJavaBridge.toV3Observable( + relay + .map { + return@map BitmapFactory.decodeStream(resources.openRawResource(it)) + } + .replayingShare() + ) /** - * Returns an Observable that will be consumed in the - * UI to subscribe to a stream of Bitmaps requested by the user. + * Returns an Observable that will be consumed in the UI to subscribe to a stream of + * Bitmaps requested by the user. * * @return stream of Bitmaps */ @@ -64,8 +62,8 @@ class ImageRepository(private val resources: Resources) { } /** - * Fires off an event on the relay that will trigger the loading - * of the Bitmap from given resource [id]. + * Fires off an event on the relay that will trigger the loading of the Bitmap from given resource + * [id]. * * @param id the id of the raw resource */ diff --git a/sample/src/main/kotlin/autodispose2/sample/repository/NetworkRepository.kt b/sample/src/main/kotlin/autodispose2/sample/repository/NetworkRepository.kt index 18f62d5bb..3a365d648 100644 --- a/sample/src/main/kotlin/autodispose2/sample/repository/NetworkRepository.kt +++ b/sample/src/main/kotlin/autodispose2/sample/repository/NetworkRepository.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -21,23 +21,19 @@ import java.util.concurrent.TimeUnit /** * Repository layer for your network requests. * - * Simulates the download request and sends the - * progress so far. + * Simulates the download request and sends the progress so far. */ class NetworkRepository { /** * Emit the progress of the requested download. * - * We simulate the download progress by emitting - * an int periodically and call onComplete after + * We simulate the download progress by emitting an int periodically and call onComplete after * it's done. * * @return [Observable] emitting download progress. */ fun downloadProgress(): Observable { - return Observable.interval(500, TimeUnit.MILLISECONDS) - .map { it.toInt() } - .take(51) + return Observable.interval(500, TimeUnit.MILLISECONDS).map { it.toInt() }.take(51) } } diff --git a/sample/src/main/kotlin/autodispose2/sample/state/DownloadState.kt b/sample/src/main/kotlin/autodispose2/sample/state/DownloadState.kt index 6194f8527..08c569f1d 100644 --- a/sample/src/main/kotlin/autodispose2/sample/state/DownloadState.kt +++ b/sample/src/main/kotlin/autodispose2/sample/state/DownloadState.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -16,17 +16,13 @@ package autodispose2.sample.state /** - * State representation for when we're downloading - * a file. + * State representation for when we're downloading a file. * - * This is used in your UI for proper state - * management. + * This is used in your UI for proper state management. */ sealed class DownloadState { - /** - * Download started. - */ + /** Download started. */ object Started : DownloadState() /** @@ -36,8 +32,6 @@ sealed class DownloadState { */ class InProgress(val progress: Int) : DownloadState() - /** - * Download has completed. - */ + /** Download has completed. */ object Completed : DownloadState() } diff --git a/sample/src/main/res/layout/activity_arch_component.xml b/sample/src/main/res/layout/activity_arch_component.xml index 35166a045..d3b20e7b8 100644 --- a/sample/src/main/res/layout/activity_arch_component.xml +++ b/sample/src/main/res/layout/activity_arch_component.xml @@ -6,7 +6,7 @@ ~ 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 + ~ https://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, diff --git a/sample/src/main/res/layout/activity_disposing_viewmodel.xml b/sample/src/main/res/layout/activity_disposing_viewmodel.xml index 2e546b81d..b6115c3fb 100644 --- a/sample/src/main/res/layout/activity_disposing_viewmodel.xml +++ b/sample/src/main/res/layout/activity_disposing_viewmodel.xml @@ -6,7 +6,7 @@ ~ 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 + ~ https://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, diff --git a/sample/src/main/res/layout/activity_home.xml b/sample/src/main/res/layout/activity_home.xml index 62b0027f8..b4ab18c24 100644 --- a/sample/src/main/res/layout/activity_home.xml +++ b/sample/src/main/res/layout/activity_home.xml @@ -6,7 +6,7 @@ ~ 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 + ~ https://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, diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index bd67559be..de7d22d36 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -6,7 +6,7 @@ ~ 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 + ~ https://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, diff --git a/sample/src/main/res/layout/content_main.xml b/sample/src/main/res/layout/content_main.xml index 50bafb4a7..1481fd965 100644 --- a/sample/src/main/res/layout/content_main.xml +++ b/sample/src/main/res/layout/content_main.xml @@ -6,7 +6,7 @@ ~ 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 + ~ https://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, diff --git a/sample/src/main/res/values/dimens.xml b/sample/src/main/res/values/dimens.xml index 11ae6a708..69a3a6f7a 100644 --- a/sample/src/main/res/values/dimens.xml +++ b/sample/src/main/res/values/dimens.xml @@ -5,7 +5,7 @@ ~ 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 + ~ https://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, diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 9277fa210..2d7bb2d7e 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -5,7 +5,7 @@ ~ 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 + ~ https://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, diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml index 784c39456..b7d045532 100644 --- a/sample/src/main/res/values/styles.xml +++ b/sample/src/main/res/values/styles.xml @@ -5,7 +5,7 @@ ~ 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 + ~ https://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, diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 019ff256c..000000000 --- a/settings.gradle +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -pluginManagement { - apply from: file('gradle/dependencies.gradle') - resolutionStrategy { - eachPlugin { - String id = requested.id.id - if (id.startsWith("com.android")) { - useModule(deps.build.gradlePlugins.android) - } else if (id.startsWith("org.jetbrains.kotlin")) { - useModule(deps.build.gradlePlugins.kotlin) - } else { - switch (id) { - case 'net.ltgt.errorprone': - useVersion(deps.versions.errorPronePlugin) - break - case 'net.ltgt.nullaway': - useVersion(deps.versions.nullawayPlugin) - break - case 'ru.vyarus.animalsniffer': - useVersion(deps.versions.animalSniffer) - break - } - } - } - } - repositories { - mavenCentral() - google() - gradlePluginPortal() - } -} - -rootProject.name = 'autodispose-root' -if (System.getenv("ANDROID_HOME") != null) { - include ':android:autodispose-android' - include ':android:autodispose-androidx-lifecycle' - include ':android:autodispose-androidx-lifecycle-test' - include ':sample' -} -include ':autodispose' -include ':autodispose-interop:coroutines' -include ':autodispose-lifecycle' -include ':test-utils' -include ':static-analysis:autodispose-error-prone' -include ':static-analysis:autodispose-lint' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 000000000..00b529e0a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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. + */ +pluginManagement { + repositories { + mavenCentral() + google() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +rootProject.name = "autodispose-root" + +if (System.getenv("ANDROID_HOME") != null) { + include( + ":android:autodispose-android", + ":android:autodispose-androidx-lifecycle", + ":android:autodispose-androidx-lifecycle-test", + ":sample", + ) +} + +include( + ":autodispose", + ":autodispose-interop:coroutines", + ":autodispose-lifecycle", + ":test-utils", + ":static-analysis:autodispose-error-prone", + ":static-analysis:autodispose-lint", +) diff --git a/spotless/copyright.java b/spotless/copyright.java index edd5a638f..9aa67ac08 100644 --- a/spotless/copyright.java +++ b/spotless/copyright.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/spotless/copyright.kt b/spotless/copyright.kt index edd5a638f..9aa67ac08 100644 --- a/spotless/copyright.kt +++ b/spotless/copyright.kt @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/static-analysis/autodispose-error-prone/build.gradle b/static-analysis/autodispose-error-prone/build.gradle deleted file mode 100644 index 0863b0268..000000000 --- a/static-analysis/autodispose-error-prone/build.gradle +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -plugins { - id "com.vanniktech.maven.publish" -} - -dependencies { - annotationProcessor deps.apt.autoService - - compileOnly deps.apt.autoService - compileOnly deps.build.errorProneCheckApi - - testImplementation(deps.build.errorProneTestHelpers) { - exclude group: "junit", module: "junit" - } - testImplementation deps.rx.java - testImplementation deps.test.junit - testImplementation project(':autodispose') - testImplementation project(':autodispose-lifecycle') -} - -if (!JavaVersion.current().isJava9Compatible()) { - test { - jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" - } -} diff --git a/static-analysis/autodispose-error-prone/build.gradle.kts b/static-analysis/autodispose-error-prone/build.gradle.kts new file mode 100644 index 000000000..213397cb5 --- /dev/null +++ b/static-analysis/autodispose-error-prone/build.gradle.kts @@ -0,0 +1,53 @@ +/* + * 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 + * + * https://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. + */ +plugins { + `java-library` + alias(libs.plugins.mavenPublish) + alias(libs.plugins.ksp) +} + +val jvmArgsNeeded = + listOf( + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + ) + +tasks.withType().configureEach { options.compilerArgs.addAll(jvmArgsNeeded) } + +tasks.withType().configureEach { jvmArgs(jvmArgsNeeded) } + +dependencies { + ksp(libs.autoService.ksp) + + compileOnly(libs.autoService.annotations) + compileOnly(libs.build.errorProneCheckApi) + + testImplementation(libs.build.errorProneTestHelpers) { + exclude(group = "junit", module = "junit") + } + testImplementation(libs.rx.java) + testImplementation(libs.test.junit) + testImplementation(project(":autodispose")) + testImplementation(project(":autodispose-lifecycle")) +} diff --git a/static-analysis/autodispose-error-prone/gradle.properties b/static-analysis/autodispose-error-prone/gradle.properties index a31b38c52..1d45e81d0 100644 --- a/static-analysis/autodispose-error-prone/gradle.properties +++ b/static-analysis/autodispose-error-prone/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, diff --git a/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/AbstractReturnValueIgnored.java b/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/AbstractReturnValueIgnored.java index c27f898ff..4d9cdbdb0 100644 --- a/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/AbstractReturnValueIgnored.java +++ b/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/AbstractReturnValueIgnored.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -21,7 +21,7 @@ import static com.google.errorprone.matchers.Matchers.expressionStatement; import static com.google.errorprone.matchers.Matchers.isLastStatementInBlock; import static com.google.errorprone.matchers.Matchers.kindIs; -import static com.google.errorprone.matchers.Matchers.methodSelect; +import static com.google.errorprone.matchers.Matchers.methodInvocation; import static com.google.errorprone.matchers.Matchers.nextStatement; import static com.google.errorprone.matchers.Matchers.not; import static com.google.errorprone.matchers.Matchers.parentNode; @@ -92,7 +92,7 @@ private Description matchMethodInvocationNew(MethodInvocationTree tree, VisitorS anyOf( AbstractReturnValueIgnored::isVoidReturningLambdaExpression, Matchers.kindIs(Kind.EXPRESSION_STATEMENT))), - not(methodSelect(toType(IdentifierTree.class, identifierHasName("super")))), + not(methodInvocation(toType(IdentifierTree.class, identifierHasName("super")))), not((t, s) -> isVoidType(getType(t), s)), not(AbstractReturnValueIgnored::expectedExceptionTest)) .matches(tree, state); @@ -215,8 +215,8 @@ private static boolean isThrowingFunctionalInterface(VisitorState state, Type cl public abstract Matcher specializedMatcher(); /** - * @return {@code true} if this should be lenient and only run the checks if the return value is - * ignored, {@code false} if it should always check {@link #specializedMatcher()}. + * Controls whether this should be lenient and only run the checks if the return value is ignored. + * Set to {@code false} if it should always check {@link #specializedMatcher()}. */ abstract boolean lenient(); diff --git a/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/UseAutoDispose.java b/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/UseAutoDispose.java index ab29ab562..70577596a 100644 --- a/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/UseAutoDispose.java +++ b/static-analysis/autodispose-error-prone/src/main/java/autodispose2/errorprone/UseAutoDispose.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -32,6 +32,8 @@ import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.suppliers.Supplier; +import com.google.inject.Inject; import com.sun.source.tree.ClassTree; import com.sun.source.tree.ExpressionTree; import com.sun.tools.javac.code.Type; @@ -49,6 +51,7 @@ * -XepOpt:OverrideScopes= * */ +@SuppressWarnings("BugPatternNaming") @AutoService(BugChecker.class) @BugPattern( name = "AutoDispose", @@ -92,6 +95,12 @@ public final class UseAutoDispose extends AbstractReturnValueIgnored .onDescendantOf("io.reactivex.rxjava3.parallel.ParallelFlowable") .named(SUBSCRIBE)); + private final Supplier disposableTypeSupplier = + VisitorState.memoize( + state -> state.getTypeFromString("io.reactivex.rxjava3.disposables.Disposable")); + private final Supplier subscriptionTypeSupplier = + VisitorState.memoize(state -> state.getTypeFromString("org.reactivestreams.Subscription")); + private final Matcher matcher; private final boolean lenient; @@ -101,6 +110,7 @@ public UseAutoDispose() { } @SuppressWarnings("WeakerAccess") // Public for ErrorProne + @Inject public UseAutoDispose(ErrorProneFlags flags) { Optional> inputClasses = flags.getList("TypesWithScope").map(ImmutableSet::copyOf); @@ -123,9 +133,8 @@ public Matcher specializedMatcher() { @Override protected boolean capturedTypeAllowed(Type type, VisitorState state) { - return isSubtype( - type, state.getTypeFromString("io.reactivex.rxjava3.disposables.Disposable"), state) - || isSubtype(type, state.getTypeFromString("org.reactivestreams.Subscription"), state); + return isSubtype(type, disposableTypeSupplier.get(state), state) + || isSubtype(type, subscriptionTypeSupplier.get(state), state); } @Override diff --git a/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/ComponentWithLifecycle.java b/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/ComponentWithLifecycle.java index 0418659d5..771e9848b 100644 --- a/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/ComponentWithLifecycle.java +++ b/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/ComponentWithLifecycle.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/UseAutoDisposeTest.java b/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/UseAutoDisposeTest.java index bb45b3c75..d2b06345b 100644 --- a/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/UseAutoDisposeTest.java +++ b/static-analysis/autodispose-error-prone/src/test/java/autodispose2/errorprone/UseAutoDisposeTest.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeCustomClassPositiveCases.java b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeCustomClassPositiveCases.java index c671d4364..e2879d99e 100644 --- a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeCustomClassPositiveCases.java +++ b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeCustomClassPositiveCases.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCases.java b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCases.java index 0133f7105..570d923f2 100644 --- a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCases.java +++ b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCases.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -38,7 +38,9 @@ public class UseAutoDisposeDefaultClassPositiveCases private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); - /** @return a sequence of lifecycle events. */ + /** + * @return a sequence of lifecycle events. + */ @CheckReturnValue public Observable lifecycle() { return lifecycleSubject.hide(); @@ -62,7 +64,9 @@ public CorrespondingEventsFunction correspondingEvents() { }; } - /** @return the last seen lifecycle event, or {@code null} if none. */ + /** + * @return the last seen lifecycle event, or {@code null} if none. + */ @Nullable public TestLifecycle peekLifecycle() { return lifecycleSubject.getValue(); diff --git a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCasesLenient.java b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCasesLenient.java index 1f8c23de2..5771f2b68 100644 --- a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCasesLenient.java +++ b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeDefaultClassPositiveCasesLenient.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -40,7 +40,9 @@ public class UseAutoDisposeDefaultClassPositiveCasesLenient private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); - /** @return a sequence of lifecycle events. */ + /** + * @return a sequence of lifecycle events. + */ @CheckReturnValue public Observable lifecycle() { return lifecycleSubject.hide(); @@ -64,7 +66,9 @@ public CorrespondingEventsFunction correspondingEvents() { }; } - /** @return the last seen lifecycle event, or {@code null} if none. */ + /** + * @return the last seen lifecycle event, or {@code null} if none. + */ @Nullable public TestLifecycle peekLifecycle() { return lifecycleSubject.getValue(); diff --git a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCases.java b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCases.java index 12e5954ab..30225b4fe 100644 --- a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCases.java +++ b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCases.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -39,7 +39,9 @@ public class UseAutoDisposeNegativeCases implements LifecycleScopeProvider lifecycleSubject = BehaviorSubject.create(); - /** @return a sequence of lifecycle events. */ + /** + * @return a sequence of lifecycle events. + */ @CheckReturnValue public Observable lifecycle() { return lifecycleSubject.hide(); @@ -63,7 +65,9 @@ public CorrespondingEventsFunction correspondingEvents() { }; } - /** @return the last seen lifecycle event, or {@code null} if none. */ + /** + * @return the last seen lifecycle event, or {@code null} if none. + */ @Nullable public TestLifecycle peekLifecycle() { return lifecycleSubject.getValue(); diff --git a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesExcluded.java b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesExcluded.java index b9584e6a2..5e685b38b 100644 --- a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesExcluded.java +++ b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesExcluded.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -39,7 +39,9 @@ public class UseAutoDisposeNegativeCasesExcluded implements LifecycleScopeProvid private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); - /** @return a sequence of lifecycle events. */ + /** + * @return a sequence of lifecycle events. + */ @CheckReturnValue public Observable lifecycle() { return lifecycleSubject.hide(); @@ -63,7 +65,9 @@ public CorrespondingEventsFunction correspondingEvents() { }; } - /** @return the last seen lifecycle event, or {@code null} if none. */ + /** + * @return the last seen lifecycle event, or {@code null} if none. + */ @Nullable public TestLifecycle peekLifecycle() { return lifecycleSubject.getValue(); diff --git a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesLenient.java b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesLenient.java index 304f72f04..9c2bc602d 100644 --- a/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesLenient.java +++ b/static-analysis/autodispose-error-prone/src/test/resources/autodispose2/errorprone/UseAutoDisposeNegativeCasesLenient.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -42,7 +42,9 @@ public class UseAutoDisposeNegativeCasesLenient implements LifecycleScopeProvide private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); - /** @return a sequence of lifecycle events. */ + /** + * @return a sequence of lifecycle events. + */ @Override @CheckReturnValue public Observable lifecycle() { @@ -68,7 +70,9 @@ public CorrespondingEventsFunction correspondingEvents() { }; } - /** @return the last seen lifecycle event, or {@code null} if none. */ + /** + * @return the last seen lifecycle event, or {@code null} if none. + */ @Override @Nullable public TestLifecycle peekLifecycle() { diff --git a/static-analysis/autodispose-lint/build.gradle b/static-analysis/autodispose-lint/build.gradle deleted file mode 100644 index 9187fb3f5..000000000 --- a/static-analysis/autodispose-lint/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2018. 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. - */ - -plugins { - id 'java-library' - id 'org.jetbrains.kotlin.jvm' - id 'org.jetbrains.kotlin.kapt' - id "com.vanniktech.maven.publish" -} - -sourceCompatibility = deps.build.javaVersion -targetCompatibility = deps.build.javaVersion - -compileKotlin { - kotlinOptions { - // Lint runs with 1.4 still, so we need to emit 1.4-compatible code - apiVersion = "1.4" - languageVersion = "1.4" - } -} - -dependencies { - kapt deps.apt.autoService - - compileOnly deps.build.lint.api - compileOnly deps.apt.autoService - - testImplementation deps.test.junit - testImplementation deps.build.lint.core - testImplementation deps.build.lint.tests -} diff --git a/static-analysis/autodispose-lint/build.gradle.kts b/static-analysis/autodispose-lint/build.gradle.kts new file mode 100644 index 000000000..6238b1fc1 --- /dev/null +++ b/static-analysis/autodispose-lint/build.gradle.kts @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2023. 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 + * + * https://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. + */ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +/* + * Copyright (C) 2018. 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 + * + * https://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. + */ + +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.ksp) + alias(libs.plugins.mavenPublish) +} + +tasks.withType().configureEach { + options.release.set(libs.versions.lintJvmTarget.get().toInt()) +} + +tasks.withType().configureEach { + compilerOptions { + // Lint forces its embedded kotlin version, so we need to match it. + apiVersion.set(KotlinVersion.KOTLIN_1_7) + languageVersion.set(KotlinVersion.KOTLIN_1_7) + jvmTarget.set(libs.versions.lintJvmTarget.map(JvmTarget::fromTarget)) + } +} + +dependencies { + ksp(libs.autoService.ksp) + + compileOnly(libs.autoService.annotations) + compileOnly(libs.build.lint.api) + + testImplementation(libs.test.junit) + testImplementation(libs.build.lint.core) + testImplementation(libs.build.lint.tests) +} diff --git a/static-analysis/autodispose-lint/gradle.properties b/static-analysis/autodispose-lint/gradle.properties index 41acfb12c..f0152bdd8 100644 --- a/static-analysis/autodispose-lint/gradle.properties +++ b/static-analysis/autodispose-lint/gradle.properties @@ -5,7 +5,7 @@ # 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 +# https://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, @@ -18,3 +18,7 @@ POM_NAME=AutoDispose Lint Checks POM_ARTIFACT_ID=autodispose-lint POM_PACKAGING=jar AUTOMATIC_MODULE_NAME=autodispose2.lint + +# Kotlin adds the stdlib dep by default in 1.4.0+, but that's not really allowed in lint jars. This +# disables that behavior for now +kotlin.stdlib.default.dependency=false diff --git a/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeDetector.kt b/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeDetector.kt index 298cafd3a..218c95fe5 100644 --- a/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeDetector.kt +++ b/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeDetector.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -33,6 +33,9 @@ import com.intellij.psi.PsiMethod import com.intellij.psi.PsiSynchronizedStatement import com.intellij.psi.PsiType import com.intellij.psi.util.PsiUtil +import java.io.StringReader +import java.util.EnumSet +import java.util.Properties import org.jetbrains.uast.UAnnotationMethod import org.jetbrains.uast.UBlockExpression import org.jetbrains.uast.UCallExpression @@ -52,48 +55,47 @@ import org.jetbrains.uast.getContainingUClass import org.jetbrains.uast.getParentOfType import org.jetbrains.uast.skipParenthesizedExprUp import org.jetbrains.uast.visitor.AbstractUastVisitor -import java.io.StringReader -import java.util.EnumSet -import java.util.Properties internal const val CUSTOM_SCOPE_KEY = "autodispose.typesWithScope" internal const val LENIENT = "autodispose.lenient" internal const val OVERRIDE_SCOPES = "autodispose.overrideScopes" internal const val KOTLIN_EXTENSION_FUNCTIONS = "autodispose.kotlinExtensionFunctions" -/** - * Detector which checks if your stream subscriptions are handled by AutoDispose. - */ +/** Detector which checks if your stream subscriptions are handled by AutoDispose. */ public class AutoDisposeDetector : Detector(), SourceCodeScanner { internal companion object { - internal const val LINT_DESCRIPTION = "Missing Disposable handling: Apply AutoDispose or cache " + - "the Disposable instance manually and enable lenient mode." - - internal val ISSUE: Issue = Issue.create( - "AutoDispose", - LINT_DESCRIPTION, - "You're subscribing to an observable but not handling its subscription. This " + - "can result in memory leaks. You can avoid memory leaks by appending " + - "`.as(autoDisposable(this))` before you subscribe or cache the Disposable instance" + - " manually and enable lenient mode. More: https://github.com/uber/AutoDispose/wiki/Lint-Check", - Category.CORRECTNESS, - 10, - Severity.ERROR, - // We use the overloaded constructor that takes a varargs of `Scope` as the last param. - // This is to enable on-the-fly IDE checks. We are telling lint to run on both - // JAVA and TEST_SOURCES in the `scope` parameter but by providing the `analysisScopes` - // params, we're indicating that this check can run on either JAVA or TEST_SOURCES and - // doesn't require both of them together. - // From discussion on lint-dev https://groups.google.com/d/msg/lint-dev/ULQMzW1ZlP0/1dG4Vj3-AQAJ - // TODO: This was supposed to be fixed in AS 3.4 but still required as recently as 3.6-alpha10. - Implementation( - AutoDisposeDetector::class.java, - EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES), - EnumSet.of(Scope.JAVA_FILE), - EnumSet.of(Scope.TEST_SOURCES) + internal const val LINT_DESCRIPTION = + "Missing Disposable handling: Apply AutoDispose or cache " + + "the Disposable instance manually and enable lenient mode." + + internal val ISSUE: Issue = + Issue.create( + "AutoDispose", + LINT_DESCRIPTION, + "You're subscribing to an observable but not handling its subscription. This " + + "can result in memory leaks. You can avoid memory leaks by appending " + + "`.as(autoDisposable(this))` before you subscribe or cache the Disposable instance" + + " manually and enable lenient mode. More: https://github.com/uber/AutoDispose/wiki/Lint-Check", + Category.CORRECTNESS, + 10, + Severity.ERROR, + // We use the overloaded constructor that takes a varargs of `Scope` as the last param. + // This is to enable on-the-fly IDE checks. We are telling lint to run on both + // JAVA and TEST_SOURCES in the `scope` parameter but by providing the `analysisScopes` + // params, we're indicating that this check can run on either JAVA or TEST_SOURCES and + // doesn't require both of them together. + // From discussion on lint-dev + // https://groups.google.com/d/msg/lint-dev/ULQMzW1ZlP0/1dG4Vj3-AQAJ + // TODO: This was supposed to be fixed in AS 3.4 but still required as recently as + // 3.6-alpha10. + Implementation( + AutoDisposeDetector::class.java, + EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES), + EnumSet.of(Scope.JAVA_FILE), + EnumSet.of(Scope.TEST_SOURCES) + ) ) - ) private const val OBSERVABLE = "io.reactivex.rxjava3.core.Observable" private const val FLOWABLE = "io.reactivex.rxjava3.core.Flowable" @@ -104,17 +106,16 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { private const val KOTLIN_EXTENSIONS = "autodispose2.KotlinExtensions" // The default scopes for Android. - private val DEFAULT_SCOPES = setOf( - "androidx.lifecycle.LifecycleOwner", - "autodispose2.ScopeProvider", - "android.app.Activity", - "android.app.Fragment" - ) - - private val REACTIVE_TYPES = setOf( - OBSERVABLE, FLOWABLE, PARALLEL_FLOWABLE, SINGLE, MAYBE, - COMPLETABLE - ) + private val DEFAULT_SCOPES = + setOf( + "androidx.lifecycle.LifecycleOwner", + "autodispose2.ScopeProvider", + "android.app.Activity", + "android.app.Fragment" + ) + + private val REACTIVE_TYPES = + setOf(OBSERVABLE, FLOWABLE, PARALLEL_FLOWABLE, SINGLE, MAYBE, COMPLETABLE) private val REACTIVE_SUBSCRIBE_METHOD_NAMES = setOf("subscribe", "subscribeWith") @@ -137,41 +138,41 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { // Add the custom scopes defined in configuration. val props = Properties() - context.project.propertyFiles.find { it.name == PROPERTY_FILE }?.apply { - val content = StringReader(context.client.readFile(this).toString()) - props.load(content) - props.getProperty(CUSTOM_SCOPE_KEY)?.let { scopeProperty -> - val customScopes = scopeProperty.split(",") - .asSequence() - .map(String::trim) - .filter(String::isNotBlank) - .toList() - scopes.addAll(customScopes) - } - props.getProperty(KOTLIN_EXTENSION_FUNCTIONS)?.let { ktExtensionProperty -> - ktExtensionProperty.split(",") - .forEach { + context.project.propertyFiles + .find { it.name == PROPERTY_FILE } + ?.apply { + val content = StringReader(context.client.readFile(this).toString()) + props.load(content) + props.getProperty(CUSTOM_SCOPE_KEY)?.let { scopeProperty -> + val customScopes = + scopeProperty + .split(",") + .asSequence() + .map(String::trim) + .filter(String::isNotBlank) + .toList() + scopes.addAll(customScopes) + } + props.getProperty(KOTLIN_EXTENSION_FUNCTIONS)?.let { ktExtensionProperty -> + ktExtensionProperty.split(",").forEach { val arr = it.split("#", limit = 2) if (arr.size >= 2) { val (packageName, methodName) = arr ktExtensionMethodToPackageMap.getOrPut(methodName, ::mutableSetOf).add(packageName) } } + } + props.getProperty(LENIENT)?.toBoolean()?.let { lenient = it } + props.getProperty(OVERRIDE_SCOPES)?.toBoolean()?.let { overrideScopes = it } } - props.getProperty(LENIENT)?.toBoolean()?.let { - lenient = it - } - props.getProperty(OVERRIDE_SCOPES)?.toBoolean()?.let { - overrideScopes = it - } - } // If scopes are not overridden, add the default ones. if (!overrideScopes) { scopes.addAll(DEFAULT_SCOPES) } this.appliedScopes = scopes this.ktExtensionMethodToPackageMap = ktExtensionMethodToPackageMap - this.appliedMethodNames = (REACTIVE_SUBSCRIBE_METHOD_NAMES + ktExtensionMethodToPackageMap.keys).toList() + this.appliedMethodNames = + (REACTIVE_SUBSCRIBE_METHOD_NAMES + ktExtensionMethodToPackageMap.keys).toList() } override fun getApplicableMethodNames(): List = appliedMethodNames @@ -191,31 +192,26 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { // Check if it's one of our withScope() higher order functions. If so, we handle that // separately and visit the passed in lambda body and run the subscribe method call checks // inside it with the "isInScope" check just hardcoded to true. - if (method.name == "withScope" && - method.containingClass?.qualifiedName == KOTLIN_EXTENSIONS + if ( + method.name == "withScope" && method.containingClass?.qualifiedName == KOTLIN_EXTENSIONS ) { val args = node.valueArguments - if (args.size == 2) { - val last = args[1] - // Check the lambda type too because it's a cheaper instance check - if (last is ULambdaExpression) { - // This is the AutoDisposeContext.() call - // TODO we can't determine this exactly with lint as far as I can tell - - val body = last.body - val visitor = SubscribeCallVisitor( - context, - callExpressionChecker = { context, node, calledMethod -> - callExpressionChecker(context, node, calledMethod) { _, _ -> true } - }, - callableReferenceChecker = { context, node, calledMethod -> - callableReferenceChecker(context, node, calledMethod) { _, _ -> true } - } - ) - body.accept(visitor) - return@let - } - } + val contextArg = args.filterIsInstance().firstOrNull() ?: return@let + // Check the lambda type too because it's a cheaper instance check + // This is the AutoDisposeContext.() call + val body = contextArg.body + val visitor = + SubscribeCallVisitor( + context, + callExpressionChecker = { context, node, calledMethod -> + callExpressionChecker(context, node, calledMethod) { _, _ -> true } + }, + callableReferenceChecker = { context, node, calledMethod -> + callableReferenceChecker(context, node, calledMethod) { _, _ -> true } + } + ) + body.accept(visitor) + return@let } callExpressionChecker(context, node, method, ::containingClassScopeChecker) } @@ -248,7 +244,8 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { private class SubscribeCallVisitor( private val context: JavaContext, private val callExpressionChecker: (JavaContext, UCallExpression, PsiMethod) -> Unit, - private val callableReferenceChecker: (JavaContext, UCallableReferenceExpression, PsiMethod) -> Unit + private val callableReferenceChecker: + (JavaContext, UCallableReferenceExpression, PsiMethod) -> Unit ) : AbstractUastVisitor() { override fun visitCallExpression(node: UCallExpression): Boolean { @@ -272,45 +269,43 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { /** * Checks if the calling method is in "scope" that can be handled by AutoDispose. * - * If your `subscribe`/`subscribeWith` method is called in a scope - * that is recognized by AutoDispose, this returns true. This indicates that - * you're subscribing in a scope and therefore, you must handle the subscription. - * Default scopes include Android activities, fragments and custom classes that - * implement ScopeProvider. + * If your `subscribe`/`subscribeWith` method is called in a scope that is recognized by + * AutoDispose, this returns true. This indicates that you're subscribing in a scope and + * therefore, you must handle the subscription. Default scopes include Android activities, + * fragments and custom classes that implement ScopeProvider. * * @param evaluator the java evaluator. * @param node the call expression. * @return whether the `subscribe` method is called "in-scope". * @see appliedScopes */ - private fun containingClassScopeChecker(evaluator: JavaEvaluator, node: UCallExpression): Boolean { + private fun containingClassScopeChecker( + evaluator: JavaEvaluator, + node: UCallExpression + ): Boolean { node.getContainingUClass()?.let { callingClass -> - return appliedScopes.any { - evaluator.inheritsFrom(callingClass, it, false) - } + return appliedScopes.any { evaluator.inheritsFrom(callingClass, it, false) } } return false } private fun isReactiveType(evaluator: JavaEvaluator, method: PsiMethod): Boolean { - return REACTIVE_SUBSCRIBE_METHOD_NAMES.contains(method.name) && REACTIVE_TYPES.any { - evaluator.isMemberInClass(method, it) - } + return REACTIVE_SUBSCRIBE_METHOD_NAMES.contains(method.name) && + REACTIVE_TYPES.any { evaluator.isMemberInClass(method, it) } } private fun isKotlinExtension(evaluator: JavaEvaluator, method: PsiMethod): Boolean { - return ktExtensionMethodToPackageMap[method.name]?.any { - evaluator.isMemberInClass(method, it) - } ?: false + return ktExtensionMethodToPackageMap[method.name]?.any { evaluator.isMemberInClass(method, it) } + ?: false } /** * Returns whether the given [returnType] is allowed to bypass the lint check. * - * If a `subscribe`/`subscribeWith` method return type is captured by the consumer - * AND the return type implements Disposable, we let it bypass the lint check. - * For example, subscribing with a plain Observer instead of a DiposableObserver will - * not bypass the lint check since Observer doesn't extend Disposable. + * If a `subscribe`/`subscribeWith` method return type is captured by the consumer AND the return + * type implements Disposable, we let it bypass the lint check. For example, subscribing with a + * plain Observer instead of a DiposableObserver will not bypass the lint check since Observer + * doesn't extend Disposable. * * @param returnType the return type of the `subscribe`/`subscribeWith` call. * @param evaluator the evaluator. @@ -339,8 +334,9 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { if (!getApplicableMethodNames().contains(method.name)) return val evaluator = context.evaluator - val shouldReport = (isReactiveType(evaluator, method) || isKotlinExtension(evaluator, method)) && - isInScope(evaluator, node) + val shouldReport = + (isReactiveType(evaluator, method) || isKotlinExtension(evaluator, method)) && + isInScope(evaluator, node) if (shouldReport) { if (!lenient) { context.report(ISSUE, node, context.getLocation(node), LINT_DESCRIPTION) @@ -358,7 +354,8 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { /** * Checks whether the given expression's return value is unused. * - * Borrowed from https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CheckResultDetector.kt;l=289;drc=c5fd7e6e7dd92bf3c57c6fe7a3a3a3ab61f4aec6 + * Borrowed from + * https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CheckResultDetector.kt;l=289;drc=c5fd7e6e7dd92bf3c57c6fe7a3a3a3ab61f4aec6 * * @param element the element to be analyzed. * @return whether the expression is unused. @@ -378,7 +375,10 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { } var curr: UElement = prev.uastParent ?: return true - while (curr is UQualifiedReferenceExpression && curr.selector === prev || curr is UParenthesizedExpression) { + while ( + curr is UQualifiedReferenceExpression && curr.selector === prev || + curr is UParenthesizedExpression + ) { prev = curr curr = curr.uastParent ?: return true } @@ -414,9 +414,10 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner { val parent = skipParenthesizedExprUp(curr.uastParent) if (parent is ULambdaExpression && isKotlin(curr.sourcePsi)) { val expressionType = parent.getExpressionType()?.canonicalText - if (expressionType != null && - expressionType.startsWith("kotlin.jvm.functions.Function") && - expressionType.endsWith("kotlin.Unit>") + if ( + expressionType != null && + expressionType.startsWith("kotlin.jvm.functions.Function") && + expressionType.endsWith("kotlin.Unit>") ) { // We know that this lambda does not return anything so the value is unused return true diff --git a/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeIssueRegistry.kt b/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeIssueRegistry.kt index d0f6ace6e..23936708b 100644 --- a/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeIssueRegistry.kt +++ b/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeIssueRegistry.kt @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/static-analysis/autodispose-lint/src/test/kotlin/autodispose2/lint/AutoDisposeDetectorTest.kt b/static-analysis/autodispose-lint/src/test/kotlin/autodispose2/lint/AutoDisposeDetectorTest.kt index 266f6bc8b..628765d13 100644 --- a/static-analysis/autodispose-lint/src/test/kotlin/autodispose2/lint/AutoDisposeDetectorTest.kt +++ b/static-analysis/autodispose-lint/src/test/kotlin/autodispose2/lint/AutoDisposeDetectorTest.kt @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -20,95 +20,103 @@ import com.android.tools.lint.checks.infrastructure.TestFile import com.android.tools.lint.checks.infrastructure.TestFiles.LibraryReferenceTestFile import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue +import java.io.File import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import java.io.File @RunWith(JUnit4::class) internal class AutoDisposeDetectorTest : LintDetectorTest() { companion object { // Stub activity - private val ACTIVITY = java( - """ + private val ACTIVITY = + java( + """ package androidx.appcompat.app; import androidx.lifecycle.LifecycleOwner; public class AppCompatActivity implements LifecycleOwner { } """ - ).indented() + ) + .indented() // Stub LifecycleOwner - private val LIFECYCLE_OWNER = java( - """ + private val LIFECYCLE_OWNER = + java(""" package androidx.lifecycle; public interface LifecycleOwner {} - """ - ).indented() + """) + .indented() // Stub Fragment - private val FRAGMENT = java( - """ + private val FRAGMENT = + java( + """ package androidx.fragment.app; import androidx.lifecycle.LifecycleOwner; public class Fragment implements LifecycleOwner {} """ - ).indented() + ) + .indented() // Stub Scope Provider - private val SCOPE_PROVIDER = kotlin( - """ + private val SCOPE_PROVIDER = + kotlin(""" package autodispose2 interface ScopeProvider - """ - ).indented() + """).indented() // Stub LifecycleScopeProvider - private val LIFECYCLE_SCOPE_PROVIDER = kotlin( - """ + private val LIFECYCLE_SCOPE_PROVIDER = + kotlin( + """ package autodispose2.lifecycle import autodispose2.ScopeProvider interface LifecycleScopeProvider: ScopeProvider """ - ).indented() + ) + .indented() // Custom Scope - private val CUSTOM_SCOPE = kotlin( - """ + private val CUSTOM_SCOPE = + kotlin(""" package autodispose2.sample class ClassWithCustomScope - """ - ).indented() + """) + .indented() - private val AUTODISPOSE_CONTEXT = kotlin( - """ + private val AUTODISPOSE_CONTEXT = + kotlin(""" package autodispose2 interface AutoDisposeContext - """ - ).indented() + """).indented() - private val WITH_SCOPE_PROVIDER = kotlin( - "autodispose2/KotlinExtensions.kt", - """ + private val WITH_SCOPE_PROVIDER = + kotlin( + "autodispose2/KotlinExtensions.kt", + """ @file:JvmName("KotlinExtensions") package autodispose2 fun withScope(scope: ScopeProvider, body: AutoDisposeContext.() -> Unit) { } """ - ).indented().within("src/") + ) + .indented() + .within("src/") - private val WITH_SCOPE_COMPLETABLE = kotlin( - "autodispose2/KotlinExtensions.kt", - """ + private val WITH_SCOPE_COMPLETABLE = + kotlin( + "autodispose2/KotlinExtensions.kt", + """ @file:JvmName("KotlinExtensions") package autodispose2 @@ -117,11 +125,14 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { fun withScope(scope: Completable, body: AutoDisposeContext.() -> Unit) { } """ - ).indented().within("src/") + ) + .indented() + .within("src/") - private val RX_KOTLIN = kotlin( - "io/reactivex/rxjava3/kotlin/subscribers.kt", - """ + private val RX_KOTLIN = + kotlin( + "io/reactivex/rxjava3/kotlin/subscribers.kt", + """ @file:JvmName("subscribers") package io.reactivex.rxjava3.kotlin @@ -132,14 +143,17 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { onNext: (G) -> Unit ): Disposable = subscribe() """ - ).indented().within("src/") - - private fun propertiesFile(lenient: Boolean = true, kotlinExtensionFunctions: String? = null): TestFile.PropertyTestFile { + ) + .indented() + .within("src/") + + private fun propertiesFile( + lenient: Boolean = true, + kotlinExtensionFunctions: String? = null + ): TestFile.PropertyTestFile { val properties = projectProperties() properties.property(LENIENT, lenient.toString()) - kotlinExtensionFunctions?.also { - properties.property(KOTLIN_EXTENSION_FUNCTIONS, it) - } + kotlinExtensionFunctions?.also { properties.property(KOTLIN_EXTENSION_FUNCTIONS, it) } properties.to(AutoDisposeDetector.PROPERTY_FILE) return properties } @@ -149,14 +163,15 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } - @Test fun observableErrorsOutOnOmittingAutoDispose() { + @Test + fun observableErrorsOutOnOmittingAutoDispose() { lint() .files( *jars(), LIFECYCLE_OWNER, FRAGMENT, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import androidx.fragment.app.Fragment; @@ -168,23 +183,26 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.java:8: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | obs.subscribe(); | ~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun observableDisposesSubscriptionJava() { + @Test + fun observableDisposesSubscriptionJava() { lint() .files( *jars(), java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import autodispose2.AutoDispose; @@ -198,21 +216,23 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .allowCompilationErrors() // Lint 30 doesn't understand subscribeProxies for some reason .run() .expectClean() } - @Test fun observableSubscribeWithNotHandled() { + @Test + fun observableSubscribeWithNotHandled() { lint() .files( *jars(), LIFECYCLE_OWNER, FRAGMENT, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.observers.DisposableObserver; @@ -235,18 +255,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.java:9: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | obs.subscribeWith(new DisposableObserver() { | ^ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun observableSubscribeWithDisposed() { + @Test + fun observableSubscribeWithDisposed() { lint() .files( *jars(), @@ -254,7 +277,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { LIFECYCLE_OWNER, FRAGMENT, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.observers.DisposableObserver; @@ -281,19 +304,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .allowCompilationErrors() // Lint 30 doesn't understand subscribeWith for some reason .run() .expectClean() } - @Test fun observableDisposesSubscriptionKotlin() { + @Test + fun observableDisposesSubscriptionKotlin() { lint() .files( *jars(), kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Observable import autodispose2.autoDispose @@ -307,21 +332,22 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU .run() .expectClean() } - @Test fun singleErrorsOutOnOmittingAutoDispose() { + @Test + fun singleErrorsOutOnOmittingAutoDispose() { lint() .files( *jars(), LIFECYCLE_OWNER, ACTIVITY, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Single; import androidx.appcompat.app.AppCompatActivity; @@ -333,23 +359,26 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.java:8: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | single.subscribe(); | ~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun singleDisposesSubscriptionJava() { + @Test + fun singleDisposesSubscriptionJava() { lint() .files( *jars(), java( - """ + """ package foo; import io.reactivex.rxjava3.core.Single; import autodispose2.AutoDispose; @@ -363,19 +392,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .allowCompilationErrors() // Lint 30 doesn't understand subscribeProxies for some reason .run() .expectClean() } - @Test fun singleDisposesSubscriptionKotlin() { + @Test + fun singleDisposesSubscriptionKotlin() { lint() .files( *jars(), kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Single import autodispose2.ScopeProvider @@ -389,20 +420,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU .run() .expectClean() } - @Test fun flowableErrorsOutOnOmittingAutoDispose() { + @Test + fun flowableErrorsOutOnOmittingAutoDispose() { lint() .files( *jars(), LIFECYCLE_OWNER, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Flowable; import androidx.lifecycle.LifecycleOwner; @@ -414,23 +446,26 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.java:8: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | flowable.subscribe(); | ~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun flowableDisposesSubscriptionJava() { + @Test + fun flowableDisposesSubscriptionJava() { lint() .files( *jars(), java( - """ + """ package foo; import io.reactivex.rxjava3.core.Flowable; import autodispose2.AutoDispose; @@ -444,22 +479,24 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .allowCompilationErrors() // Lint 30 doesn't understand subscribeProxies for some reason .run() .expectClean() } - @Test fun flowableDisposesSubscriptionKotlin() { + @Test + fun flowableDisposesSubscriptionKotlin() { lint() .files( *jars(), LIFECYCLE_SCOPE_PROVIDER, kotlin( - """ + """ package foo - import io.reactivex.rxjava3.core.Observable + import io.reactivex.rxjava3.core.Flowable import autodispose2.autoDispose import autodispose2.lifecycle.LifecycleScopeProvider @@ -470,20 +507,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU .run() .expectClean() } - @Test fun completableErrorsOutOnOmittingAutoDispose() { + @Test + fun completableErrorsOutOnOmittingAutoDispose() { lint() .files( *jars(), SCOPE_PROVIDER, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Completable import autodispose2.ScopeProvider @@ -495,23 +533,26 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.kt:8: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | completable.subscribe() | ~~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun completableSubscriptionNonScopedClass() { + @Test + fun completableSubscriptionNonScopedClass() { lint() .files( *jars(), java( - """ + """ package foo; import io.reactivex.rxjava3.core.Completable; import autodispose2.ScopeProvider; @@ -524,20 +565,22 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expectClean() } - @Test fun completableDisposesSubscriptionKotlin() { + @Test + fun completableDisposesSubscriptionKotlin() { lint() .files( *jars(), kotlin( - """ + """ package foo - import io.reactivex.rxjava3.core.Observable + import io.reactivex.rxjava3.core.Completable import autodispose2.ScopeProvider import autodispose2.autoDispose @@ -549,21 +592,22 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU .run() .expectClean() } - @Test fun maybeErrorsOutOnOmittingAutoDispose() { + @Test + fun maybeErrorsOutOnOmittingAutoDispose() { lint() .files( *jars(), LIFECYCLE_OWNER, ACTIVITY, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Maybe import androidx.appcompat.app.AppCompatActivity @@ -575,23 +619,26 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.kt:8: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | maybe.subscribe() | ~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun maybeDisposesSubscriptionJava() { + @Test + fun maybeDisposesSubscriptionJava() { lint() .files( *jars(), java( - """ + """ package foo; import io.reactivex.rxjava3.core.Maybe; import autodispose2.AutoDispose; @@ -605,19 +652,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .allowCompilationErrors() // Lint 30 doesn't understand subscribeProxies for some reason .run() .expectClean() } - @Test fun maybeDisposesSubscriptionKotlin() { + @Test + fun maybeDisposesSubscriptionKotlin() { lint() .files( *jars(), kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Maybe import autodispose2.autoDispose @@ -631,24 +680,26 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU .run() .expectClean() } - @Test fun customScopeWithoutAutoDispose() { + @Test + fun customScopeWithoutAutoDispose() { val properties = projectProperties() properties.property(CUSTOM_SCOPE_KEY, "autodispose2.sample.ClassWithCustomScope") properties.to(AutoDisposeDetector.PROPERTY_FILE) - lint().files( - *jars(), - CUSTOM_SCOPE, - properties, - kotlin( - """ + lint() + .files( + *jars(), + CUSTOM_SCOPE, + properties, + kotlin( + """ package autodispose2.sample import autodispose2.sample.ClassWithCustomScope import io.reactivex.rxjava3.core.Observable @@ -660,29 +711,33 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expect( """ src/autodispose2/sample/MyCustomClass.kt:8: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | observable.subscribe() | ~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun customScopeWithAutoDispose() { + @Test + fun customScopeWithAutoDispose() { val properties = projectProperties() properties.property(CUSTOM_SCOPE_KEY, "autodispose2.sample.ClassWithCustomScope") properties.to(AutoDisposeDetector.PROPERTY_FILE) - lint().files( - *jars(), - CUSTOM_SCOPE, - properties, - kotlin( - """ + lint() + .files( + *jars(), + CUSTOM_SCOPE, + properties, + kotlin( + """ package autodispose2.sample import autodispose2.sample.ClassWithCustomScope import io.reactivex.rxjava3.core.Observable @@ -697,23 +752,25 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU + ) + .indented() + ) .run() .expectClean() } - @Test fun emptyCustomScopeWithoutAutoDispose() { + @Test + fun emptyCustomScopeWithoutAutoDispose() { val properties = projectProperties() properties.to(AutoDisposeDetector.PROPERTY_FILE) - lint().files( - *jars(), - CUSTOM_SCOPE, - properties, - kotlin( - """ + lint() + .files( + *jars(), + CUSTOM_SCOPE, + properties, + kotlin( + """ package autodispose2.sample import autodispose2.sample.ClassWithCustomScope import io.reactivex.rxjava3.core.Observable @@ -727,25 +784,28 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expectClean() } - @Test fun overrideCustomScopeWithoutAutoDispose() { + @Test + fun overrideCustomScopeWithoutAutoDispose() { val properties = projectProperties() properties.property(CUSTOM_SCOPE_KEY, "autodispose2.sample.ClassWithCustomScope") properties.property(OVERRIDE_SCOPES, "true") properties.to(AutoDisposeDetector.PROPERTY_FILE) - lint().files( - *jars(), - LIFECYCLE_OWNER, - ACTIVITY, - properties, - kotlin( - """ + lint() + .files( + *jars(), + LIFECYCLE_OWNER, + ACTIVITY, + properties, + kotlin( + """ package autodispose2.sample import autodispose2.sample.ClassWithCustomScope import androidx.appcompat.app.AppCompatActivity @@ -760,25 +820,28 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .allowCompilationErrors() // TODO or replace with a real sample stub? .run() .expectClean() } - @Test fun overrideCustomScopeWithAutoDispose() { + @Test + fun overrideCustomScopeWithAutoDispose() { val properties = projectProperties() properties.property(CUSTOM_SCOPE_KEY, "autodispose2.sample.ClassWithCustomScope") properties.property(OVERRIDE_SCOPES, "true") properties.to(AutoDisposeDetector.PROPERTY_FILE) - lint().files( - *jars(), - CUSTOM_SCOPE, - properties, - kotlin( - """ + lint() + .files( + *jars(), + CUSTOM_SCOPE, + properties, + kotlin( + """ package autodispose2.sample import autodispose2.sample.ClassWithCustomScope import io.reactivex.rxjava3.core.Observable @@ -793,22 +856,24 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU + ) + .indented() + ) .run() .expectClean() } - @Test fun capturedDisposable() { + @Test + fun capturedDisposable() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -819,21 +884,24 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expectClean() } - @Test fun nestedDisposable() { + @Test + fun nestedDisposable() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -848,19 +916,22 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expectClean() } - @Test fun subscribeWithLambda() { - lint().files( - *jars(), - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + @Test + fun subscribeWithLambda() { + lint() + .files( + *jars(), + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -874,26 +945,30 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expect( """src/foo/MyActivity.kt:10: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | Observable.just(1,2,3).subscribe {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun checkLenientLintInIfExpression() { + @Test + fun checkLenientLintInIfExpression() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -910,8 +985,9 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expect( """ @@ -921,19 +997,22 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { |src/foo/MyActivity.kt:12: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | Observable.just(2).subscribe() | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |2 errors, 0 warnings""".trimMargin() + |2 errors, 0 warnings""" + .trimMargin() ) } - @Test fun checkLenientLintInIfExpressionCaptured() { + @Test + fun checkLenientLintInIfExpressionCaptured() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -950,21 +1029,24 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expectClean() } - @Test fun checkLenientLintInWhenExpression() { + @Test + fun checkLenientLintInWhenExpression() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -980,8 +1062,9 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expect( """ @@ -991,19 +1074,22 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { |src/foo/MyActivity.kt:11: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | false -> Observable.just(2).subscribe() | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |2 errors, 0 warnings""".trimMargin() + |2 errors, 0 warnings""" + .trimMargin() ) } - @Test fun checkLenientLintInWhenExpressionCaptured() { + @Test + fun checkLenientLintInWhenExpressionCaptured() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -1019,21 +1105,24 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expectClean() } - @Test fun checkLenientLintInLambdaWithUnitReturnExpression() { + @Test + fun checkLenientLintInLambdaWithUnitReturnExpression() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -1049,27 +1138,31 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expect( """ |src/foo/MyActivity.kt:11: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | Observable.just(1).subscribe() | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun checkLenientLintInLambdaWithNonUnitReturnExpression() { + @Test + fun checkLenientLintInLambdaWithNonUnitReturnExpression() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -1086,27 +1179,31 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expect( """ |src/foo/MyActivity.kt:11: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | Observable.just(1).subscribe() | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun checkLenientLintInLambdaExpressionCaptured() { + @Test + fun checkLenientLintInLambdaExpressionCaptured() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - kotlin( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + kotlin( + """ package foo import androidx.appcompat.app.AppCompatActivity import io.reactivex.rxjava3.core.Observable @@ -1122,21 +1219,24 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expectClean() } - @Test fun javaCapturedDisposable() { + @Test + fun javaCapturedDisposable() { val propertiesFile = lenientPropertiesFile() - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - java( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + java( + """ package foo; import androidx.appcompat.app.AppCompatActivity; import io.reactivex.rxjava3.core.Observable; @@ -1148,21 +1248,24 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expectClean() } - @Test fun javaCapturedDisposableWithoutLenientProperty() { + @Test + fun javaCapturedDisposableWithoutLenientProperty() { val propertiesFile = lenientPropertiesFile(false) - lint().files( - *jars(), - propertiesFile, - LIFECYCLE_OWNER, - ACTIVITY, - java( - """ + lint() + .files( + *jars(), + propertiesFile, + LIFECYCLE_OWNER, + ACTIVITY, + java( + """ package foo; import androidx.appcompat.app.AppCompatActivity; import io.reactivex.rxjava3.core.Observable; @@ -1174,25 +1277,28 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() - ) + ) + .indented() + ) .run() .expect( """src/foo/MyActivity.java:8: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | Disposable disposable = Observable.just(1, 2, 3).subscribe(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun subscribeWithCapturedNonDisposableFromMethodReference() { + @Test + fun subscribeWithCapturedNonDisposableFromMethodReference() { lint() .files( *jars(), LIFECYCLE_OWNER, FRAGMENT, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.observers.DisposableObserver; @@ -1231,18 +1337,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.java:13: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | Observer observer = methodReferencable(obs::subscribeWith); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun subscribeWithCapturedDisposableFromMethodReference() { + @Test + fun subscribeWithCapturedDisposableFromMethodReference() { val propertiesFile = lenientPropertiesFile() lint() .files( @@ -1251,7 +1360,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { LIFECYCLE_OWNER, FRAGMENT, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.observers.DisposableObserver; @@ -1289,13 +1398,15 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expectClean() } - @Test fun kotlinSubscribeWithCapturedNonDisposableFromMethodReference() { + @Test + fun kotlinSubscribeWithCapturedNonDisposableFromMethodReference() { val propertiesFile = lenientPropertiesFile() lint() .files( @@ -1304,7 +1415,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { LIFECYCLE_OWNER, FRAGMENT, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.observers.DisposableObserver @@ -1340,18 +1451,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.kt:12: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | val observer: Observer = methodReferencable(Function { observable.subscribeWith(it) }) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun kotlinSubscribeWithCapturedDisposableFromMethodReference() { + @Test + fun kotlinSubscribeWithCapturedDisposableFromMethodReference() { val propertiesFile = lenientPropertiesFile() lint() .files( @@ -1360,7 +1474,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { LIFECYCLE_OWNER, FRAGMENT, kotlin( - """ + """ package foo import androidx.fragment.app.Fragment import io.reactivex.rxjava3.core.Observable @@ -1393,13 +1507,15 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expectClean() } - @Test fun kotlinExtensionFunctionNotConfigured() { + @Test + fun kotlinExtensionFunctionNotConfigured() { lint() .files( *jars(), @@ -1407,7 +1523,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { RX_KOTLIN, FRAGMENT, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.observers.DisposableObserver @@ -1421,22 +1537,26 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expectClean() } - @Test fun kotlinExtensionFunctionNotHandled() { + @Test + fun kotlinExtensionFunctionNotHandled() { lint() .files( *jars(), - propertiesFile(kotlinExtensionFunctions = "io.reactivex.rxjava3.kotlin.subscribers#subscribeBy"), + propertiesFile( + kotlinExtensionFunctions = "io.reactivex.rxjava3.kotlin.subscribers#subscribeBy" + ), LIFECYCLE_OWNER, RX_KOTLIN, FRAGMENT, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.observers.DisposableObserver @@ -1450,25 +1570,28 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.kt:10: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | obs.subscribeBy { } | ~~~~~~~~~~~~~~~~~~~ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun subscribeWithCapturedNonDisposableType() { + @Test + fun subscribeWithCapturedNonDisposableType() { lint() .files( *jars(), LIFECYCLE_OWNER, FRAGMENT, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.observers.DisposableObserver; @@ -1496,18 +1619,21 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expect( """src/foo/ExampleClass.java:11: Error: ${AutoDisposeDetector.LINT_DESCRIPTION} [AutoDispose] | Observer disposable = obs.subscribeWith(new Observer() { | ^ - |1 errors, 0 warnings""".trimMargin() + |1 errors, 0 warnings""" + .trimMargin() ) } - @Test fun subscribeWithCapturedDisposable() { + @Test + fun subscribeWithCapturedDisposable() { val propertiesFile = lenientPropertiesFile() lint() .files( @@ -1516,7 +1642,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { LIFECYCLE_OWNER, FRAGMENT, java( - """ + """ package foo; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.observers.DisposableObserver; @@ -1540,13 +1666,15 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) .run() .expectClean() } - @Test fun withScope_withScopeProvider_missingAutoDispose_shouldError() { + @Test + fun withScope_withScopeProvider_missingAutoDispose_shouldError() { lint() .files( *jars(), @@ -1554,7 +1682,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { AUTODISPOSE_CONTEXT, WITH_SCOPE_PROVIDER, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Observable import autodispose2.ScopeProvider @@ -1570,21 +1698,22 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU .run() .expectErrorCount(1) } - @Test fun withScope_withCompletable_missingAutoDispose_shouldError() { + @Test + fun withScope_withCompletable_missingAutoDispose_shouldError() { lint() .files( *jars(), AUTODISPOSE_CONTEXT, WITH_SCOPE_COMPLETABLE, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.core.Observable @@ -1598,14 +1727,15 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU .run() .expectErrorCount(1) } - @Test fun withScope_withScopeProvider_expectClean() { + @Test + fun withScope_withScopeProvider_expectClean() { lint() .files( *jars(), @@ -1613,7 +1743,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { AUTODISPOSE_CONTEXT, WITH_SCOPE_PROVIDER, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Observable import autodispose2.ScopeProvider @@ -1629,23 +1759,27 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU + .allowCompilationErrors() // Until AGP 8.2.0 + // https://issuetracker.google.com/issues/283693338 .run() .expectClean() } - @Test fun withScope_withCompletable_expectClean() { + @Test + fun withScope_withCompletable_expectClean() { lint() .files( *jars(), AUTODISPOSE_CONTEXT, WITH_SCOPE_COMPLETABLE, kotlin( - """ + """ package foo import io.reactivex.rxjava3.core.Completable + import io.reactivex.rxjava3.core.Observable import autodispose2.autoDispose import autodispose2.withScope class ExampleClass { @@ -1657,9 +1791,11 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { } } """ - ).indented() + ) + .indented() ) - .allowCompilationErrors() // Until AGP 7.1.0 https://groups.google.com/g/lint-dev/c/BigCO8sMhKU + .allowCompilationErrors() // Until AGP 8.2.0 + // https://issuetracker.google.com/issues/283693338 .run() .expectClean() } @@ -1670,9 +1806,7 @@ internal class AutoDisposeDetectorTest : LintDetectorTest() { LibraryReferenceTestFile( File(classLoader.getResource("rxjava-3.1.0.jar")!!.toURI()), ), - LibraryReferenceTestFile( - File(classLoader.getResource("autodispose-2.0.0.jar")!!.toURI()) - ) + LibraryReferenceTestFile(File(classLoader.getResource("autodispose-2.0.0.jar")!!.toURI())) ) } diff --git a/test-utils/build.gradle b/test-utils/build.gradle.kts similarity index 72% rename from test-utils/build.gradle rename to test-utils/build.gradle.kts index 433d40077..dc46faa60 100644 --- a/test-utils/build.gradle +++ b/test-utils/build.gradle.kts @@ -1,11 +1,11 @@ /* - * Copyright (c) 2017. Uber Technologies + * 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 + * https://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, @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +plugins { alias(libs.plugins.kotlin.jvm) } dependencies { - api deps.rx.java - api deps.test.junit - api deps.test.truth + api(libs.rx.java) + api(libs.test.junit) + api(libs.test.truth) } diff --git a/test-utils/src/main/java/autodispose2/test/RecordingObserver.java b/test-utils/src/main/java/autodispose2/test/RecordingObserver.java index d85f70d90..933f3bdef 100644 --- a/test-utils/src/main/java/autodispose2/test/RecordingObserver.java +++ b/test-utils/src/main/java/autodispose2/test/RecordingObserver.java @@ -5,7 +5,7 @@ * 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 + * https://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, diff --git a/test-utils/src/main/java/autodispose2/test/RxErrorsRule.java b/test-utils/src/main/java/autodispose2/test/RxErrorsRule.java index 9087ea958..931a5d8bb 100644 --- a/test-utils/src/main/java/autodispose2/test/RxErrorsRule.java +++ b/test-utils/src/main/java/autodispose2/test/RxErrorsRule.java @@ -5,7 +5,7 @@ * 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 + * https://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, @@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat; +import io.reactivex.rxjava3.annotations.Nullable; import io.reactivex.rxjava3.exceptions.CompositeException; import io.reactivex.rxjava3.exceptions.UndeliverableException; import io.reactivex.rxjava3.plugins.RxJavaPlugins; @@ -33,11 +34,11 @@ @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public class RxErrorsRule extends TestWatcher { - private BlockingDeque errors = new LinkedBlockingDeque<>(); + private final BlockingDeque errors = new LinkedBlockingDeque<>(); @Override protected void starting(Description description) { - RxJavaPlugins.setErrorHandler(t -> errors.add(t)); + RxJavaPlugins.setErrorHandler(errors::add); } @Override @@ -62,6 +63,7 @@ public Throwable take() { return error; } + @Nullable public Throwable takeThrowableFromUndeliverableException() { Throwable error = take(); assertThat(error).isInstanceOf(UndeliverableException.class);