Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cc36c23
Add generation of service manager and pom.xml
RikkiGibson Jul 14, 2017
abf8c57
Add setting to control whether to regenerate managers
RikkiGibson Jul 14, 2017
d2c6152
Fix service name inference
RikkiGibson Jul 17, 2017
221fe53
Fix service name case and code duplication
RikkiGibson Jul 17, 2017
c833496
Add SDK version number to CodeModelJva
RikkiGibson Jul 18, 2017
b60ed9b
Bump minor version only if patch version is nonzero
RikkiGibson Jul 18, 2017
f654a75
Fix Azure target version constant
RikkiGibson Jul 18, 2017
6483fb6
Add generation of service manager and pom.xml
RikkiGibson Jul 14, 2017
fde4072
Add setting to control whether to regenerate managers
RikkiGibson Jul 14, 2017
2d8bed7
Fix service name inference
RikkiGibson Jul 17, 2017
667ef84
Fix service name case and code duplication
RikkiGibson Jul 17, 2017
fbce9c7
Add SDK version number to CodeModelJva
RikkiGibson Jul 18, 2017
5ed28ee
Bump minor version only if patch version is nonzero
RikkiGibson Jul 18, 2017
81d890c
Update RegenerateManager flag. Fix string constant.
RikkiGibson Jul 21, 2017
0ab7edb
Fix header comment in Java Manager generation
RikkiGibson Jul 26, 2017
5c7df4e
Add -ServiceName flag to override inferred service name
RikkiGibson Jul 28, 2017
aa7d374
Fix reference to storage manager in template
RikkiGibson Jul 31, 2017
fadfa31
Add ServiceName to AutoRest 2 branch
RikkiGibson Aug 11, 2017
6cb1133
Fix detection of sequence return types
RikkiGibson Aug 15, 2017
4a2e556
Rebase azure-gen-manager-2 onto master
RikkiGibson Aug 31, 2017
5be8472
Fix regeneration script for fluent
RikkiGibson Aug 31, 2017
1ff806d
Ignore .iml files in tests
RikkiGibson Sep 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml
*.iml

# CodeRush
.cr/
Expand All @@ -292,4 +293,4 @@ package-lock.json
test/*/target/
.settings/
.project
.classpath
.classpath
10 changes: 7 additions & 3 deletions .gulp/regeneration.iced
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
# Instead: have bunch of configuration files sitting in a well-known spot, discover them, feed them to AutoRest, done.

regenExpected = (opts,done) ->
outputDir = if !!opts.outputBaseDir then "#{opts.outputBaseDir}/#{opts.outputDir}" else opts.outputDir
outputDir = "#{opts.outputBaseDir}/#{opts.outputDir}"
keys = Object.getOwnPropertyNames(opts.mappings)
instances = keys.length

for kkey in keys
optsMappingsValue = opts.mappings[kkey]
key = kkey.trim().toLowerCase()

# If there's no outputDir provided in options, that generator must be capable of
# putting Java files in the correct output dir by itself. Don't append the key to the path.
mappingOutputDir = if !!opts.outputDir then outputDir + "/" + key else outputDir

args = [
"--java",
"--output-folder=#{outputDir}/#{key}",
"--output-folder=#{mappingOutputDir}",
"--license-header=#{if !!opts.header then opts.header else 'MICROSOFT_MIT_NO_VERSION'}",
"--java.namespace=#{['Fixtures', key.replace(/\/|\./, '')].join('.')}",
"--input-file=#{swaggerDir}/#{optsMappingsValue}"
Expand Down Expand Up @@ -85,7 +89,7 @@ task 'regenerate-javaazurefluent', '', (done) ->
regenExpected {
'outputBaseDir': 'test/azurefluent',
'mappings': defaultAzureMappings,
'outputDir': 'src/main/java/fixtures',
'outputDir': '', # Fluent generator deals with package paths itself now
'azureArm': true,
'fluent': true
},done
Expand Down
62 changes: 60 additions & 2 deletions src/azure/Model/CodeModelJva.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +8,8 @@
using AutoRest.Java.Model;
using AutoRest.Core.Utilities.Collections;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using AutoRest.Core;

namespace AutoRest.Java.Azure.Model
{
Expand Down Expand Up @@ -64,5 +66,61 @@ public string SetDefaultHeaders
return "";
}
}

/// <summary>
/// Attempts to infer the name of the service referenced by this CodeModel.
/// </summary>
[JsonIgnore]
public string ServiceName
{
get
{
var serviceNameSetting = Settings.Instance.Host?.GetValue<string>("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";
/// <summary>
/// The Azure SDK version to reference in the generated POM.
/// </summary>
[JsonIgnore]
public string PomVersion
{
get
{
return targetVersion + "-SNAPSHOT";
}
}

/// <summary>
/// The Beta.SinceVersion value to pass to the Beta annotation.
/// </summary>
[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;
}
}
}
}
}
136 changes: 136 additions & 0 deletions src/azure/Templates/AzurePomTemplate.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
@using System
@using System.Linq;
@using AutoRest.Java
@using AutoRest.Java.Model
@using AutoRest.Java.Azure.Model
@inherits AutoRest.Core.Template<AutoRest.Java.Azure.Model.CodeModelJva>
@{
var serviceName = Model.ServiceName;
}
<!--
@Header(" * ").TrimMultilineHeader()
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-parent</artifactId>
<version>@Model.PomVersion</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>azure-mgmt-@serviceName.ToLower()</artifactId>
<packaging>jar</packaging>

<name>Microsoft Azure SDK for @serviceName Management</name>
<description>This package contains Microsoft @serviceName Management SDK.</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>

<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>http://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>scm:git:https://github.com/Azure/azure-sdk-for-java</url>
<connection>scm:git:git@github.com:Azure/azure-sdk-for-java.git</connection>
<tag>HEAD</tag>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<legal><![CDATA[[INFO] Any downloads listed may be third party software. Microsoft grants you no rights for third party software.]]></legal>
</properties>

<developers>
<developer>
<id>microsoft</id>
<name>Microsoft</name>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-mgmt-resources</artifactId>
<version>@Model.PomVersion</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<annotationProcessors>
<annotationProcessor>
com.microsoft.azure.management.apigeneration.LangDefinitionProcessor
</annotationProcessor>
</annotationProcessors>
<debug>true</debug>
<optimize>true</optimize>
<compilerArguments>
<AaddGeneratedAnnotation>true</AaddGeneratedAnnotation>
<Adebug>true</Adebug>
</compilerArguments>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<excludePackageNames>*.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.search</excludePackageNames>
<bottom>
<![CDATA[<code>
/**
<br />* Copyright (c) Microsoft Corporation. All rights reserved.
<br />* Licensed under the MIT License. See License.txt in the project root for
<br />* license information.
<br />*/
</code>]]>
</bottom>
</configuration>
</plugin>

</plugins>
</build>
</project>
107 changes: 107 additions & 0 deletions src/azure/Templates/AzureServiceManagerTemplate.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
@using System
@using System.Text.RegularExpressions
@using System.Linq
@using AutoRest.Core.Utilities
@using AutoRest.Java
@using AutoRest.Java.Azure.Model
@using AutoRest.Java.Model
@inherits AutoRest.Core.Template<AutoRest.Java.Azure.Model.CodeModelJva>

@{
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.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;
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.
*/
@@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.
*
* @@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<Configurable> {
/**
* 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 @serviceName 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<Configurable> 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));
}
}
Loading