Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,7 @@ __pycache__/

package-lock.json
*.class
test/*/target/
test/*/target/
.settings/
.project
.classpath
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