Skip to content

Commit

Permalink
Merge pull request #1 from square/master
Browse files Browse the repository at this point in the history
update fork
  • Loading branch information
CShiru authored May 29, 2020
2 parents cb3d64b + 96f68b5 commit dbc42c4
Show file tree
Hide file tree
Showing 67 changed files with 4,990 additions and 21 deletions.
4 changes: 1 addition & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ forking the repository and sending a pull request.

When submitting code, please make every effort to follow existing conventions
and style in order to keep the code as readable as possible. Please also make
sure your code compiles by running `mvn clean verify`. Checkstyle failures
during compilation indicate errors in your style and can be viewed in the
`checkstyle-result.xml` file.
sure your code compiles by running `./gradlew build` (or `gradlew.bat build` on Windows).

Before your code can be accepted into the project you must also sign the
[Individual Contributor License Agreement (CLA)][1].
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
Change Log
==========

Version 2.9.0 *(2020-05-20)*
----------------------------

* New: RxJava 3 adapter!

The Maven coordinates are `com.squareup.retrofit2:adapter-rxjava3`.

Unlike the RxJava 1 and RxJava 2 adapters, the RxJava 3 adapter's `create()` method will produce asynchronous HTTP requests by default. For synchronous requests use `createSynchronous()` and for synchronous on a scheduler use `createWithScheduler(..)`.


Version 2.8.2 *(2020-05-18)*
----------------------------

* Fix: Detect running on the Android platform by using system property rather than the presence of classes.
This ensures that even when you're running on the JVM with Android classes present on the classpath you
get JVM semantics.
* Fix: Update to OkHttp 3.14.9 which contains an associated Android platform detection fix.


Version 2.8.1 *(2020-03-25)*
----------------------------

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Retrofit
========

Type-safe HTTP client for Android and Java by Square, Inc.
A type-safe HTTP client for Android and Java.

For more information please see [the website][1].


Download
--------

Download [the latest JAR][2] or grab from Maven central at the coordinates `com.squareup.retrofit2:retrofit:2.8.1`.
Download [the latest JAR][2] or grab from Maven central at the coordinates `com.squareup.retrofit2:retrofit:2.9.0`.

Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap].

Expand Down
15 changes: 15 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Releasing
========

1. Change the version in `gradle.properties` to a non-SNAPSHOT verson.
2. Update the `CHANGELOG.md` for the impending release.
3. Update the `README.md` with the new version.
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
5. `./gradlew clean uploadArchives`.
6. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact.
7. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version)
8. Update the `gradle.properties` to the next SNAPSHOT version.
9. `git commit -am "Prepare next development version."`
10. `git push && git push --tags`

If step 5 or 6 fails, drop the Sonatype repo, fix the problem, commit, and start again at step 5.
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.gradle.internal.jvm.Jvm
buildscript {
ext.versions = [
'kotlin': '1.3.50',
'okhttp': '3.14.7',
'okhttp': '3.14.9',
'protobuf': '3.10.0',
'jaxb': '2.3.1',
]
Expand All @@ -22,6 +22,7 @@ buildscript {
'androidxTestRunner': 'androidx.test:runner:1.1.0',
'rxjava': 'io.reactivex:rxjava:1.3.8',
'rxjava2': 'io.reactivex.rxjava2:rxjava:2.0.0',
'rxjava3': 'io.reactivex.rxjava3:rxjava:3.0.0',
'reactiveStreams': 'org.reactivestreams:reactive-streams:1.0.3',
'scalaLibrary': 'org.scala-lang:scala-library:2.13.1',
'gson': 'com.google.code.gson:gson:2.8.5',
Expand Down Expand Up @@ -59,6 +60,12 @@ subprojects {
jcenter()
}

tasks.withType(JavaCompile).configureEach { task ->
task.options.encoding = 'UTF-8'
task.sourceCompatibility = JavaVersion.VERSION_1_8
task.targetCompatibility = JavaVersion.VERSION_1_8
}

// Error-prone only works on JDK 11 or older currently.
if (!Jvm.current().javaVersion.isJava12Compatible()) {
apply plugin: 'net.ltgt.errorprone'
Expand All @@ -69,10 +76,6 @@ subprojects {
}

tasks.withType(JavaCompile).configureEach { task ->
task.options.encoding = 'UTF-8'
task.sourceCompatibility = JavaVersion.VERSION_1_8
task.targetCompatibility = JavaVersion.VERSION_1_8

task.options.errorprone {
excludedPaths = '.*/build/generated/source/proto/.*'
check('MissingFail', CheckSeverity.ERROR)
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
GROUP=com.squareup.retrofit2
VERSION_NAME=2.9.0-SNAPSHOT
VERSION_NAME=2.10.0-SNAPSHOT

POM_URL=https://github.com/square/retrofit
POM_SCM_URL=https://github.com/square/retrofit/
POM_SCM_CONNECTION=scm:git:git://github.com/square/retrofit.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/square/retrofit.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=square
Expand Down
1 change: 1 addition & 0 deletions retrofit-adapters/guava/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
POM_ARTIFACT_ID=adapter-guava
POM_NAME=Adapter: Guava
POM_DESCRIPTION=A Retrofit CallAdapter for Guava's ListenableFuture.
1 change: 1 addition & 0 deletions retrofit-adapters/java8/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
POM_ARTIFACT_ID=adapter-java8
POM_NAME=Adapter: Java 8
POM_DESCRIPTION=A Retrofit CallAdapter for Java 8's CompletableFuture.
1 change: 1 addition & 0 deletions retrofit-adapters/rxjava/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
POM_ARTIFACT_ID=adapter-rxjava
POM_NAME=Adapter: RxJava
POM_DESCRIPTION=A Retrofit CallAdapter for RxJava's stream types.
1 change: 1 addition & 0 deletions retrofit-adapters/rxjava2/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
POM_ARTIFACT_ID=adapter-rxjava2
POM_NAME=Adapter: RxJava 2
POM_DESCRIPTION=A Retrofit CallAdapter for RxJava 2's stream types.
65 changes: 65 additions & 0 deletions retrofit-adapters/rxjava3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
RxJava3 Adapter
==============

An `Adapter` for adapting [RxJava 3.x][1] types.

Available types:

* `Observable<T>`, `Observable<Response<T>>`, and `Observable<Result<T>>` where `T` is the body type.
* `Flowable<T>`, `Flowable<Response<T>>` and `Flowable<Result<T>>` where `T` is the body type.
* `Single<T>`, `Single<Response<T>>`, and `Single<Result<T>>` where `T` is the body type.
* `Maybe<T>`, `Maybe<Response<T>>`, and `Maybe<Result<T>>` where `T` is the body type.
* `Completable` where response bodies are discarded.


Usage
-----

Add `RxJava3CallAdapterFactory` as a `Call` adapter when building your `Retrofit` instance:
```java
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://example.com/")
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.build();
```

Your service methods can now use any of the above types as their return type.
```java
interface MyService {
@GET("/user")
Observable<User> getUser();
}
```

By default, `create()` will produce reactive types which execute their HTTP requests asynchronously
on a background thread. There are two other ways to control the threading on which a request
occurs:

* Use `createSynchronous()` and call `subscribeOn` on the returned reactive type with a `Scheduler`
of your choice.
* Use `createWithScheduler(Scheduler)` to supply a default subscription `Scheduler`.

Download
--------

Download [the latest JAR][2] or grab via [Maven][3]:
```xml
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava3</artifactId>
<version>latest.version</version>
</dependency>
```
or [Gradle][3]:
```groovy
implementation 'com.squareup.retrofit2:adapter-rxjava3:latest.version'
```

Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap].



[1]: https://github.com/ReactiveX/RxJava/tree/3.x
[2]: https://search.maven.org/remote_content?g=com.squareup.retrofit2&a=adapter-rxjava3&v=LATEST
[3]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.squareup.retrofit2%22%20a%3A%22adapter-rxjava3%22
[snap]: https://oss.sonatype.org/content/repositories/snapshots/
20 changes: 20 additions & 0 deletions retrofit-adapters/rxjava3/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apply plugin: 'java-library'
apply plugin: 'com.vanniktech.maven.publish'

dependencies {
api project(':retrofit')
api deps.rxjava3
api deps.reactiveStreams
compileOnly deps.findBugsAnnotations

testImplementation deps.junit
testImplementation deps.assertj
testImplementation deps.guava
testImplementation deps.mockwebserver
}

jar {
manifest {
attributes 'Automatic-Module-Name': 'retrofit2.adapter.rxjava3'
}
}
3 changes: 3 additions & 0 deletions retrofit-adapters/rxjava3/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=adapter-rxjava3
POM_NAME=Adapter: RxJava 3
POM_DESCRIPTION=A Retrofit CallAdapter for RxJava 3's stream types.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2020 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package retrofit2.adapter.rxjava3;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.CompositeException;
import io.reactivex.rxjava3.exceptions.Exceptions;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import retrofit2.Response;

final class BodyObservable<T> extends Observable<T> {
private final Observable<Response<T>> upstream;

BodyObservable(Observable<Response<T>> upstream) {
this.upstream = upstream;
}

@Override
protected void subscribeActual(Observer<? super T> observer) {
upstream.subscribe(new BodyObserver<>(observer));
}

private static class BodyObserver<R> implements Observer<Response<R>> {
private final Observer<? super R> observer;
private boolean terminated;

BodyObserver(Observer<? super R> observer) {
this.observer = observer;
}

@Override
public void onSubscribe(Disposable disposable) {
observer.onSubscribe(disposable);
}

@Override
public void onNext(Response<R> response) {
if (response.isSuccessful()) {
observer.onNext(response.body());
} else {
terminated = true;
Throwable t = new HttpException(response);
try {
observer.onError(t);
} catch (Throwable inner) {
Exceptions.throwIfFatal(inner);
RxJavaPlugins.onError(new CompositeException(t, inner));
}
}
}

@Override
public void onComplete() {
if (!terminated) {
observer.onComplete();
}
}

@Override
public void onError(Throwable throwable) {
if (!terminated) {
observer.onError(throwable);
} else {
// This should never happen! onNext handles and forwards errors automatically.
Throwable broken =
new AssertionError(
"This should never happen! Report as a bug with the full stacktrace.");
//noinspection UnnecessaryInitCause Two-arg AssertionError constructor is 1.7+ only.
broken.initCause(throwable);
RxJavaPlugins.onError(broken);
}
}
}
}
Loading

0 comments on commit dbc42c4

Please sign in to comment.