Skip to content

Commit 74e25df

Browse files
authored
chore: use Paths.get() for computing paths (#2926)
1 parent 28e1a8d commit 74e25df

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAwsAuthPlugin.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_CONFIG;
2121
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE;
2222

23+
import java.nio.file.Paths;
2324
import java.util.Collections;
2425
import java.util.HashMap;
2526
import java.util.List;
@@ -180,7 +181,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
180181
AwsDependency.STS_CLIENT.packageName);
181182
} else {
182183
writer.addImport("decorateDefaultCredentialProvider", "decorateDefaultCredentialProvider",
183-
"./" + CodegenUtils.SOURCE_FOLDER + "/" + STS_ROLE_ASSUMERS_FILE);
184+
Paths.get(".", CodegenUtils.SOURCE_FOLDER, STS_ROLE_ASSUMERS_FILE).toString());
184185
}
185186
writer.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE);
186187
writer.addImport("defaultProvider", "credentialDefaultProvider",
@@ -207,13 +208,13 @@ public void writeAdditionalFiles(
207208
String noTouchNoticePrefix = "// Please do not touch this file. It's generated from template in:\n"
208209
+ "// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/"
209210
+ "src/main/resources/software/amazon/smithy/aws/typescript/codegen/";
210-
writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/defaultRoleAssumers.ts", writer -> {
211+
writerFactory.accept(Paths.get(CodegenUtils.SOURCE_FOLDER, "defaultRoleAssumers.ts").toString(), writer -> {
211212
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, ROLE_ASSUMERS_FILE);
212213
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
213214
writer.write("$L$L", noTouchNoticePrefix, resourceName);
214215
writer.write("$L", source);
215216
});
216-
writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/defaultStsRoleAssumers.ts", writer -> {
217+
writerFactory.accept(Paths.get(CodegenUtils.SOURCE_FOLDER, "defaultStsRoleAssumers.ts").toString(), writer -> {
217218
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, STS_ROLE_ASSUMERS_FILE);
218219
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
219220
writer.write("$L$L", noTouchNoticePrefix, resourceName);
@@ -238,7 +239,7 @@ public void writeAdditionalExports(
238239
if (!testServiceId(service, "STS")) {
239240
return;
240241
}
241-
writer.write("export * from $S", "./" + ROLE_ASSUMERS_FILE);
242+
writer.write("export * from $S", Paths.get(".", ROLE_ASSUMERS_FILE).toString());
242243
}
243244

244245
private static boolean testServiceId(Shape serviceShape, String expectedId) {

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsEndpointGeneratorIntegration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

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

20+
import java.nio.file.Paths;
2021
import java.util.Collections;
2122
import java.util.Map;
2223
import java.util.function.BiConsumer;
@@ -48,7 +49,7 @@ public void writeAdditionalFiles(
4849
return;
4950
}
5051

51-
writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/endpoints.ts", writer -> {
52+
writerFactory.accept(Paths.get(CodegenUtils.SOURCE_FOLDER, "endpoints.ts").toString(), writer -> {
5253
new EndpointGenerator(settings.getService(model), writer).run();
5354
});
5455
}
@@ -85,7 +86,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
8586
case SHARED:
8687
return MapUtils.of("regionInfoProvider", writer -> {
8788
writer.addImport("defaultRegionInfoProvider", "defaultRegionInfoProvider",
88-
"./" + CodegenUtils.SOURCE_FOLDER + "/endpoints");
89+
Paths.get(".", CodegenUtils.SOURCE_FOLDER, "endpoints").toString());
8990
writer.write("defaultRegionInfoProvider");
9091
});
9192
default:

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsServiceIdIntegration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515

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

18+
import java.nio.file.Paths;
1819
import java.util.Arrays;
1920
import java.util.logging.Logger;
2021
import java.util.stream.Collectors;
2122
import software.amazon.smithy.aws.traits.ServiceTrait;
2223
import software.amazon.smithy.codegen.core.Symbol;
2324
import software.amazon.smithy.codegen.core.SymbolProvider;
2425
import software.amazon.smithy.model.Model;
26+
import software.amazon.smithy.typescript.codegen.CodegenUtils;
2527
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
2628
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
2729
import software.amazon.smithy.utils.SmithyInternalApi;
@@ -65,8 +67,8 @@ private static Symbol updateServiceSymbol(Symbol symbol, String serviceId) {
6567
.collect(Collectors.joining("")) + "Client";
6668
return symbol.toBuilder()
6769
.name(name)
68-
.namespace("./src/" + name, "/")
69-
.definitionFile("./src/" + name + ".ts")
70+
.namespace(Paths.get(".", CodegenUtils.SOURCE_FOLDER, name).toString(), "/")
71+
.definitionFile(Paths.get(".", CodegenUtils.SOURCE_FOLDER, name + ".ts").toString())
7072
.build();
7173
}
7274
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/DocumentAggregatedClientGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

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

18+
import java.nio.file.Paths;
1819
import java.util.Set;
1920
import java.util.TreeSet;
2021
import software.amazon.smithy.codegen.core.Symbol;
@@ -62,7 +63,7 @@ final class DocumentAggregatedClientGenerator implements Runnable {
6263
@Override
6364
public void run() {
6465
writer.addImport(DocumentClientUtils.CLIENT_NAME,
65-
DocumentClientUtils.CLIENT_NAME, "./" + DocumentClientUtils.CLIENT_NAME);
66+
DocumentClientUtils.CLIENT_NAME, Paths.get(".", DocumentClientUtils.CLIENT_NAME).toString());
6667
writer.writeDocs(DocumentClientUtils.getClientDocs());
6768
writer.openBlock("export class $L extends $L {", "}",
6869
DocumentClientUtils.CLIENT_FULL_NAME, DocumentClientUtils.CLIENT_NAME, () -> {
@@ -76,7 +77,7 @@ public void run() {
7677
private void generateStaticFactoryFrom() {
7778
String translateConfig = DocumentClientUtils.CLIENT_TRANSLATE_CONFIG_TYPE;
7879
writer.addImport(serviceName, serviceName, "@aws-sdk/client-dynamodb");
79-
writer.addImport(translateConfig, translateConfig, "./" + DocumentClientUtils.CLIENT_NAME);
80+
writer.addImport(translateConfig, translateConfig, Paths.get(".", DocumentClientUtils.CLIENT_NAME).toString());
8081
writer.openBlock("static from(client: $L, translateConfig?: $L) {", "}",
8182
serviceName, translateConfig, () -> {
8283
writer.write("return new $L(client, translateConfig);", DocumentClientUtils.CLIENT_FULL_NAME);

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/DocumentClientCommandGenerator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

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

18+
import java.nio.file.Paths;
1819
import java.util.ArrayList;
1920
import java.util.HashSet;
2021
import java.util.List;
@@ -84,11 +85,11 @@ final class DocumentClientCommandGenerator implements Runnable {
8485

8586
@Override
8687
public void run() {
87-
String serviceName = DocumentClientUtils.CLIENT_NAME;
88+
String servicePath = Paths.get(".", DocumentClientUtils.CLIENT_NAME).toString();
8889
String configType = DocumentClientUtils.CLIENT_CONFIG_NAME;
8990

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

9495
generateInputAndOutputTypes();
@@ -139,9 +140,9 @@ private void generateCommandMiddlewareResolver(String configType) {
139140
String handler = "Handler";
140141
String middlewareStack = "MiddlewareStack";
141142

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

0 commit comments

Comments
 (0)