Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class JavaSettings {

private static Logger logger;
private final boolean useKeyCredential;
private final boolean noCustomHeaders;
private boolean noCustomHeaders;

static void setHeader(String value) {
if ("MICROSOFT_MIT".equals(value)) {
header = MICROSOFT_MIT_LICENSE_HEADER + "\n" + String.format(DEFAULT_CODE_GENERATION_HEADER, VERSION);
Expand Down Expand Up @@ -170,7 +171,8 @@ public static JavaSettings getInstance() {
getBooleanValue(host, "disable-required-property-annotation", false),
getBooleanValue(host, "enable-page-size", false),
getBooleanValue(host, "use-key-credential", false),
getBooleanValue(host, "null-byte-array-maps-to-empty-array", false)
getBooleanValue(host, "null-byte-array-maps-to-empty-array", false),
getBooleanValue(host, "graal-vm-config", false)
);
}
return instance;
Expand Down Expand Up @@ -326,7 +328,8 @@ private JavaSettings(AutorestSettings autorestSettings,
boolean disableRequiredPropertyAnnotation,
boolean pageSizeEnabled,
boolean useKeyCredential,
boolean nullByteArrayMapsToEmptyArray) {
boolean nullByteArrayMapsToEmptyArray,
boolean generateGraalVmConfig) {

this.autorestSettings = autorestSettings;
this.modelerSettings = new ModelerSettings(modelerSettings);
Expand Down Expand Up @@ -425,6 +428,7 @@ private JavaSettings(AutorestSettings autorestSettings,
this.pageSizeEnabled = pageSizeEnabled;
this.useKeyCredential = useKeyCredential;
this.nullByteArrayMapsToEmptyArray = nullByteArrayMapsToEmptyArray;
this.generateGraalVmConfig = generateGraalVmConfig;
}


Expand Down Expand Up @@ -902,6 +906,12 @@ public boolean isPageSizeEnabled() {
return pageSizeEnabled;
}

private final boolean generateGraalVmConfig;

public boolean isGenerateGraalVmConfig() {
return generateGraalVmConfig;
}

public static class PollingDetails {
@JsonProperty("strategy")
private String strategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ FluentJavaPackage handleTemplate(Client client) {
javaPackage.addPackageInfo(packageInfo.getPackage(), "package-info", packageInfo);
}

// GraalVM config
if (javaSettings.isGenerateGraalVmConfig()) {
javaPackage.addGraalVmConfig("com.azure.resourcemanager", FluentUtils.getArtifactId(), client.getGraalVmConfig());
}

// Samples
if (fluentPremiumExamples != null) {
for (FluentExample example : fluentPremiumExamples) {
Expand Down
1 change: 1 addition & 0 deletions fluentnamer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ client-logger: true
generate-client-interfaces: true
required-parameter-client-methods: true
client-flattened-annotation-target: none
graal-vm-config: true
```
5 changes: 5 additions & 0 deletions javagen/src/main/java/com/azure/autorest/Javagen.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ protected JavaPackage writeToTemplates(CodeModel codeModel, Client client, JavaS
}
}

// GraalVM config
if (settings.isGenerateGraalVmConfig()) {
javaPackage.addGraalVmConfig(Project.AZURE_GROUP_ID, ClientModelUtil.getArtifactId(), client.getGraalVmConfig());
}

// Service version
if (settings.isDataPlaneClient()) {
String packageName = settings.getPackage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.azure.autorest.model.clientmodel.Client;
import com.azure.autorest.model.clientmodel.ClientBuilder;
import com.azure.autorest.model.clientmodel.ClientBuilderTrait;
import com.azure.autorest.model.clientmodel.ClientException;
import com.azure.autorest.model.clientmodel.ClientMethod;
import com.azure.autorest.model.clientmodel.ClientMethodExample;
import com.azure.autorest.model.clientmodel.ClientMethodType;
Expand Down Expand Up @@ -111,7 +112,7 @@ public Client map(CodeModel codeModel) {
builder.enums(enumTypes);

// exception
builder.exceptions(codeModel.getOperationGroups().stream()
List<ClientException> exceptions = codeModel.getOperationGroups().stream()
.flatMap(og -> og.getOperations().stream())
.flatMap(o -> o.getExceptions().stream())
.map(Response::getSchema)
Expand All @@ -120,7 +121,8 @@ public Client map(CodeModel codeModel) {
.map(s -> Mappers.getExceptionMapper().map((ObjectSchema) s))
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList()));
.collect(Collectors.toList());
builder.exceptions(exceptions);

builder.xmlSequenceWrappers(parseXmlSequenceWrappers(codeModel, settings));

Expand Down Expand Up @@ -317,6 +319,13 @@ public Client map(CodeModel codeModel) {
builder.liveTests(LiveTestsMapper.getInstance().map(codeModel.getTestModel()));
}

builder.graalVmConfig(Mappers.getGraalVmConfigMapper()
.map(new GraalVmConfigMapper.ServiceAndModel(
serviceClientsMap.keySet(),
exceptions,
clientModels,
enumTypes)));

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public UnionMapper getUnionMapper() {
public UnionModelMapper getUnionModelMapper() {
return UnionModelMapper.getInstance();
}

@Override
public GraalVmConfigMapper getGraalVmConfigMapper() {
return GraalVmConfigMapper.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.autorest.mapper;

import com.azure.autorest.extension.base.plugin.JavaSettings;
import com.azure.autorest.model.clientmodel.ClientException;
import com.azure.autorest.model.clientmodel.ClientModel;
import com.azure.autorest.model.clientmodel.EnumType;
import com.azure.autorest.model.clientmodel.GraalVmConfig;
import com.azure.autorest.model.clientmodel.ServiceClient;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class GraalVmConfigMapper implements IMapper<GraalVmConfigMapper.ServiceAndModel, GraalVmConfig> {

public static class ServiceAndModel {
private final Collection<ServiceClient> serviceClients;
private final Collection<ClientException> exceptions;
private final Collection<ClientModel> models;
private final Collection<EnumType> enums;

public ServiceAndModel(Collection<ServiceClient> serviceClients,
Collection<ClientException> exceptions,
Collection<ClientModel> models,
Collection<EnumType> enums) {
this.serviceClients = serviceClients;
this.exceptions = exceptions;
this.models = models;
this.enums = enums;
}
}

private static final GraalVmConfigMapper INSTANCE = new GraalVmConfigMapper();

protected GraalVmConfigMapper() {
}

public static GraalVmConfigMapper getInstance() {
return INSTANCE;
}

@Override
public GraalVmConfig map(ServiceAndModel data) {
List<String> proxies;
List<String> reflects;

// Reflect
reflects = data.exceptions.stream()
.map(e -> e.getPackage() + "." + e.getName())
.collect(Collectors.toList());
if (!JavaSettings.getInstance().isStreamStyleSerialization()) {
reflects.addAll(data.models.stream()
.map(e -> e.getPackage() + "." + e.getName())
.collect(Collectors.toList()));
reflects.addAll(data.enums.stream()
.map(m -> m.getPackage() + "." + m.getName())
.collect(Collectors.toList()));
}

// Proxy
proxies = data.serviceClients.stream()
.flatMap(sc -> {
if (sc.getMethodGroupClients() != null) {
return sc.getMethodGroupClients().stream();
} else {
return Stream.empty();
}
})
.filter(m -> m.getProxy() != null)
.map(m -> m.getPackage() + "." + m.getClassName() + "$" + m.getProxy().getName())
.collect(Collectors.toList());
proxies.addAll(data.serviceClients.stream()
.filter(sc -> sc.getProxy() != null)
.map(sc -> sc.getPackage() + "." + sc.getClassName() + "$" + sc.getProxy().getName())
.collect(Collectors.toList()));

return new GraalVmConfig(proxies, reflects, JavaSettings.getInstance().isFluent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ public interface MapperFactory {
UnionMapper getUnionMapper();

UnionModelMapper getUnionModelMapper();

GraalVmConfigMapper getGraalVmConfigMapper();
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ public static UnionMapper getUnionMapper() {
public static UnionModelMapper getUnionModelMapper() {
return factory.getUnionModelMapper();
}

public static GraalVmConfigMapper getGraalVmConfigMapper() {
return factory.getGraalVmConfigMapper();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class Client {
private final List<LiveTests> liveTests;
private final List<UnionModel> unionModels;
private final List<ClientMethodExample> clientMethodExamples;
private final GraalVmConfig graalVmConfig;

/**
* Create a new Client with the provided values.
Expand All @@ -88,7 +89,8 @@ private Client(String clientName, String clientDescription, List<EnumType> enums
ServiceClient serviceClient, List<ServiceClient> serviceClients, ModuleInfo moduleInfo,
List<AsyncSyncClient> syncClients, List<AsyncSyncClient> asyncClients,
List<ClientBuilder> clientBuilders, List<ProtocolExample> protocolExamples,
List<LiveTests> liveTests, List<UnionModel> unionModels, List<ClientMethodExample> clientMethodExamples
List<LiveTests> liveTests, List<UnionModel> unionModels, List<ClientMethodExample> clientMethodExamples,
GraalVmConfig graalVmConfig
) {
this.clientName = clientName;
this.clientDescription = clientDescription;
Expand All @@ -109,6 +111,7 @@ private Client(String clientName, String clientDescription, List<EnumType> enums
this.liveTests = liveTests;
this.unionModels = unionModels;
this.clientMethodExamples = clientMethodExamples;
this.graalVmConfig = graalVmConfig;
}

public final String getClientName() {
Expand Down Expand Up @@ -193,6 +196,11 @@ public List<ClientMethodExample> getClientMethodExamples() {
return clientMethodExamples;
}

/** @return the Graal VM config */
public GraalVmConfig getGraalVmConfig() {
return graalVmConfig;
}

public static class Builder {
private String clientName;
private String clientDescription;
Expand All @@ -213,6 +221,7 @@ public static class Builder {
private List<LiveTests> liveTests = Collections.emptyList();
private List<UnionModel> unionModels = Collections.emptyList();
private List<ClientMethodExample> clientMethodExamples = Collections.emptyList();
private GraalVmConfig graalVmConfig;

/**
* Sets the name of this service client.
Expand Down Expand Up @@ -394,6 +403,11 @@ public Builder liveTests(List<LiveTests> liveTests) {
return this;
}

public Builder graalVmConfig(GraalVmConfig graalVmConfig) {
this.graalVmConfig = graalVmConfig;
return this;
}

public Client build() {
if (serviceClient == null && !serviceClients.isEmpty()) {
serviceClient = serviceClients.iterator().next();
Expand All @@ -416,7 +430,8 @@ public Client build() {
protocolExamples,
liveTests,
unionModels,
clientMethodExamples
clientMethodExamples,
graalVmConfig
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.autorest.model.clientmodel;

import com.azure.autorest.util.TemplateUtil;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class GraalVmConfig {

private final List<String> proxies;
private final List<String> reflects;
private final boolean fluent;

public GraalVmConfig(List<String> proxies, List<String> reflects, boolean fluent) {
this.proxies = proxies;
this.reflects = reflects;
this.fluent = fluent;
}

private static class ReflectConfig {
@JsonProperty("name")
private final String name;
@JsonProperty("allDeclaredConstructors")
private final boolean allDeclaredConstructors = true;
@JsonProperty("allDeclaredFields")
private final boolean allDeclaredFields = true;
@JsonProperty("allDeclaredMethods")
private final boolean allDeclaredMethods = true;

private ReflectConfig(String name) {
this.name = name;
}
}

private static class ResourceConfig {

private static class Pattern {
@JsonProperty("pattern")
private final String pattern;

private Pattern(String pattern) {
this.pattern = pattern;
}
}

private static class Resource {
@JsonProperty("includes")
private final List<Pattern> includes;

public Resource(List<Pattern> includes) {
this.includes = includes;
}
}

@JsonProperty("resources")
private final Resource resources;
private final List<Object> bundles = Collections.emptyList();

private ResourceConfig(String artifactId) {
this.resources = new Resource(Collections.singletonList(
new Pattern("\\Q" + artifactId + ".properties" + "\\E")));
}
}

public boolean generateResourceConfig() {
return !this.fluent;
}

// TODO: Template
public String toProxyConfigJson() {
List<List<String>> result = proxies.stream().map(Collections::singletonList).collect(Collectors.toList());
return TemplateUtil.prettyPrintToJson(result);
}

public String toReflectConfigJson() {
List<ReflectConfig> result = reflects.stream().map(ReflectConfig::new).collect(Collectors.toList());
return TemplateUtil.prettyPrintToJson(result);
}

public String toResourceConfigJson(String artifactId) {
return TemplateUtil.prettyPrintToJson(new ResourceConfig(artifactId));
}
}
Loading