From af38939c06548881e6180499503b4a8804592700 Mon Sep 17 00:00:00 2001 From: Steven Yuan Date: Mon, 6 Nov 2023 15:39:39 -0800 Subject: [PATCH] Update Go client codegen plugin to follow idiomatic plugin name See: https://smithy.io/2.0/guides/building-codegen/configuring-the-generator.html#how-to-name-codegen-plugins --- .../smithy-go-codegen-test/smithy-build.json | 2 +- .../smithy/go/codegen/CodegenVisitor.java | 2 +- .../go/codegen/GoClientCodegenPlugin.java | 59 +++++++++++++++++++ .../smithy/go/codegen/GoCodegenPlugin.java | 45 ++------------ .../EndpointClientPluginsGenerator.java | 5 +- ...ware.amazon.smithy.build.SmithyBuildPlugin | 1 + 6 files changed, 68 insertions(+), 46 deletions(-) create mode 100644 codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoClientCodegenPlugin.java diff --git a/codegen/smithy-go-codegen-test/smithy-build.json b/codegen/smithy-go-codegen-test/smithy-build.json index b495c9292..063aab860 100644 --- a/codegen/smithy-go-codegen-test/smithy-build.json +++ b/codegen/smithy-go-codegen-test/smithy-build.json @@ -1,7 +1,7 @@ { "version": "1.0", "plugins": { - "go-codegen": { + "go-client-codegen": { "service": "example.weather#Weather", "module": "github.com/aws/smithy-go/internal/tests/service/weather", "moduleVersion": "0.0.1", diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/CodegenVisitor.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/CodegenVisitor.java index 91e68b14e..0c42c168b 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/CodegenVisitor.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/CodegenVisitor.java @@ -133,7 +133,7 @@ final class CodegenVisitor extends ShapeVisitor.Default { service = settings.getService(model); LOGGER.info(() -> "Generating Go client for service " + service.getId()); - SymbolProvider resolvedProvider = GoCodegenPlugin.createSymbolProvider(model, settings); + SymbolProvider resolvedProvider = GoClientCodegenPlugin.createSymbolProvider(model, settings); for (GoIntegration integration : integrations) { resolvedProvider = integration.decorateSymbolProvider(settings, model, resolvedProvider); } diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoClientCodegenPlugin.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoClientCodegenPlugin.java new file mode 100644 index 000000000..a5609f58b --- /dev/null +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoClientCodegenPlugin.java @@ -0,0 +1,59 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.go.codegen; + +import java.util.logging.Logger; +import software.amazon.smithy.build.PluginContext; +import software.amazon.smithy.build.SmithyBuildPlugin; +import software.amazon.smithy.codegen.core.SymbolProvider; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.utils.SmithyInternalApi; + +/** + * Plugin to trigger Go client code generation. + */ +@SmithyInternalApi +public class GoClientCodegenPlugin implements SmithyBuildPlugin { + private static final Logger LOGGER = Logger.getLogger(GoClientCodegenPlugin.class.getName()); + + @Override + public String getName() { + return "go-client-codegen"; + } + + @Override + public void execute(PluginContext context) { + String onlyBuild = System.getenv("SMITHY_GO_BUILD_API"); + if (onlyBuild != null && !onlyBuild.isEmpty()) { + String targetServiceId = GoSettings.from(context.getSettings()).getService().toString(); + + boolean found = false; + for (String includeServiceId : onlyBuild.split(",")) { + if (targetServiceId.startsWith(includeServiceId)) { + found = true; + break; + } + } + if (!found) { + LOGGER.info("skipping " + targetServiceId); + return; + } + } + + new CodegenVisitor(context).execute(); + } + + /** + * Creates a Go symbol provider. + * + * @param model The model to generate symbols for. + * @param settings The Gosettings to use to create symbol provider + * @return Returns the created provider. + */ + public static SymbolProvider createSymbolProvider(Model model, GoSettings settings) { + return new SymbolVisitor(model, settings); + } +} diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoCodegenPlugin.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoCodegenPlugin.java index 935b03cb4..1a3a661d4 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoCodegenPlugin.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoCodegenPlugin.java @@ -15,53 +15,16 @@ package software.amazon.smithy.go.codegen; -import java.util.logging.Logger; -import software.amazon.smithy.build.PluginContext; -import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.model.Model; +import software.amazon.smithy.utils.SmithyInternalApi; /** * Plugin to trigger Go code generation. */ -public final class GoCodegenPlugin implements SmithyBuildPlugin { - private static final Logger LOGGER = Logger.getLogger(GoCodegenPlugin.class.getName()); - +@SmithyInternalApi +@Deprecated +public final class GoCodegenPlugin extends GoClientCodegenPlugin { @Override public String getName() { return "go-codegen"; } - - @Override - public void execute(PluginContext context) { - String onlyBuild = System.getenv("SMITHY_GO_BUILD_API"); - if (onlyBuild != null && !onlyBuild.isEmpty()) { - String targetServiceId = GoSettings.from(context.getSettings()).getService().toString(); - - boolean found = false; - for (String includeServiceId : onlyBuild.split(",")) { - if (targetServiceId.startsWith(includeServiceId)) { - found = true; - break; - } - } - if (!found) { - LOGGER.info("skipping " + targetServiceId); - return; - } - } - - new CodegenVisitor(context).execute(); - } - - /** - * Creates a Go symbol provider. - * - * @param model The model to generate symbols for. - * @param settings The Gosettings to use to create symbol provider - * @return Returns the created provider. - */ - public static SymbolProvider createSymbolProvider(Model model, GoSettings settings) { - return new SymbolVisitor(model, settings); - } } diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java index ae51cd219..accaf2ef1 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointClientPluginsGenerator.java @@ -20,7 +20,7 @@ import java.util.Optional; import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.go.codegen.GoCodegenPlugin; +import software.amazon.smithy.go.codegen.GoClientCodegenPlugin; import software.amazon.smithy.go.codegen.GoSettings; import software.amazon.smithy.go.codegen.SymbolUtils; import software.amazon.smithy.go.codegen.integration.ConfigField; @@ -106,7 +106,7 @@ public void processFinalizedModel(GoSettings settings, Model model) { for (ToShapeId operationId : topDownIndex.getContainedOperations(service)) { OperationShape operationShape = model.expectShape(operationId.toShapeId(), OperationShape.class); - SymbolProvider symbolProvider = GoCodegenPlugin.createSymbolProvider(model, settings); + SymbolProvider symbolProvider = GoClientCodegenPlugin.createSymbolProvider(model, settings); String inputHelperFuncName = getAddEndpointMiddlewareFuncName( symbolProvider.toSymbol(operationShape).getName() @@ -151,4 +151,3 @@ public void processFinalizedModel(GoSettings settings, Model model) { } } } - diff --git a/codegen/smithy-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin b/codegen/smithy-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin index 9a66c8f58..5ef06f300 100644 --- a/codegen/smithy-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin +++ b/codegen/smithy-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin @@ -1 +1,2 @@ +software.amazon.smithy.go.codegen.GoClientCodegenPlugin software.amazon.smithy.go.codegen.GoCodegenPlugin