From 921ba17ea30689bc0807344d140dc2708bbf25ab Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Fri, 14 Jul 2017 15:34:37 -0700 Subject: [PATCH 01/20] Add generation of service manager and pom.xml --- src/azure/Model/CodeModelJva.cs | 18 ++- src/azurefluent/CodeGeneratorJvaf.cs | 31 +++- .../Templates/AzurePomTemplate.cshtml | 138 ++++++++++++++++++ .../AzureServiceManagerTemplate.cshtml | 106 ++++++++++++++ 4 files changed, 284 insertions(+), 9 deletions(-) create mode 100644 src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml create mode 100644 src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index c21b0169cf..991c190616 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. using System.Collections.Generic; @@ -8,6 +8,7 @@ using AutoRest.Java.Model; using AutoRest.Core.Utilities.Collections; using Newtonsoft.Json; +using System.Text.RegularExpressions; namespace AutoRest.Java.Azure.Model { @@ -64,5 +65,20 @@ public string SetDefaultHeaders return ""; } } + + /// + /// Attempts to infer the name of the service referenced by this CodeModel. + /// + [JsonIgnore] + public string ServiceName + { + get + { + var method = Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); + var serviceName = match.Groups[1].Value; + return serviceName; + } + } } } \ No newline at end of file diff --git a/src/azurefluent/CodeGeneratorJvaf.cs b/src/azurefluent/CodeGeneratorJvaf.cs index 9c218afeef..a5783dcf0c 100644 --- a/src/azurefluent/CodeGeneratorJvaf.cs +++ b/src/azurefluent/CodeGeneratorJvaf.cs @@ -16,6 +16,7 @@ using AutoRest.Java.Model; using AutoRest.Java.vanilla.Templates; using System; +using System.Text.RegularExpressions; namespace AutoRest.Java.Azure.Fluent { @@ -35,6 +36,8 @@ public class CodeGeneratorJvaf : CodeGeneratorJva /// public override async Task Generate(CodeModel cm) { + var packagePath = Path.Combine("src/main/java", cm.Namespace.Replace('.', '/')); + // get Azure Java specific codeModel var codeModel = cm as CodeModelJvaf; if (codeModel == null) @@ -44,14 +47,14 @@ public override async Task Generate(CodeModel cm) // Service client var serviceClientTemplate = new AzureServiceClientTemplate { Model = codeModel }; - await Write(serviceClientTemplate, $"{Path.Combine("implementation", codeModel.Name.ToPascalCase() + "Impl")}{ImplementationFileExtension}"); + await Write(serviceClientTemplate, Path.Combine(packagePath, "implementation", codeModel.Name.ToPascalCase() + "Impl" + ImplementationFileExtension)); // operations foreach (MethodGroupJvaf methodGroup in codeModel.AllOperations) { // Operation var operationsTemplate = new AzureMethodGroupTemplate { Model = methodGroup }; - await Write(operationsTemplate, $"{Path.Combine("implementation", methodGroup.TypeName.ToPascalCase())}Inner{ImplementationFileExtension}"); + await Write(operationsTemplate, Path.Combine(packagePath, "implementation", methodGroup.TypeName.ToPascalCase()) + "Inner" + ImplementationFileExtension); } //Models @@ -68,14 +71,14 @@ public override async Task Generate(CodeModel cm) } var modelTemplate = new ModelTemplate { Model = modelType }; - await Write(modelTemplate, Path.Combine(modelType.ModelsPackage.Trim('.'), $"{modelType.Name.ToPascalCase()}{ImplementationFileExtension}")); + await Write(modelTemplate, Path.Combine(packagePath, modelType.ModelsPackage.Trim('.'), $"{modelType.Name.ToPascalCase()}{ImplementationFileExtension}")); } //Enums foreach (EnumTypeJvaf enumType in cm.EnumTypes) { var enumTemplate = new EnumTemplate { Model = enumType }; - await Write(enumTemplate, Path.Combine(enumType.ModelsPackage.Trim('.'), $"{enumTemplate.Model.Name.ToPascalCase()}{ImplementationFileExtension}")); + await Write(enumTemplate, Path.Combine(packagePath, enumType.ModelsPackage.Trim('.'), $"{enumTemplate.Model.Name.ToPascalCase()}{ImplementationFileExtension}")); } // Page class @@ -85,7 +88,7 @@ public override async Task Generate(CodeModel cm) { Model = new PageJvaf(pageClass.Value, pageClass.Key.Key, pageClass.Key.Value), }; - await Write(pageTemplate, Path.Combine("implementation", $"{pageTemplate.Model.TypeDefinitionName.ToPascalCase()}{ImplementationFileExtension}")); + await Write(pageTemplate, Path.Combine(packagePath, "implementation", $"{pageTemplate.Model.TypeDefinitionName.ToPascalCase()}{ImplementationFileExtension}")); } // Exceptions @@ -97,18 +100,30 @@ public override async Task Generate(CodeModel cm) } var exceptionTemplate = new ExceptionTemplate { Model = exceptionType }; - await Write(exceptionTemplate, Path.Combine(exceptionType.ModelsPackage.Trim('.'), $"{exceptionTemplate.Model.ExceptionTypeDefinitionName}{ImplementationFileExtension}")); + await Write(exceptionTemplate, Path.Combine(packagePath, exceptionType.ModelsPackage.Trim('.'), $"{exceptionTemplate.Model.ExceptionTypeDefinitionName}{ImplementationFileExtension}")); } // package-info.java await Write(new PackageInfoTemplate { Model = new PackageInfoTemplateModel(cm) - }, _packageInfoFileName); + }, Path.Combine(packagePath, _packageInfoFileName)); await Write(new PackageInfoTemplate { Model = new PackageInfoTemplateModel(cm, "implementation") - }, Path.Combine("implementation", _packageInfoFileName)); + }, Path.Combine(packagePath, "implementation", _packageInfoFileName)); + + // Manager + var method = codeModel.Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); + var serviceName = match.Groups[1].Value; + + await Write( + new AzureServiceManagerTemplate { Model = codeModel }, + Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); + + // POM + await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); } } } diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml new file mode 100644 index 0000000000..70e25fbe2b --- /dev/null +++ b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml @@ -0,0 +1,138 @@ +@using System +@using AutoRest.Java.Azure.Templates +@using AutoRest.Java.Templates +@using System.Linq; +@using AutoRest.Java +@using AutoRest.Java.Model +@using AutoRest.Java.Azure.Model +@inherits AutoRest.Core.Template +@{ + var serviceName = Model.ServiceName; +} + + + 4.0.0 + + com.microsoft.azure + azure-parent + 1.1.3-SNAPSHOT + ../pom.xml + + + azure-mgmt-@serviceName.ToLower() + jar + + Microsoft Azure SDK for @serviceName Management + This package contains Microsoft @serviceName Management SDK. + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + UTF-8 + + + + + + microsoft + Microsoft + + + + + + com.microsoft.azure + azure-client-runtime + + + com.microsoft.azure + azure-mgmt-resources + 1.1.3-SNAPSHOT + + + junit + junit + test + + + com.microsoft.azure + azure-client-authentication + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + true + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + com.microsoft.azure.management.apigeneration.LangDefinitionProcessor + + + true + true + + true + true + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8 + + *.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.search + + + /** +
* Copyright (c) Microsoft Corporation. All rights reserved. +
* Licensed under the MIT License. See License.txt in the project root for +
* license information. +
*/ + ]]> +
+
+
+ +
+
+
diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml new file mode 100644 index 0000000000..12be11aae0 --- /dev/null +++ b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml @@ -0,0 +1,106 @@ +@using System +@using System.Text.RegularExpressions +@using AutoRest.Java.Azure.Templates +@using AutoRest.Java.Templates +@using System.Linq +@using AutoRest.Core.Utilities +@using AutoRest.Java +@using AutoRest.Java.Azure.Model +@using AutoRest.Java.Model +@inherits AutoRest.Core.Template + +@{ + var serviceName = Model.ServiceName; + var className = serviceName + "Manager"; +} + +/** +@Header("").TrimMultilineHeader() + */ +@EmptyLine + +package @(Settings.Namespace.ToLower()).@(Model.ImplPackage); + +@EmptyLine +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.AzureResponseBuilder; +import com.microsoft.azure.credentials.AzureTokenCredentials; +import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; +import com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor; +import com.microsoft.azure.serializer.AzureJacksonAdapter; +import com.microsoft.rest.RestClient; +@EmptyLine + +/** + * Entry point to Azure @(serviceName) resource management. + */ +public final class @(className) extends Manager<@(className), @(Model.Name + "Impl")> { + /** + * Get a Configurable instance that can be used to create @(className) with optional configuration. + * + * @@return the instance allowing configurations + */ + public static Configurable configure() { + return new @(className).ConfigurableImpl(); + } + + /** + * Creates an instance of @className that exposes @serviceName resource management API entry points. + * + * @@param credentials the credentials to use + * @@param subscriptionId the subscription UUID + * @@return the @className + */ + public static @className authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new @(className)(new RestClient.Builder() + .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) + .withCredentials(credentials) + .withSerializerAdapter(new AzureJacksonAdapter()) + .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) + .withInterceptor(new ProviderRegistrationInterceptor(credentials)) + .build(), subscriptionId); + } + + /** + * Creates an instance of @className that exposes @serviceName resource management API entry points. + * + * @@param restClient the RestClient to be used for API calls. + * @@param subscriptionId the subscription UUID + * @@return the @className + */ + public static @className authenticate(RestClient restClient, String subscriptionId) { + return new @(className)(restClient, subscriptionId); + } + + /** + * The interface allowing configurations to be set. + */ + public interface Configurable extends AzureConfigurable { + /** + * Creates an instance of @className that exposes @serviceName management API entry points. + * + * @@param credentials the credentials to use + * @@param subscriptionId the subscription UUID + * @@return the interface exposing storage management API entry points that work across subscriptions + */ + @className authenticate(AzureTokenCredentials credentials, String subscriptionId); + } + + /** + * The implementation for Configurable interface. + */ + private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { + public @className authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return @(className).authenticate(buildRestClient(credentials), subscriptionId); + } + } + + private @(className)(RestClient restClient, String subscriptionId) { + super( + restClient, + subscriptionId, + new @(Model.Name)Impl(restClient).withSubscriptionId(subscriptionId)); + } +} From f22fa066341ea3faa9fd198b7a1d95bc9f850a39 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Fri, 14 Jul 2017 16:52:44 -0700 Subject: [PATCH 02/20] Add setting to control whether to regenerate managers --- src/azurefluent/CodeGeneratorJvaf.cs | 29 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/azurefluent/CodeGeneratorJvaf.cs b/src/azurefluent/CodeGeneratorJvaf.cs index a5783dcf0c..7bfb7efecc 100644 --- a/src/azurefluent/CodeGeneratorJvaf.cs +++ b/src/azurefluent/CodeGeneratorJvaf.cs @@ -26,7 +26,7 @@ public class CodeGeneratorJvaf : CodeGeneratorJva private const string _packageInfoFileName = "package-info.java"; public override bool IsSingleFileGenerationSupported => true; - + public override string UsageInstructions => $"The {ClientRuntimePackage} maven dependency is required to execute the generated code."; /// @@ -36,7 +36,7 @@ public class CodeGeneratorJvaf : CodeGeneratorJva /// public override async Task Generate(CodeModel cm) { - var packagePath = Path.Combine("src/main/java", cm.Namespace.Replace('.', '/')); + var packagePath = Path.Combine("src/main/java", cm.Namespace.ToLower().Replace('.', '/')); // get Azure Java specific codeModel var codeModel = cm as CodeModelJvaf; @@ -113,17 +113,24 @@ await Write(new PackageInfoTemplate Model = new PackageInfoTemplateModel(cm, "implementation") }, Path.Combine(packagePath, "implementation", _packageInfoFileName)); - // Manager - var method = codeModel.Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); - var serviceName = match.Groups[1].Value; + object value; + bool regenerateManager; + if (Settings.Instance.CustomSettings.TryGetValue("RegenerateManager", out value) && + bool.TryParse(value.ToString(), out regenerateManager) && + regenerateManager) + { + // Manager + var method = codeModel.Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); + var serviceName = match.Groups[1].Value; - await Write( - new AzureServiceManagerTemplate { Model = codeModel }, - Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); + await Write( + new AzureServiceManagerTemplate { Model = codeModel }, + Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); - // POM - await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); + // POM + await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); + } } } } From 4f15ac24080ef59f93530b445c9d732a7f0306bf Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Mon, 17 Jul 2017 15:51:28 -0700 Subject: [PATCH 03/20] Fix service name inference --- src/azure/Model/CodeModelJva.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 991c190616..266970ded1 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -75,7 +75,7 @@ public string ServiceName get { var method = Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); + var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); var serviceName = match.Groups[1].Value; return serviceName; } From 4bf28e8739e4358d651b32ae596e62b669fda3d4 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Mon, 17 Jul 2017 16:02:14 -0700 Subject: [PATCH 04/20] Fix service name case and code duplication --- src/azure/Model/CodeModelJva.cs | 2 +- src/azurefluent/CodeGeneratorJvaf.cs | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 266970ded1..2c46388e42 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -76,7 +76,7 @@ public string ServiceName { var method = Methods[0]; var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); - var serviceName = match.Groups[1].Value; + var serviceName = match.Groups[1].Value.ToPascalCase(); return serviceName; } } diff --git a/src/azurefluent/CodeGeneratorJvaf.cs b/src/azurefluent/CodeGeneratorJvaf.cs index 7bfb7efecc..07651c3e3e 100644 --- a/src/azurefluent/CodeGeneratorJvaf.cs +++ b/src/azurefluent/CodeGeneratorJvaf.cs @@ -120,13 +120,9 @@ await Write(new PackageInfoTemplate regenerateManager) { // Manager - var method = codeModel.Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); - var serviceName = match.Groups[1].Value; - await Write( new AzureServiceManagerTemplate { Model = codeModel }, - Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); + Path.Combine(packagePath, "implementation", codeModel.ServiceName + "Manager" + ImplementationFileExtension)); // POM await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); From c818fb9865939109c80745af3fe8571499f51e1e Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 18 Jul 2017 11:42:50 -0700 Subject: [PATCH 05/20] Add SDK version number to CodeModelJva --- src/azure/Model/CodeModelJva.cs | 29 +++++++++++++++++++ .../Templates/AzurePomTemplate.cshtml | 4 +-- .../AzureServiceManagerTemplate.cshtml | 3 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 2c46388e42..5359f2221d 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -80,5 +80,34 @@ public string ServiceName return serviceName; } } + + + const string targetVersion = "1.1.3"; + /// + /// The Azure SDK version to reference in the generated POM. + /// + [JsonIgnore] + public string PomVersion + { + get + { + return targetVersion + "-SNAPSHOT"; + } + } + + /// + /// The Beta.SinceVersion value to pass to the Beta annotation. + /// + [JsonIgnore] + public string BetaSinceVersion + { + get + { + var versionParts = targetVersion.Split('.'); + var minorVersion = int.Parse(versionParts[1]) + 1; + var result = "V" + versionParts[0] + "_" + minorVersion + "_0"; + return result; + } + } } } \ No newline at end of file diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml index 70e25fbe2b..993780bebe 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml @@ -17,7 +17,7 @@ com.microsoft.azure azure-parent - 1.1.3-SNAPSHOT + @Model.PomVersion ../pom.xml @@ -62,7 +62,7 @@ com.microsoft.azure azure-mgmt-resources - 1.1.3-SNAPSHOT + @Model.PomVersion junit diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml index 12be11aae0..f3d2396635 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml @@ -25,6 +25,8 @@ package @(Settings.Namespace.ToLower()).@(Model.ImplPackage); import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.AzureResponseBuilder; import com.microsoft.azure.credentials.AzureTokenCredentials; +import com.microsoft.azure.management.apigeneration.Beta; +import com.microsoft.azure.management.apigeneration.Beta.SinceVersion; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; @@ -36,6 +38,7 @@ import com.microsoft.rest.RestClient; /** * Entry point to Azure @(serviceName) resource management. */ +@@Beta(SinceVersion.@Model.BetaSinceVersion) public final class @(className) extends Manager<@(className), @(Model.Name + "Impl")> { /** * Get a Configurable instance that can be used to create @(className) with optional configuration. From b7da488b8994097caf719688e719e00b5a25b154 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 18 Jul 2017 13:12:52 -0700 Subject: [PATCH 06/20] Bump minor version only if patch version is nonzero --- src/azure/Model/CodeModelJva.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 5359f2221d..ba71f669d3 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -82,7 +82,7 @@ public string ServiceName } - const string targetVersion = "1.1.3"; + const string targetVersion = "1.1.0"; /// /// The Azure SDK version to reference in the generated POM. /// @@ -104,10 +104,16 @@ public string BetaSinceVersion get { var versionParts = targetVersion.Split('.'); - var minorVersion = int.Parse(versionParts[1]) + 1; - var result = "V" + versionParts[0] + "_" + minorVersion + "_0"; + var minorVersion = int.Parse(versionParts[1]); + var patchVersion = int.Parse(versionParts[2]); + + var newMinorVersion = patchVersion == 0 + ? minorVersion + : minorVersion + 1; + + var result = "V" + versionParts[0] + "_" + newMinorVersion + "_0"; return result; } } } -} \ No newline at end of file +} From 64c57ed29fe8d1abce9c3aab973518f4a5ca8acd Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 18 Jul 2017 14:21:39 -0700 Subject: [PATCH 07/20] Fix Azure target version constant This constant should become a parameter at some point anyway. --- src/azure/Model/CodeModelJva.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index ba71f669d3..b2cfb673cf 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -82,7 +82,7 @@ public string ServiceName } - const string targetVersion = "1.1.0"; + const string targetVersion = "1.1.3"; /// /// The Azure SDK version to reference in the generated POM. /// From e48158e52b3c4fe2bd0e3d290f82eed62fad789f Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Fri, 14 Jul 2017 15:34:37 -0700 Subject: [PATCH 08/20] Add generation of service manager and pom.xml --- src/azure/Model/CodeModelJva.cs | 39 +------------------ src/azurefluent/CodeGeneratorJvaf.cs | 25 ++++++------ .../Templates/AzurePomTemplate.cshtml | 8 ++++ .../AzureServiceManagerTemplate.cshtml | 6 +++ 4 files changed, 27 insertions(+), 51 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index b2cfb673cf..d4c0c8366b 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -75,45 +75,10 @@ public string ServiceName get { var method = Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); - var serviceName = match.Groups[1].Value.ToPascalCase(); + var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); + var serviceName = match.Groups[1].Value; return serviceName; } } - - - const string targetVersion = "1.1.3"; - /// - /// The Azure SDK version to reference in the generated POM. - /// - [JsonIgnore] - public string PomVersion - { - get - { - return targetVersion + "-SNAPSHOT"; - } - } - - /// - /// The Beta.SinceVersion value to pass to the Beta annotation. - /// - [JsonIgnore] - public string BetaSinceVersion - { - get - { - var versionParts = targetVersion.Split('.'); - var minorVersion = int.Parse(versionParts[1]); - var patchVersion = int.Parse(versionParts[2]); - - var newMinorVersion = patchVersion == 0 - ? minorVersion - : minorVersion + 1; - - var result = "V" + versionParts[0] + "_" + newMinorVersion + "_0"; - return result; - } - } } } diff --git a/src/azurefluent/CodeGeneratorJvaf.cs b/src/azurefluent/CodeGeneratorJvaf.cs index 07651c3e3e..d791ab79a7 100644 --- a/src/azurefluent/CodeGeneratorJvaf.cs +++ b/src/azurefluent/CodeGeneratorJvaf.cs @@ -36,7 +36,7 @@ public class CodeGeneratorJvaf : CodeGeneratorJva /// public override async Task Generate(CodeModel cm) { - var packagePath = Path.Combine("src/main/java", cm.Namespace.ToLower().Replace('.', '/')); + var packagePath = Path.Combine("src/main/java", cm.Namespace.Replace('.', '/')); // get Azure Java specific codeModel var codeModel = cm as CodeModelJvaf; @@ -113,20 +113,17 @@ await Write(new PackageInfoTemplate Model = new PackageInfoTemplateModel(cm, "implementation") }, Path.Combine(packagePath, "implementation", _packageInfoFileName)); - object value; - bool regenerateManager; - if (Settings.Instance.CustomSettings.TryGetValue("RegenerateManager", out value) && - bool.TryParse(value.ToString(), out regenerateManager) && - regenerateManager) - { - // Manager - await Write( - new AzureServiceManagerTemplate { Model = codeModel }, - Path.Combine(packagePath, "implementation", codeModel.ServiceName + "Manager" + ImplementationFileExtension)); + // Manager + var method = codeModel.Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); + var serviceName = match.Groups[1].Value; - // POM - await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); - } + await Write( + new AzureServiceManagerTemplate { Model = codeModel }, + Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); + + // POM + await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); } } } diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml index 993780bebe..2434b61b3e 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml @@ -17,7 +17,11 @@ com.microsoft.azure azure-parent +<<<<<<< HEAD @Model.PomVersion +======= + 1.1.3-SNAPSHOT +>>>>>>> Add generation of service manager and pom.xml ../pom.xml @@ -62,7 +66,11 @@ com.microsoft.azure azure-mgmt-resources +<<<<<<< HEAD @Model.PomVersion +======= + 1.1.3-SNAPSHOT +>>>>>>> Add generation of service manager and pom.xml junit diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml index f3d2396635..13ff57e8a9 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml @@ -25,8 +25,11 @@ package @(Settings.Namespace.ToLower()).@(Model.ImplPackage); import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.AzureResponseBuilder; import com.microsoft.azure.credentials.AzureTokenCredentials; +<<<<<<< HEAD import com.microsoft.azure.management.apigeneration.Beta; import com.microsoft.azure.management.apigeneration.Beta.SinceVersion; +======= +>>>>>>> Add generation of service manager and pom.xml import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; @@ -38,7 +41,10 @@ import com.microsoft.rest.RestClient; /** * Entry point to Azure @(serviceName) resource management. */ +<<<<<<< HEAD @@Beta(SinceVersion.@Model.BetaSinceVersion) +======= +>>>>>>> Add generation of service manager and pom.xml public final class @(className) extends Manager<@(className), @(Model.Name + "Impl")> { /** * Get a Configurable instance that can be used to create @(className) with optional configuration. From 2ecad3dab824484fc5ef155ddfe10113aa3a5612 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Fri, 14 Jul 2017 16:52:44 -0700 Subject: [PATCH 09/20] Add setting to control whether to regenerate managers --- src/azurefluent/CodeGeneratorJvaf.cs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/azurefluent/CodeGeneratorJvaf.cs b/src/azurefluent/CodeGeneratorJvaf.cs index d791ab79a7..7bfb7efecc 100644 --- a/src/azurefluent/CodeGeneratorJvaf.cs +++ b/src/azurefluent/CodeGeneratorJvaf.cs @@ -36,7 +36,7 @@ public class CodeGeneratorJvaf : CodeGeneratorJva /// public override async Task Generate(CodeModel cm) { - var packagePath = Path.Combine("src/main/java", cm.Namespace.Replace('.', '/')); + var packagePath = Path.Combine("src/main/java", cm.Namespace.ToLower().Replace('.', '/')); // get Azure Java specific codeModel var codeModel = cm as CodeModelJvaf; @@ -113,17 +113,24 @@ await Write(new PackageInfoTemplate Model = new PackageInfoTemplateModel(cm, "implementation") }, Path.Combine(packagePath, "implementation", _packageInfoFileName)); - // Manager - var method = codeModel.Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); - var serviceName = match.Groups[1].Value; + object value; + bool regenerateManager; + if (Settings.Instance.CustomSettings.TryGetValue("RegenerateManager", out value) && + bool.TryParse(value.ToString(), out regenerateManager) && + regenerateManager) + { + // Manager + var method = codeModel.Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); + var serviceName = match.Groups[1].Value; - await Write( - new AzureServiceManagerTemplate { Model = codeModel }, - Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); + await Write( + new AzureServiceManagerTemplate { Model = codeModel }, + Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); - // POM - await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); + // POM + await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); + } } } } From 041d8f5cff053be90ad717d82998045937a2acc3 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Mon, 17 Jul 2017 15:51:28 -0700 Subject: [PATCH 10/20] Fix service name inference --- src/azure/Model/CodeModelJva.cs | 168 ++++++++++++++++---------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index d4c0c8366b..a06488aa4e 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -1,84 +1,84 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Linq; -using AutoRest.Core.Model; -using AutoRest.Core.Utilities; -using AutoRest.Java.Model; -using AutoRest.Core.Utilities.Collections; -using Newtonsoft.Json; -using System.Text.RegularExpressions; - -namespace AutoRest.Java.Azure.Model -{ - public class CodeModelJva : CodeModelJv - { - public IDictionary, string> pageClasses = - new Dictionary, string>(); - - public const string ExternalExtension = "x-ms-external"; - - [JsonIgnore] - public IEnumerable PropertiesEx => Properties.Where(p => p.ModelType.Name != "ServiceClientCredentials"); - - [JsonIgnore] - public virtual string ParentDeclaration - { - get - { - return " extends AzureServiceClient implements " + Name; - } - } - - [JsonIgnore] - public override List InterfaceImports - { - get - { - var imports = base.InterfaceImports; - imports.Add("com.microsoft.azure.AzureClient"); - return imports.OrderBy(i => i).ToList(); - } - } - - [JsonIgnore] - public override IEnumerable ImplImports - { - get - { - var imports = base.ImplImports.ToList(); - imports.Add("com.microsoft.azure.AzureClient"); - imports.Remove("com.microsoft.rest.ServiceClient"); - imports.Remove("okhttp3.OkHttpClient"); - imports.Remove("retrofit2.Retrofit"); - imports.Add("com.microsoft.azure.AzureServiceClient"); - return imports.OrderBy(i => i).ToList(); - } - } - - [JsonIgnore] - public string SetDefaultHeaders - { - get - { - return ""; - } - } - - /// - /// Attempts to infer the name of the service referenced by this CodeModel. - /// - [JsonIgnore] - public string ServiceName - { - get - { - var method = Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); - var serviceName = match.Groups[1].Value; - return serviceName; - } - } - } -} +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using AutoRest.Core.Model; +using AutoRest.Core.Utilities; +using AutoRest.Java.Model; +using AutoRest.Core.Utilities.Collections; +using Newtonsoft.Json; +using System.Text.RegularExpressions; + +namespace AutoRest.Java.Azure.Model +{ + public class CodeModelJva : CodeModelJv + { + public IDictionary, string> pageClasses = + new Dictionary, string>(); + + public const string ExternalExtension = "x-ms-external"; + + [JsonIgnore] + public IEnumerable PropertiesEx => Properties.Where(p => p.ModelType.Name != "ServiceClientCredentials"); + + [JsonIgnore] + public virtual string ParentDeclaration + { + get + { + return " extends AzureServiceClient implements " + Name; + } + } + + [JsonIgnore] + public override List InterfaceImports + { + get + { + var imports = base.InterfaceImports; + imports.Add("com.microsoft.azure.AzureClient"); + return imports.OrderBy(i => i).ToList(); + } + } + + [JsonIgnore] + public override IEnumerable ImplImports + { + get + { + var imports = base.ImplImports.ToList(); + imports.Add("com.microsoft.azure.AzureClient"); + imports.Remove("com.microsoft.rest.ServiceClient"); + imports.Remove("okhttp3.OkHttpClient"); + imports.Remove("retrofit2.Retrofit"); + imports.Add("com.microsoft.azure.AzureServiceClient"); + return imports.OrderBy(i => i).ToList(); + } + } + + [JsonIgnore] + public string SetDefaultHeaders + { + get + { + return ""; + } + } + + /// + /// Attempts to infer the name of the service referenced by this CodeModel. + /// + [JsonIgnore] + public string ServiceName + { + get + { + var method = Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); + var serviceName = match.Groups[1].Value; + return serviceName; + } + } + } +} From 38088c252cf0aed899611caa59f13c6dfdc832b4 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Mon, 17 Jul 2017 16:02:14 -0700 Subject: [PATCH 11/20] Fix service name case and code duplication --- src/azure/Model/CodeModelJva.cs | 2 +- src/azurefluent/CodeGeneratorJvaf.cs | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index a06488aa4e..56b05af07c 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -76,7 +76,7 @@ public string ServiceName { var method = Methods[0]; var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); - var serviceName = match.Groups[1].Value; + var serviceName = match.Groups[1].Value.ToPascalCase(); return serviceName; } } diff --git a/src/azurefluent/CodeGeneratorJvaf.cs b/src/azurefluent/CodeGeneratorJvaf.cs index 7bfb7efecc..07651c3e3e 100644 --- a/src/azurefluent/CodeGeneratorJvaf.cs +++ b/src/azurefluent/CodeGeneratorJvaf.cs @@ -120,13 +120,9 @@ await Write(new PackageInfoTemplate regenerateManager) { // Manager - var method = codeModel.Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/Microsoft\.(\w+)/"); - var serviceName = match.Groups[1].Value; - await Write( new AzureServiceManagerTemplate { Model = codeModel }, - Path.Combine(packagePath, "implementation", serviceName + "Manager" + ImplementationFileExtension)); + Path.Combine(packagePath, "implementation", codeModel.ServiceName + "Manager" + ImplementationFileExtension)); // POM await Write(new AzurePomTemplate { Model = codeModel }, "pom.xml"); From ff9727a36929aa1608d291d581a406d7888b70b4 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 18 Jul 2017 11:42:50 -0700 Subject: [PATCH 12/20] Add SDK version number to CodeModelJva --- src/azure/Model/CodeModelJva.cs | 29 +++++++++++++++++++ .../Templates/AzurePomTemplate.cshtml | 8 ----- .../AzureServiceManagerTemplate.cshtml | 6 ---- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 56b05af07c..6a9f466f75 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -80,5 +80,34 @@ public string ServiceName return serviceName; } } + + + const string targetVersion = "1.1.3"; + /// + /// The Azure SDK version to reference in the generated POM. + /// + [JsonIgnore] + public string PomVersion + { + get + { + return targetVersion + "-SNAPSHOT"; + } + } + + /// + /// The Beta.SinceVersion value to pass to the Beta annotation. + /// + [JsonIgnore] + public string BetaSinceVersion + { + get + { + var versionParts = targetVersion.Split('.'); + var minorVersion = int.Parse(versionParts[1]) + 1; + var result = "V" + versionParts[0] + "_" + minorVersion + "_0"; + return result; + } + } } } diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml index 2434b61b3e..993780bebe 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml @@ -17,11 +17,7 @@ com.microsoft.azure azure-parent -<<<<<<< HEAD @Model.PomVersion -======= - 1.1.3-SNAPSHOT ->>>>>>> Add generation of service manager and pom.xml ../pom.xml @@ -66,11 +62,7 @@ com.microsoft.azure azure-mgmt-resources -<<<<<<< HEAD @Model.PomVersion -======= - 1.1.3-SNAPSHOT ->>>>>>> Add generation of service manager and pom.xml junit diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml index 13ff57e8a9..f3d2396635 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml @@ -25,11 +25,8 @@ package @(Settings.Namespace.ToLower()).@(Model.ImplPackage); import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.AzureResponseBuilder; import com.microsoft.azure.credentials.AzureTokenCredentials; -<<<<<<< HEAD import com.microsoft.azure.management.apigeneration.Beta; import com.microsoft.azure.management.apigeneration.Beta.SinceVersion; -======= ->>>>>>> Add generation of service manager and pom.xml import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; @@ -41,10 +38,7 @@ import com.microsoft.rest.RestClient; /** * Entry point to Azure @(serviceName) resource management. */ -<<<<<<< HEAD @@Beta(SinceVersion.@Model.BetaSinceVersion) -======= ->>>>>>> Add generation of service manager and pom.xml public final class @(className) extends Manager<@(className), @(Model.Name + "Impl")> { /** * Get a Configurable instance that can be used to create @(className) with optional configuration. From 4ca3cd1b040dc64d3d7c2709602b70a816b5bc44 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 18 Jul 2017 13:12:52 -0700 Subject: [PATCH 13/20] Bump minor version only if patch version is nonzero --- src/azure/Model/CodeModelJva.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 6a9f466f75..340ee759d1 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -82,7 +82,7 @@ public string ServiceName } - const string targetVersion = "1.1.3"; + const string targetVersion = "1.1.0"; /// /// The Azure SDK version to reference in the generated POM. /// @@ -104,8 +104,14 @@ public string BetaSinceVersion get { var versionParts = targetVersion.Split('.'); - var minorVersion = int.Parse(versionParts[1]) + 1; - var result = "V" + versionParts[0] + "_" + minorVersion + "_0"; + var minorVersion = int.Parse(versionParts[1]); + var patchVersion = int.Parse(versionParts[2]); + + var newMinorVersion = patchVersion == 0 + ? minorVersion + : minorVersion + 1; + + var result = "V" + versionParts[0] + "_" + newMinorVersion + "_0"; return result; } } From 592a7d9fa9f4545c719f80d939d03d5d75f1c679 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Fri, 21 Jul 2017 14:40:56 -0700 Subject: [PATCH 14/20] Update RegenerateManager flag. Fix string constant. --- src/azure/Model/CodeModelJva.cs | 2 +- src/azurefluent/CodeGeneratorJvaf.cs | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 340ee759d1..0811fa1b6f 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -82,7 +82,7 @@ public string ServiceName } - const string targetVersion = "1.1.0"; + const string targetVersion = "1.1.3"; /// /// The Azure SDK version to reference in the generated POM. /// diff --git a/src/azurefluent/CodeGeneratorJvaf.cs b/src/azurefluent/CodeGeneratorJvaf.cs index 07651c3e3e..494ff2e9eb 100644 --- a/src/azurefluent/CodeGeneratorJvaf.cs +++ b/src/azurefluent/CodeGeneratorJvaf.cs @@ -26,7 +26,7 @@ public class CodeGeneratorJvaf : CodeGeneratorJva private const string _packageInfoFileName = "package-info.java"; public override bool IsSingleFileGenerationSupported => true; - + public override string UsageInstructions => $"The {ClientRuntimePackage} maven dependency is required to execute the generated code."; /// @@ -113,11 +113,7 @@ await Write(new PackageInfoTemplate Model = new PackageInfoTemplateModel(cm, "implementation") }, Path.Combine(packagePath, "implementation", _packageInfoFileName)); - object value; - bool regenerateManager; - if (Settings.Instance.CustomSettings.TryGetValue("RegenerateManager", out value) && - bool.TryParse(value.ToString(), out regenerateManager) && - regenerateManager) + if (true == AutoRest.Core.Settings.Instance.Host?.GetValue("regenerate-manager").Result) { // Manager await Write( From 7973d701ca323b6af2dfb03359cc2dcee2f2ed96 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Wed, 26 Jul 2017 15:33:01 -0700 Subject: [PATCH 15/20] Fix header comment in Java Manager generation --- .../Templates/AzureServiceManagerTemplate.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml index f3d2396635..4a7542e5e9 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml @@ -15,7 +15,7 @@ } /** -@Header("").TrimMultilineHeader() +@Header(" * ").TrimMultilineHeader() */ @EmptyLine From 82ebbc9e8e689955e0f01a0ea50593c919901529 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Fri, 28 Jul 2017 13:30:56 -0700 Subject: [PATCH 16/20] Add -ServiceName flag to override inferred service name --- src/azure/Model/CodeModelJva.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 0811fa1b6f..cee4b59047 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -9,6 +9,7 @@ using AutoRest.Core.Utilities.Collections; using Newtonsoft.Json; using System.Text.RegularExpressions; +using AutoRest.Core; namespace AutoRest.Java.Azure.Model { @@ -74,6 +75,11 @@ public string ServiceName { get { + if (Settings.Instance.CustomSettings.TryGetValue("ServiceName", out object obj)) + { + return obj.ToString(); + } + var method = Methods[0]; var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); var serviceName = match.Groups[1].Value.ToPascalCase(); From d080c2b5a78e0dd1f551554ffcbf53a5b8e13c3e Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Mon, 31 Jul 2017 14:33:57 -0700 Subject: [PATCH 17/20] Fix reference to storage manager in template --- .../Templates/AzureServiceManagerTemplate.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml index 4a7542e5e9..dc555dcab3 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml +++ b/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml @@ -86,7 +86,7 @@ public final class @(className) extends Manager<@(className), @(Model.Name + "Im * * @@param credentials the credentials to use * @@param subscriptionId the subscription UUID - * @@return the interface exposing storage management API entry points that work across subscriptions + * @@return the interface exposing @serviceName management API entry points that work across subscriptions */ @className authenticate(AzureTokenCredentials credentials, String subscriptionId); } From c8789b2c17f7e5b3fd3f69145df990c85b54ca60 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Thu, 10 Aug 2017 18:06:21 -0700 Subject: [PATCH 18/20] Add ServiceName to AutoRest 2 branch --- src/azure/Model/CodeModelJva.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index cee4b59047..686b3810c8 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -75,9 +75,10 @@ public string ServiceName { get { - if (Settings.Instance.CustomSettings.TryGetValue("ServiceName", out object obj)) + var serviceNameSetting = Settings.Instance.Host?.GetValue("service-name").Result; + if (!string.IsNullOrEmpty(serviceNameSetting)) { - return obj.ToString(); + return serviceNameSetting; } var method = Methods[0]; From 46d0b8814679f4dc8485be6c1b678ad54b60ee67 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 15 Aug 2017 13:36:52 -0700 Subject: [PATCH 19/20] Fix detection of sequence return types --- src/azure/Model/CodeModelJva.cs | 252 ++++++++++++++-------------- src/azurefluent/Model/MethodJvaf.cs | 19 ++- 2 files changed, 143 insertions(+), 128 deletions(-) diff --git a/src/azure/Model/CodeModelJva.cs b/src/azure/Model/CodeModelJva.cs index 686b3810c8..63d5c99031 100644 --- a/src/azure/Model/CodeModelJva.cs +++ b/src/azure/Model/CodeModelJva.cs @@ -1,126 +1,126 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Linq; -using AutoRest.Core.Model; -using AutoRest.Core.Utilities; -using AutoRest.Java.Model; -using AutoRest.Core.Utilities.Collections; -using Newtonsoft.Json; -using System.Text.RegularExpressions; -using AutoRest.Core; - -namespace AutoRest.Java.Azure.Model -{ - public class CodeModelJva : CodeModelJv - { - public IDictionary, string> pageClasses = - new Dictionary, string>(); - - public const string ExternalExtension = "x-ms-external"; - - [JsonIgnore] - public IEnumerable PropertiesEx => Properties.Where(p => p.ModelType.Name != "ServiceClientCredentials"); - - [JsonIgnore] - public virtual string ParentDeclaration - { - get - { - return " extends AzureServiceClient implements " + Name; - } - } - - [JsonIgnore] - public override List InterfaceImports - { - get - { - var imports = base.InterfaceImports; - imports.Add("com.microsoft.azure.AzureClient"); - return imports.OrderBy(i => i).ToList(); - } - } - - [JsonIgnore] - public override IEnumerable ImplImports - { - get - { - var imports = base.ImplImports.ToList(); - imports.Add("com.microsoft.azure.AzureClient"); - imports.Remove("com.microsoft.rest.ServiceClient"); - imports.Remove("okhttp3.OkHttpClient"); - imports.Remove("retrofit2.Retrofit"); - imports.Add("com.microsoft.azure.AzureServiceClient"); - return imports.OrderBy(i => i).ToList(); - } - } - - [JsonIgnore] - public string SetDefaultHeaders - { - get - { - return ""; - } - } - - /// - /// Attempts to infer the name of the service referenced by this CodeModel. - /// - [JsonIgnore] - public string ServiceName - { - get - { - var serviceNameSetting = Settings.Instance.Host?.GetValue("service-name").Result; - if (!string.IsNullOrEmpty(serviceNameSetting)) - { - return serviceNameSetting; - } - - var method = Methods[0]; - var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); - var serviceName = match.Groups[1].Value.ToPascalCase(); - return serviceName; - } - } - - - const string targetVersion = "1.1.3"; - /// - /// The Azure SDK version to reference in the generated POM. - /// - [JsonIgnore] - public string PomVersion - { - get - { - return targetVersion + "-SNAPSHOT"; - } - } - - /// - /// The Beta.SinceVersion value to pass to the Beta annotation. - /// - [JsonIgnore] - public string BetaSinceVersion - { - get - { - var versionParts = targetVersion.Split('.'); - var minorVersion = int.Parse(versionParts[1]); - var patchVersion = int.Parse(versionParts[2]); - - var newMinorVersion = patchVersion == 0 - ? minorVersion - : minorVersion + 1; - - var result = "V" + versionParts[0] + "_" + newMinorVersion + "_0"; - return result; - } - } - } -} +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using AutoRest.Core.Model; +using AutoRest.Core.Utilities; +using AutoRest.Java.Model; +using AutoRest.Core.Utilities.Collections; +using Newtonsoft.Json; +using System.Text.RegularExpressions; +using AutoRest.Core; + +namespace AutoRest.Java.Azure.Model +{ + public class CodeModelJva : CodeModelJv + { + public IDictionary, string> pageClasses = + new Dictionary, string>(); + + public const string ExternalExtension = "x-ms-external"; + + [JsonIgnore] + public IEnumerable PropertiesEx => Properties.Where(p => p.ModelType.Name != "ServiceClientCredentials"); + + [JsonIgnore] + public virtual string ParentDeclaration + { + get + { + return " extends AzureServiceClient implements " + Name; + } + } + + [JsonIgnore] + public override List InterfaceImports + { + get + { + var imports = base.InterfaceImports; + imports.Add("com.microsoft.azure.AzureClient"); + return imports.OrderBy(i => i).ToList(); + } + } + + [JsonIgnore] + public override IEnumerable ImplImports + { + get + { + var imports = base.ImplImports.ToList(); + imports.Add("com.microsoft.azure.AzureClient"); + imports.Remove("com.microsoft.rest.ServiceClient"); + imports.Remove("okhttp3.OkHttpClient"); + imports.Remove("retrofit2.Retrofit"); + imports.Add("com.microsoft.azure.AzureServiceClient"); + return imports.OrderBy(i => i).ToList(); + } + } + + [JsonIgnore] + public string SetDefaultHeaders + { + get + { + return ""; + } + } + + /// + /// Attempts to infer the name of the service referenced by this CodeModel. + /// + [JsonIgnore] + public string ServiceName + { + get + { + var serviceNameSetting = Settings.Instance.Host?.GetValue("service-name").Result; + if (!string.IsNullOrEmpty(serviceNameSetting)) + { + return serviceNameSetting; + } + + var method = Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); + var serviceName = match.Groups[1].Value.ToPascalCase(); + return serviceName; + } + } + + + const string targetVersion = "1.1.3"; + /// + /// The Azure SDK version to reference in the generated POM. + /// + [JsonIgnore] + public string PomVersion + { + get + { + return targetVersion + "-SNAPSHOT"; + } + } + + /// + /// The Beta.SinceVersion value to pass to the Beta annotation. + /// + [JsonIgnore] + public string BetaSinceVersion + { + get + { + var versionParts = targetVersion.Split('.'); + var minorVersion = int.Parse(versionParts[1]); + var patchVersion = int.Parse(versionParts[2]); + + var newMinorVersion = patchVersion == 0 + ? minorVersion + : minorVersion + 1; + + var result = "V" + versionParts[0] + "_" + newMinorVersion + "_0"; + return result; + } + } + } +} diff --git a/src/azurefluent/Model/MethodJvaf.cs b/src/azurefluent/Model/MethodJvaf.cs index db6ea8d569..88da06a653 100644 --- a/src/azurefluent/Model/MethodJvaf.cs +++ b/src/azurefluent/Model/MethodJvaf.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. using System.Collections.Generic; @@ -223,6 +223,21 @@ private enum MethodType Delete } + private static bool HasSequenceType(IModelType mt) + { + if (mt is SequenceType) + { + return true; + } + + if (mt is CompositeType ct) + { + return ct.Properties.Any(p => HasSequenceType(p.ModelType)); + } + + return false; + } + private static MethodType GetMethodType(MethodJvaf method) { Regex leading = new Regex("^/+"); @@ -233,7 +248,7 @@ private static MethodType GetMethodType(MethodJvaf method) var urlSplits = methodUrl.Split('/'); if ((urlSplits.Count() == 5 || urlSplits.Count() == 7) && StringComparer.OrdinalIgnoreCase.Equals(urlSplits[0], "subscriptions") - && method.ReturnType.Body is SequenceType) + && HasSequenceType(method.ReturnType.Body)) { if (urlSplits.Count() == 5) { From e0038346f03a74bb735a6d4b101a86652626742d Mon Sep 17 00:00:00 2001 From: Johannes Bader Date: Tue, 29 Aug 2017 11:10:44 -0700 Subject: [PATCH 20/20] fix paths --- .gitignore | 5 ++++- .../Templates/AzurePomTemplate.cshtml | 2 -- .../Templates/AzureServiceManagerTemplate.cshtml | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) rename src/{generator/AutoRest.Java.Azure => azure}/Templates/AzurePomTemplate.cshtml (98%) rename src/{generator/AutoRest.Java.Azure => azure}/Templates/AzureServiceManagerTemplate.cshtml (98%) diff --git a/.gitignore b/.gitignore index 565e7ae9fb..b796b11f6e 100644 --- a/.gitignore +++ b/.gitignore @@ -289,4 +289,7 @@ __pycache__/ package-lock.json *.class -test/*/target/ \ No newline at end of file +test/*/target/ +.settings/ +.project +.classpath \ No newline at end of file diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml b/src/azure/Templates/AzurePomTemplate.cshtml similarity index 98% rename from src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml rename to src/azure/Templates/AzurePomTemplate.cshtml index 993780bebe..6ce1102091 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzurePomTemplate.cshtml +++ b/src/azure/Templates/AzurePomTemplate.cshtml @@ -1,6 +1,4 @@ @using System -@using AutoRest.Java.Azure.Templates -@using AutoRest.Java.Templates @using System.Linq; @using AutoRest.Java @using AutoRest.Java.Model diff --git a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml b/src/azure/Templates/AzureServiceManagerTemplate.cshtml similarity index 98% rename from src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml rename to src/azure/Templates/AzureServiceManagerTemplate.cshtml index dc555dcab3..2e6a85caae 100644 --- a/src/generator/AutoRest.Java.Azure/Templates/AzureServiceManagerTemplate.cshtml +++ b/src/azure/Templates/AzureServiceManagerTemplate.cshtml @@ -1,7 +1,5 @@ @using System @using System.Text.RegularExpressions -@using AutoRest.Java.Azure.Templates -@using AutoRest.Java.Templates @using System.Linq @using AutoRest.Core.Utilities @using AutoRest.Java