diff --git a/.travis.yml b/.travis.yml index 936d5c5252..e7fa69d187 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,11 @@ jdk: before_install: ./travis/sign.sh +script: + - ./mvnw clean install -B + # fail build if there are any local changes to sources + - ./travis/no-git-changes.sh + jobs: include: - stage: snapshot diff --git a/core/src/main/java/feign/Client.java b/core/src/main/java/feign/Client.java index 43563eb1c6..a2de4f791d 100644 --- a/core/src/main/java/feign/Client.java +++ b/core/src/main/java/feign/Client.java @@ -22,7 +22,6 @@ import static feign.Util.isBlank; import static feign.Util.isNotBlank; import static java.lang.String.format; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -37,11 +36,9 @@ import java.util.Map; import java.util.zip.DeflaterOutputStream; import java.util.zip.GZIPOutputStream; - import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSocketFactory; - import feign.Request.Options; /** diff --git a/core/src/main/java/feign/FeignException.java b/core/src/main/java/feign/FeignException.java index ac1ae65fd2..ce88d22f11 100644 --- a/core/src/main/java/feign/FeignException.java +++ b/core/src/main/java/feign/FeignException.java @@ -23,7 +23,8 @@ */ public class FeignException extends RuntimeException { - private static final String EXCEPTION_MESSAGE_TEMPLATE_NULL_REQUEST = "request should not be null"; + private static final String EXCEPTION_MESSAGE_TEMPLATE_NULL_REQUEST = + "request should not be null"; private static final long serialVersionUID = 0; private int status; private byte[] content; diff --git a/core/src/test/java/feign/FeignExceptionTest.java b/core/src/test/java/feign/FeignExceptionTest.java index 7a69d72145..9fe5bbddd5 100644 --- a/core/src/test/java/feign/FeignExceptionTest.java +++ b/core/src/test/java/feign/FeignExceptionTest.java @@ -17,43 +17,43 @@ public class FeignExceptionTest { - @Test(expected = NullPointerException.class) - public void nullRequestShouldThrowNPEwThrowable() { - new Derived(404, "message", null, new Throwable()); + @Test(expected = NullPointerException.class) + public void nullRequestShouldThrowNPEwThrowable() { + new Derived(404, "message", null, new Throwable()); + } + + @Test(expected = NullPointerException.class) + public void nullRequestShouldThrowNPEwThrowableAndBytes() { + new Derived(404, "message", null, new Throwable(), new byte[1]); + } + + @Test(expected = NullPointerException.class) + public void nullRequestShouldThrowNPE() { + new Derived(404, "message", null); + } + + @Test(expected = NullPointerException.class) + public void nullRequestShouldThrowNPEwBytes() { + new Derived(404, "message", null, new byte[1]); + } + + static class Derived extends FeignException { + + public Derived(int status, String message, Request request, Throwable cause) { + super(status, message, request, cause); } - @Test(expected = NullPointerException.class) - public void nullRequestShouldThrowNPEwThrowableAndBytes() { - new Derived(404, "message", null, new Throwable(), new byte[1]); + public Derived(int status, String message, Request request, Throwable cause, byte[] content) { + super(status, message, request, cause, content); } - @Test(expected = NullPointerException.class) - public void nullRequestShouldThrowNPE() { - new Derived(404, "message", null); + public Derived(int status, String message, Request request) { + super(status, message, request); } - @Test(expected = NullPointerException.class) - public void nullRequestShouldThrowNPEwBytes() { - new Derived(404, "message", null, new byte[1]); + public Derived(int status, String message, Request request, byte[] content) { + super(status, message, request, content); } + } - static class Derived extends FeignException { - - public Derived(int status, String message, Request request, Throwable cause) { - super(status, message, request, cause); - } - - public Derived(int status, String message, Request request, Throwable cause, byte[] content) { - super(status, message, request, cause, content); - } - - public Derived(int status, String message, Request request) { - super(status, message, request); - } - - public Derived(int status, String message, Request request, byte[] content) { - super(status, message, request, content); - } - } - -} \ No newline at end of file +} diff --git a/core/src/test/java/feign/MultipleLoggerTest.java b/core/src/test/java/feign/MultipleLoggerTest.java index d438025fb7..a9857c09d2 100644 --- a/core/src/test/java/feign/MultipleLoggerTest.java +++ b/core/src/test/java/feign/MultipleLoggerTest.java @@ -13,11 +13,16 @@ */ package feign; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.lang.reflect.Field; public class MultipleLoggerTest { + @Rule + public TemporaryFolder tmp = new TemporaryFolder(); + private static java.util.logging.Logger getInnerLogger(Logger.JavaLogger logger) throws Exception { Field inner = logger.getClass().getDeclaredField("logger"); @@ -27,15 +32,19 @@ private static java.util.logging.Logger getInnerLogger(Logger.JavaLogger logger) @Test public void testAppendSeveralFilesToOneJavaLogger() throws Exception { - Logger.JavaLogger logger = new Logger.JavaLogger().appendToFile("1.log").appendToFile("2.log"); + Logger.JavaLogger logger = new Logger.JavaLogger() + .appendToFile(tmp.newFile("1.log").getAbsolutePath()) + .appendToFile(tmp.newFile("2.log").getAbsolutePath()); java.util.logging.Logger inner = getInnerLogger(logger); assert (inner.getHandlers().length == 2); } @Test public void testJavaLoggerInstantationWithLoggerName() throws Exception { - Logger.JavaLogger l1 = new Logger.JavaLogger("First client").appendToFile("1.log"); - Logger.JavaLogger l2 = new Logger.JavaLogger("Second client").appendToFile("2.log"); + Logger.JavaLogger l1 = new Logger.JavaLogger("First client") + .appendToFile(tmp.newFile("1.log").getAbsolutePath()); + Logger.JavaLogger l2 = new Logger.JavaLogger("Second client") + .appendToFile(tmp.newFile("2.log").getAbsolutePath()); java.util.logging.Logger logger1 = getInnerLogger(l1); assert (logger1.getHandlers().length == 1); java.util.logging.Logger logger2 = getInnerLogger(l2); @@ -44,8 +53,10 @@ public void testJavaLoggerInstantationWithLoggerName() throws Exception { @Test public void testJavaLoggerInstantationWithClazz() throws Exception { - Logger.JavaLogger l1 = new Logger.JavaLogger(String.class).appendToFile("1.log"); - Logger.JavaLogger l2 = new Logger.JavaLogger(Integer.class).appendToFile("2.log"); + Logger.JavaLogger l1 = new Logger.JavaLogger(String.class) + .appendToFile(tmp.newFile("1.log").getAbsolutePath()); + Logger.JavaLogger l2 = new Logger.JavaLogger(Integer.class) + .appendToFile(tmp.newFile("2.log").getAbsolutePath()); java.util.logging.Logger logger1 = getInnerLogger(l1); assert (logger1.getHandlers().length == 1); java.util.logging.Logger logger2 = getInnerLogger(l2); diff --git a/core/src/test/java/feign/RetryerTest.java b/core/src/test/java/feign/RetryerTest.java index 63e38bdc6d..5bdb5ced53 100644 --- a/core/src/test/java/feign/RetryerTest.java +++ b/core/src/test/java/feign/RetryerTest.java @@ -17,7 +17,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import java.util.Collections; import java.util.Date; import feign.Retryer.Default; @@ -29,7 +28,7 @@ public class RetryerTest { public final ExpectedException thrown = ExpectedException.none(); private final static Request REQUEST = Request - .create(Request.HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8); + .create(Request.HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8); @Test public void only5TriesAllowedAndExponentialBackoff() throws Exception { @@ -83,7 +82,8 @@ public void defaultRetryerFailsOnInterruptedException() { Thread.currentThread().interrupt(); RetryableException expected = - new RetryableException(-1, null, null, new Date(System.currentTimeMillis() + 5000), REQUEST); + new RetryableException(-1, null, null, new Date(System.currentTimeMillis() + 5000), + REQUEST); try { retryer.continueOrPropagate(expected); Thread.interrupted(); // reset interrupted flag in case it wasn't diff --git a/core/src/test/java/feign/client/DefaultClientTest.java b/core/src/test/java/feign/client/DefaultClientTest.java index be3281037e..b6370db9ac 100644 --- a/core/src/test/java/feign/client/DefaultClientTest.java +++ b/core/src/test/java/feign/client/DefaultClientTest.java @@ -16,7 +16,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.core.Is.isA; import static org.junit.Assert.assertEquals; - import feign.Client.Proxied; import java.io.IOException; import java.net.HttpURLConnection; @@ -116,9 +115,9 @@ public void canOverrideHostnameVerifier() throws IOException, InterruptedExcepti new InetSocketAddress("proxy.example.com", 8080); /** - * Test that the proxy is being used, but don't check the credentials. Credentials can still - * be used, but they must be set using the appropriate system properties and testing that is - * not what we are looking to do here. + * Test that the proxy is being used, but don't check the credentials. Credentials can still be + * used, but they must be set using the appropriate system properties and testing that is not what + * we are looking to do here. */ @Test public void canCreateWithImplicitOrNoCredentials() throws Exception { diff --git a/googlehttpclient/src/main/java/feign/googlehttpclient/GoogleHttpClient.java b/googlehttpclient/src/main/java/feign/googlehttpclient/GoogleHttpClient.java index 1f5b181fb2..4a061983d4 100644 --- a/googlehttpclient/src/main/java/feign/googlehttpclient/GoogleHttpClient.java +++ b/googlehttpclient/src/main/java/feign/googlehttpclient/GoogleHttpClient.java @@ -23,12 +23,10 @@ import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.javanet.NetHttpTransport; - import java.io.IOException; import java.util.Collection; import java.util.Map; import java.util.HashMap; - import feign.Client; import feign.Request; import feign.Response; @@ -37,92 +35,96 @@ /** * This module directs Feign's http requests to - * Google HTTP Client. + * Google + * HTTP Client. * *
* GitHub github = Feign.builder().client(new GoogleHttpCliest()).target(GitHub.class, * "https://api.github.com"); */ public class GoogleHttpClient implements Client { - private final HttpTransport transport; - private final HttpRequestFactory requestFactory; + private final HttpTransport transport; + private final HttpRequestFactory requestFactory; - public GoogleHttpClient() { - this(new NetHttpTransport()); - } + public GoogleHttpClient() { + this(new NetHttpTransport()); + } - public GoogleHttpClient(final HttpTransport transport) { - this.transport = transport; - this.requestFactory = transport.createRequestFactory(); - } + public GoogleHttpClient(final HttpTransport transport) { + this.transport = transport; + this.requestFactory = transport.createRequestFactory(); + } - @Override - public final Response execute(final Request inputRequest, - final Request.Options options) throws IOException { - final HttpRequest request = convertRequest(inputRequest, options); - final HttpResponse response = request.execute(); - return convertResponse(inputRequest, response); - } + @Override + public final Response execute(final Request inputRequest, + final Request.Options options) + throws IOException { + final HttpRequest request = convertRequest(inputRequest, options); + final HttpResponse response = request.execute(); + return convertResponse(inputRequest, response); + } - private final HttpRequest convertRequest(final Request inputRequest, - final Request.Options options) throws IOException { - // Setup the request body - HttpContent content = null; - if (inputRequest.requestBody().length() > 0) { - final CollectioncontentTypeValues = inputRequest.headers().get("Content-Type"); - String contentType = null; - if (contentTypeValues != null && contentTypeValues.size() > 0) { - contentType = contentTypeValues.iterator().next(); - } else { - contentType = "application/octet-stream"; - } - content = new ByteArrayContent(contentType, inputRequest.requestBody().asBytes()); - } - - // Build the request - final HttpRequest request = requestFactory.buildRequest(inputRequest.httpMethod().name(), - new GenericUrl(inputRequest.url()), - content); - // Setup headers - final HttpHeaders headers = new HttpHeaders(); - for (final Map.Entry > header : inputRequest.headers().entrySet()) { - headers.set(header.getKey(), header.getValue()); - } - // Some servers don't do well with no Accept header - if (inputRequest.headers().get("Accept") == null) { - headers.setAccept("*/*"); - } - request.setHeaders(headers); + private final HttpRequest convertRequest(final Request inputRequest, + final Request.Options options) + throws IOException { + // Setup the request body + HttpContent content = null; + if (inputRequest.requestBody().length() > 0) { + final Collection contentTypeValues = inputRequest.headers().get("Content-Type"); + String contentType = null; + if (contentTypeValues != null && contentTypeValues.size() > 0) { + contentType = contentTypeValues.iterator().next(); + } else { + contentType = "application/octet-stream"; + } + content = new ByteArrayContent(contentType, inputRequest.requestBody().asBytes()); + } - // Setup request options - request.setReadTimeout(options.readTimeoutMillis()) - .setConnectTimeout(options.connectTimeoutMillis()) - .setFollowRedirects(options.isFollowRedirects()) - .setThrowExceptionOnExecuteError(false); - return request; + // Build the request + final HttpRequest request = requestFactory.buildRequest(inputRequest.httpMethod().name(), + new GenericUrl(inputRequest.url()), + content); + // Setup headers + final HttpHeaders headers = new HttpHeaders(); + for (final Map.Entry > header : inputRequest.headers().entrySet()) { + headers.set(header.getKey(), header.getValue()); } + // Some servers don't do well with no Accept header + if (inputRequest.headers().get("Accept") == null) { + headers.setAccept("*/*"); + } + request.setHeaders(headers); + + // Setup request options + request.setReadTimeout(options.readTimeoutMillis()) + .setConnectTimeout(options.connectTimeoutMillis()) + .setFollowRedirects(options.isFollowRedirects()) + .setThrowExceptionOnExecuteError(false); + return request; + } - private final Response convertResponse(final Request inputRequest, - final HttpResponse inputResponse) throws IOException { - final HttpHeaders headers = inputResponse.getHeaders(); - Integer contentLength = null; - if (headers.getContentLength() != null && headers.getContentLength() <= Integer.MAX_VALUE) { - contentLength = inputResponse.getHeaders().getContentLength().intValue(); - } - return Response.builder() - .body(inputResponse.getContent(), contentLength) - .status(inputResponse.getStatusCode()) - .reason(inputResponse.getStatusMessage()) - .headers(toMap(inputResponse.getHeaders())) - .request(inputRequest) - .build(); + private final Response convertResponse(final Request inputRequest, + final HttpResponse inputResponse) + throws IOException { + final HttpHeaders headers = inputResponse.getHeaders(); + Integer contentLength = null; + if (headers.getContentLength() != null && headers.getContentLength() <= Integer.MAX_VALUE) { + contentLength = inputResponse.getHeaders().getContentLength().intValue(); } + return Response.builder() + .body(inputResponse.getContent(), contentLength) + .status(inputResponse.getStatusCode()) + .reason(inputResponse.getStatusMessage()) + .headers(toMap(inputResponse.getHeaders())) + .request(inputRequest) + .build(); + } - private final Map > toMap(final HttpHeaders headers) { - final Map > map = new HashMap >(); - for (final String header : headers.keySet()) { - map.put(header, headers.getHeaderStringValues(header)); - } - return map; + private final Map > toMap(final HttpHeaders headers) { + final Map > map = new HashMap >(); + for (final String header : headers.keySet()) { + map.put(header, headers.getHeaderStringValues(header)); } + return map; + } } diff --git a/googlehttpclient/src/test/java/feign/googlehttpclient/GoogleHttpClientTest.java b/googlehttpclient/src/test/java/feign/googlehttpclient/GoogleHttpClientTest.java index 4632682225..03c0b61fb0 100644 --- a/googlehttpclient/src/test/java/feign/googlehttpclient/GoogleHttpClientTest.java +++ b/googlehttpclient/src/test/java/feign/googlehttpclient/GoogleHttpClientTest.java @@ -19,18 +19,17 @@ import feign.client.AbstractClientTest; public class GoogleHttpClientTest extends AbstractClientTest { - @Override - public Builder newBuilder() { - return Feign.builder() - .client(new GoogleHttpClient()); - } + @Override + public Builder newBuilder() { + return Feign.builder() + .client(new GoogleHttpClient()); + } - // Google http client doesn't support PATCH. See: https://github.com/googleapis/google-http-java-client/issues/167 - @Override - public void noResponseBodyForPatch() { - } + // Google http client doesn't support PATCH. See: + // https://github.com/googleapis/google-http-java-client/issues/167 + @Override + public void noResponseBodyForPatch() {} - @Override - public void testPatch() { - } + @Override + public void testPatch() {} } diff --git a/travis/no-git-changes.sh b/travis/no-git-changes.sh new file mode 100755 index 0000000000..784199ab38 --- /dev/null +++ b/travis/no-git-changes.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Copyright 2012-2019 The Feign Authors +# +# 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. +# + + +set -euo pipefail +set -x + +# make sure there are no local changes to repository after build +if [ -z $(git status --porcelain) ]; +then + echo "No changes detected, all good" +else + echo "The following files have formatting changes:" + git status --porcelain + echo "" + echo "Please run 'mvn clean install' locally to format files" + exit 1 +fi +