Skip to content

Commit

Permalink
fold integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Feb 26, 2024
1 parent 70a8eaf commit e42814f
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 182 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
Expand Up @@ -8,7 +8,7 @@
"generateGoMod": true,
"goDirective": "1.18"
},
"go-service-codegen": {
"go-server-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 @@ -20,14 +20,16 @@
import software.amazon.smithy.codegen.core.CodegenContext;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.codegen.core.WriterDelegator;
import software.amazon.smithy.go.codegen.service.GoServiceIntegration;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.utils.SmithyInternalApi;

@SmithyInternalApi
public record GoCodegenContext(
Model model,
GoSettings settings,
SymbolProvider symbolProvider,
FileManifest fileManifest,
WriterDelegator<GoWriter> writerDelegator,
List<GoServiceIntegration> integrations
) implements CodegenContext<GoSettings, GoWriter, GoServiceIntegration> {}
List<GoIntegration> integrations
) implements CodegenContext<GoSettings, GoWriter, GoIntegration> {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package software.amazon.smithy.go.codegen;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import software.amazon.smithy.go.codegen.GoSettings.ArtifactType;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.TriConsumer;
import software.amazon.smithy.go.codegen.service.ServiceProtocolGenerator;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
Expand Down Expand Up @@ -162,6 +163,13 @@ default List<ProtocolGenerator> getProtocolGenerators() {
return Collections.emptyList();
}

/**
* Gets a list of server protocol generators to register. Protocol generators should generally be written to accept
* the codegen context at construction time, such that all the model information necessary for codegen is available.
*/
default List<ServiceProtocolGenerator> getServerProtocolGenerators(GoCodegenContext ctx) {
return Collections.emptyList();
}

/**
* Processes the finalized model before runtime plugins are consumed and
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import software.amazon.smithy.go.codegen.GoCodegenContext;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
Expand All @@ -33,7 +34,7 @@ public final class ServiceCodegenPlugin implements SmithyBuildPlugin {

@Override
public String getName() {
return "go-service-codegen";
return "go-server-codegen";
}

@Override
Expand Down Expand Up @@ -61,14 +62,14 @@ public void execute(PluginContext context) {

private void generate(PluginContext context) {
CodegenDirector<GoWriter,
GoServiceIntegration,
GoIntegration,
GoCodegenContext,
GoSettings> runner = new CodegenDirector<>();

runner.model(context.getModel());
runner.directedCodegen(new ServiceDirectedCodegen());

runner.integrationClass(GoServiceIntegration.class);
runner.integrationClass(GoIntegration.class);

runner.fileManifest(context.getFileManifest());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,22 @@
import software.amazon.smithy.go.codegen.StructureGenerator;
import software.amazon.smithy.go.codegen.SymbolVisitor;
import software.amazon.smithy.go.codegen.UnionGenerator;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.shapes.EnumShape;
import software.amazon.smithy.model.shapes.IntEnumShape;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.utils.SmithyInternalApi;

public class ServiceDirectedCodegen implements DirectedCodegen<GoCodegenContext, GoSettings, GoServiceIntegration> {
@SmithyInternalApi
public class ServiceDirectedCodegen implements DirectedCodegen<GoCodegenContext, GoSettings, GoIntegration> {
@Override
public SymbolProvider createSymbolProvider(CreateSymbolProviderDirective<GoSettings> directive) {
return new SymbolVisitor(withUnit(directive.model()), directive.settings());
}

@Override
public GoCodegenContext createContext(CreateContextDirective<GoSettings, GoServiceIntegration> directive) {
public GoCodegenContext createContext(CreateContextDirective<GoSettings, GoIntegration> directive) {
return new GoCodegenContext(
withUnit(directive.model()),
directive.settings(),
Expand Down Expand Up @@ -200,7 +203,7 @@ private ServiceProtocolGenerator resolveProtocolGenerator(GoCodegenContext ctx)
var service = ctx.settings().getService(model);

var protocolGenerators = ctx.integrations().stream()
.flatMap(it -> it.getProtocolGenerators(ctx).stream())
.flatMap(it -> it.getServerProtocolGenerators(ctx).stream())
.filter(it -> service.hasTrait(it.getProtocol()))
.toList();
if (protocolGenerators.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@

import java.util.List;
import software.amazon.smithy.go.codegen.GoCodegenContext;
import software.amazon.smithy.go.codegen.service.GoServiceIntegration;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.go.codegen.service.ServiceProtocolGenerator;
import software.amazon.smithy.go.codegen.service.protocol.aws.AwsJson10ProtocolGenerator;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

public class DefaultProtocols implements GoServiceIntegration {
@SmithyInternalApi
public class DefaultProtocols implements GoIntegration {
@Override
public List<ServiceProtocolGenerator> getProtocolGenerators(GoCodegenContext ctx) {
public GoSettings.ArtifactType getArtifactType() {
return GoSettings.ArtifactType.SERVER;
}

@Override
public List<ServiceProtocolGenerator> getServerProtocolGenerators(GoCodegenContext ctx) {
return ListUtils.of(
new AwsJson10ProtocolGenerator(ctx)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ software.amazon.smithy.go.codegen.endpoints.EndpointClientPluginsGenerator
software.amazon.smithy.go.codegen.integration.auth.SigV4AuthScheme
software.amazon.smithy.go.codegen.integration.auth.AnonymousAuthScheme

software.amazon.smithy.go.codegen.requestcompression.RequestCompression
software.amazon.smithy.go.codegen.requestcompression.RequestCompression

# server
software.amazon.smithy.go.codegen.service.integration.DefaultProtocols

This file was deleted.

0 comments on commit e42814f

Please sign in to comment.