Skip to content

Commit

Permalink
Update Go client codegen plugin to follow idiomatic plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yuan committed Nov 6, 2023
1 parent ea97698 commit af38939
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 46 deletions.
2 changes: 1 addition & 1 deletion codegen/smithy-go-codegen-test/smithy-build.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ final class CodegenVisitor extends ShapeVisitor.Default<Void> {
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -151,4 +151,3 @@ public void processFinalizedModel(GoSettings settings, Model model) {
}
}
}

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
software.amazon.smithy.go.codegen.GoClientCodegenPlugin
software.amazon.smithy.go.codegen.GoCodegenPlugin

0 comments on commit af38939

Please sign in to comment.