From 41224f8b48ebb30ad3a786a9a4ae7821aa211928 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 11 May 2016 16:27:20 -0700 Subject: [PATCH] ComputeManager, rename region->location, etc --- azure-client-authentication/build.gradle | 2 +- azure-client-authentication/pom.xml | 6 +++--- .../ApplicationTokenCredentials.java | 1 + .../azure/credentials/UserTokenCredentials.java | 1 + .../credentials/UserTokenCredentialsTests.java | 3 +-- .../com/microsoft/azure}/AzureEnvironment.java | 14 +++++++++++++- .../java/com/microsoft/rest/RestClient.java | 17 ++++++++++------- 7 files changed, 30 insertions(+), 14 deletions(-) rename {azure-client-authentication/src/main/java/com/microsoft/azure/credentials => azure-client-runtime/src/main/java/com/microsoft/azure}/AzureEnvironment.java (88%) diff --git a/azure-client-authentication/build.gradle b/azure-client-authentication/build.gradle index 5f20108264785..a2cd81b3f0c23 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.rest:client-runtime:1.0.0-beta1' + compile 'com.microsoft.azure:azure-client-runtime:1.0.0-beta1' 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/pom.xml b/azure-client-authentication/pom.xml index 4dc317b73c131..47582ca1eaa87 100644 --- a/azure-client-authentication/pom.xml +++ b/azure-client-authentication/pom.xml @@ -47,9 +47,9 @@ - com.microsoft.rest - client-runtime - ${parent.version} + com.microsoft.azure + azure-client-runtime + 1.0.0-SNAPSHOT com.microsoft.azure 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 c9eb75f58209f..f5914f24362f5 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 @@ -10,6 +10,7 @@ import com.microsoft.aad.adal4j.AuthenticationContext; import com.microsoft.aad.adal4j.AuthenticationResult; import com.microsoft.aad.adal4j.ClientCredential; +import com.microsoft.azure.AzureEnvironment; import com.microsoft.rest.credentials.TokenCredentials; import java.io.File; diff --git a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index af02c07507b74..60d6bdb3c0a58 100644 --- a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -9,6 +9,7 @@ import com.microsoft.aad.adal4j.AuthenticationContext; import com.microsoft.aad.adal4j.AuthenticationResult; +import com.microsoft.azure.AzureEnvironment; import com.microsoft.rest.credentials.TokenCredentials; import java.io.IOException; diff --git a/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java b/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java index afce04b56ecdf..7905ba7e7b21e 100644 --- a/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java +++ b/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java @@ -8,9 +8,8 @@ package com.microsoft.azure.credentials; import com.microsoft.aad.adal4j.AuthenticationResult; - +import com.microsoft.azure.AzureEnvironment; import org.junit.Assert; - import org.junit.Test; import java.io.IOException; diff --git a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/AzureEnvironment.java b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java similarity index 88% rename from azure-client-authentication/src/main/java/com/microsoft/azure/credentials/AzureEnvironment.java rename to azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index fe02d2133037e..a17c920a05158 100644 --- a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/AzureEnvironment.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -5,7 +5,10 @@ * */ -package com.microsoft.azure.credentials; +package com.microsoft.azure; + +import com.microsoft.azure.serializer.AzureJacksonMapperAdapter; +import com.microsoft.rest.RestClient; /** * An instance of this class describes an environment in Azure. @@ -74,6 +77,15 @@ public AzureEnvironment( public String getBaseUrl() { return this.baseURL; } + + /** + * Gets a builder for {@link RestClient}. + * + * @return a builder for the rest client. + */ + public RestClient.Builder newRestClientBuilder() { + return new RestClient.Builder(baseURL).withMapperAdapter(new AzureJacksonMapperAdapter()); + } /** * Gets the ActiveDirectory Endpoint for the Azure Environment. 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 e1a94ee6b7b40..151b6d30d3539 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/RestClient.java +++ b/client-runtime/src/main/java/com/microsoft/rest/RestClient.java @@ -138,7 +138,7 @@ public static class Builder { /** * Creates an instance of the builder with a base URL to the service. * - * @param baseUrl the dynamic base URL with varialbes wrapped in "{" and "}". + * @param baseUrl the dynamic base URL with variables wrapped in "{" and "}". */ public Builder(String baseUrl) { this(baseUrl, new OkHttpClient.Builder(), new Retrofit.Builder()); @@ -147,7 +147,7 @@ public Builder(String baseUrl) { /** * Creates an instance of the builder with a base URL and 2 custom builders. * - * @param baseUrl the dynamic base URL with varialbes wrapped in "{" and "}". + * @param baseUrl the dynamic base URL with variables wrapped in "{" and "}". * @param httpClientBuilder the builder to build an {@link OkHttpClient}. * @param retrofitBuilder the builder to build a {@link Retrofit}. */ @@ -204,10 +204,7 @@ public Builder withUserAgent(String userAgent) { * @return the builder itself for chaining. */ public Builder withMapperAdapter(JacksonMapperAdapter mapperAdapter) { - if (mapperAdapter != null) { - this.mapperAdapter = mapperAdapter; - this.retrofitBuilder = retrofitBuilder.addConverterFactory(mapperAdapter.getConverterFactory()); - } + this.mapperAdapter = mapperAdapter; return this; } @@ -253,12 +250,18 @@ public Builder withInterceptor(Interceptor interceptor) { * @return a {@link RestClient}. */ public RestClient build() { + if (mapperAdapter == null) { + throw new IllegalArgumentException("Please set mapper adapter."); + } OkHttpClient httpClient = httpClientBuilder .addInterceptor(baseUrlHandler) .addInterceptor(customHeadersInterceptor) .build(); return new RestClient(httpClient, - retrofitBuilder.client(httpClient).build(), + retrofitBuilder + .client(httpClient) + .addConverterFactory(mapperAdapter.getConverterFactory()) + .build(), credentials, customHeadersInterceptor, baseUrlHandler,