From 13575b40b65f303b9f29d01195ef2e6f0456cef4 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 18 May 2016 22:58:00 -0700 Subject: [PATCH 1/8] Pull runtimes subtree --- .../build.gradle | 2 +- azure-client-authentication/build.gradle | 2 +- .../ApplicationTokenCredentials.java | 157 ++++++++++-------- .../java/com/microsoft/azure/AzureClient.java | 3 + .../com/microsoft/azure/AzureEnvironment.java | 34 ++-- .../microsoft/azure/AzureServiceClient.java | 5 + .../java/com/microsoft/rest/RestClient.java | 11 +- .../microsoft/rest/UserAgentInterceptor.java | 26 ++- .../com/microsoft/rest/CredentialsTests.java | 3 + .../com/microsoft/rest/RetryHandlerTests.java | 7 +- .../microsoft/rest/ServiceClientTests.java | 6 +- .../com/microsoft/rest/UserAgentTests.java | 11 +- 12 files changed, 163 insertions(+), 104 deletions(-) diff --git a/azure-android-client-authentication/build.gradle b/azure-android-client-authentication/build.gradle index df85a81cc546..24d340936121 100644 --- a/azure-android-client-authentication/build.gradle +++ b/azure-android-client-authentication/build.gradle @@ -51,7 +51,7 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.microsoft.aad:adal:1.1.11' - compile 'com.microsoft.rest:client-runtime:1.0.0-beta1' + compile 'com.microsoft.azure:azure-client-runtime:1.0.0-SNAPSHOT' testCompile 'junit:junit:4.12' testCompile 'junit:junit-dep:4.11' deployerJars "org.apache.maven.wagon:wagon-ftp:2.10" diff --git a/azure-client-authentication/build.gradle b/azure-client-authentication/build.gradle index a2cd81b3f0c2..b56a80eeb306 100644 --- a/azure-client-authentication/build.gradle +++ b/azure-client-authentication/build.gradle @@ -20,7 +20,7 @@ checkstyle { dependencies { compile 'com.microsoft.azure:adal4j:1.1.2' - compile 'com.microsoft.azure:azure-client-runtime:1.0.0-beta1' + compile 'com.microsoft.azure:azure-client-runtime:1.0.0-SNAPSHOT' testCompile 'junit:junit:4.12' testCompile 'junit:junit-dep:4.11' deployerJars "org.apache.maven.wagon:wagon-ftp:2.10" diff --git a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index f5914f24362f..163d10f60a1d 100644 --- a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -34,9 +34,9 @@ public class ApplicationTokenCredentials extends TokenCredentials { private AzureEnvironment environment; /** The current authentication result. */ private AuthenticationResult authenticationResult; - /** The default subscription to use, if any */ + /** The default subscription to use, if any. */ private String defaultSubscription; - + /** * Initializes a new instance of the UserTokenCredentials. * @@ -58,90 +58,103 @@ public ApplicationTokenCredentials(String clientId, String domain, String secret } } - /** - * Contains the keys of the settings in a Properties file to read credentials from + * Contains the keys of the settings in a Properties file to read credentials from. */ - private enum CredentialSettings { - SUBSCRIPTION_ID("subscription"), - TENANT_ID("tenant"), - CLIENT_ID("client"), - CLIENT_KEY("key"), - MANAGEMENT_URI("managementURI"), - BASE_URL("baseURL"), - AUTH_URL("authURL"); - - private final String name; - - private CredentialSettings(String name) { - this.name = name; - } - - @Override - public String toString() { - return this.name; - } - } + private enum CredentialSettings { + /** The subscription GUID. */ + SUBSCRIPTION_ID("subscription"), + /** The tenant GUID or domain. */ + TENANT_ID("tenant"), + /** The client id for the client application. */ + CLIENT_ID("client"), + /** The client secret for the service principal. */ + CLIENT_KEY("key"), + /** The management endpoint. */ + MANAGEMENT_URI("managementURI"), + /** The base URL to the current Azure environment. */ + BASE_URL("baseURL"), + /** The URL to Active Directory authentication. */ + AUTH_URL("authURL"); + + /** The name of the key in the properties file. */ + private final String name; + + CredentialSettings(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + } /** * @return The default subscription ID, if any */ public String defaultSubscriptionId() { - return defaultSubscription; + return defaultSubscription; } - - ApplicationTokenCredentials withDefaultSubscriptionId(String subscriptionId) { - this.defaultSubscription = subscriptionId; - return this; + + /** + * Set default subscription ID. + * + * @param subscriptionId the default subscription ID. + * @return the credentials object itself. + */ + public ApplicationTokenCredentials withDefaultSubscriptionId(String subscriptionId) { + this.defaultSubscription = subscriptionId; + return this; } - + /** - * Initializes the credentials based on the provided credentials file - * @param credentialsFile A file with credentials, using the standard Java properties format + * Initializes the credentials based on the provided credentials file. + * + * @param credentialsFile A file with credentials, using the standard Java properties format. * and the following keys: - * subscription= - * tenant= - * client= - * key= - * managementURI= - * baseURL= - * authURL= + * subscription= + * tenant= + * client= + * key= + * managementURI= + * baseURL= + * authURL= * @return The credentials based on the file. - * @throws IOException + * @throws IOException exception thrown from file access errors. */ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws IOException { - // Set defaults - Properties authSettings = new Properties(); - authSettings.put(CredentialSettings.AUTH_URL.toString(), AzureEnvironment.AZURE.getAuthenticationEndpoint()); - authSettings.put(CredentialSettings.BASE_URL.toString(), AzureEnvironment.AZURE.getBaseUrl()); - authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getTokenAudience()); - - // Load the credentials from the file - FileInputStream credentialsFileStream = new FileInputStream(credentialsFile); - authSettings.load(credentialsFileStream); - credentialsFileStream.close(); - - final String clientId = authSettings.getProperty(CredentialSettings.CLIENT_ID.toString()); - final String tenantId = authSettings.getProperty(CredentialSettings.TENANT_ID.toString()); - final String clientKey = authSettings.getProperty(CredentialSettings.CLIENT_KEY.toString()); - final String mgmtUri = authSettings.getProperty(CredentialSettings.MANAGEMENT_URI.toString()); - final String authUrl = authSettings.getProperty(CredentialSettings.AUTH_URL.toString()); - final String baseUrl = authSettings.getProperty(CredentialSettings.BASE_URL.toString()); - final String defaultSubscriptionId = authSettings.getProperty(CredentialSettings.SUBSCRIPTION_ID.toString()); - - return new ApplicationTokenCredentials( - clientId, - tenantId, - clientKey, - new AzureEnvironment( - authUrl, - mgmtUri, - true, - baseUrl) - ).withDefaultSubscriptionId(defaultSubscriptionId); + // Set defaults + Properties authSettings = new Properties(); + authSettings.put(CredentialSettings.AUTH_URL.toString(), AzureEnvironment.AZURE.getAuthenticationEndpoint()); + authSettings.put(CredentialSettings.BASE_URL.toString(), AzureEnvironment.AZURE.getBaseUrl()); + authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getTokenAudience()); + + // Load the credentials from the file + FileInputStream credentialsFileStream = new FileInputStream(credentialsFile); + authSettings.load(credentialsFileStream); + credentialsFileStream.close(); + + final String clientId = authSettings.getProperty(CredentialSettings.CLIENT_ID.toString()); + final String tenantId = authSettings.getProperty(CredentialSettings.TENANT_ID.toString()); + final String clientKey = authSettings.getProperty(CredentialSettings.CLIENT_KEY.toString()); + final String mgmtUri = authSettings.getProperty(CredentialSettings.MANAGEMENT_URI.toString()); + final String authUrl = authSettings.getProperty(CredentialSettings.AUTH_URL.toString()); + final String baseUrl = authSettings.getProperty(CredentialSettings.BASE_URL.toString()); + final String defaultSubscriptionId = authSettings.getProperty(CredentialSettings.SUBSCRIPTION_ID.toString()); + + return new ApplicationTokenCredentials( + clientId, + tenantId, + clientKey, + new AzureEnvironment( + authUrl, + mgmtUri, + true, + baseUrl) + ).withDefaultSubscriptionId(defaultSubscriptionId); } - - + /** * Gets the active directory application client id. * @@ -168,7 +181,7 @@ public String getDomain() { public String getSecret() { return secret; } - + /** * Gets the Azure environment to authenticate with. * diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java index 9c442977b2d4..56f377008512 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java @@ -44,6 +44,9 @@ public class AzureClient extends AzureServiceClient { */ private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + /** + * The user agent from the service client that owns this Azure Client. + */ private final String serviceClientUserAgent; /** diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index 5b91e595b4c9..1721e2ff97bb 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -14,19 +14,21 @@ * An instance of this class describes an environment in Azure. */ public final class AzureEnvironment { - /** - * Base URL for calls to Azure management API. - */ - private final String baseURL; - - /** + /** + * Base URL for calls to Azure management API. + */ + private final String baseURL; + + /** * ActiveDirectory Endpoint for the Azure Environment. */ private String authenticationEndpoint; + /** * Token audience for an endpoint. */ private String tokenAudience; + /** * Determines whether the authentication endpoint should * be validated with Azure AD. Default value is true. @@ -40,12 +42,13 @@ public final class AzureEnvironment { * @param tokenAudience token audience for an endpoint. * @param validateAuthority whether the authentication endpoint should * be validated with Azure AD. + * @param baseUrl the base URL for the current environment. */ public AzureEnvironment( - String authenticationEndpoint, - String tokenAudience, - boolean validateAuthority, - String baseUrl) { + String authenticationEndpoint, + String tokenAudience, + boolean validateAuthority, + String baseUrl) { this.authenticationEndpoint = authenticationEndpoint; this.tokenAudience = tokenAudience; this.validateAuthority = validateAuthority; @@ -68,14 +71,15 @@ public AzureEnvironment( "https://login.chinacloudapi.cn/", "https://management.core.chinacloudapi.cn/", true, - "https://management.chinacloudapi.cn"); //TODO: Should be confirmed... + "https://management.chinacloudapi.cn"); /** - * Gets the base URL of the management service - * @return the Base URL for the management service + * Gets the base URL of the management service. + * + * @return the Base URL for the management service. */ public String getBaseUrl() { - return this.baseURL; + return this.baseURL; } /** @@ -88,7 +92,7 @@ public RestClient.Builder newRestClientBuilder() { .withInterceptor(new RequestIdHeaderInterceptor()) .withMapperAdapter(new AzureJacksonMapperAdapter()); } - + /** * Gets the ActiveDirectory Endpoint for the Azure Environment. * diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceClient.java b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceClient.java index ae76abb9d561..08094b67d507 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceClient.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceClient.java @@ -30,6 +30,11 @@ protected AzureServiceClient(RestClient restClient) { super(restClient); } + /** + * The default User-Agent header. Override this method to override the user agent. + * + * @return the user agent string. + */ public String userAgent() { return "Azure-SDK-For-Java/" + getClass().getPackage().getImplementationVersion(); } diff --git a/client-runtime/src/main/java/com/microsoft/rest/RestClient.java b/client-runtime/src/main/java/com/microsoft/rest/RestClient.java index afd69a02e50f..0d5436b4fa6e 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/RestClient.java +++ b/client-runtime/src/main/java/com/microsoft/rest/RestClient.java @@ -10,15 +10,16 @@ import com.microsoft.rest.credentials.ServiceClientCredentials; import com.microsoft.rest.retry.RetryHandler; import com.microsoft.rest.serializer.JacksonMapperAdapter; + +import java.net.CookieManager; +import java.net.CookiePolicy; + import okhttp3.Interceptor; import okhttp3.JavaNetCookieJar; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; -import java.net.CookieManager; -import java.net.CookiePolicy; - /** * An instance of this class stores the client information for making REST calls. */ @@ -95,7 +96,11 @@ public Retrofit retrofit() { * URL instead of the raw one might be returned. * * @return the base URL. +<<<<<<< HEAD + * @see {@link RestClient#setBaseUrl(String...)} +======= * @see RestClient#setBaseUrl(String...) +>>>>>>> fddca6a8917951772a65a3e5b47c5e72c1f42fb5 */ public String baseUrl() { return baseUrlHandler.baseUrl(); diff --git a/client-runtime/src/main/java/com/microsoft/rest/UserAgentInterceptor.java b/client-runtime/src/main/java/com/microsoft/rest/UserAgentInterceptor.java index bb15c0f4305d..ac4a5ec5a73c 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/UserAgentInterceptor.java +++ b/client-runtime/src/main/java/com/microsoft/rest/UserAgentInterceptor.java @@ -35,10 +35,20 @@ public UserAgentInterceptor() { this.userAgent = DEFAULT_USER_AGENT_HEADER; } + /** + * Overwrite the User-Agent header. + * + * @param userAgent the new user agent value. + */ public void setUserAgent(String userAgent) { this.userAgent = userAgent; } + /** + * Append a text to the User-Agent header. + * + * @param userAgent the user agent value to append. + */ public void appendUserAgent(String userAgent) { this.userAgent += " " + userAgent; } @@ -47,11 +57,19 @@ public void appendUserAgent(String userAgent) { public Response intercept(Chain chain) throws IOException { Request request = chain.request(); String header = request.header("User-Agent"); - if (header == null || !userAgent.equals(DEFAULT_USER_AGENT_HEADER)) { - request = chain.request().newBuilder() - .header("User-Agent", userAgent + " " + header) - .build(); + if (header == null) { + header = DEFAULT_USER_AGENT_HEADER; + } + if (!userAgent.equals(DEFAULT_USER_AGENT_HEADER)) { + if (header.equals(DEFAULT_USER_AGENT_HEADER)) { + header = userAgent; + } else { + header = userAgent + " " + header; + } } + request = chain.request().newBuilder() + .header("User-Agent", header) + .build(); return chain.proceed(request); } } diff --git a/client-runtime/src/test/java/com/microsoft/rest/CredentialsTests.java b/client-runtime/src/test/java/com/microsoft/rest/CredentialsTests.java index 19b7a8ca2a4f..3e05c5d723fd 100644 --- a/client-runtime/src/test/java/com/microsoft/rest/CredentialsTests.java +++ b/client-runtime/src/test/java/com/microsoft/rest/CredentialsTests.java @@ -9,6 +9,7 @@ import com.microsoft.rest.credentials.BasicAuthenticationCredentials; import com.microsoft.rest.credentials.TokenCredentials; +import com.microsoft.rest.serializer.JacksonMapperAdapter; import org.junit.Assert; import org.junit.Test; @@ -29,6 +30,7 @@ public void basicCredentialsTest() throws Exception { Retrofit.Builder retrofitBuilder = new Retrofit.Builder(); BasicAuthenticationCredentials credentials = new BasicAuthenticationCredentials("user", "pass"); RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder) + .withMapperAdapter(new JacksonMapperAdapter()) .withCredentials(credentials) .withInterceptor(new Interceptor() { @Override @@ -53,6 +55,7 @@ public void tokenCredentialsTest() throws Exception { Retrofit.Builder retrofitBuilder = new Retrofit.Builder(); TokenCredentials credentials = new TokenCredentials(null, "this_is_a_token"); RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder) + .withMapperAdapter(new JacksonMapperAdapter()) .withCredentials(credentials) .withInterceptor(new Interceptor() { @Override diff --git a/client-runtime/src/test/java/com/microsoft/rest/RetryHandlerTests.java b/client-runtime/src/test/java/com/microsoft/rest/RetryHandlerTests.java index 050e7374aba1..97c46f6fe4fc 100644 --- a/client-runtime/src/test/java/com/microsoft/rest/RetryHandlerTests.java +++ b/client-runtime/src/test/java/com/microsoft/rest/RetryHandlerTests.java @@ -9,6 +9,7 @@ import com.microsoft.rest.retry.RetryHandler; +import com.microsoft.rest.serializer.JacksonMapperAdapter; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Protocol; @@ -41,7 +42,8 @@ public Response intercept(Chain chain) throws IOException { .build(); } }); - RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder); + RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder) + .withMapperAdapter(new JacksonMapperAdapter()); ServiceClient serviceClient = new ServiceClient(restBuilder.build()) { }; Response response = serviceClient.restClient().httpClient().newCall( new Request.Builder().url("http://localhost").get().build()).execute(); @@ -67,7 +69,8 @@ public Response intercept(Chain chain) throws IOException { .build(); } }); - RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder); + RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder) + .withMapperAdapter(new JacksonMapperAdapter()); ServiceClient serviceClient = new ServiceClient(restBuilder.build()) { }; Response response = serviceClient.restClient().httpClient().newCall( new Request.Builder().url("http://localhost").get().build()).execute(); diff --git a/client-runtime/src/test/java/com/microsoft/rest/ServiceClientTests.java b/client-runtime/src/test/java/com/microsoft/rest/ServiceClientTests.java index 5497d607549d..6423ef23d808 100644 --- a/client-runtime/src/test/java/com/microsoft/rest/ServiceClientTests.java +++ b/client-runtime/src/test/java/com/microsoft/rest/ServiceClientTests.java @@ -7,8 +7,10 @@ package com.microsoft.rest; +import com.microsoft.rest.serializer.JacksonMapperAdapter; import org.junit.Assert; import org.junit.Test; +import retrofit2.Retrofit; import java.io.IOException; @@ -17,7 +19,6 @@ import okhttp3.Protocol; import okhttp3.Request; import okhttp3.Response; -import retrofit2.Retrofit; public class ServiceClientTests { @Test @@ -38,7 +39,8 @@ public Response intercept(Chain chain) throws IOException { .build(); } }); - RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder); + RestClient.Builder restBuilder = new RestClient.Builder("http://localhost", clientBuilder, retrofitBuilder) + .withMapperAdapter(new JacksonMapperAdapter()); ServiceClient serviceClient = new ServiceClient(restBuilder.build()) { }; Response response = serviceClient.restClient().httpClient().newCall(new Request.Builder().url("http://localhost").build()).execute(); Assert.assertEquals(200, response.code()); diff --git a/client-runtime/src/test/java/com/microsoft/rest/UserAgentTests.java b/client-runtime/src/test/java/com/microsoft/rest/UserAgentTests.java index af1e35617e83..35970714e3a8 100644 --- a/client-runtime/src/test/java/com/microsoft/rest/UserAgentTests.java +++ b/client-runtime/src/test/java/com/microsoft/rest/UserAgentTests.java @@ -8,15 +8,17 @@ package com.microsoft.rest; import com.microsoft.rest.serializer.JacksonMapperAdapter; -import okhttp3.Interceptor; -import okhttp3.Protocol; -import okhttp3.Request; -import okhttp3.Response; + import org.junit.Assert; import org.junit.Test; import java.io.IOException; +import okhttp3.Interceptor; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.Response; + public class UserAgentTests { @Test public void defaultUserAgentTests() throws Exception { @@ -42,6 +44,7 @@ public Response intercept(Chain chain) throws IOException { @Test public void customUserAgentTests() throws Exception { + RestClient.Builder restBuilder = new RestClient.Builder("http://localhost") .withUserAgent("Awesome") .withInterceptor(new Interceptor() { From 9071c8d6abef26646a08c6fed01168f52520f59c Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 19 May 2016 14:36:21 -0700 Subject: [PATCH 2/8] Add checkstyle rules --- azure-client-authentication/pom.xml | 2 ++ azure-client-runtime/pom.xml | 2 ++ .../java/com/microsoft/azure/AzureClient.java | 23 ++++++++----------- .../java/com/microsoft/azure/PagedList.java | 7 +++--- client-runtime/pom.xml | 2 ++ pom.xml | 12 ++-------- 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/azure-client-authentication/pom.xml b/azure-client-authentication/pom.xml index 47582ca1eaa8..e3adb48c5f3f 100644 --- a/azure-client-authentication/pom.xml +++ b/azure-client-authentication/pom.xml @@ -35,6 +35,8 @@ UTF-8 + ${project.basedir}/../../tools/checkstyle.xml + ${project.basedir}/../../tools/suppressions.xml diff --git a/azure-client-runtime/pom.xml b/azure-client-runtime/pom.xml index 98d91b43e802..2a1d2234e959 100644 --- a/azure-client-runtime/pom.xml +++ b/azure-client-runtime/pom.xml @@ -35,6 +35,8 @@ UTF-8 + ${project.basedir}/../../tools/checkstyle.xml + ${project.basedir}/../../tools/suppressions.xml diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java index 56f377008512..f6eaecdb4467 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java @@ -13,6 +13,12 @@ import com.microsoft.rest.ServiceResponse; import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.ServiceResponseWithHeaders; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Response; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Url; import java.io.IOException; import java.lang.reflect.Type; @@ -22,13 +28,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import okhttp3.ResponseBody; -import retrofit2.Call; -import retrofit2.Response; -import retrofit2.http.GET; -import retrofit2.http.Header; -import retrofit2.http.Url; - /** * An instance of this class defines a ServiceClient that handles polling and * retrying for long running operations when accessing Azure resources. @@ -288,8 +287,7 @@ public ServiceResponse getPostOrDeleteResult(Response respo } // Check if operation failed - if (AzureAsyncOperation.getFailedStatuses().contains(pollingState.getStatus())) - { + if (AzureAsyncOperation.getFailedStatuses().contains(pollingState.getStatus())) { throw new CloudException("Async operation failed"); } @@ -778,7 +776,7 @@ class PutPatchPollingTask extends AsyncPollingTask { * @param serviceCall the ServiceCall object tracking Retrofit calls. * @param clientCallback the client callback to call when a terminal status is hit. */ - public PutPatchPollingTask(final PollingState pollingState, final String url, final ServiceCall serviceCall, final ServiceCallback clientCallback) { + PutPatchPollingTask(final PollingState pollingState, final String url, final ServiceCall serviceCall, final ServiceCallback clientCallback) { this.serviceCall = serviceCall; this.pollingState = pollingState; this.url = url; @@ -835,7 +833,7 @@ class PostDeletePollingTask extends AsyncPollingTask { * @param serviceCall the ServiceCall object tracking Retrofit calls. * @param clientCallback the client callback to call when a terminal status is hit. */ - public PostDeletePollingTask(final PollingState pollingState, final ServiceCall serviceCall, final ServiceCallback clientCallback) { + PostDeletePollingTask(final PollingState pollingState, final ServiceCall serviceCall, final ServiceCallback clientCallback) { this.serviceCall = serviceCall; this.pollingState = pollingState; this.clientCallback = clientCallback; @@ -867,8 +865,7 @@ public void run() { } } else { // Check if operation failed - if (AzureAsyncOperation.getFailedStatuses().contains(pollingState.getStatus())) - { + if (AzureAsyncOperation.getFailedStatuses().contains(pollingState.getStatus())) { clientCallback.failure(new ServiceException("Async operation failed")); } else { clientCallback.success(new ServiceResponse<>(pollingState.getResource(), pollingState.getResponse())); diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index f501163ff03e..a88a044f751e 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -9,6 +9,8 @@ import com.microsoft.rest.RestException; +import javax.xml.bind.DataBindingException; +import javax.xml.ws.WebServiceException; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -17,9 +19,6 @@ import java.util.ListIterator; import java.util.NoSuchElementException; -import javax.xml.bind.DataBindingException; -import javax.xml.ws.WebServiceException; - /** * Defines a list response from a paging operation. The pages are * lazy initialized when an instance of this class is iterated. @@ -128,7 +127,7 @@ private class ListItr implements ListIterator { * * @param index the position in the list to start. */ - public ListItr(int index) { + ListItr(int index) { itemsListItr = items.listIterator(index); } diff --git a/client-runtime/pom.xml b/client-runtime/pom.xml index a7c0b7441b02..35af73ebb9a1 100644 --- a/client-runtime/pom.xml +++ b/client-runtime/pom.xml @@ -36,6 +36,8 @@ UTF-8 + ${project.basedir}/../../tools/checkstyle.xml + ${project.basedir}/../../tools/suppressions.xml diff --git a/pom.xml b/pom.xml index b6bb0bb29b04..11ef8bb1ce53 100644 --- a/pom.xml +++ b/pom.xml @@ -31,8 +31,9 @@ UTF-8 + ${project.basedir}/../tools/checkstyle.xml + ${project.basedir}/../tools/suppressions.xml - playback @@ -172,12 +173,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - org.apache.maven.plugins maven-resources-plugin @@ -195,9 +190,6 @@ **/*Tests.java **/*TestCase.java - - ${testMode} - From 0bcf347dca49573e758260370ac8b94e4f743595 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 20 May 2016 14:31:23 -0700 Subject: [PATCH 3/8] Move checkstyle rules to runtimes --- azure-client-authentication/build.gradle | 6 +- azure-client-runtime/build.gradle | 6 +- checkstyle/checkstyle.xml | 255 +++++++++++++++++++++++ checkstyle/suppressions.xml | 36 ++++ client-runtime/build.gradle | 6 +- 5 files changed, 300 insertions(+), 9 deletions(-) create mode 100644 checkstyle/checkstyle.xml create mode 100644 checkstyle/suppressions.xml diff --git a/azure-client-authentication/build.gradle b/azure-client-authentication/build.gradle index b56a80eeb306..75d0404be1f5 100644 --- a/azure-client-authentication/build.gradle +++ b/azure-client-authentication/build.gradle @@ -13,9 +13,9 @@ apply plugin: 'checkstyle' version = '1.0.0-SNAPSHOT' checkstyle { - configFile = new File("$rootDir/Tools/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/Tools/checkstyle"] - reportsDir = new File("$rootDir/Tools/checkstyle/reports") + configFile = new File("$rootDir/ClientRuntimes/Java/checkstyle/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/checkstyle"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/checkstyle/reports") } dependencies { diff --git a/azure-client-runtime/build.gradle b/azure-client-runtime/build.gradle index e8a50ca11242..775736ec22db 100644 --- a/azure-client-runtime/build.gradle +++ b/azure-client-runtime/build.gradle @@ -14,9 +14,9 @@ version = '1.0.0-SNAPSHOT' checkstyle { toolVersion = "6.9" - configFile = new File("$rootDir/Tools/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/Tools/checkstyle"] - reportsDir = new File("$rootDir/Tools/checkstyle/reports") + configFile = new File("$rootDir/ClientRuntimes/Java/checkstyle/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/checkstyle"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/checkstyle/reports") } dependencies { diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml new file mode 100644 index 000000000000..d2b92aa67f9e --- /dev/null +++ b/checkstyle/checkstyle.xml @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/checkstyle/suppressions.xml b/checkstyle/suppressions.xml new file mode 100644 index 000000000000..690bb7a9fc35 --- /dev/null +++ b/checkstyle/suppressions.xml @@ -0,0 +1,36 @@ + + + + + + + + + \ No newline at end of file diff --git a/client-runtime/build.gradle b/client-runtime/build.gradle index 2558fc5055f9..b17a86a50ead 100644 --- a/client-runtime/build.gradle +++ b/client-runtime/build.gradle @@ -16,9 +16,9 @@ version = '1.0.0-SNAPSHOT' checkstyle { toolVersion = "6.9" - configFile = new File("$rootDir/Tools/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/Tools/checkstyle"] - reportsDir = new File("$rootDir/Tools/checkstyle/reports") + configFile = new File("$rootDir/ClientRuntimes/Java/checkstyle/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/checkstyle"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/checkstyle/reports") } dependencies { From de698f75c1c2e7466ab61fe29779366a14f3b268 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 20 May 2016 17:34:26 -0700 Subject: [PATCH 4/8] Optional suppression file for maven scenario --- checkstyle/checkstyle.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml index d2b92aa67f9e..d156ff63e65f 100644 --- a/checkstyle/checkstyle.xml +++ b/checkstyle/checkstyle.xml @@ -38,6 +38,7 @@ + + + 4.0.0 + + com.microsoft.azure + autorest-clientruntime-for-java + 1.0.0-SNAPSHOT + ../pom.xml + + + autorest-build-tools + jar + + Build tools for AutoRest client runtime for Java + This package contains the build tools for AutoRest generated Java clients. + https://github.com/Azure/autorest-clientruntime-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + scm:git:https://github.com/Azure/autorest-clientruntime-for-java + scm:git:git@github.com:Azure/autorest-clientruntime-for-java.git + HEAD + + + + UTF-8 + + + + + + microsoft + Microsoft + + + diff --git a/checkstyle/checkstyle.xml b/build-tools/src/main/resources/checkstyle.xml similarity index 100% rename from checkstyle/checkstyle.xml rename to build-tools/src/main/resources/checkstyle.xml diff --git a/checkstyle/suppressions.xml b/build-tools/src/main/resources/suppressions.xml similarity index 100% rename from checkstyle/suppressions.xml rename to build-tools/src/main/resources/suppressions.xml diff --git a/client-runtime/pom.xml b/client-runtime/pom.xml index 35af73ebb9a1..a7c0b7441b02 100644 --- a/client-runtime/pom.xml +++ b/client-runtime/pom.xml @@ -36,8 +36,6 @@ UTF-8 - ${project.basedir}/../../tools/checkstyle.xml - ${project.basedir}/../../tools/suppressions.xml diff --git a/pom.xml b/pom.xml index 11ef8bb1ce53..51a8ab8ffdcc 100644 --- a/pom.xml +++ b/pom.xml @@ -31,8 +31,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml @@ -144,6 +142,29 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.microsoft.azure + autorest-build-tools + 1.0.0-SNAPSHOT + + + com.puppycrawl.tools + checkstyle + 6.18 + + + + checkstyle.xml + samedir=build-tools/src/main/resources + suppressions.xml + + + org.apache.maven.plugins maven-compiler-plugin @@ -201,8 +222,9 @@ - ./client-runtime - ./azure-client-runtime - ./azure-client-authentication + build-tools + client-runtime + azure-client-runtime + azure-client-authentication From 122b780266d29fba70b1fa8315263a5a4984b0be Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 23 May 2016 14:42:41 -0700 Subject: [PATCH 7/8] Update travis to install build tools --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 31d396e9f028..05c26fa53735 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,6 @@ android: - extra-android-m2repository sudo: false script: - - mvn clean package + - mvn clean install - mvn checkstyle:check - cd ./azure-android-client-authentication && ./gradlew check From 9b363b45a5ff81307079f6a6b3543e52aaf37d2d Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 23 May 2016 14:51:14 -0700 Subject: [PATCH 8/8] Making corresponding changes to gradle --- azure-client-authentication/build.gradle | 7 ++++--- azure-client-runtime/build.gradle | 8 ++++---- client-runtime/build.gradle | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/azure-client-authentication/build.gradle b/azure-client-authentication/build.gradle index 75d0404be1f5..7c4d070dc10a 100644 --- a/azure-client-authentication/build.gradle +++ b/azure-client-authentication/build.gradle @@ -13,9 +13,10 @@ apply plugin: 'checkstyle' version = '1.0.0-SNAPSHOT' checkstyle { - configFile = new File("$rootDir/ClientRuntimes/Java/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/ClientRuntimes/Java/checkstyle"] - reportsDir = new File("$rootDir/ClientRuntimes/Java/checkstyle/reports") + toolVersion = "6.18" + configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports") } dependencies { diff --git a/azure-client-runtime/build.gradle b/azure-client-runtime/build.gradle index 775736ec22db..5c29359536ab 100644 --- a/azure-client-runtime/build.gradle +++ b/azure-client-runtime/build.gradle @@ -13,10 +13,10 @@ apply plugin: 'checkstyle' version = '1.0.0-SNAPSHOT' checkstyle { - toolVersion = "6.9" - configFile = new File("$rootDir/ClientRuntimes/Java/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/ClientRuntimes/Java/checkstyle"] - reportsDir = new File("$rootDir/ClientRuntimes/Java/checkstyle/reports") + toolVersion = "6.18" + configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports") } dependencies { diff --git a/client-runtime/build.gradle b/client-runtime/build.gradle index b17a86a50ead..a163e9a9f89f 100644 --- a/client-runtime/build.gradle +++ b/client-runtime/build.gradle @@ -15,10 +15,10 @@ group = 'com.microsoft.rest' version = '1.0.0-SNAPSHOT' checkstyle { - toolVersion = "6.9" - configFile = new File("$rootDir/ClientRuntimes/Java/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/ClientRuntimes/Java/checkstyle"] - reportsDir = new File("$rootDir/ClientRuntimes/Java/checkstyle/reports") + toolVersion = "6.18" + configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports") } dependencies {