Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use Paths.get() for computing paths #2926

Merged
merged 2 commits into from
Oct 26, 2021
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 @@ -20,6 +20,7 @@
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_CONFIG;
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE;

import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -180,7 +181,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
AwsDependency.STS_CLIENT.packageName);
} else {
writer.addImport("decorateDefaultCredentialProvider", "decorateDefaultCredentialProvider",
"./" + CodegenUtils.SOURCE_FOLDER + "/" + STS_ROLE_ASSUMERS_FILE);
Paths.get(".", CodegenUtils.SOURCE_FOLDER, STS_ROLE_ASSUMERS_FILE).toString());
}
writer.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE);
writer.addImport("defaultProvider", "credentialDefaultProvider",
Expand All @@ -207,13 +208,13 @@ public void writeAdditionalFiles(
String noTouchNoticePrefix = "// Please do not touch this file. It's generated from template in:\n"
+ "// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/"
+ "src/main/resources/software/amazon/smithy/aws/typescript/codegen/";
writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/defaultRoleAssumers.ts", writer -> {
writerFactory.accept(Paths.get(CodegenUtils.SOURCE_FOLDER, "defaultRoleAssumers.ts").toString(), writer -> {
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, ROLE_ASSUMERS_FILE);
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
writer.write("$L$L", noTouchNoticePrefix, resourceName);
writer.write("$L", source);
});
writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/defaultStsRoleAssumers.ts", writer -> {
writerFactory.accept(Paths.get(CodegenUtils.SOURCE_FOLDER, "defaultStsRoleAssumers.ts").toString(), writer -> {
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, STS_ROLE_ASSUMERS_FILE);
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
writer.write("$L$L", noTouchNoticePrefix, resourceName);
Expand All @@ -238,7 +239,7 @@ public void writeAdditionalExports(
if (!testServiceId(service, "STS")) {
return;
}
writer.write("export * from $S", "./" + ROLE_ASSUMERS_FILE);
writer.write("export * from $S", Paths.get(".", ROLE_ASSUMERS_FILE).toString());
}

private static boolean testServiceId(Shape serviceShape, String expectedId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isAwsService;

import java.nio.file.Paths;
import java.util.Collections;
import java.util.Map;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -48,7 +49,7 @@ public void writeAdditionalFiles(
return;
}

writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/endpoints.ts", writer -> {
writerFactory.accept(Paths.get(CodegenUtils.SOURCE_FOLDER, "endpoints.ts").toString(), writer -> {
new EndpointGenerator(settings.getService(model), writer).run();
});
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
case SHARED:
return MapUtils.of("regionInfoProvider", writer -> {
writer.addImport("defaultRegionInfoProvider", "defaultRegionInfoProvider",
"./" + CodegenUtils.SOURCE_FOLDER + "/endpoints");
Paths.get(".", CodegenUtils.SOURCE_FOLDER, "endpoints").toString());
writer.write("defaultRegionInfoProvider");
});
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

package software.amazon.smithy.aws.typescript.codegen;

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.typescript.codegen.CodegenUtils;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
import software.amazon.smithy.utils.SmithyInternalApi;
Expand Down Expand Up @@ -65,8 +67,8 @@ private static Symbol updateServiceSymbol(Symbol symbol, String serviceId) {
.collect(Collectors.joining("")) + "Client";
return symbol.toBuilder()
.name(name)
.namespace("./src/" + name, "/")
.definitionFile("./src/" + name + ".ts")
.namespace(Paths.get(".", CodegenUtils.SOURCE_FOLDER, name).toString(), "/")
.definitionFile(Paths.get(".", CodegenUtils.SOURCE_FOLDER, name + ".ts").toString())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package software.amazon.smithy.aws.typescript.codegen;

import java.nio.file.Paths;
import java.util.Set;
import java.util.TreeSet;
import software.amazon.smithy.codegen.core.Symbol;
Expand Down Expand Up @@ -62,7 +63,7 @@ final class DocumentAggregatedClientGenerator implements Runnable {
@Override
public void run() {
writer.addImport(DocumentClientUtils.CLIENT_NAME,
DocumentClientUtils.CLIENT_NAME, "./" + DocumentClientUtils.CLIENT_NAME);
DocumentClientUtils.CLIENT_NAME, Paths.get(".", DocumentClientUtils.CLIENT_NAME).toString());
writer.writeDocs(DocumentClientUtils.getClientDocs());
writer.openBlock("export class $L extends $L {", "}",
DocumentClientUtils.CLIENT_FULL_NAME, DocumentClientUtils.CLIENT_NAME, () -> {
Expand All @@ -76,7 +77,7 @@ public void run() {
private void generateStaticFactoryFrom() {
String translateConfig = DocumentClientUtils.CLIENT_TRANSLATE_CONFIG_TYPE;
writer.addImport(serviceName, serviceName, "@aws-sdk/client-dynamodb");
writer.addImport(translateConfig, translateConfig, "./" + DocumentClientUtils.CLIENT_NAME);
writer.addImport(translateConfig, translateConfig, Paths.get(".", DocumentClientUtils.CLIENT_NAME).toString());
writer.openBlock("static from(client: $L, translateConfig?: $L) {", "}",
serviceName, translateConfig, () -> {
writer.write("return new $L(client, translateConfig);", DocumentClientUtils.CLIENT_FULL_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package software.amazon.smithy.aws.typescript.codegen;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -84,11 +85,11 @@ final class DocumentClientCommandGenerator implements Runnable {

@Override
public void run() {
String serviceName = DocumentClientUtils.CLIENT_NAME;
String servicePath = Paths.get(".", DocumentClientUtils.CLIENT_NAME).toString();
String configType = DocumentClientUtils.CLIENT_CONFIG_NAME;

// Add required imports.
writer.addImport(configType, configType, "./" + serviceName);
writer.addImport(configType, configType, servicePath);
writer.addImport("Command", "$Command", "@aws-sdk/smithy-client");

generateInputAndOutputTypes();
Expand Down Expand Up @@ -139,9 +140,9 @@ private void generateCommandMiddlewareResolver(String configType) {
String handler = "Handler";
String middlewareStack = "MiddlewareStack";

String serviceName = DocumentClientUtils.CLIENT_NAME;
writer.addImport(serviceInputTypes, serviceInputTypes, "./" + serviceName);
writer.addImport(serviceOutputTypes, serviceOutputTypes, "./" + serviceName);
String servicePath = Paths.get(".", DocumentClientUtils.CLIENT_NAME).toString();
writer.addImport(serviceInputTypes, serviceInputTypes, servicePath);
writer.addImport(serviceOutputTypes, serviceOutputTypes, servicePath);
writer.addImport(handler, handler, "@aws-sdk/types");
writer.addImport(middlewareStack, middlewareStack, "@aws-sdk/types");

Expand Down