Skip to content

Commit

Permalink
Merge pull request #3132 from square/jakew/updates/2019-06-22
Browse files Browse the repository at this point in the history
Update to Java 8 and OkHttp 3.14
  • Loading branch information
swankjesse committed Jul 3, 2019
2 parents 06978cc + 8c487d4 commit 2851c14
Show file tree
Hide file tree
Showing 55 changed files with 357 additions and 672 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ Download [the latest JAR][2] or grab from Maven central at the coordinates `com.

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

Retrofit requires at minimum Java 7 or Android 2.3.
Retrofit requires at minimum Java 8+ or Android API 21+.


R8 / ProGuard
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Expand Up @@ -25,7 +25,7 @@

<groupId>com.squareup.retrofit2</groupId>
<artifactId>parent</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Retrofit (Parent)</name>
Expand All @@ -45,12 +45,12 @@
<project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>

<!-- Compilation -->
<java.version>1.7</java.version>
<java.version>1.8</java.version>
<kotlin.version>1.3.10</kotlin.version>

<!-- Dependencies -->
<android.version>4.1.1.4</android.version>
<okhttp.version>3.12.0</okhttp.version>
<okhttp.version>3.14.0</okhttp.version>
<kotlinx.coroutines.version>1.1.0</kotlinx.coroutines.version>
<animal.sniffer.version>1.14</animal.sniffer.version>

Expand Down Expand Up @@ -319,8 +319,8 @@
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.1</version>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion retrofit-adapters/guava/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit-adapters</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package retrofit2.adapter.guava;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.MediaType;
Expand All @@ -26,21 +25,13 @@

final class StringConverterFactory extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
public Converter<ResponseBody, String> responseBodyConverter(Type type, Annotation[] annotations,
Retrofit retrofit) {
return new Converter<ResponseBody, String>() {
@Override public String convert(ResponseBody value) throws IOException {
return value.string();
}
};
return ResponseBody::string;
}

@Override public Converter<?, RequestBody> requestBodyConverter(Type type,
@Override public Converter<String, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return new Converter<String, RequestBody>() {
@Override public RequestBody convert(String value) throws IOException {
return RequestBody.create(MediaType.get("text/plain"), value);
}
};
return value -> RequestBody.create(MediaType.get("text/plain"), value);
}
}
14 changes: 1 addition & 13 deletions retrofit-adapters/java8/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit-adapters</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -53,18 +53,6 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>${animal.sniffer.version}</version>
<configuration>
<signature>
<groupId>org.kaazing.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package retrofit2.adapter.java8;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.MediaType;
Expand All @@ -26,21 +25,13 @@

final class StringConverterFactory extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
public Converter<ResponseBody, String> responseBodyConverter(Type type, Annotation[] annotations,
Retrofit retrofit) {
return new Converter<ResponseBody, String>() {
@Override public String convert(ResponseBody value) throws IOException {
return value.string();
}
};
return ResponseBody::string;
}

@Override public Converter<?, RequestBody> requestBodyConverter(Type type,
@Override public Converter<String, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return new Converter<String, RequestBody>() {
@Override public RequestBody convert(String value) throws IOException {
return RequestBody.create(MediaType.get("text/plain"), value);
}
};
return value -> RequestBody.create(MediaType.get("text/plain"), value);
}
}
2 changes: 1 addition & 1 deletion retrofit-adapters/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>parent</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion retrofit-adapters/rxjava/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit-adapters</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Expand Up @@ -26,7 +26,6 @@
import retrofit2.Retrofit;
import retrofit2.http.GET;
import rx.Observable;
import rx.functions.Action1;

import static okhttp3.mockwebserver.SocketPolicy.DISCONNECT_AFTER_REQUEST;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -139,12 +138,7 @@ interface Service {

final RecordingSubscriber<Response<String>> subscriber = subscriberRule.create();
service.response()
.doOnNext(new Action1<Response<String>>() {
@Override
public void call(Response<String> response) {
subscriber.unsubscribe();
}
})
.doOnNext(response -> subscriber.unsubscribe())
.subscribe(subscriber);

assertThat(subscriber.takeValue().body()).isEqualTo("Hi");
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package retrofit2.adapter.rxjava;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.MediaType;
Expand All @@ -26,21 +25,13 @@

final class StringConverterFactory extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
public Converter<ResponseBody, String> responseBodyConverter(Type type, Annotation[] annotations,
Retrofit retrofit) {
return new Converter<ResponseBody, String>() {
@Override public String convert(ResponseBody value) throws IOException {
return value.string();
}
};
return ResponseBody::string;
}

@Override public Converter<?, RequestBody> requestBodyConverter(Type type,
@Override public Converter<String, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return new Converter<String, RequestBody>() {
@Override public RequestBody convert(String value) throws IOException {
return RequestBody.create(MediaType.get("text/plain"), value);
}
};
return value -> RequestBody.create(MediaType.get("text/plain"), value);
}
}
2 changes: 1 addition & 1 deletion retrofit-adapters/rxjava2/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit-adapters</artifactId>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Expand Up @@ -18,7 +18,6 @@
import io.reactivex.Completable;
import io.reactivex.exceptions.CompositeException;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.Consumer;
import io.reactivex.observers.TestObserver;
import io.reactivex.plugins.RxJavaPlugins;
import java.io.IOException;
Expand All @@ -27,7 +26,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicReference;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -60,16 +58,10 @@ interface Service {
private List<Throwable> uncaughtExceptions = new ArrayList<>();

@Before public void setUp() {
ExecutorService executorService = Executors.newCachedThreadPool(new ThreadFactory() {
@Override public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override public void uncaughtException(Thread t, Throwable e) {
uncaughtExceptions.add(e);
}
});
return thread;
}
ExecutorService executorService = Executors.newCachedThreadPool(r -> {
Thread thread = new Thread(r);
thread.setUncaughtExceptionHandler((t, e) -> uncaughtExceptions.add(e));
return thread;
});

OkHttpClient client = new OkHttpClient.Builder()
Expand Down Expand Up @@ -113,13 +105,11 @@ interface Service {

final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override public void accept(Throwable throwable) throws Exception {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
latch.countDown();
RxJavaPlugins.setErrorHandler(throwable -> {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
latch.countDown();
});

TestObserver<Void> observer = new TestObserver<>();
Expand All @@ -139,13 +129,11 @@ interface Service {

final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override public void accept(Throwable throwable) throws Exception {
if (!pluginRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
latch.countDown();
RxJavaPlugins.setErrorHandler(throwable -> {
if (!pluginRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
latch.countDown();
});

TestObserver<Void> observer = new TestObserver<>();
Expand Down
Expand Up @@ -20,7 +20,6 @@
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.CompositeException;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.Consumer;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicReference;
import okhttp3.mockwebserver.MockResponse;
Expand Down Expand Up @@ -58,11 +57,9 @@ interface Service {
server.enqueue(new MockResponse());

final AtomicReference<Throwable> errorRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override public void accept(Throwable throwable) throws Exception {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
RxJavaPlugins.setErrorHandler(throwable -> {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
});

Expand All @@ -81,11 +78,9 @@ interface Service {
server.enqueue(new MockResponse().setResponseCode(404));

final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override public void accept(Throwable throwable) throws Exception {
if (!pluginRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
RxJavaPlugins.setErrorHandler(throwable -> {
if (!pluginRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
}
});

Expand Down

0 comments on commit 2851c14

Please sign in to comment.