Skip to content

Commit

Permalink
Remove setting to disable formatting (#2652)
Browse files Browse the repository at this point in the history
Remove setting to disable formatting
  • Loading branch information
alzimmermsft authored Mar 29, 2024
1 parent 0d202bc commit 05eb8e4
Show file tree
Hide file tree
Showing 32 changed files with 381 additions and 362 deletions.
5 changes: 4 additions & 1 deletion Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,25 @@ Write-Host "Parallelization: $Parallelization"
$ExitCode = 0

$generateScript = {
$timer = [Diagnostics.Stopwatch]::StartNew()
$generateOutput = Invoke-Expression "autorest $_"
$timer.Stop()
$global:ExitCode = $global:ExitCode -bor $LASTEXITCODE

if ($LASTEXITCODE -ne 0) {
Write-Host "
========================
autorest $_
========================
FAILED (Time elapsed: $($timer.ToString()))
$([String]::Join("`n", $generateOutput))
"
} else {
Write-Host "
========================
autorest $_
========================
SUCCEEDED
SUCCEEDED (Time elapsed: $($timer.ToString()))
"
}

Expand Down
3 changes: 3 additions & 0 deletions eng/pipelines/variables/globals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ variables:
JavaVersion: '1.11'
NodeVersion: '18.x'

# Sets the Maven log level to either the LogLevel passed in the manual pipeline run or the default 'warn'
MavenLogLevel: $[coalesce(variables['LogLevel'], 'warn')]

# Maven build/test options
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
# See https://github.com/actions/virtual-environments/issues/1499 for more info about the wagon options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public static JavaSettings getInstance() {
getStringValue(host, "client-flattened-annotation-target", ""),
getStringValue(host, "key-credential-header-name", ""),
getBooleanValue(host, "disable-client-builder", false),
getBooleanValue(host, "skip-formatting", false),
host.getValue(TYPE_FACTORY.constructMapType(Map.class, String.class, PollingDetails.class), "polling"),
getBooleanValue(host, "generate-samples", false),
getBooleanValue(host, "generate-tests", false),
Expand Down Expand Up @@ -226,7 +225,6 @@ public static JavaSettings getInstance() {
* x-ms-client-flatten.
* @param keyCredentialHeaderName The header name for the key credential.
* @param clientBuilderDisabled Whether to disable the client builder.
* @param skipFormatting Whether to skip formatting the generated code.
* @param pollingConfig The polling configuration.
* @param generateSamples Whether to generate samples.
* @param generateTests Whether to generate tests.
Expand Down Expand Up @@ -303,7 +301,6 @@ private JavaSettings(AutorestSettings autorestSettings,
String clientFlattenAnnotationTarget,
String keyCredentialHeaderName,
boolean clientBuilderDisabled,
boolean skipFormatting,
Map<String, PollingDetails> pollingConfig,
boolean generateSamples,
boolean generateTests,
Expand Down Expand Up @@ -389,7 +386,6 @@ private JavaSettings(AutorestSettings autorestSettings,
this.customizationClass = customizationClass;
this.keyCredentialHeaderName = keyCredentialHeaderName;
this.clientBuilderDisabled = clientBuilderDisabled;
this.skipFormatting = skipFormatting;
if (pollingConfig != null) {
if (!pollingConfig.containsKey("default")) {
pollingConfig.put("default", new PollingDetails());
Expand Down Expand Up @@ -1143,17 +1139,6 @@ public final String getCustomizationClass() {
return customizationClass;
}

boolean skipFormatting;

/**
* Whether to skip formatting java files.
*
* @return whether to skip formatting java files.
*/
public boolean isSkipFormatting() {
return skipFormatting;
}

private final boolean optionalConstantAsEnum;

/**
Expand Down Expand Up @@ -1555,33 +1540,33 @@ public boolean isNullByteArrayMapsToEmptyArray() {
return nullByteArrayMapsToEmptyArray;
}

private static final String DEFAULT_CODE_GENERATION_HEADER = String.join("\r\n",
private static final String DEFAULT_CODE_GENERATION_HEADER = String.join("\n",
"Code generated by Microsoft (R) AutoRest Code Generator %s",
"Changes may cause incorrect behavior and will be lost if the code is regenerated.");

private static final String DEFAULT_CODE_GENERATION_HEADER_WITHOUT_VERSION = String.join("\r\n",
private static final String DEFAULT_CODE_GENERATION_HEADER_WITHOUT_VERSION = String.join("\n",
"Code generated by Microsoft (R) AutoRest Code Generator.",
"Changes may cause incorrect behavior and will be lost if the code is regenerated.");

private static final String MICROSOFT_APACHE_LICENSE_HEADER = String.join("\r\n",
"Copyright (c) Microsoft and contributors. All rights reserved.\r\n",
private static final String MICROSOFT_APACHE_LICENSE_HEADER = String.join("\n",
"Copyright (c) Microsoft and contributors. All rights reserved.\n",
"Licensed under the Apache License, Version 2.0 (the \"License\");",
"you may not use this file except in compliance with the License.",
"You may obtain a copy of the License at",
" https://www.apache.org/licenses/LICENSE-2.0\r\n",
" https://www.apache.org/licenses/LICENSE-2.0\n",
"Unless required by applicable law or agreed to in writing, software",
"distributed under the License is distributed on an \"AS IS\" BASIS,",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"See the License for the specific language governing permissions and",
"limitations under the License.",
"");

private static final String MICROSOFT_MIT_LICENSE_HEADER = String.join("\r\n",
private static final String MICROSOFT_MIT_LICENSE_HEADER = String.join("\n",
"Copyright (c) Microsoft Corporation. All rights reserved.",
"Licensed under the MIT License. See License.txt in the project root for license information.",
"");

private static final String MICROSOFT_MIT_SMALL_LICENSE_HEADER = String.join("\r\n",
private static final String MICROSOFT_MIT_SMALL_LICENSE_HEADER = String.join("\n",
"Copyright (c) Microsoft Corporation. All rights reserved.",
"Licensed under the MIT License.",
"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ private List<XmlSequenceWrapper> parseXmlSequenceWrappers(CodeModel codeModel, J
Schema responseBodySchema = SchemaUtil.getLowestCommonParent(operation.getResponses().stream()
.map(Response::getSchema)
.filter(Objects::nonNull)
.collect(Collectors.toList()));
.iterator());

if (responseBodySchema instanceof ArraySchema) {
parseXmlSequenceWrappers((ArraySchema) responseBodySchema, xmlSequenceWrappers, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ private ReturnTypeHolder getReturnTypes(Operation operation, boolean isProtocolM
if (operation.getExtensions() != null && operation.getExtensions().getXmsPageable() != null) {
// Mono<SimpleResponse<Page>>
Schema responseBodySchema = SchemaUtil.getLowestCommonParent(operation.getResponses().stream()
.map(Response::getSchema).filter(Objects::nonNull).collect(Collectors.toList()));
.map(Response::getSchema).filter(Objects::nonNull).iterator());
if (!(responseBodySchema instanceof ObjectSchema)) {
throw new IllegalArgumentException(String.format("[JavaCheck/SchemaError] no common parent found for client models %s",
operation.getResponses().stream().map(Response::getSchema).filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<LiveTests> map(TestModel testModel) {
}

private static String getFilename(String filePath) {
String[] split = filePath.replaceAll("\\\\", "/").split("/");
String[] split = filePath.replace("\\\\", "/").split("/");
String filename = split[split.length - 1];
filename = filename.split("\\.")[0];
return CodeNamer.toPascalCase(filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* Contains utility methods to help map from modelerfour to Java Autorest.
Expand Down Expand Up @@ -92,7 +91,7 @@ static IType createEnumType(ChoiceSchema enumType, boolean expandable) {

static IType handleResponseSchema(Operation operation, JavaSettings settings) {
Schema responseBodySchema = SchemaUtil.getLowestCommonParent(operation.getResponses().stream()
.map(Response::getSchema).filter(Objects::nonNull).collect(Collectors.toList()));
.map(Response::getSchema).filter(Objects::nonNull).iterator());
boolean xmlWrapperResponse = responseBodySchema != null && responseBodySchema.getSerialization() != null
&& responseBodySchema.getSerialization().getXml() != null
&& responseBodySchema.getSerialization().getXml().isWrapped();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static boolean isPlainObject(ObjectSchema compositeType) {
* @return The predefined type.
*/
protected ClassType mapPredefinedModel(ObjectSchema compositeType) {
return SchemaUtil.mapExternalModel(compositeType).orElse(null);
return SchemaUtil.mapExternalModel(compositeType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -67,8 +66,6 @@ public class ProxyMethodMapper implements IMapper<Operation, Map<Request, List<P
UNIX_TIME_TYPES.stream()).collect(Collectors.toList());
private static final ProxyMethodMapper INSTANCE = new ProxyMethodMapper();

private static final Pattern APOSTROPHE = Pattern.compile("'");

private final Map<Request, List<ProxyMethod>> parsed = new ConcurrentHashMap<>();

protected ProxyMethodMapper() {
Expand Down Expand Up @@ -102,7 +99,7 @@ public Map<Request, List<ProxyMethod>> map(Operation operation) {

List<Integer> expectedStatusCodes = operation.getResponses().stream()
.flatMap(r -> r.getProtocol().getHttp().getStatusCodes().stream())
.map(s -> APOSTROPHE.matcher(s).replaceAll(""))
.map(s -> s.replace("'", ""))
.map(Integer::parseInt)
.sorted().collect(Collectors.toList());
builder.responseExpectedStatusCodes(expectedStatusCodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@ public static Usage fromValue(String value) {
return constant;
}
}

/**
* Get the Usage instance from the SchemaContext.
*
* @param schemaContext the SchemaContext.
* @return the Usage instance.
* @throws IllegalArgumentException thrown if the SchemaContext doesn't match any Usage.
*/
public static Usage fromSchemaContext(SchemaContext schemaContext) {
switch (schemaContext) {
case INPUT:
return INPUT;
case OUTPUT:
return OUTPUT;
case EXCEPTION:
return EXCEPTION;
case PUBLIC:
return PUBLIC;
case PAGED:
return PAGED;
case ANONYMOUS:
return ANONYMOUS;
case INTERNAL:
return INTERNAL;
case JSON_MERGE_PATCH:
return JSON_MERGE_PATCH;
default:
throw new IllegalArgumentException(schemaContext.toString());
}
}
}

private final boolean implementationOnly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class ProxyMethodExample {
Expand Down Expand Up @@ -238,7 +237,7 @@ public String getRelativeOriginalFileName() {
case "http":
case "https":
{
String[] segments = url.getPath().split(Pattern.quote("/"));
String[] segments = url.getPath().split("/");
if (segments.length > 3) {
// first 3 should be owner, name, branch
originalFileName = Arrays.stream(segments)
Expand All @@ -251,7 +250,7 @@ public String getRelativeOriginalFileName() {

case "file":
{
String[] segments = url.getPath().split(Pattern.quote("/"));
String[] segments = url.getPath().split("/");
int resourceManagerOrDataPlaneSegmentIndex = -1;
for (int i = 0; i < segments.length; ++i) {
if ("resource-manager".equals(segments[i]) || "data-plane".equals(segments[i])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ public class JavaFile implements JavaContext {
private final JavaFileContents contents;

public JavaFile(String filePath) {
this(filePath, null);
}

public JavaFile(String filePath, String fileContents) {
this.filePath = filePath;
contents = new JavaFileContents(fileContents);
this.contents = new JavaFileContents();
}

public final String getFilePath() {
Expand Down
Loading

0 comments on commit 05eb8e4

Please sign in to comment.