diff --git a/aws/aws-mcp-types/build.gradle.kts b/aws/aws-mcp-types/build.gradle.kts index 35b193157..c140f41ee 100644 --- a/aws/aws-mcp-types/build.gradle.kts +++ b/aws/aws-mcp-types/build.gradle.kts @@ -8,13 +8,13 @@ extra["displayName"] = "Smithy :: Java :: AWS MCP types" extra["moduleName"] = "software.amazon.smithy.java.awsmcp.types" dependencies { - smithyBuild(project(":codegen:plugins:types-codegen")) + smithyBuild(project(":codegen:codegen-plugin")) api(project(":core")) api(libs.smithy.model) } afterEvaluate { - val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-type-codegen") + val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/aws/aws-mcp-types/smithy-build.json b/aws/aws-mcp-types/smithy-build.json index 829c45533..7c8e223a2 100644 --- a/aws/aws-mcp-types/smithy-build.json +++ b/aws/aws-mcp-types/smithy-build.json @@ -1,9 +1,10 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { + "java-codegen": { "namespace": "software.amazon.smithy.awsmcp", - "headerFile": "license.txt" + "headerFile": "license.txt", + "modes": ["types"] } } } diff --git a/buildSrc/src/main/kotlin/smithy-java.codegen-plugin-conventions.gradle.kts b/buildSrc/src/main/kotlin/smithy-java.codegen-plugin-conventions.gradle.kts index a3a074b3d..f1ebde812 100644 --- a/buildSrc/src/main/kotlin/smithy-java.codegen-plugin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/smithy-java.codegen-plugin-conventions.gradle.kts @@ -13,9 +13,9 @@ dependencies { implementation(project(":core")) implementation(project(":logging")) - // Avoid circular dependency in codegen core - if (project.name != "codegen-core") { - api(project(":codegen:codegen-core")) + // Avoid circular dependency in codegen plugin + if (project.name != "codegen-plugin") { + api(project(":codegen:codegen-plugin")) } } diff --git a/client/client-api/build.gradle.kts b/client/client-api/build.gradle.kts new file mode 100644 index 000000000..5cdcde464 --- /dev/null +++ b/client/client-api/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + id("smithy-java.module-conventions") + id("smithy-java.publishing-conventions") +} + +description = "This module provides the core client API types" + +extra["displayName"] = "Smithy :: Java :: Client :: API" +extra["moduleName"] = "software.amazon.smithy.java.client.core" + +dependencies { + api(project(":context")) + api(project(":core")) + api(project(":auth-api")) + api(project(":client:client-auth-api")) + api(project(":retries-api")) + implementation(project(":logging")) +} diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/AutoClientPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/AutoClientPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/AutoClientPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/AutoClientPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/CallContext.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/CallContext.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/CallContext.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/CallContext.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/Client.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/Client.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/Client.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/Client.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientCall.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientCall.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientCall.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientCall.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientConfig.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientConfig.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientConfig.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientConfig.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientContext.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientContext.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientContext.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientContext.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientPipeline.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientPipeline.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientPipeline.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientPipeline.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientProtocol.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientProtocol.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientProtocol.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientProtocol.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientProtocolFactory.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientProtocolFactory.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientProtocolFactory.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientProtocolFactory.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientSetting.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientSetting.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientSetting.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientSetting.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientTransportFactory.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransportFactory.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ClientTransportFactory.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransportFactory.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/FeatureId.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/FeatureId.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/FeatureId.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/FeatureId.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/MessageExchange.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/MessageExchange.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/MessageExchange.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/MessageExchange.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/ProtocolSettings.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ProtocolSettings.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/ProtocolSettings.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/ProtocolSettings.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/RequestOverrideConfig.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/RequestOverrideConfig.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/RequestOverrideConfig.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/RequestOverrideConfig.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/Endpoint.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/Endpoint.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/Endpoint.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/Endpoint.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthScheme.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthScheme.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthScheme.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthScheme.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthSchemeImpl.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthSchemeImpl.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthSchemeImpl.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointAuthSchemeImpl.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointContext.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointContext.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointContext.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointContext.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointImpl.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointImpl.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointImpl.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointImpl.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolver.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolver.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolver.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolver.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolverParams.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolverParams.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolverParams.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/EndpointResolverParams.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelEndpointResolver.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelEndpointResolver.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelEndpointResolver.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelEndpointResolver.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelSerializer.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelSerializer.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelSerializer.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/HostLabelSerializer.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/StaticHostResolver.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/StaticHostResolver.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/endpoint/StaticHostResolver.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/endpoint/StaticHostResolver.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/ConnectTimeoutException.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/ConnectTimeoutException.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/ConnectTimeoutException.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/ConnectTimeoutException.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionAcquireTimeoutException.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionAcquireTimeoutException.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionAcquireTimeoutException.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionAcquireTimeoutException.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionClosedException.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionClosedException.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionClosedException.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/ConnectionClosedException.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TlsException.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TlsException.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TlsException.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TlsException.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportException.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportException.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportException.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportException.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportProtocolException.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportProtocolException.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportProtocolException.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportProtocolException.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketException.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketException.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketException.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketException.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketTimeout.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketTimeout.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketTimeout.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/error/TransportSocketTimeout.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/CallHook.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/CallHook.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/CallHook.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/CallHook.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptor.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptor.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptor.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptor.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptorChain.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptorChain.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptorChain.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/ClientInterceptorChain.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/InputHook.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/InputHook.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/InputHook.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/InputHook.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/OutputHook.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/OutputHook.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/OutputHook.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/OutputHook.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/RequestHook.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/RequestHook.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/RequestHook.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/RequestHook.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/ResponseHook.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/ResponseHook.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/interceptors/ResponseHook.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/interceptors/ResponseHook.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/package-info.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/package-info.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/package-info.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/package-info.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/DefaultSyncPaginator.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/DefaultSyncPaginator.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/DefaultSyncPaginator.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/DefaultSyncPaginator.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationInputSetter.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationInputSetter.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationInputSetter.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationInputSetter.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationTokenExtractor.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationTokenExtractor.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationTokenExtractor.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginationTokenExtractor.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/Paginator.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/Paginator.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/Paginator.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/Paginator.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginatorSettings.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginatorSettings.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginatorSettings.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/pagination/PaginatorSettings.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/ApplyModelRetryInfoPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/ApplyModelRetryInfoPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/ApplyModelRetryInfoPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/ApplyModelRetryInfoPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/AutoPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/AutoPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/AutoPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/AutoPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/DefaultPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/DefaultPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/DefaultPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/DefaultPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/DiscoverTransportPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/DiscoverTransportPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/DiscoverTransportPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/DiscoverTransportPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/ExceptionMapperPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/ExceptionMapperPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/ExceptionMapperPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/ExceptionMapperPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/InjectIdempotencyTokenPlugin.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/InjectIdempotencyTokenPlugin.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/plugins/InjectIdempotencyTokenPlugin.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/plugins/InjectIdempotencyTokenPlugin.java diff --git a/client/client-core/src/main/java/software/amazon/smithy/java/client/core/settings/ClockSetting.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/settings/ClockSetting.java similarity index 100% rename from client/client-core/src/main/java/software/amazon/smithy/java/client/core/settings/ClockSetting.java rename to client/client-api/src/main/java/software/amazon/smithy/java/client/core/settings/ClockSetting.java diff --git a/client/client-core/build.gradle.kts b/client/client-core/build.gradle.kts index 0a536f4a8..33640aebe 100644 --- a/client/client-core/build.gradle.kts +++ b/client/client-core/build.gradle.kts @@ -8,11 +8,7 @@ extra["displayName"] = "Smithy :: Java :: Client :: Core" extra["moduleName"] = "software.amazon.smithy.java.client.core" dependencies { - api(project(":context")) - api(project(":core")) - api(project(":auth-api")) - api(project(":client:client-auth-api")) - api(project(":retries-api")) + api(project(":client:client-api")) api(project(":framework-errors")) implementation(project(":logging")) diff --git a/client/client-rulesengine/build.gradle.kts b/client/client-rulesengine/build.gradle.kts index 7dedc73cf..d50813282 100644 --- a/client/client-rulesengine/build.gradle.kts +++ b/client/client-rulesengine/build.gradle.kts @@ -8,7 +8,7 @@ extra["displayName"] = "Smithy :: Java :: Client :: Endpoint Rules" extra["moduleName"] = "software.amazon.smithy.java.client.endpointrules" dependencies { - api(project(":client:client-core")) + api(project(":client:client-api")) api(project(":jmespath")) api(libs.smithy.rules) implementation(project(":logging")) diff --git a/client/client-waiters/build.gradle.kts b/client/client-waiters/build.gradle.kts index bc5714957..e1d087e2a 100644 --- a/client/client-waiters/build.gradle.kts +++ b/client/client-waiters/build.gradle.kts @@ -11,5 +11,5 @@ dependencies { api(libs.smithy.waiters) implementation(project(":jmespath")) implementation(project(":logging")) - implementation(project(":client:client-core")) + implementation(project(":client:client-api")) } diff --git a/codegen/codegen-core/README.md b/codegen/codegen-core/README.md deleted file mode 100644 index 57aedf617..000000000 --- a/codegen/codegen-core/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## codegen-core -Provides the base functionality for Java code generation used -by all Smithy Java codegen plugins. diff --git a/codegen/codegen-core/build.gradle.kts b/codegen/codegen-core/build.gradle.kts deleted file mode 100644 index 68644e47d..000000000 --- a/codegen/codegen-core/build.gradle.kts +++ /dev/null @@ -1,16 +0,0 @@ -plugins { - id("smithy-java.codegen-plugin-conventions") - id("smithy-java.publishing-conventions") -} - -description = "This module provides the core codegen functionality for Smithy java" - -extra["displayName"] = "Smithy :: Java :: Codegen :: Core" -extra["moduleName"] = "software.amazon.smithy.java.codegen.core" - -dependencies { - api(libs.smithy.codegen) - itImplementation(project(":codecs:json-codec", configuration = "shadow")) -} - -addGenerateSrcsTask("software.amazon.smithy.java.codegen.utils.TestJavaCodegenRunner") diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/BuilderTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/BuilderTest.java deleted file mode 100644 index d8c10292d..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/BuilderTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; -import java.util.Map; -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.codegen.test.model.ListMembersInput; -import software.amazon.smithy.java.codegen.test.model.MapMembersInput; - -public class BuilderTest { - - @Test - public void testToBuilderList() { - ListMembersInput original = ListMembersInput.builder() - .requiredList(List.of("A")) - .build(); - var copy = original.toBuilder().optionalList(List.of("1")).build(); - assertThat(copy) - .returns(original.getRequiredList(), ListMembersInput::getRequiredList) - .returns(List.of("1"), ListMembersInput::getOptionalList); - } - - @Test - public void testToBuilderMap() { - MapMembersInput original = MapMembersInput.builder() - .requiredMap(Map.of("A", "B")) - .build(); - var copy = original.toBuilder().optionalMap(Map.of("1", "2")).build(); - assertThat(copy) - .returns(original.getRequiredMap(), MapMembersInput::getRequiredMap) - .returns(Map.of("1", "2"), MapMembersInput::getOptionalMap); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ClientErrorCorrectionTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ClientErrorCorrectionTest.java deleted file mode 100644 index ba266034d..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ClientErrorCorrectionTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.time.Instant; -import java.util.List; -import java.util.Map; -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.codegen.test.model.ClientErrorCorrectionInput; -import software.amazon.smithy.java.codegen.test.model.NestedEnum; -import software.amazon.smithy.java.codegen.test.model.NestedIntEnum; - -public class ClientErrorCorrectionTest { - - @Test - void correctsErrors() { - var corrected = ClientErrorCorrectionInput.builder() - .errorCorrection() - .build(); - - assertFalse(corrected.isBoolean()); - assertEquals(corrected.getBigDecimal(), BigDecimal.ZERO); - assertEquals(corrected.getBigInteger(), BigInteger.ZERO); - assertEquals(corrected.getByte(), (byte) 0); - assertEquals(corrected.getDouble(), 0); - assertEquals(corrected.getFloat(), 0); - assertEquals(corrected.getInteger(), 0); - assertEquals(corrected.getLong(), 0); - assertEquals(corrected.getShort(), (short) 0); - assertEquals(corrected.getBlob(), ByteBuffer.allocate(0)); - assertEquals(corrected.getStreamingBlob().contentLength(), 0); - assertEquals(0, corrected.getStreamingBlob().asByteBuffer().remaining()); - assertNull(corrected.getDocument()); - assertEquals(corrected.getList(), List.of()); - assertEquals(corrected.getMap(), Map.of()); - assertEquals(corrected.getTimestamp(), Instant.EPOCH); - assertEquals(NestedEnum.$Unknown.class, corrected.getEnum().getClass()); - assertEquals(corrected.getEnum().getValue(), ""); - assertEquals(NestedIntEnum.$Unknown.class, corrected.getIntEnum().getClass()); - assertEquals(corrected.getIntEnum().getValue(), 0); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/DefaultsTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/DefaultsTest.java deleted file mode 100644 index 75a8f2676..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/DefaultsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.time.Instant; -import java.util.Base64; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.codegen.test.model.DefaultsInput; -import software.amazon.smithy.java.codegen.test.model.NestedEnum; -import software.amazon.smithy.java.codegen.test.model.NestedIntEnum; -import software.amazon.smithy.java.core.serde.document.Document; - -public class DefaultsTest { - @Test - void setsCorrectDefault() { - var defaults = DefaultsInput.builder().build(); - - assertTrue(defaults.isBoolean()); - assertEquals(defaults.getBigDecimal(), new BigDecimal("1e309")); - assertEquals(defaults.getBigInteger(), - new BigInteger("123456789123456789123456789123456789123456789123456789")); - assertEquals(defaults.getByte(), (byte) 1); - assertEquals(defaults.getDouble(), 1.0); - assertEquals(defaults.getFloat(), 1f); - assertEquals(defaults.getInteger(), 1); - assertEquals(defaults.getLong(), 1); - assertEquals(defaults.getShort(), (short) 1); - assertEquals(defaults.getBlob(), ByteBuffer.wrap(Base64.getDecoder().decode("YmxvYg=="))); - assertEquals(defaults.getStreamingBlob().asByteBuffer(), - ByteBuffer.wrap(Base64.getDecoder().decode("c3RyZWFtaW5n"))); - assertEquals(defaults.getBoolDoc(), Document.of(true)); - assertEquals(defaults.getStringDoc(), Document.of("string")); - assertEquals(defaults.getNumberDoc(), Document.of(1)); - assertEquals(defaults.getFloatingPointnumberDoc(), Document.of(1.2)); - assertEquals(defaults.getListDoc(), Document.of(Collections.emptyList())); - assertEquals(defaults.getMapDoc(), Document.of(Collections.emptyMap())); - assertEquals(defaults.getList(), List.of()); - assertEquals(defaults.getMap(), Map.of()); - assertEquals(defaults.getTimestamp(), Instant.parse("1985-04-12T23:20:50.52Z")); - assertEquals(defaults.getEnum(), NestedEnum.A); - assertEquals(defaults.getIntEnum(), NestedIntEnum.A); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/EffectiveAuthSchemeTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/EffectiveAuthSchemeTest.java deleted file mode 100644 index 2a5fdf785..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/EffectiveAuthSchemeTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.codegen.test.model.AllAuth; -import software.amazon.smithy.java.codegen.test.model.NoAuth; -import software.amazon.smithy.java.codegen.test.model.ScopedAuth; -import software.amazon.smithy.model.traits.HttpApiKeyAuthTrait; -import software.amazon.smithy.model.traits.HttpBasicAuthTrait; -import software.amazon.smithy.model.traits.synthetic.NoAuthTrait; - -public class EffectiveAuthSchemeTest { - @Test - void generatedOperationHaveExpectedSchemes() { - assertEquals(NoAuth.instance().effectiveAuthSchemes(), List.of(NoAuthTrait.ID)); - assertEquals( - AllAuth.instance().effectiveAuthSchemes(), - List.of(HttpApiKeyAuthTrait.ID, HttpBasicAuthTrait.ID)); - assertEquals(ScopedAuth.instance().effectiveAuthSchemes(), List.of(HttpBasicAuthTrait.ID)); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/EnumTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/EnumTest.java deleted file mode 100644 index ff9a65066..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/EnumTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.codegen.test.model.EnumType; -import software.amazon.smithy.java.json.JsonCodec; - -public class EnumTest { - - @Test - void unknownTypeDeserializedIntoUnknownVariant() { - EnumType output; - try (var codec = JsonCodec.builder().useJsonName(true).useTimestampFormat(true).build()) { - output = codec.deserializeShape("\"option-n\"", EnumType.builder()); - } - switch (output) { - case EnumType.$Unknown(String value) -> assertEquals("option-n", value); - default -> fail("Expected UnknownEnumType"); - } - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ExceptionsTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ExceptionsTest.java deleted file mode 100644 index 9b8030786..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ExceptionsTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -import java.util.stream.Stream; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.java.codegen.test.model.EmptyException; -import software.amazon.smithy.java.codegen.test.model.ExceptionWithCapitalMessage; -import software.amazon.smithy.java.codegen.test.model.ExceptionWithExtraStringException; -import software.amazon.smithy.java.codegen.test.model.OptionalMessageException; -import software.amazon.smithy.java.codegen.test.model.SimpleException; -import software.amazon.smithy.java.core.error.ModeledException; -import software.amazon.smithy.java.core.schema.SerializableShape; - -@ExtendWith(ReloadClassesExtension.class) -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class ExceptionsTest { - static Stream exceptions() { - return Stream.of( - SimpleException.builder().message("OOOPS!").build(), - ExceptionWithExtraStringException.builder().message("whoopsy").extra("daisy").build(), - EmptyException.builder().build(), - OptionalMessageException.builder().build(), - OptionalMessageException.builder().message("optional").build()); - } - - @ParameterizedTest - @MethodSource("exceptions") - @Order(1) - void simpleExceptionToDocumentRoundTrip(ModeledException exception) { - var output = Utils.pojoToDocumentRoundTrip(exception); - assertEquals(exception.getMessage(), output.getMessage()); - assertEquals(exception.getCause(), output.getCause()); - assertNotEquals(exception.hashCode(), output.hashCode()); - } - - @Test - @Order(2) - void exceptionWithExplicitStackTraceCapture() { - var cause = getCauseThrowable(); - var exception = SimpleException.builder().withCause(cause).withStackTrace().message("OOOPS!").build(); - assertThat(exception) - .hasStackTraceContaining("exceptionWithExplicitStackTraceCapture") - .hasStackTraceContaining("getCauseThrowable") - .hasCause(cause); - } - - @Test - @Order(3) - void defaultExceptionHasNoStackTrace() { - var exception = SimpleException.builder().message("OOOPS!").build(); - assertThat(exception.getStackTrace()).isEmpty(); - } - - @Test - @Order(4) - @ReloadClasses - void explicitDisableStackTraceCapture() { - enableGlobalStackTraceCapture(); - try { - var exception = SimpleException.builder().message("OOOPS!").build(); - assertThat(exception) - .hasStackTraceContaining("explicitDisableStackTraceCapture"); - var exceptionWithoutStackTrace = SimpleException.builder().withoutStackTrace().message("OOOPS!").build(); - assertThat(exceptionWithoutStackTrace.getStackTrace()).isEmpty(); - var cause = getCauseThrowable(); - var exceptionWithCauseWithoutStackTrace = SimpleException.builder() - .withoutStackTrace() - .withCause(cause) - .message("OOOPS!") - .build(); - assertThat(exceptionWithCauseWithoutStackTrace.getStackTrace()).isEmpty(); - assertThat(exceptionWithCauseWithoutStackTrace) - .hasStackTraceContaining("getCauseThrowable") - .hasCause(cause); - } finally { - disableGlobalStackTraceCapture(); - } - } - - @Test - void testMessageMemberCapital() { - var exception = ExceptionWithCapitalMessage.builder().message("OOOPS!").build(); - assertThat(exception.getMessage()).isEqualTo("OOOPS!"); - } - - private static Throwable getCauseThrowable() { - return new Throwable(); - } - - private static void enableGlobalStackTraceCapture() { - System.setProperty("smithy.java.captureExceptionStackTraces", "true"); - } - - private static void disableGlobalStackTraceCapture() { - System.setProperty("smithy.java.captureExceptionStackTraces", "false"); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/IdempotencyTokenRequiredTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/IdempotencyTokenRequiredTest.java deleted file mode 100644 index 78445428f..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/IdempotencyTokenRequiredTest.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.codegen.test.model.IdempotencyTokenRequiredInput; - -public class IdempotencyTokenRequiredTest { - @Test - void makesRequiredTokensClientOptional() { - // Will not fail to build because the token was made client optional. - IdempotencyTokenRequiredInput.builder().build(); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ListsTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ListsTest.java deleted file mode 100644 index d10d56d89..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ListsTest.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static java.nio.ByteBuffer.wrap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.time.Instant; -import java.util.Base64; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.java.codegen.test.model.ListAllTypesInput; -import software.amazon.smithy.java.codegen.test.model.NestedEnum; -import software.amazon.smithy.java.codegen.test.model.NestedIntEnum; -import software.amazon.smithy.java.codegen.test.model.NestedListsInput; -import software.amazon.smithy.java.codegen.test.model.NestedStruct; -import software.amazon.smithy.java.codegen.test.model.NestedUnion; -import software.amazon.smithy.java.codegen.test.model.SetsAllTypesInput; -import software.amazon.smithy.java.codegen.test.model.SparseListsInput; -import software.amazon.smithy.java.core.schema.SerializableShape; -import software.amazon.smithy.java.core.schema.SerializableStruct; -import software.amazon.smithy.java.core.serde.document.Document; -import software.amazon.smithy.java.json.JsonCodec; -import software.amazon.smithy.utils.ListUtils; - -public class ListsTest { - - static Stream listTypes() { - return Stream.of( - ListAllTypesInput.builder() - .listOfBoolean( - List.of(true, true, false)) - .build(), - ListAllTypesInput.builder() - .listOfBigDecimal( - List.of(BigDecimal.TEN, BigDecimal.ZERO)) - .build(), - ListAllTypesInput.builder() - .listOfBigInteger( - List.of(BigInteger.TEN, BigInteger.ZERO)) - .build(), - ListAllTypesInput.builder() - .listOfByte( - List.of((byte) 1, (byte) 2)) - .build(), - ListAllTypesInput.builder() - .listOfDouble( - List.of(2.0, 3.0)) - .build(), - ListAllTypesInput.builder() - .listOfFloat( - List.of(2f, 3f)) - .build(), - ListAllTypesInput.builder() - .listOfInteger( - List.of(1, 2)) - .build(), - ListAllTypesInput.builder() - .listOfLong( - List.of(1L, 2L)) - .build(), - ListAllTypesInput.builder() - .listOfShort( - List.of((short) 1, (short) 2)) - .build(), - ListAllTypesInput.builder() - .listOfString( - List.of("a", "b")) - .build(), - ListAllTypesInput.builder() - .listOfBlobs( - Stream.of(Base64.getDecoder().decode("YmxvYg=="), - Base64.getDecoder().decode("YmlyZHM=")) - .map(ByteBuffer::wrap) - .toList()) - .build(), - ListAllTypesInput.builder() - .listOfTimestamps( - List.of(Instant.EPOCH, Instant.MIN)) - .build(), - ListAllTypesInput.builder() - .listOfUnion( - List.of(new NestedUnion.AMember("string"), new NestedUnion.BMember(2))) - .build(), - ListAllTypesInput.builder() - .listOfEnum( - List.of(NestedEnum.A, NestedEnum.B)) - .build(), - ListAllTypesInput.builder() - .listOfIntEnum( - List.of(NestedIntEnum.A, NestedIntEnum.B)) - .build(), - ListAllTypesInput.builder() - .listOfStruct( - List.of(NestedStruct.builder().build(), NestedStruct.builder().build())) - .build(), - ListAllTypesInput.builder() - .listOfDocuments( - List.of(Document.of(2.0), Document.of("string"))) - .build()); - } - - static Stream nestedLists() { - return Stream.of( - NestedListsInput.builder() - .listOfLists( - List.of(List.of("a", "b"), List.of("c", "d"))) - .build(), - NestedListsInput.builder() - .listOfListOfList( - List.of(List.of(List.of("a", "b"), List.of("c", "d")))) - .build(), - NestedListsInput.builder() - .listOfMaps( - List.of(Map.of("a", "b"), Map.of("c", "d"))) - .build()); - } - - static Stream sparseLists() { - return Stream.of( - SparseListsInput.builder() - .listOfBooleans( - ListUtils.of(true, true, null, false)) - .build(), - SparseListsInput.builder() - .listOfBigDecimal( - ListUtils.of(BigDecimal.TEN, null, BigDecimal.ZERO)) - .build(), - SparseListsInput.builder() - .listOfBigInteger( - ListUtils.of(BigInteger.TEN, null, BigInteger.ZERO)) - .build(), - SparseListsInput.builder() - .listOfByte( - ListUtils.of((byte) 1, null, (byte) 2)) - .build(), - SparseListsInput.builder() - .listOfDouble( - ListUtils.of(2.0, null, 3.0)) - .build(), - SparseListsInput.builder() - .listOfFloat( - ListUtils.of(2f, null, 3f)) - .build(), - SparseListsInput.builder() - .listOfInteger( - ListUtils.of(1, null, 2)) - .build(), - SparseListsInput.builder() - .listOfLong( - ListUtils.of(1L, null, 2L)) - .build(), - SparseListsInput.builder() - .listOfShort( - ListUtils.of((short) 1, null, (short) 2)) - .build(), - SparseListsInput.builder() - .listOfString( - ListUtils.of("a", null, "b")) - .build(), - SparseListsInput.builder() - .listOfBlobs( - ListUtils.of( - wrap(Base64.getDecoder().decode("YmxvYg==")), - null, - wrap(Base64.getDecoder().decode("YmlyZHM=")))) - .build(), - SparseListsInput.builder() - .listOfTimestamps( - ListUtils.of(Instant.EPOCH, null, Instant.MIN)) - .build(), - SparseListsInput.builder() - .listOfUnion( - ListUtils.of(new NestedUnion.AMember("string"), null, new NestedUnion.BMember(2))) - .build(), - SparseListsInput.builder() - .listOfEnum( - ListUtils.of(NestedEnum.A, null, NestedEnum.B)) - .build(), - SparseListsInput.builder() - .listOfIntEnum( - ListUtils.of(NestedIntEnum.A, null, NestedIntEnum.B)) - .build(), - SparseListsInput.builder() - .listOfStruct( - ListUtils.of(NestedStruct.builder().build(), null, NestedStruct.builder().build())) - .build(), - SparseListsInput.builder() - .listOfDocuments( - ListUtils.of(Document.of(2.0), null, Document.of("string"))) - .build()); - } - - @ParameterizedTest - @MethodSource({"listTypes", "nestedLists", "sparseLists"}) - void pojoToDocumentRoundTrip(SerializableStruct pojo) { - var output = Utils.pojoToDocumentRoundTrip(pojo); - assertEquals(pojo.hashCode(), output.hashCode()); - assertEquals(pojo, output); - } - - @Test - void nullDistinctFromEmpty() { - var emptyInput = ListAllTypesInput.builder().listOfBoolean(List.of()).build(); - var nullInput = ListAllTypesInput.builder().build(); - assertNotEquals(emptyInput, nullInput); - assertTrue(emptyInput.hasListOfBoolean()); - assertFalse(nullInput.hasListOfBoolean()); - // Collections should return empty collections for access - assertEquals(emptyInput.getListOfBoolean(), Collections.emptyList()); - assertEquals(emptyInput.getListOfBoolean(), nullInput.getListOfBoolean()); - var emptyDocument = Document.of(emptyInput); - var nullDocument = Document.of(nullInput); - assertNotNull(emptyDocument.getMember("listOfBoolean")); - assertNull(nullDocument.getMember("listOfBoolean")); - } - - static Stream nonUniqueSources() { - return Stream.of( - "{\"setOfBoolean\":[true, false, false]}", - "{\"setOfNumber\":[1,2,2]}", - "{\"setOfString\":[\"a\", \"a\", \"b\"]}", - "{\"setOfBlobs\":[\"YmxvYg==\", \"YmxvYg==\"]}", - "{\"setOfTimestamps\":[0, 20, 0]}", - "{\"setOfUnion\":[{\"a\": \"str\"}, {\"b\": 1}, {\"a\": \"str\"}]}", - "{\"setOfEnum\":[\"A\", \"B\", \"A\"]}", - "{\"setOfIntEnum\":[1,1,2]}", - "{\"setOfStruct\":[{\"fieldA\": \"a\"}, {\"fieldA\": \"a\"}, {\"fieldA\": \"z\"}]}", - "{\"setOfStringList\":[[\"a\", \"b\"],[\"c\", \"d\"],[\"a\", \"b\"]]}", - "{\"setOfStringMap\": [{\"a\": \"b\", \"c\": \"d\"}, {\"c\": \"d\", \"a\": \"b\"}]}"); - } - - // Uniqueness is enforced in validation only. - @ParameterizedTest - @MethodSource("nonUniqueSources") - void nonUniqueIsAllowed(String source) { - try (var codec = JsonCodec.builder().useJsonName(true).build()) { - // This not throwing is the test. - codec.deserializeShape(source, SetsAllTypesInput.builder()); - } - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/MapsTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/MapsTest.java deleted file mode 100644 index 1dc1960ba..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/MapsTest.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static java.nio.ByteBuffer.wrap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.time.Instant; -import java.util.Base64; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.java.codegen.test.model.EnumKey; -import software.amazon.smithy.java.codegen.test.model.EnumMapKeysInput; -import software.amazon.smithy.java.codegen.test.model.MapAllTypesInput; -import software.amazon.smithy.java.codegen.test.model.NestedEnum; -import software.amazon.smithy.java.codegen.test.model.NestedIntEnum; -import software.amazon.smithy.java.codegen.test.model.NestedMapsInput; -import software.amazon.smithy.java.codegen.test.model.NestedStruct; -import software.amazon.smithy.java.codegen.test.model.NestedUnion; -import software.amazon.smithy.java.codegen.test.model.SparseMapsInput; -import software.amazon.smithy.java.core.schema.SerializableShape; -import software.amazon.smithy.java.core.schema.SerializableStruct; -import software.amazon.smithy.java.core.serde.document.Document; -import software.amazon.smithy.utils.MapUtils; - -public class MapsTest { - - static Stream mapTypes() { - return Stream.of( - MapAllTypesInput.builder() - .stringBooleanMap( - Map.of("a", true, "b", false)) - .build(), - MapAllTypesInput.builder() - .stringBigDecimalMap( - Map.of("one", BigDecimal.ONE, "ten", BigDecimal.TEN)) - .build(), - MapAllTypesInput.builder() - .stringBigIntegerMap( - Map.of("one", BigInteger.ONE, "ten", BigInteger.TEN)) - .build(), - MapAllTypesInput.builder() - .stringByteMap( - Map.of("one", (byte) 1, "two", (byte) 2)) - .build(), - MapAllTypesInput.builder() - .stringDoubleMap( - Map.of("one", 1.0, "two", 2.0)) - .build(), - MapAllTypesInput.builder() - .stringFloatMap( - Map.of("one", 1f, "two", 2f)) - .build(), - MapAllTypesInput.builder() - .stringIntegerMap( - Map.of("one", 1, "two", 2)) - .build(), - MapAllTypesInput.builder() - .stringLongMap( - Map.of("one", 1L, "two", 2L)) - .build(), - MapAllTypesInput.builder() - .stringShortMap( - Map.of("one", (short) 1, "two", (short) 2)) - .build(), - MapAllTypesInput.builder() - .stringStringMap( - Map.of("a", "b", "c", "d")) - .build(), - MapAllTypesInput.builder() - .stringBlobMap( - Map.of( - "a", - wrap(Base64.getDecoder().decode("YmxvYg==")), - "b", - wrap(Base64.getDecoder().decode("YmlyZHM=")))) - .build(), - MapAllTypesInput.builder() - .stringTimestampMap( - Map.of("epoch", Instant.EPOCH, "min", Instant.MIN)) - .build(), - MapAllTypesInput.builder() - .stringUnionMap( - Map.of("a", new NestedUnion.AMember("a"), "b", new NestedUnion.BMember(1))) - .build(), - MapAllTypesInput.builder() - .stringEnumMap( - Map.of("a", NestedEnum.A, "b", NestedEnum.B)) - .build(), - MapAllTypesInput.builder() - .stringIntEnumMap( - Map.of("a", NestedIntEnum.A, "b", NestedIntEnum.B)) - .build(), - MapAllTypesInput.builder() - .stringStructMap( - Map.of("a", - NestedStruct.builder().build(), - "b", - NestedStruct.builder().fieldA("a").build())) - .build()); - } - - static Stream nestedMaps() { - return Stream.of( - NestedMapsInput.builder() - .mapOfStringMap( - Map.of("a", Map.of("b", "c"), "d", Map.of("e", "f"))) - .build(), - NestedMapsInput.builder() - .mapOfMapOfStringMap( - Map.of("a", Map.of("b", Map.of("c", "d")))) - .build(), - NestedMapsInput.builder() - .mapOfStringList( - Map.of("a", List.of("b", "c"))) - .build(), - NestedMapsInput.builder() - .mapOfMapList( - Map.of("a", List.of(Map.of("b", "c"), Map.of("d", "e")))) - .build()); - } - - static Stream sparseMaps() { - return Stream.of( - SparseMapsInput.builder() - .stringBooleanMap( - MapUtils.of("a", true, "null", null, "b", false)) - .build(), - SparseMapsInput.builder() - .stringBigDecimalMap( - MapUtils.of("one", BigDecimal.ONE, "null", null, "ten", BigDecimal.TEN)) - .build(), - SparseMapsInput.builder() - .stringBigIntegerMap( - MapUtils.of("one", BigInteger.ONE, "null", null, "ten", BigInteger.TEN)) - .build(), - SparseMapsInput.builder() - .stringByteMap( - MapUtils.of("one", (byte) 1, "null", null, "two", (byte) 2)) - .build(), - SparseMapsInput.builder() - .stringDoubleMap( - MapUtils.of("one", 1.0, "null", null, "two", 2.0)) - .build(), - SparseMapsInput.builder() - .stringFloatMap( - MapUtils.of("one", 1f, "null", null, "two", 2f)) - .build(), - SparseMapsInput.builder() - .stringIntegerMap( - MapUtils.of("one", 1, "null", null, "two", 2)) - .build(), - SparseMapsInput.builder() - .stringLongMap( - MapUtils.of("one", 1L, "null", null, "two", 2L)) - .build(), - SparseMapsInput.builder() - .stringShortMap( - MapUtils.of("one", (short) 1, "null", null, "two", (short) 2)) - .build(), - SparseMapsInput.builder() - .stringStringMap( - MapUtils.of("a", "b", "null", null, "c", "d")) - .build(), - SparseMapsInput.builder() - .stringBlobMap( - MapUtils.of( - "a", - wrap(Base64.getDecoder().decode("YmxvYg==")), - "null", - null, - "b", - wrap(Base64.getDecoder().decode("YmlyZHM=")))) - .build(), - SparseMapsInput.builder() - .stringTimestampMap( - MapUtils.of("epoch", Instant.EPOCH, "null", null, "min", Instant.MIN)) - .build(), - SparseMapsInput.builder() - .stringUnionMap( - MapUtils.of("a", - new NestedUnion.AMember("a"), - "null", - null, - "b", - new NestedUnion.BMember(1))) - .build(), - SparseMapsInput.builder() - .stringEnumMap( - MapUtils.of("a", NestedEnum.A, "null", null, "b", NestedEnum.B)) - .build(), - SparseMapsInput.builder() - .stringIntEnumMap( - MapUtils.of("a", NestedIntEnum.A, "null", null, "b", NestedIntEnum.B)) - .build(), - SparseMapsInput.builder() - .stringStructMap( - MapUtils.of( - "a", - NestedStruct.builder().build(), - "null", - null, - "b", - NestedStruct.builder().fieldA("a").build())) - .build()); - } - - static Stream enumMaps() { - return Stream.of( - EnumMapKeysInput.builder() - .mapOfEnumValue( - MapUtils.of(EnumKey.A, "a")) - .build(), - EnumMapKeysInput.builder() - .mapOfEnumValue( - MapUtils.of(EnumKey.A, "a", EnumKey.B, "b", EnumKey.C, "c")) - .build()); - } - - @ParameterizedTest - @MethodSource({"mapTypes", "nestedMaps", "sparseMaps", "enumMaps"}) - void pojoToDocumentRoundTrip(SerializableStruct pojo) { - var output = Utils.pojoToDocumentRoundTrip(pojo); - assertEquals(pojo.hashCode(), output.hashCode()); - assertEquals(pojo, output); - } - - @Test - void nullDistinctFromEmpty() { - var emptyInput = MapAllTypesInput.builder().stringBooleanMap(Map.of()).build(); - var nullInput = MapAllTypesInput.builder().build(); - assertNotEquals(emptyInput, nullInput); - assertTrue(emptyInput.hasStringBooleanMap()); - assertFalse(nullInput.hasStringBooleanMap()); - // Collections should return empty collections for access - assertEquals(emptyInput.getStringBooleanMap(), Collections.emptyMap()); - assertEquals(emptyInput.getStringBooleanMap(), nullInput.getStringBooleanMap()); - - var emptyDocument = Document.of(emptyInput); - var nullDocument = Document.of(nullInput); - assertNotNull(emptyDocument.getMember("stringBooleanMap")); - assertNull(nullDocument.getMember("stringBooleanMap")); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/PresenceTrackingTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/PresenceTrackingTest.java deleted file mode 100644 index f88125b4d..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/PresenceTrackingTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.codegen.test.model.BooleanMembersInput; -import software.amazon.smithy.java.codegen.test.model.NestedStruct; -import software.amazon.smithy.java.codegen.test.model.StructureMembersInput; -import software.amazon.smithy.java.core.serde.SerializationException; - -public class PresenceTrackingTest { - @Test - void throwsSerdeExceptionOnMissingRequiredForPrimitiveField() { - var exc = assertThrows(SerializationException.class, () -> { - // Missing requiredBooleanField - BooleanMembersInput.builder().optionalBoolean(true).build(); - }); - assertTrue(exc.getMessage().contains("requiredBoolean")); - } - - @Test - void throwsSerdeExceptionOnMissingRequiredForNonPrimitiveField() { - var exc = assertThrows(SerializationException.class, () -> { - // Missing requiredBooleanField - StructureMembersInput.builder().optionalStruct(NestedStruct.builder().build()).build(); - }); - assertTrue(exc.getMessage().contains("requiredStruct")); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/RecursionTests.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/RecursionTests.java deleted file mode 100644 index ee62924f4..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/RecursionTests.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.java.codegen.test.model.AttributeValue; -import software.amazon.smithy.java.codegen.test.model.IntermediateListStructure; -import software.amazon.smithy.java.codegen.test.model.IntermediateMapStructure; -import software.amazon.smithy.java.codegen.test.model.RecursiveStructA; -import software.amazon.smithy.java.codegen.test.model.RecursiveStructB; -import software.amazon.smithy.java.codegen.test.model.SelfReferencing; -import software.amazon.smithy.java.core.schema.SerializableShape; -import software.amazon.smithy.java.core.schema.SerializableStruct; -import software.amazon.smithy.java.core.schema.ShapeBuilder; -import software.amazon.smithy.java.core.serde.document.Document; -import software.amazon.smithy.java.json.JsonCodec; - -public class RecursionTests { - - static Stream recursiveTypeSource() { - return Stream.of( - SelfReferencing.builder() - .self(SelfReferencing.builder().self(SelfReferencing.builder().build()).build()) - .build(), - IntermediateListStructure.builder() - .foo( - List.of( - IntermediateListStructure.builder() - .foo( - List.of(IntermediateListStructure.builder().build())) - .build())) - .build(), - IntermediateMapStructure.builder() - .foo( - Map.of( - "a", - IntermediateMapStructure.builder() - .foo( - Map.of("b", IntermediateMapStructure.builder().build())) - .build())) - .build(), - RecursiveStructA.builder() - .b( - RecursiveStructB.builder() - .a( - RecursiveStructA.builder().build()) - .build()) - .build()); - } - - @ParameterizedTest - @MethodSource("recursiveTypeSource") - void pojoToDocumentRoundTrip(SerializableStruct pojo) { - var output = Utils.pojoToDocumentRoundTrip(pojo); - assertEquals(pojo.hashCode(), output.hashCode()); - assertEquals(pojo, output); - } - - static Stream recursiveJsonSource() { - return Stream.of( - Arguments.of("{\"self\":{\"self\":{}}}", SelfReferencing.builder()), - Arguments.of("{\"foo\":[{\"foo\":[{\"foo\":[]}]}]}", IntermediateListStructure.builder()), - Arguments.of( - "{\"foo\":{\"a\":{\"foo\":{}},\"b\":{\"foo\":{\"c\":{\"foo\":{}}}}}}", - IntermediateMapStructure.builder()), - Arguments.of("{\"b\":{\"a\":{\"b\":{}}}}", RecursiveStructA.builder())); - } - - @ParameterizedTest - @MethodSource("recursiveJsonSource") - , T extends SerializableShape> void jsonDeserializationOfSelfReferencing( - String json, - B builder - ) { - try (var codec = JsonCodec.builder().useJsonName(true).useTimestampFormat(true).build()) { - var output = codec.deserializeShape(json, builder); - var serialized = codec.serializeToString(output); - assertEquals(serialized, json); - } - } - - @Test - void multiplyRecursiveUnionWorks() { - var recursive = new AttributeValue.LMember( - List.of( - new AttributeValue.MMember( - Map.of( - "stringList", - new AttributeValue.LMember(List.of()))))); - var document = Document.of(recursive); - var builder = AttributeValue.builder(); - document.deserializeInto(builder); - var output = builder.build(); - assertEquals(recursive.hashCode(), output.hashCode()); - assertEquals(recursive, output); - assertNotEquals(AttributeValue.$Unknown.class, output.getClass()); - } - - @Test - void verifyRecursiveSchemaResolved() { - assertThat(AttributeValue.$SCHEMA.resolve()).isSameAs(AttributeValue.$SCHEMA); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ReloadClasses.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ReloadClasses.java deleted file mode 100644 index fda82377d..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ReloadClasses.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -public @interface ReloadClasses {} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ReloadClassesExtension.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ReloadClassesExtension.java deleted file mode 100644 index c6d1fe6a6..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ReloadClassesExtension.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.File; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Arrays; -import java.util.Optional; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.InvocationInterceptor; -import org.junit.jupiter.api.extension.ReflectiveInvocationContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.platform.commons.util.ReflectionUtils; - -public class ReloadClassesExtension implements InvocationInterceptor { - - @Override - @SuppressFBWarnings("DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED") - public void interceptTestMethod( - Invocation invocation, - ReflectiveInvocationContext invocationContext, - ExtensionContext extensionContext - ) throws Throwable { - ReloadClasses annotation = invocationContext.getExecutable().getAnnotation(ReloadClasses.class); - if (annotation == null) { - InvocationInterceptor.super.interceptTestMethod(invocation, invocationContext, extensionContext); - return; - } - if (invocationContext.getExecutable().isAnnotationPresent(ParameterizedTest.class)) { - throw new IllegalStateException("ReloadClasses does not support Parameterized tests, yet"); - } - invocation.skip(); - URL[] jars; - if (ClassLoader.getSystemClassLoader() instanceof URLClassLoader u) { - jars = u.getURLs(); - } else { - String classPath = System.getProperty("java.class.path"); - jars = Arrays.stream(classPath.split(File.pathSeparator)) - .map(this::getURL) - .toArray(URL[]::new); - } - - try (URLClassLoader classLoader = new URLClassLoader(jars, null)) { - invokeMethodWithModifiedClasspath(invocationContext, classLoader); - } - } - - private URL getURL(String s) { - try { - return new File(s).toURI().toURL(); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - - private void invokeMethodWithModifiedClasspath( - ReflectiveInvocationContext invocationContext, - ClassLoader modifiedClassLoader - ) { - ClassLoader prev = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(modifiedClassLoader); - - try { - invokeMethodWithModifiedClasspath( - invocationContext.getExecutable().getDeclaringClass().getName(), - invocationContext.getExecutable().getName(), - modifiedClassLoader); - } finally { - Thread.currentThread().setContextClassLoader(prev); - } - } - - private void invokeMethodWithModifiedClasspath(String className, String methodName, ClassLoader classLoader) { - final Class testClass; - try { - testClass = classLoader.loadClass(className); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Cannot load test class [" + className + "] from modified classloader", e); - } - - Object testInstance = ReflectionUtils.newInstance(testClass); - final Optional method = ReflectionUtils.findMethod(testClass, methodName); - ReflectionUtils.invokeMethod( - method.orElseThrow(() -> new IllegalStateException("No test method named " + methodName)), - testInstance); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/StructuresTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/StructuresTest.java deleted file mode 100644 index efb50b677..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/StructuresTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.java.codegen.test.model.BigDecimalMembersInput; -import software.amazon.smithy.java.codegen.test.model.BigIntegerMembersInput; -import software.amazon.smithy.java.codegen.test.model.BooleanMembersInput; -import software.amazon.smithy.java.codegen.test.model.ByteMembersInput; -import software.amazon.smithy.java.codegen.test.model.DocumentMembersInput; -import software.amazon.smithy.java.codegen.test.model.DoubleMembersInput; -import software.amazon.smithy.java.codegen.test.model.EnumMembersInput; -import software.amazon.smithy.java.codegen.test.model.EnumType; -import software.amazon.smithy.java.codegen.test.model.FloatMembersInput; -import software.amazon.smithy.java.codegen.test.model.IntEnumMembersInput; -import software.amazon.smithy.java.codegen.test.model.IntEnumType; -import software.amazon.smithy.java.codegen.test.model.IntegerMembersInput; -import software.amazon.smithy.java.codegen.test.model.ListMembersInput; -import software.amazon.smithy.java.codegen.test.model.LongMembersInput; -import software.amazon.smithy.java.codegen.test.model.MapMembersInput; -import software.amazon.smithy.java.codegen.test.model.NestedStruct; -import software.amazon.smithy.java.codegen.test.model.NestedUnion; -import software.amazon.smithy.java.codegen.test.model.ShortMembersInput; -import software.amazon.smithy.java.codegen.test.model.StringMembersInput; -import software.amazon.smithy.java.codegen.test.model.StructureMembersInput; -import software.amazon.smithy.java.codegen.test.model.TimestampMembersInput; -import software.amazon.smithy.java.codegen.test.model.UnionMembersInput; -import software.amazon.smithy.java.core.schema.SerializableShape; -import software.amazon.smithy.java.core.schema.SerializableStruct; -import software.amazon.smithy.java.core.serde.document.Document; - -public class StructuresTest { - static Stream memberTypes() { - return Stream.of( - BooleanMembersInput.builder().requiredBoolean(true).build(), - DocumentMembersInput.builder().requiredDoc(Document.of("str")).build(), - ListMembersInput.builder().requiredList(List.of("a", "b", "c")).build(), - MapMembersInput.builder().requiredMap(Map.of("a", "b")).build(), - BigDecimalMembersInput.builder().requiredBigDecimal(BigDecimal.valueOf(1.0)).build(), - BigIntegerMembersInput.builder().requiredBigInteger(BigInteger.valueOf(1L)).build(), - ByteMembersInput.builder().requiredByte((byte) 1).build(), - DoubleMembersInput.builder().requiredDouble(2.0).build(), - FloatMembersInput.builder().requiredFloat(1f).build(), - IntegerMembersInput.builder().requiredInt(1).build(), - LongMembersInput.builder().requiredLongs(1L).build(), - ShortMembersInput.builder().requiredShort((short) 1).build(), - StringMembersInput.builder().requiredString("required").build(), - StructureMembersInput.builder() - .requiredStruct(NestedStruct.builder().fieldA("a").fieldB(2).build()) - .build(), - TimestampMembersInput.builder().requiredTimestamp(Instant.ofEpochMilli(111111111L)).build(), - UnionMembersInput.builder().requiredUnion(new NestedUnion.AMember("string")).build(), - EnumMembersInput.builder().requiredEnum(EnumType.OPTION_ONE).build(), - IntEnumMembersInput.builder().requiredEnum(IntEnumType.OPTION_ONE).build()); - } - - @ParameterizedTest - @MethodSource("memberTypes") - void pojoToDocumentRoundTrip(SerializableStruct pojo) { - var output = Utils.pojoToDocumentRoundTrip(pojo); - assertEquals(pojo.hashCode(), output.hashCode()); - assertEquals(pojo, output); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/UnionTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/UnionTest.java deleted file mode 100644 index 6edec9de5..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/UnionTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.time.Instant; -import java.util.Base64; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Stream; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.java.codegen.test.model.NestedEnum; -import software.amazon.smithy.java.codegen.test.model.NestedIntEnum; -import software.amazon.smithy.java.codegen.test.model.NestedStruct; -import software.amazon.smithy.java.codegen.test.model.NestedUnion; -import software.amazon.smithy.java.codegen.test.model.UnionType; -import software.amazon.smithy.java.core.serde.ShapeSerializer; -import software.amazon.smithy.java.core.serde.document.Document; -import software.amazon.smithy.model.shapes.ShapeType; - -public class UnionTest { - - static Stream unionTypes() { - return Stream.of( - new UnionType.BooleanValueMember(true), - new UnionType.ListValueMember(List.of("a", "b")), - new UnionType.MapValueMember(Map.of("a", "b")), - new UnionType.BigDecimalValueMember(BigDecimal.ONE), - new UnionType.BigIntegerValueMember(BigInteger.ONE), - new UnionType.ByteValueMember((byte) 1), - new UnionType.DoubleValueMember(2.0), - new UnionType.FloatValueMember(2f), - new UnionType.IntegerValueMember(1), - new UnionType.LongValueMember(1L), - new UnionType.ShortValueMember((short) 1), - new UnionType.StringValueMember("string"), - new UnionType.BlobValueMember(ByteBuffer.wrap(Base64.getDecoder().decode("c3RyZWFtaW5n"))), - new UnionType.StructureValueMember(NestedStruct.builder().build()), - new UnionType.TimestampValueMember(Instant.EPOCH), - new UnionType.UnionValueMember(new NestedUnion.BMember(1)), - new UnionType.EnumValueMember(NestedEnum.A), - new UnionType.IntEnumValueMember(NestedIntEnum.A), - new UnionType.UnitValueMember()); - } - - @ParameterizedTest - @MethodSource("unionTypes") - void pojoToDocumentRoundTrip(UnionType pojo) { - var document = Document.of(pojo); - var builder = UnionType.builder(); - document.deserializeInto(builder); - var output = builder.build(); - assertEquals(pojo.hashCode(), output.hashCode()); - assertEquals(pojo, output); - } - - record UnknownDocument() implements Document { - - private static final Map members = Map.of("UNKNOWN!!!", Document.of(3.2)); - - @Override - public ShapeType type() { - return ShapeType.UNION; - } - - @Override - public void serializeContents(ShapeSerializer serializer) { - throw new UnsupportedOperationException(); - } - - @Override - public Document getMember(String memberName) { - return members.get(memberName); - } - - @Override - public Set getMemberNames() { - return members.keySet(); - } - - @Override - public Map asStringMap() { - return members; - } - } - - @Test - void unknownUnionDeser() { - var document = new UnknownDocument(); - var builder = UnionType.builder(); - document.deserializeInto(builder); - var output = builder.build(); - - if (output instanceof UnionType.$Unknown(String memberName)) { - assertEquals("UNKNOWN!!!", memberName); - } else { - throw new AssertionError("Expected $Unknown variant"); - } - assertEquals("UNKNOWN!!!", output.getValue()); - } - - @Test - void unknownUnionSerFails() { - var union = UnionType.builder().$unknownMember("foo").build(); - assertThrows(UnsupportedOperationException.class, () -> Document.of(union)); - } - - @Test - void showExhaustiveMatchRequired() { - var union = getNestedUnion(); - switch (union) { - case NestedUnion.AMember(var a) -> assertNotNull(a); - case NestedUnion.BMember(var b) -> assertNotEquals(0, b); - case NestedUnion.$Unknown(var memberName) -> assertNotNull(memberName); - default -> throw new IllegalArgumentException("Unexpected member: " + union); - } - } - - private static NestedUnion getNestedUnion() { - return NestedUnion.builder().a("a").build(); - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/Utils.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/Utils.java deleted file mode 100644 index d9b6775ce..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/Utils.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test; - -import java.lang.reflect.InvocationTargetException; -import software.amazon.smithy.java.core.schema.SerializableShape; -import software.amazon.smithy.java.core.schema.SerializableStruct; -import software.amazon.smithy.java.core.schema.ShapeBuilder; -import software.amazon.smithy.java.core.serde.document.Document; - -final class Utils { - private Utils() {} - - static T pojoToDocumentRoundTrip(T pojo) { - var document = Document.of(pojo); - ShapeBuilder builder = getBuilder(pojo); - document.deserializeInto(builder); - return builder.build(); - } - - @SuppressWarnings("unchecked") - static

ShapeBuilder

getBuilder(P pojo) { - try { - var method = pojo.getClass().getDeclaredMethod("builder"); - return (ShapeBuilder

) method.invoke(pojo); - } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) { - throw new RuntimeException(e); - } - } -} diff --git a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/model/TraitsTest.java b/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/model/TraitsTest.java deleted file mode 100644 index f184c77b6..000000000 --- a/codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/model/TraitsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.test.model; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.math.BigDecimal; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.java.core.schema.TraitKey; -import software.amazon.smithy.model.node.Node; -import software.amazon.smithy.model.traits.DefaultTrait; -import software.amazon.smithy.model.traits.LengthTrait; -import software.amazon.smithy.model.traits.RangeTrait; -import software.amazon.smithy.model.traits.RetryableTrait; -import software.amazon.smithy.model.traits.Trait; -import software.amazon.smithy.model.traits.XmlNamespaceTrait; - -public class TraitsTest { - - private static List memberSchemaSource() { - return List.of( - Arguments.of("stringDefault", DefaultTrait.class, new DefaultTrait(Node.from("string"))), - Arguments.of("stringWithLength", LengthTrait.class, LengthTrait.builder().min(10L).build()), - Arguments.of("numberWithRange", - RangeTrait.class, - RangeTrait.builder().max(new BigDecimal("100")).build()), - Arguments.of( - "xmlNamespaced", - XmlNamespaceTrait.class, - XmlNamespaceTrait.builder().uri("http://foo.com").build())); - } - - @ParameterizedTest - @MethodSource("memberSchemaSource") - void testStructureMemberSchemaTraitsSet(String memberName, Class traitClass, Trait expected) { - var memberSchema = TraitsInput.$SCHEMA.member(memberName); - var traitValue = memberSchema.expectTrait(TraitKey.get(traitClass)); - assertEquals(traitValue, expected); - } - - @Test - void testErrorTraitsSet() { - var retryableTrait = RetryableError.$SCHEMA.expectTrait(TraitKey.get(RetryableTrait.class)); - assertEquals(retryableTrait, RetryableTrait.builder().build()); - } -} diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/externaltypes/ExternalTypesIntegration.java b/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/externaltypes/ExternalTypesIntegration.java deleted file mode 100644 index af25a32ad..000000000 --- a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/externaltypes/ExternalTypesIntegration.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.integrations.externaltypes; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import software.amazon.smithy.codegen.core.CodegenException; -import software.amazon.smithy.codegen.core.Symbol; -import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.codegen.core.SymbolReference; -import software.amazon.smithy.java.codegen.CodegenUtils; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.SymbolProperties; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.shapes.ListShape; -import software.amazon.smithy.model.shapes.MapShape; -import software.amazon.smithy.model.shapes.MemberShape; -import software.amazon.smithy.model.shapes.Shape; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.utils.SmithyInternalApi; - -@SmithyInternalApi -public final class ExternalTypesIntegration implements JavaCodegenIntegration { - private static final String PROPERTY_FILE = "META-INF/smithy-java/type-mappings.properties"; - private static final Map TYPE_MAPPINGS = getTypeMappings(); - - private static Map getTypeMappings() { - try { - Map result = new HashMap<>(); - var classLoader = ExternalTypesIntegration.class.getClassLoader(); - var mappings = classLoader.getResources(PROPERTY_FILE); - while (mappings.hasMoreElements()) { - var properties = new Properties(); - try (InputStream is = mappings.nextElement().openStream()) { - properties.load(is); - } - for (var property : properties.entrySet()) { - var shapeId = ShapeId.from((String) property.getKey()); - var shapeClass = Class.forName((String) property.getValue()); - var symbol = CodegenUtils.fromClass(shapeClass) - .toBuilder() - .putProperty(SymbolProperties.EXTERNAL_TYPE, true) - .build(); - var existing = result.put(shapeId, symbol); - if (existing != null) { - throw new CodegenException( - "Found duplicate mapping for external type: " - + property.getKey() + ". Existing: " + existing - + "Duplicate: " + property.getValue()); - } - } - } - return result; - } catch (IOException exc) { - throw new UncheckedIOException("Error while loading external type mappings", exc); - } catch (ClassNotFoundException e) { - throw new CodegenException("Could not find class for mapped external type."); - } - } - - @Override - public String name() { - return "external-types"; - } - - @Override - public byte priority() { - return -1; - } - - @Override - public SymbolProvider decorateSymbolProvider( - Model model, - JavaCodegenSettings settings, - SymbolProvider symbolProvider - ) { - return new SymbolProvider() { - @Override - public Symbol toSymbol(Shape shape) { - if (TYPE_MAPPINGS.containsKey(shape.toShapeId())) { - return TYPE_MAPPINGS.get(shape.toShapeId()); - } else if (shape instanceof MemberShape ms && TYPE_MAPPINGS.containsKey(ms.getTarget())) { - return TYPE_MAPPINGS.get(ms.getTarget()); - } else if (shape instanceof ListShape ls && TYPE_MAPPINGS.containsKey(ls.getMember().getTarget())) { - var targetSymbol = TYPE_MAPPINGS.get(ls.getMember().getTarget()); - return symbolProvider.toSymbol(shape) - .toBuilder() - .references(List.of(new SymbolReference(targetSymbol))) - .build(); - } else if (shape instanceof MapShape ms && TYPE_MAPPINGS.containsKey(ms.getValue().getTarget())) { - var valueSymbol = TYPE_MAPPINGS.get(ms.getValue().getTarget()); - var keySymbol = symbolProvider.toSymbol(ms.getKey()); - return symbolProvider.toSymbol(shape) - .toBuilder() - .references(List.of(new SymbolReference(keySymbol), new SymbolReference(valueSymbol))) - .build(); - } - return symbolProvider.toSymbol(shape); - } - - @Override - public String toMemberName(MemberShape shape) { - return symbolProvider.toMemberName(shape); - } - }; - } -} diff --git a/codegen/codegen-core/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService b/codegen/codegen-core/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService deleted file mode 100644 index 781633b23..000000000 --- a/codegen/codegen-core/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService +++ /dev/null @@ -1 +0,0 @@ -software.amazon.smithy.java.codegen.CodegenContextTest$SelectedTrait$Provider \ No newline at end of file diff --git a/codegen/codegen-plugin/build.gradle.kts b/codegen/codegen-plugin/build.gradle.kts new file mode 100644 index 000000000..b25f1cba9 --- /dev/null +++ b/codegen/codegen-plugin/build.gradle.kts @@ -0,0 +1,72 @@ +plugins { + id("smithy-java.codegen-plugin-conventions") + id("smithy-java.publishing-conventions") +} + +description = "Smithy Java code generation plugin" + +extra["displayName"] = "Smithy :: Java :: Codegen :: Plugin" +extra["moduleName"] = "software.amazon.smithy.java.codegen.plugin" + +dependencies { + api(libs.smithy.codegen) + compileOnly(project(":client:client-api")) + compileOnly(project(":client:client-rulesengine")) + compileOnly(project(":client:client-waiters")) + compileOnly(project(":server:server-api")) + // Test deps (needed to compile and run generated code in tests) + testImplementation(project(":client:client-api")) + testImplementation(project(":client:client-core")) + testImplementation(project(":client:client-rulesengine")) + testImplementation(project(":client:client-waiters")) + testImplementation(project(":server:server-api")) + testImplementation(project(":server:server-core")) + testImplementation(project(":aws:client:aws-client-restjson")) + testImplementation(libs.smithy.aws.traits) + testImplementation(libs.smithy.rules) + testImplementation(project(":codegen:test-utils")) + + // Integration test deps + itImplementation(project(":client:client-core")) + itImplementation(project(":client:client-rulesengine")) + itImplementation(project(":server:server-core")) + itImplementation(project(":server:server-api")) + itImplementation(project(":client:client-waiters")) + itImplementation(project(":aws:client:aws-client-restjson")) + itImplementation(project(":codecs:json-codec", configuration = "shadow")) + itImplementation(libs.smithy.aws.traits) + itImplementation(libs.smithy.rules) +} + +// Core codegen test runner +addGenerateSrcsTask("software.amazon.smithy.java.codegen.utils.TestJavaCodegenRunner") +// Client codegen test runner +addGenerateSrcsTask("software.amazon.smithy.java.codegen.client.TestServerJavaClientCodegenRunner", "Client", null) +// Server codegen test runner +addGenerateSrcsTask("software.amazon.smithy.java.codegen.server.TestServerJavaCodegenRunner", "Server", null) +// Types codegen test runner +addGenerateSrcsTask("software.amazon.smithy.java.codegen.types.TestJavaTypeCodegenRunner", "Types", null) + +sourceSets { + it { + // Add test plugin to classpath + compileClasspath += sourceSets["test"].output + resources.srcDir("${layout.buildDirectory.get()}/generated-src/resources") + } +} + +tasks.named("processItResources") { + dependsOn("generateSources", "generateSourcesClient") + from("${layout.buildDirectory.get()}/generated-src-Client/resources") +} + +// Ensure generate tasks that use it source set resources depend on base generateSources +listOf("generateSourcesClient", "generateSourcesServer", "generateSourcesTypes").forEach { taskName -> + tasks.named(taskName) { + dependsOn("generateSources") + } +} + +tasks.test { + failOnNoDiscoveredTests = false +} diff --git a/codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/AuthSchemeTest.java b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/AuthSchemeTest.java similarity index 100% rename from codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/AuthSchemeTest.java rename to codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/AuthSchemeTest.java diff --git a/codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/BddTest.java b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/BddTest.java similarity index 100% rename from codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/BddTest.java rename to codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/BddTest.java diff --git a/codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/GenericClientTest.java b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/GenericClientTest.java similarity index 100% rename from codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/GenericClientTest.java rename to codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/GenericClientTest.java diff --git a/codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/util/EchoServer.java b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/util/EchoServer.java similarity index 100% rename from codegen/plugins/client-codegen/src/it/java/software/amazon/smithy/java/codegen/client/util/EchoServer.java rename to codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/client/util/EchoServer.java diff --git a/codegen/plugins/server-codegen/src/it/java/software/amazon/smithy/java/codegen/server/ServiceBuilderTest.java b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/server/ServiceBuilderTest.java similarity index 84% rename from codegen/plugins/server-codegen/src/it/java/software/amazon/smithy/java/codegen/server/ServiceBuilderTest.java rename to codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/server/ServiceBuilderTest.java index 3e957f865..a49e35d71 100644 --- a/codegen/plugins/server-codegen/src/it/java/software/amazon/smithy/java/codegen/server/ServiceBuilderTest.java +++ b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/server/ServiceBuilderTest.java @@ -13,18 +13,18 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.Test; -import smithy.java.codegen.server.test.model.Beer; -import smithy.java.codegen.server.test.model.EchoInput; -import smithy.java.codegen.server.test.model.EchoOutput; -import smithy.java.codegen.server.test.model.EchoPayload; -import smithy.java.codegen.server.test.model.GetBeerInput; -import smithy.java.codegen.server.test.model.GetBeerOutput; -import smithy.java.codegen.server.test.model.GetErrorInput; -import smithy.java.codegen.server.test.model.GetErrorOutput; -import smithy.java.codegen.server.test.service.EchoOperation; -import smithy.java.codegen.server.test.service.GetBeerOperationAsync; -import smithy.java.codegen.server.test.service.GetErrorOperationAsync; -import smithy.java.codegen.server.test.service.TestService; +import smithy.java.codegen.server.only.test.model.Beer; +import smithy.java.codegen.server.only.test.model.EchoInput; +import smithy.java.codegen.server.only.test.model.EchoOutput; +import smithy.java.codegen.server.only.test.model.EchoPayload; +import smithy.java.codegen.server.only.test.model.GetBeerInput; +import smithy.java.codegen.server.only.test.model.GetBeerOutput; +import smithy.java.codegen.server.only.test.model.GetErrorInput; +import smithy.java.codegen.server.only.test.model.GetErrorOutput; +import smithy.java.codegen.server.only.test.service.EchoOperation; +import smithy.java.codegen.server.only.test.service.GetBeerOperationAsync; +import smithy.java.codegen.server.only.test.service.GetErrorOperationAsync; +import smithy.java.codegen.server.only.test.service.TestService; import software.amazon.smithy.java.core.error.ModeledException; import software.amazon.smithy.java.framework.model.InternalFailureException; import software.amazon.smithy.java.framework.model.UnknownOperationException; diff --git a/codegen/plugins/types-codegen/src/it/java/software/amazon/smithy/java/codegen/types/GenericSerdeTest.java b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/types/GenericSerdeTest.java similarity index 81% rename from codegen/plugins/types-codegen/src/it/java/software/amazon/smithy/java/codegen/types/GenericSerdeTest.java rename to codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/types/GenericSerdeTest.java index 73edea540..4a1a52f90 100644 --- a/codegen/plugins/types-codegen/src/it/java/software/amazon/smithy/java/codegen/types/GenericSerdeTest.java +++ b/codegen/codegen-plugin/src/it/java/software/amazon/smithy/java/codegen/types/GenericSerdeTest.java @@ -11,14 +11,14 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import smithy.java.codegen.server.test.model.Astruct; -import smithy.java.codegen.server.test.model.Bstruct; -import smithy.java.codegen.server.test.model.MyNestedStruct; -import smithy.java.codegen.server.test.model.MyStruct; -import smithy.java.codegen.server.test.model.MyUnion; -import smithy.java.codegen.server.test.model.NestedIntEnum; -import smithy.java.codegen.server.test.model.UsesOtherStructs; -import smithy.java.codegen.server.test.model.YesOrNo; +import smithy.java.codegen.types.test.model.Astruct; +import smithy.java.codegen.types.test.model.Bstruct; +import smithy.java.codegen.types.test.model.MyNestedStruct; +import smithy.java.codegen.types.test.model.MyStruct; +import smithy.java.codegen.types.test.model.MyUnion; +import smithy.java.codegen.types.test.model.NestedIntEnum; +import smithy.java.codegen.types.test.model.UsesOtherStructs; +import smithy.java.codegen.types.test.model.YesOrNo; import software.amazon.smithy.java.core.schema.SerializableShape; import software.amazon.smithy.java.core.schema.ShapeBuilder; import software.amazon.smithy.java.core.serde.document.Document; diff --git a/codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/a.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/a.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/a.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/a.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/authScheme.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/authScheme.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/authScheme.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/authScheme.smithy diff --git a/codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/b.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/b.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/b.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/b.smithy diff --git a/codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/bdd-test.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/bdd-test.smithy similarity index 100% rename from codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/bdd-test.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/bdd-test.smithy diff --git a/codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/main.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/client-main.smithy similarity index 100% rename from codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/main.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/client-main.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/common.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/common.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/common.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/common.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/enums/enum-tests.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/enum-tests.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/enums/enum-tests.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/enum-tests.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/enums/lower-case-variant-names.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/lower-case-variant-names.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/enums/lower-case-variant-names.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/lower-case-variant-names.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/enums/non-sequential.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/non-sequential.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/enums/non-sequential.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/non-sequential.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/enums/unsafe-value-name.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/unsafe-value-name.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/enums/unsafe-value-name.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/enums/unsafe-value-name.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/exceptions/exception-tests.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/exceptions/exception-tests.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/exceptions/exception-tests.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/exceptions/exception-tests.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/idempotencytoken/idempotency-token.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/idempotencytoken/idempotency-token.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/idempotencytoken/idempotency-token.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/idempotencytoken/idempotency-token.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/lists/list-all-types.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/list-all-types.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/lists/list-all-types.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/list-all-types.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/lists/list-tests.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/list-tests.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/lists/list-tests.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/list-tests.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/lists/nested-lists.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/nested-lists.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/lists/nested-lists.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/nested-lists.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/lists/sparse-lists.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/sparse-lists.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/lists/sparse-lists.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/sparse-lists.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/lists/unique-items.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/unique-items.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/lists/unique-items.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/lists/unique-items.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/main.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/main.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/main.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/main.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/manifest b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/manifest similarity index 93% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/manifest rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/manifest index deccb3476..777c99c73 100644 --- a/codegen/codegen-core/src/it/resources/META-INF/smithy/manifest +++ b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/manifest @@ -51,4 +51,10 @@ unions/unions-all-types.smithy common.smithy authScheme.smithy main.smithy - +client-main.smithy +server-main.smithy +test-auth-scheme.smithy +bdd-test.smithy +a.smithy +b.smithy +nested/c.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/maps/enum-map-keys.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/enum-map-keys.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/maps/enum-map-keys.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/enum-map-keys.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/maps/map-all-types.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/map-all-types.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/maps/map-all-types.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/map-all-types.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/maps/map-tests.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/map-tests.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/maps/map-tests.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/map-tests.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/maps/nested-maps.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/nested-maps.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/maps/nested-maps.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/nested-maps.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/maps/sparse-maps.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/sparse-maps.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/maps/sparse-maps.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/maps/sparse-maps.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/naming/naming-collision.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/naming/naming-collision.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/naming/naming-collision.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/naming/naming-collision.smithy diff --git a/codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/nested/c.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/nested/c.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/nested/c.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/nested/c.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/multiple-recursion.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/multiple-recursion.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/multiple-recursion.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/multiple-recursion.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/mutual-recursion-list.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/mutual-recursion-list.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/mutual-recursion-list.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/mutual-recursion-list.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/mutual-recursion-map.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/mutual-recursion-map.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/mutual-recursion-map.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/mutual-recursion-map.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/mutual-recursion-struct.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/mutual-recursion-struct.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/mutual-recursion-struct.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/mutual-recursion-struct.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/recursion-tests.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/recursion-tests.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/recursion-tests.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/recursion-tests.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/self-referential-shape.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/self-referential-shape.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/recursion/self-referential-shape.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/recursion/self-referential-shape.smithy diff --git a/codegen/plugins/server-codegen/src/it/resources/META-INF/smithy/main.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/server-main.smithy similarity index 96% rename from codegen/plugins/server-codegen/src/it/resources/META-INF/smithy/main.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/server-main.smithy index 2fdbe2582..3472837fd 100644 --- a/codegen/plugins/server-codegen/src/it/resources/META-INF/smithy/main.smithy +++ b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/server-main.smithy @@ -1,6 +1,6 @@ $version: "2.0" -namespace smithy.java.codegen.server.test +namespace smithy.java.codegen.server.only.test service TestService { version: "today" diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/big-decimal-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/big-decimal-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/big-decimal-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/big-decimal-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/big-integer-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/big-integer-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/big-integer-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/big-integer-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/blob-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/blob-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/blob-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/blob-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/boolean-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/boolean-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/boolean-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/boolean-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/byte-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/byte-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/byte-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/byte-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/defaults.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/defaults.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/defaults.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/defaults.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/document-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/document-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/document-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/document-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/double-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/double-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/double-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/double-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/enum-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/enum-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/enum-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/enum-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/error-correction.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/error-correction.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/error-correction.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/error-correction.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/float-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/float-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/float-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/float-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/int-enum-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/int-enum-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/int-enum-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/int-enum-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/integer-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/integer-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/integer-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/integer-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/list-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/list-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/list-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/list-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/long-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/long-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/long-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/long-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/map-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/map-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/map-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/map-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/set-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/set-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/set-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/set-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/short-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/short-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/short-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/short-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/streaming-blob-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/streaming-blob-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/streaming-blob-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/streaming-blob-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/string-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/string-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/string-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/string-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/structure-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/structure-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/structure-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/structure-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/structure-tests.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/structure-tests.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/structure-tests.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/structure-tests.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/timestamp-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/timestamp-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/timestamp-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/timestamp-members.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/structures/union-members.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/union-members.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/structures/union-members.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/structures/union-members.smithy diff --git a/codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/test-auth-scheme.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/test-auth-scheme.smithy similarity index 100% rename from codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/test-auth-scheme.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/test-auth-scheme.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/traits/traits.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/traits/traits.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/traits/traits.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/traits/traits.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/unions/union-tests.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/unions/union-tests.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/unions/union-tests.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/unions/union-tests.smithy diff --git a/codegen/codegen-core/src/it/resources/META-INF/smithy/unions/unions-all-types.smithy b/codegen/codegen-plugin/src/it/resources/META-INF/smithy/unions/unions-all-types.smithy similarity index 100% rename from codegen/codegen-core/src/it/resources/META-INF/smithy/unions/unions-all-types.smithy rename to codegen/codegen-plugin/src/it/resources/META-INF/smithy/unions/unions-all-types.smithy diff --git a/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/knowledge/ImplicitErrorIndex.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/knowledge/ImplicitErrorIndex.java new file mode 100644 index 000000000..05524143b --- /dev/null +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/knowledge/ImplicitErrorIndex.java @@ -0,0 +1,72 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.framework.knowledge; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import software.amazon.smithy.framework.traits.ImplicitErrorsTrait; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.knowledge.KnowledgeIndex; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.ToShapeId; + +/** + * Provides an index of the implicit errors of a service. + * TODO: Upstream to smithy-model package along with implicitError trait + */ +public final class ImplicitErrorIndex implements KnowledgeIndex { + + private final Map> serviceImplicitErrorMap; + private final Set implicitErrors; + + private ImplicitErrorIndex(Model model) { + var serviceImplicitError = new HashMap>(); + var allImplicitErrors = new TreeSet(); + + for (var service : model.getServiceShapes()) { + for (var traitEntry : service.getAllTraits().entrySet()) { + var traitShapeOptional = model.getShape(traitEntry.getKey()); + if (traitShapeOptional.isEmpty()) { + // Ignore traits not found in model. This can happen if a user + // has --allow-unknown-traits set to true. + continue; + } + + var traitShape = traitShapeOptional.get(); + if (traitShape.hasTrait(ImplicitErrorsTrait.class)) { + var implicitErrorsTrait = traitShape.expectTrait(ImplicitErrorsTrait.class); + var implicitErrorList = serviceImplicitError.computeIfAbsent( + service.toShapeId(), + k -> new TreeSet<>()); + implicitErrorList.addAll(implicitErrorsTrait.getValues()); + allImplicitErrors.addAll(implicitErrorsTrait.getValues()); + } + } + } + + var immutableServiceMap = new HashMap>(); + for (var entry : serviceImplicitError.entrySet()) { + immutableServiceMap.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue())); + } + this.serviceImplicitErrorMap = Collections.unmodifiableMap(immutableServiceMap); + this.implicitErrors = Collections.unmodifiableSet(allImplicitErrors); + } + + public static ImplicitErrorIndex of(Model model) { + return model.getKnowledge(ImplicitErrorIndex.class, ImplicitErrorIndex::new); + } + + public Set getImplicitErrorsForService(ToShapeId toShapeId) { + return serviceImplicitErrorMap.getOrDefault(toShapeId.toShapeId(), Collections.emptySet()); + } + + public boolean isImplicitError(ShapeId shapeId) { + return implicitErrors.contains(shapeId); + } +} diff --git a/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/traits/ImplicitErrorsTrait.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/traits/ImplicitErrorsTrait.java new file mode 100644 index 000000000..c8e6d2570 --- /dev/null +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/traits/ImplicitErrorsTrait.java @@ -0,0 +1,118 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.framework.traits; + +import java.util.List; +import software.amazon.smithy.model.node.ArrayNode; +import software.amazon.smithy.model.node.ExpectationNotMetException; +import software.amazon.smithy.model.node.Node; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.traits.AbstractTrait; +import software.amazon.smithy.model.traits.AbstractTraitBuilder; +import software.amazon.smithy.model.traits.Trait; +import software.amazon.smithy.utils.BuilderRef; +import software.amazon.smithy.utils.SmithyBuilder; +import software.amazon.smithy.utils.SmithyGenerated; +import software.amazon.smithy.utils.ToSmithyBuilder; + +@SmithyGenerated +public final class ImplicitErrorsTrait extends AbstractTrait implements ToSmithyBuilder { + public static final ShapeId ID = ShapeId.from("smithy.framework#implicitErrors"); + + private final List values; + + private ImplicitErrorsTrait(Builder builder) { + super(ID, builder.getSourceLocation()); + this.values = builder.values.copy(); + } + + @Override + protected Node createNode() { + var builder = ArrayNode.builder(); + for (var value : values) { + builder.withValue(value.toString()); + } + return builder.build(); + } + + /** + * Creates a {@link ImplicitErrorsTrait} from a {@link Node}. + * + * @param node Node to create the AddsImplicitErrorsTrait from. + * @return Returns the created AddsImplicitErrorsTrait. + * @throws ExpectationNotMetException if the given Node is invalid. + */ + public static ImplicitErrorsTrait fromNode(Node node) { + Builder builder = builder(); + for (var element : node.expectArrayNode().getElements()) { + builder.addValues(ShapeId.fromNode(element)); + } + return builder.build(); + } + + public List getValues() { + return values; + } + + /** + * Creates a builder used to build a {@link ImplicitErrorsTrait}. + */ + public SmithyBuilder toBuilder() { + return builder().sourceLocation(getSourceLocation()).values(getValues()); + } + + public static Builder builder() { + return new Builder(); + } + + /** + * Builder for {@link ImplicitErrorsTrait}. + */ + public static final class Builder extends AbstractTraitBuilder { + private final BuilderRef> values = BuilderRef.forList(); + + private Builder() {} + + public Builder values(List values) { + clearValues(); + this.values.get().addAll(values); + return this; + } + + public Builder clearValues() { + values.get().clear(); + return this; + } + + public Builder addValues(ShapeId value) { + values.get().add(value); + return this; + } + + public Builder removeValues(ShapeId value) { + values.get().remove(value); + return this; + } + + @Override + public ImplicitErrorsTrait build() { + return new ImplicitErrorsTrait(this); + } + } + + public static final class Provider extends AbstractTrait.Provider { + public Provider() { + super(ID); + } + + @Override + public Trait createTrait(ShapeId target, Node value) { + ImplicitErrorsTrait result = ImplicitErrorsTrait.fromNode(value); + result.setNodeCache(value); + return result; + } + } +} diff --git a/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/transform/AddFrameworkErrorsTransform.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/transform/AddFrameworkErrorsTransform.java new file mode 100644 index 000000000..7a10279d1 --- /dev/null +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/framework/transform/AddFrameworkErrorsTransform.java @@ -0,0 +1,73 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.framework.transform; + +import java.util.HashSet; +import java.util.Set; +import software.amazon.smithy.framework.traits.ImplicitErrorsTrait; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.node.Node; +import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.StructureShape; +import software.amazon.smithy.model.traits.ErrorTrait; +import software.amazon.smithy.model.traits.Trait; +import software.amazon.smithy.model.traits.TraitDefinition; +import software.amazon.smithy.model.transform.ModelTransformer; + +/** + * Adds any framework errors (error shapes found in `smithy.framework` namespace) to service shapes in the model. + * TODO: Upstream this transform to directed codegen and a smithy-build transform + */ +public final class AddFrameworkErrorsTransform { + private static final String SMITHY_FRAMEWORK_NAMESPACE = "smithy.framework"; + private static final ShapeId SYNTHETIC_TRAIT_ID = ShapeId.from("smithy.synthetic#frameworkErrors"); + + private AddFrameworkErrorsTransform() {} + + public static Model transform(ModelTransformer transformer, Model model) { + Set frameworkErrors = new HashSet<>(); + for (var struct : model.getStructureShapes()) { + if (struct.hasTrait(ErrorTrait.class) && struct.getId().getNamespace().equals(SMITHY_FRAMEWORK_NAMESPACE)) { + frameworkErrors.add(struct.getId()); + } + } + var addedFrameworkErrors = ImplicitErrorsTrait.builder().values(frameworkErrors.stream().toList()).build(); + var syntheticFrameworkTraitShape = getSyntheticTraitBuilder().addTrait(addedFrameworkErrors) + .build(); + Set updated = new HashSet<>(); + updated.add(syntheticFrameworkTraitShape); + for (var service : model.getServiceShapes()) { + updated.add(service.toBuilder().addTrait(new SyntheticErrorTrait()).build()); + } + + return transformer.replaceShapes(model, updated); + } + + private static StructureShape.Builder getSyntheticTraitBuilder() { + return StructureShape.builder() + .id(SYNTHETIC_TRAIT_ID) + .addTrait(TraitDefinition.builder().build()); + } + + private static final class SyntheticErrorTrait implements Trait { + + @Override + public Node toNode() { + return Node.objectNode(); + } + + @Override + public ShapeId toShapeId() { + return SYNTHETIC_TRAIT_ID; + } + + @Override + public boolean isSynthetic() { + return true; + } + } +} diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/ClientSymbolProperties.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ClientSymbolProperties.java similarity index 93% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/ClientSymbolProperties.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ClientSymbolProperties.java index 18875b1bd..f1dab0e10 100644 --- a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/ClientSymbolProperties.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ClientSymbolProperties.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.java.codegen.client; +package software.amazon.smithy.java.codegen; import software.amazon.smithy.codegen.core.Property; import software.amazon.smithy.codegen.core.Symbol; diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/CodeGenerationContext.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/CodeGenerationContext.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/CodeGenerationContext.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/CodeGenerationContext.java diff --git a/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/CodegenMode.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/CodegenMode.java new file mode 100644 index 000000000..6b6904865 --- /dev/null +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/CodegenMode.java @@ -0,0 +1,18 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.java.codegen; + +import software.amazon.smithy.utils.SmithyUnstableApi; + +/** + * Specifies which code generation mode(s) to use. + */ +@SmithyUnstableApi +public enum CodegenMode { + CLIENT, + SERVER, + TYPES +} diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/CodegenUtils.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/CodegenUtils.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/CodegenUtils.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/CodegenUtils.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/DefaultTransforms.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/DefaultTransforms.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/DefaultTransforms.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/DefaultTransforms.java diff --git a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/DirectedJavaServerCodegen.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/DirectedJavaCodegen.java similarity index 54% rename from codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/DirectedJavaServerCodegen.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/DirectedJavaCodegen.java index 2097cb260..d5b25b208 100644 --- a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/DirectedJavaServerCodegen.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/DirectedJavaCodegen.java @@ -3,8 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.java.codegen.server; +package software.amazon.smithy.java.codegen; +import java.util.Set; import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.codegen.core.directed.CreateContextDirective; import software.amazon.smithy.codegen.core.directed.CreateSymbolProviderDirective; @@ -20,9 +21,10 @@ import software.amazon.smithy.codegen.core.directed.GenerateServiceDirective; import software.amazon.smithy.codegen.core.directed.GenerateStructureDirective; import software.amazon.smithy.codegen.core.directed.GenerateUnionDirective; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; +import software.amazon.smithy.java.codegen.client.generators.BddFileGenerator; +import software.amazon.smithy.java.codegen.client.generators.ClientImplementationGenerator; +import software.amazon.smithy.java.codegen.client.generators.ClientInterfaceGenerator; +import software.amazon.smithy.java.codegen.client.waiters.WaiterContainerGenerator; import software.amazon.smithy.java.codegen.generators.ApiServiceGenerator; import software.amazon.smithy.java.codegen.generators.EnumGenerator; import software.amazon.smithy.java.codegen.generators.ListGenerator; @@ -37,110 +39,153 @@ import software.amazon.smithy.java.codegen.generators.UnionGenerator; import software.amazon.smithy.java.codegen.server.generators.OperationInterfaceGenerator; import software.amazon.smithy.java.codegen.server.generators.ServiceGenerator; +import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.utils.SmithyUnstableApi; -final class DirectedJavaServerCodegen +/** + * Unified directed codegen for all modes (client, server, types). + */ +@SmithyUnstableApi +final class DirectedJavaCodegen implements DirectedCodegen { + private final Set modes; + + DirectedJavaCodegen(Set modes) { + this.modes = modes; + } + @Override public SymbolProvider createSymbolProvider( CreateSymbolProviderDirective directive ) { - return new ServiceJavaSymbolProvider( + return new JavaSymbolProvider( directive.model(), directive.service(), directive.settings().packageNamespace(), - directive.settings().name()); + directive.settings().name(), + modes); } @Override public CodeGenerationContext createContext( CreateContextDirective directive ) { - return new CodeGenerationContext( - directive, - "server"); + String pluginName = getPluginName(); + return new CodeGenerationContext(directive, pluginName); + } + + private String getPluginName() { + if (modes.contains(CodegenMode.CLIENT) && modes.contains(CodegenMode.SERVER)) { + return "client+server"; + } else if (modes.contains(CodegenMode.CLIENT)) { + return "client"; + } else if (modes.contains(CodegenMode.SERVER)) { + return "server"; + } else { + return "type"; + } } @Override public void generateStructure(GenerateStructureDirective directive) { - if (!directive.settings().useExternalTypes()) { + if (!isSynthetic(directive.shape())) { new StructureGenerator<>().accept(directive); } } @Override public void generateError(GenerateErrorDirective directive) { - if (!directive.settings().useExternalTypes()) { - new StructureGenerator<>().accept(directive); - } + new StructureGenerator<>().accept(directive); } @Override public void generateUnion(GenerateUnionDirective directive) { - if (!directive.settings().useExternalTypes()) { - new UnionGenerator().accept(directive); - } + new UnionGenerator().accept(directive); } @Override public void generateList(GenerateListDirective directive) { - if (!directive.settings().useExternalTypes()) { - new ListGenerator().accept(directive); - } + new ListGenerator().accept(directive); } @Override public void generateMap(GenerateMapDirective directive) { - if (!directive.settings().useExternalTypes()) { - new MapGenerator().accept(directive); - } + new MapGenerator().accept(directive); } @Override public void generateEnumShape(GenerateEnumDirective directive) { - if (!directive.settings().useExternalTypes()) { - new EnumGenerator<>().accept(directive); - } + new EnumGenerator<>().accept(directive); } @Override public void generateIntEnumShape(GenerateIntEnumDirective directive) { - if (!directive.settings().useExternalTypes()) { - new EnumGenerator<>().accept(directive); + new EnumGenerator<>().accept(directive); + } + + @Override + public void generateOperation(GenerateOperationDirective directive) { + if (isSynthetic(directive.shape())) { + return; + } + if (modes.contains(CodegenMode.SERVER)) { + new OperationInterfaceGenerator().accept(directive); } + new OperationGenerator().accept(directive); } @Override public void generateService(GenerateServiceDirective directive) { - new ServiceGenerator().accept(directive); + // In TYPES-only mode, generateService is a no-op (the synthetic service has no real service shape) + if (modes.contains(CodegenMode.TYPES) && !modes.contains(CodegenMode.CLIENT) + && !modes.contains(CodegenMode.SERVER)) { + return; + } - if (!directive.context().settings().useExternalTypes()) { - new ApiServiceGenerator().accept(directive); - new ServiceExceptionGenerator<>().accept(directive); + if (modes.contains(CodegenMode.CLIENT)) { + new ClientInterfaceGenerator().accept(directive); + new ClientImplementationGenerator().accept(directive); } - } - @Override - public void generateOperation(GenerateOperationDirective directive) { - new OperationInterfaceGenerator().accept(directive); - if (!directive.settings().useExternalTypes()) { - new OperationGenerator().accept(directive); + if (modes.contains(CodegenMode.SERVER)) { + new ServiceGenerator().accept(directive); + } + + new ApiServiceGenerator().accept(directive); + new ServiceExceptionGenerator<>().accept(directive); + + if (modes.contains(CodegenMode.CLIENT)) { + var service = directive.service(); + if (service.hasTrait(ShapeId.from("smithy.rules#endpointBdd")) + || service.hasTrait(ShapeId.from("smithy.rules#endpointRuleSet"))) { + new BddFileGenerator().accept(directive); + } } } @Override public void generateResource(GenerateResourceDirective directive) { - if (!directive.settings().useExternalTypes()) { - new ResourceGenerator().accept(directive); - } + new ResourceGenerator().accept(directive); } @Override public void customizeBeforeIntegrations(CustomizeDirective directive) { - if (!directive.settings().useExternalTypes()) { - new SharedSerdeGenerator().accept(directive); - new SchemasGenerator().accept(directive); - new SchemaIndexGenerator().accept(directive); + new SchemasGenerator().accept(directive); + new SharedSerdeGenerator().accept(directive); + new SchemaIndexGenerator().accept(directive); + } + + @Override + public void customizeAfterIntegrations(CustomizeDirective directive) { + if (modes.contains(CodegenMode.CLIENT) + && !directive.model().getShapesWithTrait(ShapeId.from("smithy.waiters#waitable")).isEmpty()) { + new WaiterContainerGenerator().accept(directive.context()); } } + + private static boolean isSynthetic(Shape shape) { + return shape.getId().getNamespace().equals(SyntheticServiceTransform.SYNTHETIC_NAMESPACE); + } } diff --git a/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ExternalSymbols.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ExternalSymbols.java new file mode 100644 index 000000000..58f80a7e3 --- /dev/null +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ExternalSymbols.java @@ -0,0 +1,26 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.java.codegen; + +import software.amazon.smithy.codegen.core.Symbol; + +/** + * Pre-built Symbol objects for types from modules that are NOT on the compile classpath + * of codegen-plugin (e.g., framework-errors generated types). + */ +public final class ExternalSymbols { + private ExternalSymbols() {} + + /** + * Symbol for {@code software.amazon.smithy.java.framework.model.UnknownOperationException}. + * This class lives in the framework-errors module which is NOT on the compile classpath. + */ + public static final Symbol UNKNOWN_OPERATION_EXCEPTION = Symbol.builder() + .name("UnknownOperationException") + .namespace("software.amazon.smithy.java.framework.model", ".") + .putProperty(SymbolProperties.IS_PRIMITIVE, false) + .build(); +} diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenIntegration.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenIntegration.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenIntegration.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenIntegration.java diff --git a/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenPlugin.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenPlugin.java new file mode 100644 index 000000000..541cf7cb2 --- /dev/null +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenPlugin.java @@ -0,0 +1,235 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.java.codegen; + +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; +import java.util.stream.Collectors; +import software.amazon.smithy.build.PluginContext; +import software.amazon.smithy.build.SmithyBuildPlugin; +import software.amazon.smithy.codegen.core.CodegenException; +import software.amazon.smithy.codegen.core.directed.CodegenDirector; +import software.amazon.smithy.framework.knowledge.ImplicitErrorIndex; +import software.amazon.smithy.framework.transform.AddFrameworkErrorsTransform; +import software.amazon.smithy.java.codegen.generators.SyntheticTrait; +import software.amazon.smithy.java.codegen.writer.JavaWriter; +import software.amazon.smithy.java.logging.InternalLogger; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.loader.Prelude; +import software.amazon.smithy.model.neighbor.Walker; +import software.amazon.smithy.model.node.ObjectNode; +import software.amazon.smithy.model.selector.Selector; +import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.traits.MixinTrait; +import software.amazon.smithy.model.traits.TraitDefinition; +import software.amazon.smithy.model.transform.ModelTransformer; +import software.amazon.smithy.utils.SmithyInternalApi; + +/** + * Unified plugin for Java code generation. Supports modes: client, server, types. + * + *

Configure via {@code smithy-build.json}: + *

{@code
+ * {
+ *   "plugins": {
+ *     "java-codegen": {
+ *       "service": "com.example#MyService",
+ *       "namespace": "com.example",
+ *       "modes": ["client", "server"]
+ *     }
+ *   }
+ * }
+ * }
+ */ +@SmithyInternalApi +public final class JavaCodegenPlugin implements SmithyBuildPlugin { + private static final InternalLogger LOGGER = InternalLogger.getLogger(JavaCodegenPlugin.class); + + @Override + public String getName() { + return "java-codegen"; + } + + @Override + public void execute(PluginContext context) { + var settingsNode = context.getSettings(); + var modes = parseModes(settingsNode); + LOGGER.info("Running java-codegen with modes: {}", modes); + + if (modes.contains(CodegenMode.TYPES) + && !modes.contains(CodegenMode.CLIENT) + && !modes.contains(CodegenMode.SERVER)) { + executeTypesMode(context, settingsNode, modes); + } else { + executeServiceMode(context, settingsNode, modes); + } + } + + private void executeServiceMode(PluginContext context, ObjectNode settingsNode, Set modes) { + CodegenDirector runner = + new CodegenDirector<>(); + + var settings = JavaCodegenSettings.fromNode(settingsNode); + runner.settings(settings); + runner.directedCodegen(new DirectedJavaCodegen(modes)); + runner.fileManifest(context.getFileManifest()); + runner.service(settings.service()); + // TODO: use built-in once this has been upstreamed + var model = AddFrameworkErrorsTransform.transform(ModelTransformer.create(), context.getModel()); + if (modes.contains(CodegenMode.TYPES)) { + model = expandServiceClosureForTypes(model, settings.service()); + } + validateDependencies(modes, model, settings); + runner.model(model); + runner.integrationClass(JavaCodegenIntegration.class); + DefaultTransforms.apply(runner, settings); + runner.run(); + LOGGER.info("Smithy-Java code generation complete (modes: {})", modes); + } + + private void executeTypesMode(PluginContext context, ObjectNode settingsNode, Set modes) { + LOGGER.info("Generating Java types from smithy model."); + CodegenDirector runner = + new CodegenDirector<>(); + + var settings = TypeCodegenSettings.fromNode(settingsNode); + var codegenSettings = settings.codegenSettings(); + runner.settings(codegenSettings); + runner.directedCodegen(new DirectedJavaCodegen(modes)); + runner.fileManifest(context.getFileManifest()); + runner.service(codegenSettings.service()); + + // Compute closure and create synthetic service + var closure = getClosure(context.getModel(), settings); + LOGGER.info("Found {} shapes in generation closure", closure.size()); + var model = SyntheticServiceTransform.transform(context.getModel(), closure, settings.renames()); + runner.model(model); + runner.integrationClass(JavaCodegenIntegration.class); + DefaultTransforms.apply(runner, codegenSettings); + runner.run(); + LOGGER.info("Successfully generated Java class files."); + } + + /** + * Expands the service closure to include all model types not already reachable from the service. + * This is used when TYPES mode is combined with CLIENT or SERVER mode, so that standalone types + * outside the service closure are also generated. + */ + private static Model expandServiceClosureForTypes(Model model, ShapeId serviceId) { + var service = model.expectShape(serviceId, ServiceShape.class); + var walker = new Walker(model); + var serviceClosure = walker.walkShapes(service); + var implicitErrorIndex = ImplicitErrorIndex.of(model); + + // Default types selector: all structures, unions, enums, and intEnums + var selector = Selector.parse(":is(structure, union, enum, intEnum)"); + var allTypes = selector.shapes(model) + .filter(s -> !s.isMemberShape()) + .filter(s -> !Prelude.isPreludeShape(s)) + .filter(s -> !s.hasTrait(MixinTrait.class)) + .filter(s -> !s.hasTrait(TraitDefinition.class)) + .filter(s -> !s.hasTrait(SyntheticTrait.class)) + .filter(s -> !implicitErrorIndex.isImplicitError(s.getId())) + .filter(s -> !serviceClosure.contains(s)) + .collect(Collectors.toSet()); + + if (allTypes.isEmpty()) { + return model; + } + + LOGGER.info("Expanding service closure with {} additional type shapes for TYPES mode", allTypes.size()); + return SyntheticServiceTransform.expandServiceClosure(model, serviceId, allTypes); + } + + private static Set parseModes(ObjectNode settingsNode) { + var modesNode = settingsNode.getArrayMember("modes"); + if (modesNode.isEmpty()) { + throw new CodegenException("java-codegen plugin requires a 'modes' property. " + + "Valid modes: client, server, types"); + } + var modes = modesNode.get() + .getElements() + .stream() + .map(n -> { + var value = n.expectStringNode().getValue().toUpperCase(Locale.ENGLISH); + try { + return CodegenMode.valueOf(value); + } catch (IllegalArgumentException e) { + throw new CodegenException( + "Invalid codegen mode: '" + n.expectStringNode().getValue() + + "'. Valid modes: client, server, types"); + } + }) + .collect(Collectors.toCollection(() -> java.util.EnumSet.noneOf(CodegenMode.class))); + if (modes.isEmpty()) { + throw new CodegenException("java-codegen plugin requires at least one mode. " + + "Valid modes: client, server, types"); + } + return modes; + } + + private static void validateDependencies(Set modes, Model model, JavaCodegenSettings settings) { + if (modes.contains(CodegenMode.CLIENT)) { + requireDependency( + "software.amazon.smithy.java.client.core.Client", + "client-api", + "client"); + var service = model.expectShape(settings.service(), ServiceShape.class); + if (service.hasTrait(ShapeId.from("smithy.rules#endpointBdd")) + || service.hasTrait(ShapeId.from("smithy.rules#endpointRuleSet"))) { + requireDependency( + "software.amazon.smithy.java.client.rulesengine.RulesEngineBuilder", + "client-rulesengine", + "client (with endpoint rules)"); + } + if (!model.getShapesWithTrait(ShapeId.from("smithy.waiters#waitable")).isEmpty()) { + requireDependency( + "software.amazon.smithy.java.client.waiters.Waiter", + "client-waiters", + "client (with waiters)"); + } + } + if (modes.contains(CodegenMode.SERVER)) { + requireDependency( + "software.amazon.smithy.java.server.Service", + "server-api", + "server"); + } + } + + private static void requireDependency(String className, String moduleName, String modeDescription) { + try { + Class.forName(className); + } catch (ClassNotFoundException e) { + throw new CodegenException( + "Codegen mode '" + modeDescription + "' requires the '" + moduleName + "' dependency. " + + "Add 'software.amazon.smithy.java:" + moduleName + "' to your smithyBuild dependencies."); + } + } + + private static Set getClosure(Model model, TypeCodegenSettings settings) { + Set closure = new HashSet<>(); + settings.shapes() + .stream() + .map(model::expectShape) + .forEach(closure::add); + settings.selector() + .shapes(model) + .filter(s -> !s.isMemberShape()) + .filter(s -> !Prelude.isPreludeShape(s)) + .forEach(closure::add); + + if (closure.isEmpty()) { + throw new CodegenException("Could not generate types. No shapes found in closure"); + } + LOGGER.info("Found {} shapes in generation closure.", closure.size()); + + return closure; + } +} diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenSettings.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenSettings.java similarity index 98% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenSettings.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenSettings.java index 949c71da3..eaa580ac3 100644 --- a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenSettings.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaCodegenSettings.java @@ -49,6 +49,7 @@ public final class JavaCodegenSettings { private static final String USE_EXTERNAL_TYPES = "useExternalTypes"; private static final String RUNTIME_TRAITS = "runtimeTraits"; private static final String RUNTIME_TRAITS_SELECTOR = "runtimeTraitsSelector"; + private static final String MODES = "modes"; private static final List PROPERTIES = List.of( SERVICE, NAME, @@ -64,7 +65,8 @@ public final class JavaCodegenSettings { EDITION, USE_EXTERNAL_TYPES, RUNTIME_TRAITS, - RUNTIME_TRAITS_SELECTOR); + RUNTIME_TRAITS_SELECTOR, + MODES); private final ShapeId service; private final String name; @@ -234,7 +236,7 @@ private static String getHeader(String headerFile, String sourceLocation) { if (!file.exists()) { throw new CodegenException("Header file " + file.getAbsolutePath() + " does not exist."); } - LOGGER.trace("Reading header file: {}" + file.getAbsolutePath()); + LOGGER.trace("Reading header file: {}", file.getAbsolutePath()); return IoUtils.readUtf8File(file.getAbsolutePath()); } diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaSymbolProvider.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaSymbolProvider.java similarity index 61% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaSymbolProvider.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaSymbolProvider.java index c78b4d7f0..bd7f18abc 100644 --- a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/JavaSymbolProvider.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/JavaSymbolProvider.java @@ -12,12 +12,16 @@ import java.nio.ByteBuffer; import java.time.Instant; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import software.amazon.smithy.codegen.core.CodegenException; import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.codegen.core.SymbolProvider; +import software.amazon.smithy.codegen.core.SymbolReference; +import software.amazon.smithy.java.core.schema.SchemaIndex; import software.amazon.smithy.java.core.schema.Unit; import software.amazon.smithy.java.core.serde.document.Document; import software.amazon.smithy.java.core.serde.event.EventStream; @@ -43,6 +47,7 @@ import software.amazon.smithy.model.shapes.ResourceShape; import software.amazon.smithy.model.shapes.ServiceShape; import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.ShapeVisitor; import software.amazon.smithy.model.shapes.ShortShape; import software.amazon.smithy.model.shapes.StringShape; @@ -52,10 +57,13 @@ import software.amazon.smithy.model.traits.StreamingTrait; import software.amazon.smithy.model.traits.UnitTypeTrait; import software.amazon.smithy.utils.CaseUtils; +import software.amazon.smithy.utils.SmithyInternalApi; +import software.amazon.smithy.utils.StringUtils; /** - * Maps Smithy types to Java Symbols + * Maps Smithy types to Java Symbols, with mode-aware symbol generation for services and operations. */ +@SmithyInternalApi public class JavaSymbolProvider implements ShapeVisitor, SymbolProvider { private static final InternalLogger LOGGER = InternalLogger.getLogger(JavaSymbolProvider.class); @@ -64,15 +72,64 @@ public class JavaSymbolProvider implements ShapeVisitor, SymbolProvider private final Model model; private final ServiceShape service; private final String packageNamespace; - - public JavaSymbolProvider(Model model, ServiceShape service, String packageNamespace) { + private final String serviceName; + private final Set modes; + private final Map externalTypes; + + public JavaSymbolProvider( + Model model, + ServiceShape service, + String packageNamespace, + String serviceName, + Set modes + ) { this.model = model; this.service = service; this.packageNamespace = packageNamespace; + this.serviceName = serviceName; + this.modes = modes; + this.externalTypes = buildExternalTypes(); + } + + private static Map buildExternalTypes() { + Map mappings = new HashMap<>(); + SchemaIndex.getCombinedSchemaIndex().visit(schema -> { + if (schema.shapeClass() != null) { + mappings.put(schema.id(), + CodegenUtils.fromClass(schema.shapeClass()) + .toBuilder() + .putProperty(SymbolProperties.EXTERNAL_TYPE, true) + .build()); + } + }); + return Map.copyOf(mappings); } @Override public Symbol toSymbol(Shape shape) { + // Direct match (structure, union, enum, etc.) + var ext = externalTypes.get(shape.toShapeId()); + if (ext != null) { + return ext; + } + return switch (shape) { + case MemberShape ms when externalTypes.containsKey(ms.getTarget()) -> + externalTypes.get(ms.getTarget()); + case ListShape ls when externalTypes.containsKey(ls.getMember().getTarget()) -> + resolveSymbol(shape).toBuilder() + .references(List.of(new SymbolReference(externalTypes.get(ls.getMember().getTarget())))) + .build(); + case MapShape ms when externalTypes.containsKey(ms.getValue().getTarget()) -> + resolveSymbol(shape).toBuilder() + .references(List.of( + new SymbolReference(resolveSymbol(ms.getKey())), + new SymbolReference(externalTypes.get(ms.getValue().getTarget())))) + .build(); + default -> resolveSymbol(shape); + }; + } + + private Symbol resolveSymbol(Shape shape) { Symbol symbol = shape.accept(this); LOGGER.trace("Creating symbol from {}: {}", shape, symbol); return symbol; @@ -232,7 +289,34 @@ public Symbol memberShape(MemberShape memberShape) { @Override public Symbol operationShape(OperationShape operationShape) { - return getJavaClassSymbol(operationShape); + var baseSymbol = getJavaClassSymbol(operationShape); + if (modes.contains(CodegenMode.SERVER)) { + String stubName = baseSymbol.getName() + "Operation"; + String asyncStubName = stubName + "Async"; + String operationFieldName = StringUtils.uncapitalize(baseSymbol.getName()); + var stubSymbol = Symbol.builder() + .name(stubName) + .putProperty(SymbolProperties.IS_PRIMITIVE, false) + .namespace(format("%s.service", packageNamespace), ".") + .declarationFile( + format("./%s/service/%s.java", packageNamespace.replace(".", "/"), stubName)) + .build(); + var asyncStubSymbol = Symbol.builder() + .name(asyncStubName) + .putProperty(SymbolProperties.IS_PRIMITIVE, false) + .namespace(format("%s.service", packageNamespace), ".") + .declarationFile( + format("./%s/service/%s.java", packageNamespace.replace(".", "/"), asyncStubName)) + .build(); + return baseSymbol.toBuilder() + .putProperty(SymbolProperties.IS_PRIMITIVE, false) + .putProperty(ServerSymbolProperties.OPERATION_FIELD_NAME, operationFieldName) + .putProperty(ServerSymbolProperties.ASYNC_STUB_OPERATION, asyncStubSymbol) + .putProperty(ServerSymbolProperties.STUB_OPERATION, stubSymbol) + .putProperty(ServerSymbolProperties.API_OPERATION, baseSymbol) + .build(); + } + return baseSymbol; } @Override @@ -240,13 +324,23 @@ public Symbol resourceShape(ResourceShape resourceShape) { return getJavaClassSymbol(resourceShape); } - /** - * @implNote Code generators that need to create service shapes should extend the {@link JavaSymbolProvider} class - * and override this method. - */ @Override public Symbol serviceShape(ServiceShape serviceShape) { - // Service shape not supported by default java symbol provider. + if (modes.contains(CodegenMode.CLIENT)) { + var clientSymbol = getClientServiceSymbol(); + if (modes.contains(CodegenMode.SERVER)) { + // Combined mode: attach server symbol as a property + var serverSymbol = getServerServiceSymbol(); + return clientSymbol.toBuilder() + .putProperty(ServerSymbolProperties.SERVER_SERVICE_SYMBOL, serverSymbol) + .build(); + } + return clientSymbol; + } + if (modes.contains(CodegenMode.SERVER)) { + return getServerServiceSymbol(); + } + // TYPES mode: no service symbol return null; } @@ -289,4 +383,43 @@ private Symbol getJavaClassSymbol(Shape shape) { .declarationFile(format("./%s/model/%s.java", packageNamespace.replace(".", "/"), name)) .build(); } + + private Symbol getClientServiceSymbol() { + var name = serviceName + "Client"; + var symbol = Symbol.builder() + .name(name) + .putProperty(SymbolProperties.IS_PRIMITIVE, false) + .putProperty(SymbolProperties.SERVICE_EXCEPTION, + CodegenUtils.getServiceExceptionSymbol(packageNamespace, serviceName)) + .putProperty(SymbolProperties.SERVICE_API_SERVICE, + CodegenUtils.getServiceApiSymbol(packageNamespace, serviceName)) + .namespace(format("%s.client", packageNamespace), ".") + .definitionFile(format("./%s/client/%s.java", packageNamespace.replace(".", "/"), name)) + .build(); + + return symbol.toBuilder() + .putProperty( + ClientSymbolProperties.CLIENT_IMPL, + symbol.toBuilder() + .name(name + "Impl") + .definitionFile( + format("./%s/client/%sImpl.java", packageNamespace.replace(".", "/"), name)) + .build()) + .build(); + } + + private Symbol getServerServiceSymbol() { + return Symbol.builder() + .name(serviceName) + .putProperty(SymbolProperties.IS_PRIMITIVE, false) + .putProperty(SymbolProperties.SERVICE_EXCEPTION, + CodegenUtils.getServiceExceptionSymbol(packageNamespace, serviceName)) + .putProperty(SymbolProperties.SERVICE_API_SERVICE, + CodegenUtils.getServiceApiSymbol(packageNamespace, serviceName)) + .putProperty(ServerSymbolProperties.TYPES_NAMESPACE, format("%s.model", packageNamespace)) + .namespace(format("%s.service", packageNamespace), ".") + .declarationFile( + format("./%s/service/%s.java", packageNamespace.replace(".", "/"), serviceName)) + .build(); + } } diff --git a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/ServerSymbolProperties.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ServerSymbolProperties.java similarity index 75% rename from codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/ServerSymbolProperties.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ServerSymbolProperties.java index fa05a05d3..47979994d 100644 --- a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/ServerSymbolProperties.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/ServerSymbolProperties.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.java.codegen.server; +package software.amazon.smithy.java.codegen; import software.amazon.smithy.codegen.core.Property; import software.amazon.smithy.codegen.core.Symbol; @@ -41,4 +41,12 @@ private ServerSymbolProperties() {} * Namespace under which types of this service would be generated. */ public static final Property TYPES_NAMESPACE = Property.named("types-namespace"); + + /** + * Symbol for the server service class, used in combined client+server mode. + * + *

When both CLIENT and SERVER modes are active, the symbol provider returns a client service symbol. + * This property holds the server service symbol so that the ServiceGenerator can retrieve it. + */ + public static final Property SERVER_SERVICE_SYMBOL = Property.named("server-service-symbol"); } diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/SmithyJavaCodegenEdition.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/SmithyJavaCodegenEdition.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/SmithyJavaCodegenEdition.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/SmithyJavaCodegenEdition.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/SymbolProperties.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/SymbolProperties.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/SymbolProperties.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/SymbolProperties.java diff --git a/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/SyntheticServiceTransform.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/SyntheticServiceTransform.java new file mode 100644 index 000000000..0aca09faf --- /dev/null +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/SyntheticServiceTransform.java @@ -0,0 +1,146 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.java.codegen; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import software.amazon.smithy.java.codegen.generators.SyntheticTrait; +import software.amazon.smithy.java.logging.InternalLogger; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.shapes.OperationShape; +import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.StructureShape; +import software.amazon.smithy.model.traits.ErrorTrait; +import software.amazon.smithy.model.traits.PrivateTrait; +import software.amazon.smithy.model.transform.ModelTransformer; + +/** + * Generates a synthetic service for a set of shapes. + * + *

Adds a set of shapes to the closure of a synthetic service shape. Operation shapes are added directly + * to the service shape while all other shapes are added via a single synthetic operation with a synthetic input + * that references each type as a member. + * + *

Directed codegen requires a root service shape to use for generating types. This service shape also + * provides renames for a set of shapes as well as the list of protocols the shapes should support. This + * transform creates a synthetic service that Directed codegen can use to generate the provided set of shapes. + */ +public final class SyntheticServiceTransform { + private static final InternalLogger LOGGER = InternalLogger.getLogger(SyntheticServiceTransform.class); + public static final String SYNTHETIC_NAMESPACE = "smithy.synthetic"; + static final ShapeId SYNTHETIC_SERVICE_ID = ShapeId.fromParts(SYNTHETIC_NAMESPACE, "TypesGenService"); + + /** + * Types-only mode: creates a new synthetic service wrapping closure shapes. + */ + static Model transform(Model model, Set closure, Map renames) { + + ServiceShape.Builder serviceBuilder = ServiceShape.builder() + .id(SYNTHETIC_SERVICE_ID) + .addTrait(new SyntheticTrait()); + serviceBuilder.rename(renames); + + List typesToWrap = new ArrayList<>(); + List errorShapes = new ArrayList<>(); + + for (Shape shape : closure) { + switch (shape.getType()) { + case SERVICE, RESOURCE -> LOGGER.debug( + "Skipping service-associated shape {} for type codegen...", + shape); + case OPERATION -> serviceBuilder.addOperation(shape.asOperationShape().orElseThrow()); + case STRUCTURE, ENUM, INT_ENUM, UNION -> { + typesToWrap.add(shape); + if (shape.hasTrait(ErrorTrait.class)) { + errorShapes.add(shape); + } + } + default -> { + // All other shapes are skipped with no logging as they should be + // implicitly added by aggregate shapes. + } + } + } + + Set shapesToAdd = new HashSet<>(); + if (!typesToWrap.isEmpty()) { + var syntheticShapes = createSyntheticShapes(typesToWrap, errorShapes); + shapesToAdd.addAll(syntheticShapes); + // Find the operation shape to add to the service + for (Shape s : syntheticShapes) { + if (s instanceof OperationShape op) { + serviceBuilder.addOperation(op); + } + } + } + + shapesToAdd.add(serviceBuilder.build()); + return ModelTransformer.create().replaceShapes(model, shapesToAdd); + } + + /** + * Combined mode: adds a synthetic operation to an existing service to include additional shapes + * in its closure. + */ + static Model expandServiceClosure(Model model, ShapeId serviceId, Set additionalShapes) { + if (additionalShapes.isEmpty()) { + return model; + } + + List errorShapes = new ArrayList<>(); + for (Shape shape : additionalShapes) { + if (shape.hasTrait(ErrorTrait.class)) { + errorShapes.add(shape); + } + } + + var syntheticShapes = createSyntheticShapes(new ArrayList<>(additionalShapes), errorShapes); + + var service = model.expectShape(serviceId, ServiceShape.class); + var serviceBuilder = service.toBuilder(); + Set shapesToAdd = new HashSet<>(syntheticShapes); + for (Shape s : syntheticShapes) { + if (s instanceof OperationShape op) { + serviceBuilder.addOperation(op); + } + } + shapesToAdd.add(serviceBuilder.build()); + + return ModelTransformer.create().replaceShapes(model, shapesToAdd); + } + + private static Set createSyntheticShapes(List typesToWrap, List errorShapes) { + var inputBuilder = StructureShape.builder() + .id(ShapeId.fromParts(SYNTHETIC_NAMESPACE, "TypesOperationInput")) + .addTrait(new SyntheticTrait()); + for (int i = 0; i < typesToWrap.size(); i++) { + inputBuilder.addMember("m" + i, typesToWrap.get(i).getId()); + } + var syntheticInput = inputBuilder.build(); + + var syntheticOutput = StructureShape.builder() + .id(ShapeId.fromParts(SYNTHETIC_NAMESPACE, "TypesOperationOutput")) + .addTrait(new SyntheticTrait()) + .build(); + + var opBuilder = OperationShape.builder() + .id(ShapeId.fromParts(SYNTHETIC_NAMESPACE, "TypesOperation")) + .addTrait(new SyntheticTrait()) + .addTrait(new PrivateTrait()) + .input(syntheticInput) + .output(syntheticOutput); + for (Shape error : errorShapes) { + opBuilder.addError(error.toShapeId()); + } + + return Set.of(syntheticInput, syntheticOutput, opBuilder.build()); + } +} diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/TraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/TraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/TraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/TraitInitializer.java diff --git a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/TypeCodegenSettings.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/TypeCodegenSettings.java similarity index 96% rename from codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/TypeCodegenSettings.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/TypeCodegenSettings.java index 3bb205506..f85a3069d 100644 --- a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/TypeCodegenSettings.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/TypeCodegenSettings.java @@ -3,20 +3,19 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.java.codegen.types; +package software.amazon.smithy.java.codegen; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.node.ObjectNode; import software.amazon.smithy.model.selector.Selector; import software.amazon.smithy.model.shapes.ShapeId; -final class TypeCodegenSettings { +public final class TypeCodegenSettings { private static final String SHAPES = "shapes"; private static final String SELECTOR = "selector"; private static final String RENAMES = "renames"; diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/BddFileGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/BddFileGenerator.java similarity index 100% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/BddFileGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/BddFileGenerator.java diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientImplementationGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientImplementationGenerator.java similarity index 82% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientImplementationGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientImplementationGenerator.java index 187c12d10..15f8940d0 100644 --- a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientImplementationGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientImplementationGenerator.java @@ -16,11 +16,13 @@ import software.amazon.smithy.framework.knowledge.ImplicitErrorIndex; import software.amazon.smithy.java.client.core.Client; import software.amazon.smithy.java.client.core.RequestOverrideConfig; +import software.amazon.smithy.java.codegen.ClientSymbolProperties; import software.amazon.smithy.java.codegen.CodeGenerationContext; import software.amazon.smithy.java.codegen.CodegenUtils; import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.client.ClientSymbolProperties; +import software.amazon.smithy.java.codegen.SyntheticServiceTransform; import software.amazon.smithy.java.codegen.client.sections.ClientImplAdditionalMethodsSection; +import software.amazon.smithy.java.codegen.client.waiters.WaiterCodegenUtils; import software.amazon.smithy.java.codegen.generators.TypeRegistryGenerator; import software.amazon.smithy.java.codegen.sections.ApplyDocumentation; import software.amazon.smithy.java.codegen.sections.ClassSection; @@ -30,6 +32,7 @@ import software.amazon.smithy.model.knowledge.OperationIndex; import software.amazon.smithy.model.knowledge.TopDownIndex; import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.utils.SmithyInternalApi; import software.amazon.smithy.utils.StringUtils; @@ -37,6 +40,8 @@ public final class ClientImplementationGenerator implements Consumer> { + private static final ShapeId WAITABLE_TRAIT = ShapeId.from("smithy.waiters#waitable"); + @Override public void accept(GenerateServiceDirective directive) { writeForSymbol(directive.symbol(), directive); @@ -85,7 +90,8 @@ final class ${impl:T} extends ${client:T} implements ${interface:T} {${?implicit writer, directive.shape(), directive.symbolProvider(), - directive.model())); + directive.model(), + directive.settings())); writer.write(template); writer.popState(); }); @@ -95,7 +101,8 @@ private record OperationMethodGenerator( JavaWriter writer, ServiceShape service, SymbolProvider symbolProvider, - Model model) implements Runnable { + Model model, + JavaCodegenSettings settings) implements Runnable { @Override public void run() { @@ -114,6 +121,9 @@ public void run() { writer.putContext("overrideConfig", RequestOverrideConfig.class); var opIndex = OperationIndex.of(model); for (var operation : TopDownIndex.of(model).getContainedOperations(service)) { + if (operation.getId().getNamespace().equals(SyntheticServiceTransform.SYNTHETIC_NAMESPACE)) { + continue; + } writer.pushState(); writer.putContext("name", StringUtils.uncapitalize(CodegenUtils.getDefaultName(operation, service))); writer.putContext("operation", symbolProvider.toSymbol(operation)); @@ -122,6 +132,21 @@ public void run() { writer.write(template); writer.popState(); } + + // Generate waiter() implementation for clients with waitable operations + if (!model.getShapesWithTrait(WAITABLE_TRAIT).isEmpty()) { + var clientSymbol = symbolProvider.toSymbol(service); + writer.pushState(); + writer.putContext("container", WaiterCodegenUtils.getWaiterSymbol(clientSymbol, settings)); + writer.write(""" + @Override + public ${container:T} waiter() { + return new ${container:T}(this); + } + """); + writer.popState(); + } + writer.injectSection(new ClientImplAdditionalMethodsSection(service)); writer.popState(); } diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientInterfaceGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientInterfaceGenerator.java similarity index 94% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientInterfaceGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientInterfaceGenerator.java index 52a874120..418f8ec91 100644 --- a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientInterfaceGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/generators/ClientInterfaceGenerator.java @@ -31,12 +31,14 @@ import software.amazon.smithy.java.client.core.pagination.Paginator; import software.amazon.smithy.java.client.rulesengine.RulesEngineBuilder; import software.amazon.smithy.java.client.rulesengine.RulesEngineSettings; +import software.amazon.smithy.java.codegen.ClientSymbolProperties; import software.amazon.smithy.java.codegen.CodeGenerationContext; import software.amazon.smithy.java.codegen.CodegenUtils; import software.amazon.smithy.java.codegen.JavaCodegenSettings; import software.amazon.smithy.java.codegen.SymbolProperties; -import software.amazon.smithy.java.codegen.client.ClientSymbolProperties; +import software.amazon.smithy.java.codegen.SyntheticServiceTransform; import software.amazon.smithy.java.codegen.client.sections.ClientInterfaceAdditionalMethodsSection; +import software.amazon.smithy.java.codegen.client.waiters.WaiterCodegenUtils; import software.amazon.smithy.java.codegen.integrations.core.GenericTraitInitializer; import software.amazon.smithy.java.codegen.sections.ClassSection; import software.amazon.smithy.java.codegen.sections.OperationSection; @@ -59,8 +61,6 @@ import software.amazon.smithy.model.shapes.ToShapeId; import software.amazon.smithy.model.traits.PaginatedTrait; import software.amazon.smithy.model.traits.Trait; -import software.amazon.smithy.rulesengine.traits.EndpointBddTrait; -import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait; import software.amazon.smithy.utils.SmithyInternalApi; import software.amazon.smithy.utils.StringUtils; @@ -70,6 +70,9 @@ public final class ClientInterfaceGenerator implements Consumer> { private static final InternalLogger LOGGER = InternalLogger.getLogger(ClientInterfaceGenerator.class); + private static final ShapeId ENDPOINT_BDD_TRAIT = ShapeId.from("smithy.rules#endpointBdd"); + private static final ShapeId ENDPOINT_RULESET_TRAIT = ShapeId.from("smithy.rules#endpointRuleSet"); + private static final ShapeId WAITABLE_TRAIT = ShapeId.from("smithy.waiters#waitable"); private static final Map> authSchemeFactories = new HashMap<>(); private static final Map> clientTransportFactories = @@ -183,8 +186,8 @@ final class RequestOverrideBuilder extends ${requestOverride:T}.OverrideBuilder< writer.putContext("impl", symbol.expectProperty(ClientSymbolProperties.CLIENT_IMPL)); writer.putContext("hasDefaultTransport", settings.transport() != null); writer.putContext("hasBdd", - directive.service().hasTrait(EndpointBddTrait.ID) - || directive.service().hasTrait(EndpointRuleSetTrait.ID)); + directive.service().hasTrait(ENDPOINT_BDD_TRAIT) + || directive.service().hasTrait(ENDPOINT_RULESET_TRAIT)); writer.putContext("loadBddInfo", new LoadBddInfoGenerator(writer, directive.service().toShapeId().getName())); var hasTransportSettings = settings.transportSettings() != null && !settings.transportSettings() @@ -203,7 +206,8 @@ final class RequestOverrideBuilder extends ${requestOverride:T}.OverrideBuilder< directive.shape(), directive.symbolProvider(), symbol, - directive.model())); + directive.model(), + directive.settings())); var defaultAuth = getAuthFactoryMapping(directive.model(), directive.service()); writer.putContext( "defaultAuth", @@ -315,7 +319,8 @@ private record OperationMethodGenerator( ServiceShape service, SymbolProvider symbolProvider, Symbol symbol, - Model model) implements Runnable { + Model model, + JavaCodegenSettings settings) implements Runnable { @Override public void run() { @@ -346,6 +351,9 @@ public void run() { var opIndex = OperationIndex.of(model); for (var operation : TopDownIndex.of(model).getContainedOperations(service)) { + if (operation.getId().getNamespace().equals(SyntheticServiceTransform.SYNTHETIC_NAMESPACE)) { + continue; + } writer.pushState(); writer.putContext("name", StringUtils.uncapitalize(CodegenUtils.getDefaultName(operation, service))); writer.putContext("input", symbolProvider.toSymbol(opIndex.expectInputShape(operation))); @@ -366,6 +374,23 @@ public void run() { } writer.popState(); } + + // Generate waiter() method for clients with waitable operations + if (!model.getShapesWithTrait(WAITABLE_TRAIT).isEmpty()) { + var clientSymbol = symbolProvider.toSymbol(service); + writer.pushState(); + writer.putContext("container", WaiterCodegenUtils.getWaiterSymbol(clientSymbol, settings)); + writer.write(""" + /** + * Create a new {@link ${container:T}} instance that uses this client for polling. + * + * @return new {@link ${container:T}} instance. + */ + ${container:T} waiter(); + """); + writer.popState(); + } + // Add any additional operations from integrations writer.injectSection(new ClientInterfaceAdditionalMethodsSection(service)); writer.popState(); diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegration.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegration.java similarity index 100% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegration.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegration.java diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ExamplesTraitInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ExamplesTraitInterceptor.java similarity index 100% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ExamplesTraitInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ExamplesTraitInterceptor.java diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientImplAdditionalMethodsSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientImplAdditionalMethodsSection.java similarity index 100% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientImplAdditionalMethodsSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientImplAdditionalMethodsSection.java diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientInterfaceAdditionalMethodsSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientInterfaceAdditionalMethodsSection.java similarity index 100% rename from codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientInterfaceAdditionalMethodsSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/sections/ClientInterfaceAdditionalMethodsSection.java diff --git a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenUtils.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenUtils.java similarity index 90% rename from codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenUtils.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenUtils.java index 4939610aa..a4d6e555d 100644 --- a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenUtils.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenUtils.java @@ -11,14 +11,14 @@ import software.amazon.smithy.java.codegen.JavaCodegenSettings; import software.amazon.smithy.java.codegen.SymbolProperties; -final class WaiterCodegenUtils { +public final class WaiterCodegenUtils { /** * Determine the symbol to use for the Waiter container * @param clientSymbol Symbol for the client this waiter container is being created for. * @param settings Code generation settings * @return Symbol representing waiter container class. */ - static Symbol getWaiterSymbol(Symbol clientSymbol, JavaCodegenSettings settings) { + public static Symbol getWaiterSymbol(Symbol clientSymbol, JavaCodegenSettings settings) { var baseClientName = clientSymbol.getName().substring(0, clientSymbol.getName().lastIndexOf("Client")); var waiterName = baseClientName + "Waiter"; return Symbol.builder() diff --git a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterContainerGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterContainerGenerator.java similarity index 90% rename from codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterContainerGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterContainerGenerator.java index 897c7a090..92df58175 100644 --- a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterContainerGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterContainerGenerator.java @@ -17,9 +17,9 @@ import software.amazon.smithy.java.client.waiters.jmespath.Comparator; import software.amazon.smithy.java.client.waiters.jmespath.JMESPathBiPredicate; import software.amazon.smithy.java.client.waiters.jmespath.JMESPathPredicate; +import software.amazon.smithy.java.codegen.ClientSymbolProperties; import software.amazon.smithy.java.codegen.CodeGenerationContext; import software.amazon.smithy.java.codegen.CodegenUtils; -import software.amazon.smithy.java.codegen.client.ClientSymbolProperties; import software.amazon.smithy.java.codegen.writer.JavaWriter; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.knowledge.OperationIndex; @@ -33,7 +33,7 @@ /** * Generates the waiter container class for a client */ -final class WaiterContainerGenerator implements Consumer { +public final class WaiterContainerGenerator implements Consumer { @Override public void accept(CodeGenerationContext context) { @@ -100,7 +100,7 @@ public void run() { writer.putContext("backoff", BackoffStrategy.class); writer.putContext("deprecated", Deprecated.class); for (var waiterEntry : trait.getWaiters().entrySet()) { - writer.pushState(new WaiterSection(waiterEntry.getValue())); + writer.pushState(); writer.putContext("waiterName", StringUtils.uncapitalize(waiterEntry.getKey())); var waiter = waiterEntry.getValue(); // Min and max delay on trait are always in seconds. Convert to millis and add to context @@ -108,6 +108,19 @@ public void run() { writer.putContext("minDelay", waiter.getMinDelay() * 1000); writer.putContext("isDeprecated", waiter.isDeprecated()); + // Inline waiter documentation + var waiterDoc = waiter.getDocumentation().orElse(null); + if (waiterDoc != null || waiter.isDeprecated()) { + writer.writeWithNoFormatting("/**"); + if (waiterDoc != null) { + writer.writeWithNoFormatting(" * " + waiterDoc); + } + if (waiter.isDeprecated()) { + writer.writeWithNoFormatting(" * @deprecated Waiter is deprecated"); + } + writer.writeWithNoFormatting(" */"); + } + var template = """ ${?isDeprecated}@${deprecated:T} diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ApiServiceGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ApiServiceGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ApiServiceGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ApiServiceGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/BuilderGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/BuilderGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/BuilderGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/BuilderGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/DeserializerGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/DeserializerGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/DeserializerGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/DeserializerGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/EnumGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/EnumGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/EnumGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/EnumGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/GetMemberValueGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/GetMemberValueGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/GetMemberValueGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/GetMemberValueGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/IdStringGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/IdStringGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/IdStringGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/IdStringGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ListGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ListGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ListGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ListGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/MapGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/MapGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/MapGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/MapGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/OperationGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/OperationGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/OperationGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/OperationGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ResourceGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ResourceGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ResourceGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ResourceGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldGenerator.java similarity index 91% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldGenerator.java index 76d50e8db..8794c03e2 100644 --- a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldGenerator.java @@ -134,11 +134,13 @@ public Void enumShape(EnumShape shape) { writer.putContext("name", "$SCHEMA"); writer.putContext("variants", shape.members().stream().map(symbolProvider::toMemberName).toList()); writer.putContext("set", Set.class); - writer.write(""" - ${schemaClass:T} ${name:L} = ${schemaClass:T}.createEnum(${shapeId:T}.from(${id:S}), - ${set:T}.of(${#variants}${value:L}.getValue()${^key.last}, ${/key.last}${/variants})${traits:C} - ); - """); + writer.putContext("shapeTypeClass", symbolProvider.toSymbol(shape)); + writer.write( + """ + ${schemaClass:T} ${name:L} = ${schemaClass:T}.createEnum(${shapeId:T}.from(${id:S}), + ${set:T}.of(${#variants}${value:L}.getValue()${^key.last}, ${/key.last}${/variants}), ${shapeTypeClass:T}.class${traits:C} + ); + """); writer.popState(); return null; } @@ -149,10 +151,11 @@ public Void intEnumShape(IntEnumShape shape) { writer.putContext("name", "$SCHEMA"); writer.putContext("variants", shape.members().stream().map(symbolProvider::toMemberName).toList()); writer.putContext("set", Set.class); + writer.putContext("shapeTypeClass", symbolProvider.toSymbol(shape)); writer.write( """ ${schemaClass:T} ${name:L} = ${schemaClass:T}.createIntEnum(${shapeId:T}.from(${id:S}), - ${set:T}.of(${#variants}${value:L}.getValue()${^key.last}, ${/key.last}${/variants})${traits:C} + ${set:T}.of(${#variants}${value:L}.getValue()${^key.last}, ${/key.last}${/variants}), ${shapeTypeClass:T}.class${traits:C} ); """); writer.popState(); diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldOrder.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldOrder.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldOrder.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaFieldOrder.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaIndexGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaIndexGenerator.java similarity index 81% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaIndexGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaIndexGenerator.java index 763a2303e..b06403923 100644 --- a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaIndexGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemaIndexGenerator.java @@ -12,10 +12,13 @@ import software.amazon.smithy.java.codegen.CodeGenerationContext; import software.amazon.smithy.java.codegen.CodegenUtils; import software.amazon.smithy.java.codegen.JavaCodegenSettings; +import software.amazon.smithy.java.codegen.SymbolProperties; import software.amazon.smithy.java.codegen.writer.JavaWriter; import software.amazon.smithy.java.core.schema.Schema; import software.amazon.smithy.java.core.schema.SchemaIndex; +import software.amazon.smithy.model.loader.Prelude; import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.ShapeType; import software.amazon.smithy.utils.SmithyInternalApi; @SmithyInternalApi @@ -113,6 +116,22 @@ public void run() { writer.popState(); } } + + // Register enum and intEnum schemas (excluded from SchemaFieldOrder partitions) + for (var shape : directive.connectedShapes().values()) { + if ((shape.getType() == ShapeType.ENUM || shape.getType() == ShapeType.INT_ENUM) + && !Prelude.isPreludeShape(shape) + && !shape.hasTrait(SyntheticTrait.class)) { + var symbol = directive.symbolProvider().toSymbol(shape); + if (symbol.getProperty(SymbolProperties.EXTERNAL_TYPE).orElse(false)) { + continue; + } + writer.pushState(); + writer.putContext("enumClass", symbol); + writer.write("SCHEMA_MAP.put(${enumClass:T}.$$SCHEMA.id(), ${enumClass:T}.$$SCHEMA);"); + writer.popState(); + } + } } } } diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemasGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemasGenerator.java similarity index 99% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemasGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemasGenerator.java index 882a8c1b8..91ed19d80 100644 --- a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SchemasGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SchemasGenerator.java @@ -316,6 +316,7 @@ private void generateStructMemberSchemas(Shape shape, String builderMethod) { ${name:L}_BUILDER${?hasMembers} ${C|} ${/hasMembers}.builderSupplier(${schemaTypeClass:T}::builder) + .shapeClass(${schemaTypeClass:T}.class) .build(); """; } else { @@ -324,6 +325,7 @@ private void generateStructMemberSchemas(Shape shape, String builderMethod) { static final ${schemaClass:T} ${name:L} = ${schemaClass:T}.${builderMethod:L}(${shapeId:T}.from(${id:S})${traits:C})${?hasMembers} ${C|} ${/hasMembers}.builderSupplier(${schemaTypeClass:T}::builder) + .shapeClass(${schemaTypeClass:T}.class) .build(); """; } diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SerializerMemberGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SerializerMemberGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SerializerMemberGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SerializerMemberGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ServiceExceptionGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ServiceExceptionGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ServiceExceptionGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ServiceExceptionGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SharedSerdeGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SharedSerdeGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SharedSerdeGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SharedSerdeGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SnippetGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SnippetGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SnippetGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SnippetGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/StructureDeserializerGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/StructureDeserializerGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/StructureDeserializerGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/StructureDeserializerGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/StructureGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/StructureGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/StructureGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/StructureGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/StructureSerializerGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/StructureSerializerGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/StructureSerializerGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/StructureSerializerGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SyntheticTrait.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SyntheticTrait.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SyntheticTrait.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/SyntheticTrait.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ToStringGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ToStringGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/ToStringGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/ToStringGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/TraitInitializerGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/TraitInitializerGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/TraitInitializerGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/TraitInitializerGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/TypeRegistryGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/TypeRegistryGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/TypeRegistryGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/TypeRegistryGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/UnionGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/UnionGenerator.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/UnionGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/generators/UnionGenerator.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/AnnotationTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/AnnotationTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/AnnotationTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/AnnotationTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/CoreIntegration.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/CoreIntegration.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/CoreIntegration.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/CoreIntegration.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/DefaultTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/DefaultTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/DefaultTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/DefaultTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/EndpointTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/EndpointTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/EndpointTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/EndpointTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/GenericTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/GenericTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/GenericTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/GenericTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpApiKeyAuthTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpApiKeyAuthTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpApiKeyAuthTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpApiKeyAuthTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpErrorTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpErrorTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpErrorTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpErrorTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/HttpTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/LengthTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/LengthTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/LengthTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/LengthTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/NodeWriter.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/NodeWriter.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/NodeWriter.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/NodeWriter.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/PaginatedTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/PaginatedTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/PaginatedTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/PaginatedTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RangeTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RangeTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RangeTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RangeTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RequestCompressionTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RequestCompressionTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RequestCompressionTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RequestCompressionTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RetryableTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RetryableTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RetryableTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/RetryableTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringListTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringListTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringListTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringListTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/StringTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/XmlNamespaceTraitInitializer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/XmlNamespaceTraitInitializer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/core/XmlNamespaceTraitInitializer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/core/XmlNamespaceTraitInitializer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/BuilderSetterDocumentationInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/BuilderSetterDocumentationInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/BuilderSetterDocumentationInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/BuilderSetterDocumentationInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DeprecatedTraitInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DeprecatedTraitInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DeprecatedTraitInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DeprecatedTraitInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DocumentationTraitInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DocumentationTraitInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DocumentationTraitInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/DocumentationTraitInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/ExternalDocumentationTraitInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/ExternalDocumentationTraitInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/ExternalDocumentationTraitInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/ExternalDocumentationTraitInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocFormatterInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocFormatterInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocFormatterInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocFormatterInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocInjectorInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocInjectorInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocInjectorInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocInjectorInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegration.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegration.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegration.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegration.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/OperationErrorInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/OperationErrorInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/OperationErrorInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/OperationErrorInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SinceTraitInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SinceTraitInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SinceTraitInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SinceTraitInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SmithyGeneratedInterceptor.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SmithyGeneratedInterceptor.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SmithyGeneratedInterceptor.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/integrations/javadoc/SmithyGeneratedInterceptor.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/ApplyDocumentation.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/ApplyDocumentation.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/ApplyDocumentation.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/ApplyDocumentation.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/BuilderSetterSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/BuilderSetterSection.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/BuilderSetterSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/BuilderSetterSection.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/ClassSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/ClassSection.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/ClassSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/ClassSection.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/DocumentedSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/DocumentedSection.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/DocumentedSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/DocumentedSection.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/EnumVariantSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/EnumVariantSection.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/EnumVariantSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/EnumVariantSection.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/GetterSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/GetterSection.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/GetterSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/GetterSection.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/JavadocSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/JavadocSection.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/JavadocSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/JavadocSection.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/OperationSection.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/OperationSection.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/sections/OperationSection.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/sections/OperationSection.java diff --git a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/generators/OperationInterfaceGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/server/generators/OperationInterfaceGenerator.java similarity index 97% rename from codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/generators/OperationInterfaceGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/server/generators/OperationInterfaceGenerator.java index 6f8864a2f..04211d6ab 100644 --- a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/generators/OperationInterfaceGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/server/generators/OperationInterfaceGenerator.java @@ -13,8 +13,8 @@ import software.amazon.smithy.java.codegen.CodeGenerationContext; import software.amazon.smithy.java.codegen.CodegenUtils; import software.amazon.smithy.java.codegen.JavaCodegenSettings; +import software.amazon.smithy.java.codegen.ServerSymbolProperties; import software.amazon.smithy.java.codegen.sections.ClassSection; -import software.amazon.smithy.java.codegen.server.ServerSymbolProperties; import software.amazon.smithy.java.server.RequestContext; import software.amazon.smithy.utils.SmithyInternalApi; diff --git a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/generators/ServiceGenerator.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/server/generators/ServiceGenerator.java similarity index 66% rename from codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/generators/ServiceGenerator.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/server/generators/ServiceGenerator.java index c03cb4478..fef77bd89 100644 --- a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/generators/ServiceGenerator.java +++ b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/server/generators/ServiceGenerator.java @@ -15,18 +15,19 @@ import software.amazon.smithy.codegen.core.directed.GenerateServiceDirective; import software.amazon.smithy.framework.knowledge.ImplicitErrorIndex; import software.amazon.smithy.java.codegen.CodeGenerationContext; +import software.amazon.smithy.java.codegen.ExternalSymbols; import software.amazon.smithy.java.codegen.JavaCodegenSettings; +import software.amazon.smithy.java.codegen.ServerSymbolProperties; +import software.amazon.smithy.java.codegen.SyntheticServiceTransform; import software.amazon.smithy.java.codegen.generators.IdStringGenerator; import software.amazon.smithy.java.codegen.generators.SchemaFieldGenerator; import software.amazon.smithy.java.codegen.generators.TypeRegistryGenerator; import software.amazon.smithy.java.codegen.sections.ClassSection; -import software.amazon.smithy.java.codegen.server.ServerSymbolProperties; import software.amazon.smithy.java.codegen.writer.JavaWriter; import software.amazon.smithy.java.core.schema.Schema; import software.amazon.smithy.java.core.schema.SchemaIndex; import software.amazon.smithy.java.core.schema.SerializableStruct; import software.amazon.smithy.java.core.serde.TypeRegistry; -import software.amazon.smithy.java.framework.model.UnknownOperationException; import software.amazon.smithy.java.server.Operation; import software.amazon.smithy.java.server.Service; import software.amazon.smithy.model.Model; @@ -47,6 +48,7 @@ public void accept( TopDownIndex index = TopDownIndex.of(directive.model()); List operationsInfo = index.getContainedOperations(shape) .stream() + .filter(o -> !o.getId().getNamespace().equals(SyntheticServiceTransform.SYNTHETIC_NAMESPACE)) .map(o -> { var inputSymbol = directive.symbolProvider().toSymbol(directive.model().expectShape(o.getInputShape())); @@ -56,93 +58,107 @@ public void accept( }) .toList(); var operations = operationsInfo.stream().map(OperationInfo::symbol).toList(); + // In combined client+server mode, the directive symbol is the client symbol. + // The server symbol is stored as a property. + Symbol serverSymbol = directive.symbol() + .getProperty(ServerSymbolProperties.SERVER_SERVICE_SYMBOL) + .orElse(directive.symbol()); var generatedSchemaIndex = - directive.symbol().expectProperty(ServerSymbolProperties.TYPES_NAMESPACE) + ".GeneratedSchemaIndex"; - directive.context().writerDelegator().useShapeWriter(shape, writer -> { - writer.pushState(new ClassSection(shape)); - var template = - """ - public final class ${service:T} implements ${serviceType:T} { - - ${schema:C} - - ${id:C|} - - ${typeRegistry:C|} - - ${properties:C|} - - ${constructor:C|} - - ${builder:C|} - - private static final ${schemaIndex:T} SCHEMA_INDEX = new ${generatedSchemaIndex:L}(); - - @Override - @SuppressWarnings("unchecked") - public ${operationHolder:T} getOperation(String operationName) { - ${getOperation:C|} - } - - @Override - public ${operationList:T}<${operationHolder:T}> getAllOperations() { - return allOperations; - } - - @Override - public ${schemaClass:T} schema() { - return $$SCHEMA; - } - - @Override - public ${typeRegistryClass:T} typeRegistry() { - return TYPE_REGISTRY; - } - - @Override - public ${schemaIndex:T} schemaIndex() { - return SCHEMA_INDEX; - } - } - """; - writer.putContext("operationHolder", Operation.class); - writer.putContext("serviceType", Service.class); - writer.putContext("serializableStruct", SerializableStruct.class); - writer.putContext("schemaClass", Schema.class); - writer.putContext("service", directive.symbol()); - writer.putContext("id", new IdStringGenerator(writer, shape)); - writer.putContext("typeRegistryClass", TypeRegistry.class); - writer.putContext("schemaIndex", SchemaIndex.class); - writer.putContext("generatedSchemaIndex", generatedSchemaIndex); - var errorSymbols = getImplicitErrorSymbols( - directive.symbolProvider(), - directive.model(), - directive.service()); - writer.putContext( - "typeRegistry", - new TypeRegistryGenerator(writer, errorSymbols)); - writer.putContext( - "properties", - new PropertyGenerator(writer, shape, directive.symbolProvider(), operationsInfo, false)); - writer.putContext( - "constructor", - new ConstructorGenerator(writer, shape, directive.symbolProvider(), operations)); - writer.putContext( - "builder", - new BuilderGenerator(writer, shape, directive.symbolProvider(), operationsInfo)); - writer.putContext( - "getOperation", - new GetOperationGenerator(writer, shape, directive.symbolProvider(), operations)); - writer.putContext( - "schema", - new SchemaFieldGenerator( - directive, - writer, - shape)); - writer.putContext("operationList", List.class); - writer.write(template); - writer.popState(); - }); + serverSymbol.expectProperty(ServerSymbolProperties.TYPES_NAMESPACE) + ".GeneratedSchemaIndex"; + directive.context() + .writerDelegator() + .useFileWriter( + serverSymbol.getDeclarationFile(), + serverSymbol.getNamespace(), + writer -> { + writer.pushState(new ClassSection(shape)); + var template = + """ + public final class ${service:T} implements ${serviceType:T} { + + ${schema:C} + + ${id:C|} + + ${typeRegistry:C|} + + ${properties:C|} + + ${constructor:C|} + + ${builder:C|} + + private static final ${schemaIndex:T} SCHEMA_INDEX = new ${generatedSchemaIndex:L}(); + + @Override + @SuppressWarnings("unchecked") + public ${operationHolder:T} getOperation(String operationName) { + ${getOperation:C|} + } + + @Override + public ${operationList:T}<${operationHolder:T}> getAllOperations() { + return allOperations; + } + + @Override + public ${schemaClass:T} schema() { + return $$SCHEMA; + } + + @Override + public ${typeRegistryClass:T} typeRegistry() { + return TYPE_REGISTRY; + } + + @Override + public ${schemaIndex:T} schemaIndex() { + return SCHEMA_INDEX; + } + } + """; + writer.putContext("operationHolder", Operation.class); + writer.putContext("serviceType", Service.class); + writer.putContext("serializableStruct", SerializableStruct.class); + writer.putContext("schemaClass", Schema.class); + writer.putContext("service", serverSymbol); + writer.putContext("id", new IdStringGenerator(writer, shape)); + writer.putContext("typeRegistryClass", TypeRegistry.class); + writer.putContext("schemaIndex", SchemaIndex.class); + writer.putContext("generatedSchemaIndex", generatedSchemaIndex); + var errorSymbols = getImplicitErrorSymbols( + directive.symbolProvider(), + directive.model(), + directive.service()); + writer.putContext( + "typeRegistry", + new TypeRegistryGenerator(writer, errorSymbols)); + writer.putContext( + "properties", + new PropertyGenerator(writer, + shape, + directive.symbolProvider(), + operationsInfo, + false)); + writer.putContext( + "constructor", + new ConstructorGenerator(writer, shape, directive.symbolProvider(), operations)); + writer.putContext( + "builder", + new BuilderGenerator(writer, shape, directive.symbolProvider(), operationsInfo)); + writer.putContext( + "getOperation", + new GetOperationGenerator(writer, shape, directive.symbolProvider(), operations)); + writer.putContext( + "schema", + new SchemaFieldGenerator( + directive, + writer, + shape)); + writer.putContext("operationList", List.class); + writer.write(template); + writer.popState(); + }); } @@ -328,7 +344,7 @@ public void run() { } writer.write( "default -> throw $T.builder().message(\"Unknown operation name: \" + operationName).build();", - UnknownOperationException.class); + ExternalSymbols.UNKNOWN_OPERATION_EXCEPTION); }); } diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/writer/DeferredSymbolWriter.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/writer/DeferredSymbolWriter.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/writer/DeferredSymbolWriter.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/writer/DeferredSymbolWriter.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/writer/JavaImportContainer.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/writer/JavaImportContainer.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/writer/JavaImportContainer.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/writer/JavaImportContainer.java diff --git a/codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/writer/JavaWriter.java b/codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/writer/JavaWriter.java similarity index 100% rename from codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/writer/JavaWriter.java rename to codegen/codegen-plugin/src/main/java/software/amazon/smithy/java/codegen/writer/JavaWriter.java diff --git a/codegen/codegen-plugin/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin b/codegen/codegen-plugin/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin new file mode 100644 index 000000000..d7089d6d2 --- /dev/null +++ b/codegen/codegen-plugin/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin @@ -0,0 +1 @@ +software.amazon.smithy.java.codegen.JavaCodegenPlugin diff --git a/codegen/codegen-core/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration b/codegen/codegen-plugin/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration similarity index 60% rename from codegen/codegen-core/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration rename to codegen/codegen-plugin/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration index 31813e940..578d9ebca 100644 --- a/codegen/codegen-core/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration +++ b/codegen/codegen-plugin/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration @@ -1,3 +1,3 @@ -software.amazon.smithy.java.codegen.integrations.javadoc.JavadocIntegration software.amazon.smithy.java.codegen.integrations.core.CoreIntegration -software.amazon.smithy.java.codegen.integrations.externaltypes.ExternalTypesIntegration +software.amazon.smithy.java.codegen.integrations.javadoc.JavadocIntegration +software.amazon.smithy.java.codegen.client.integrations.javadoc.ClientJavadocExamplesIntegration diff --git a/codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/object-reserved-members.txt b/codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/object-reserved-members.txt similarity index 100% rename from codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/object-reserved-members.txt rename to codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/object-reserved-members.txt diff --git a/codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/reserved-words.txt b/codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/reserved-words.txt similarity index 100% rename from codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/reserved-words.txt rename to codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/reserved-words.txt diff --git a/codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-members.txt b/codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-members.txt similarity index 100% rename from codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-members.txt rename to codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-members.txt diff --git a/codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-methods.txt b/codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-methods.txt similarity index 100% rename from codegen/codegen-core/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-methods.txt rename to codegen/codegen-plugin/src/main/resources/software/amazon/smithy/java/codegen/smithy-reserved-methods.txt diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/CodegenContextTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/CodegenContextTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/CodegenContextTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/CodegenContextTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/CodegenUtilsTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/CodegenUtilsTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/CodegenUtilsTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/CodegenUtilsTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/NamingTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/NamingTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/NamingTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/NamingTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/NonNullAnnotationTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/NonNullAnnotationTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/NonNullAnnotationTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/NonNullAnnotationTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/RelativeDeprecationFilteringTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/RelativeDeprecationFilteringTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/RelativeDeprecationFilteringTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/RelativeDeprecationFilteringTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/SchemasTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/SchemasTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/SchemasTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/SchemasTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/TestJavaCodegen.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/TestJavaCodegen.java similarity index 97% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/TestJavaCodegen.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/TestJavaCodegen.java index 731fe6402..fe044301f 100644 --- a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/TestJavaCodegen.java +++ b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/TestJavaCodegen.java @@ -50,7 +50,9 @@ public SymbolProvider createSymbolProvider( return new JavaSymbolProvider( directive.model(), directive.service(), - directive.settings().packageNamespace()) { + directive.settings().packageNamespace(), + directive.settings().name(), + java.util.Set.of()) { @Override public Symbol serviceShape(ServiceShape serviceShape) { var serviceName = directive.settings().name(); diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthScheme.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthScheme.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthScheme.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthScheme.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthSchemeTrait.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthSchemeTrait.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthSchemeTrait.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestAuthSchemeTrait.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestClientPlugin.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestClientPlugin.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestClientPlugin.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestClientPlugin.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestServerJavaClientCodegenRunner.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestServerJavaClientCodegenRunner.java similarity index 90% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestServerJavaClientCodegenRunner.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestServerJavaClientCodegenRunner.java index b7be3178e..40f19ad03 100644 --- a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/TestServerJavaClientCodegenRunner.java +++ b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/TestServerJavaClientCodegenRunner.java @@ -8,6 +8,7 @@ import java.nio.file.Paths; import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.build.PluginContext; +import software.amazon.smithy.java.codegen.JavaCodegenPlugin; import software.amazon.smithy.java.codegen.client.settings.TestSettings; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.node.ArrayNode; @@ -22,7 +23,7 @@ private TestServerJavaClientCodegenRunner() { } public static void main(String[] args) { - JavaClientCodegenPlugin plugin = new JavaClientCodegenPlugin(); + JavaCodegenPlugin plugin = new JavaCodegenPlugin(); Model model = Model.assembler(TestServerJavaClientCodegenRunner.class.getClassLoader()) .discoverModels(TestServerJavaClientCodegenRunner.class.getClassLoader()) .assemble() @@ -33,6 +34,7 @@ public static void main(String[] args) { ObjectNode.builder() .withMember("service", "smithy.java.codegen.server.test#TestService") .withMember("namespace", "smithy.java.codegen.server.test") + .withMember("modes", ArrayNode.fromStrings("client")) .withMember( "transport", ObjectNode.builder() @@ -53,6 +55,7 @@ public static void main(String[] args) { ObjectNode.builder() .withMember("service", "smithy.java.codegen.server.test#ServiceWithEndpointBdd") .withMember("namespace", "smithy.java.codegen.server.bddTest") + .withMember("modes", ArrayNode.fromStrings("client")) .build()) .model(model) .build(); @@ -64,6 +67,7 @@ public static void main(String[] args) { ObjectNode.builder() .withMember("service", "smithy.java.codegen.server.test#ServiceWithEndpointRuleSet") .withMember("namespace", "smithy.java.codegen.server.bddTest") + .withMember("modes", ArrayNode.fromStrings("client")) .build()) .model(model) .build(); diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegrationTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegrationTest.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegrationTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/integrations/javadoc/ClientJavadocExamplesIntegrationTest.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/AbSetting.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/AbSetting.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/AbSetting.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/AbSetting.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/Nested.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/Nested.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/Nested.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/Nested.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/NestedSettings.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/NestedSettings.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/NestedSettings.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/NestedSettings.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/TestSettings.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/TestSettings.java similarity index 100% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/settings/TestSettings.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/settings/TestSettings.java diff --git a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/utils/AbstractCodegenFileTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/utils/AbstractCodegenFileTest.java similarity index 87% rename from codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/utils/AbstractCodegenFileTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/utils/AbstractCodegenFileTest.java index e108f6be2..27fb5bb43 100644 --- a/codegen/plugins/client-codegen/src/test/java/software/amazon/smithy/java/codegen/client/utils/AbstractCodegenFileTest.java +++ b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/client/utils/AbstractCodegenFileTest.java @@ -14,14 +14,15 @@ import software.amazon.smithy.build.MockManifest; import software.amazon.smithy.build.PluginContext; import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.java.codegen.client.JavaClientCodegenPlugin; +import software.amazon.smithy.java.codegen.JavaCodegenPlugin; import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.node.ArrayNode; import software.amazon.smithy.model.node.ObjectNode; public abstract class AbstractCodegenFileTest { protected final MockManifest manifest = new MockManifest(); - protected final SmithyBuildPlugin plugin = new JavaClientCodegenPlugin(); + protected final SmithyBuildPlugin plugin = new JavaCodegenPlugin(); @BeforeEach public void setup() { @@ -44,6 +45,7 @@ protected ObjectNode settings() { return ObjectNode.builder() .withMember("service", "smithy.java.codegen#TestService") .withMember("namespace", "test.smithy.codegen") + .withMember("modes", ArrayNode.fromStrings("client")) .build(); } diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/generators/SnippetGeneratorTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/generators/SnippetGeneratorTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/generators/SnippetGeneratorTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/generators/SnippetGeneratorTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/integrations/core/PreludeTraitInitializerTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/integrations/core/PreludeTraitInitializerTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/integrations/core/PreludeTraitInitializerTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/integrations/core/PreludeTraitInitializerTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegrationTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegrationTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegrationTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/integrations/javadoc/JavadocIntegrationTest.java diff --git a/codegen/plugins/server-codegen/src/test/java/software/amazon/smithy/java/codegen/server/TestServerJavaCodegenRunner.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/server/TestServerJavaCodegenRunner.java similarity index 80% rename from codegen/plugins/server-codegen/src/test/java/software/amazon/smithy/java/codegen/server/TestServerJavaCodegenRunner.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/server/TestServerJavaCodegenRunner.java index 1cfed682c..773e6e8cb 100644 --- a/codegen/plugins/server-codegen/src/test/java/software/amazon/smithy/java/codegen/server/TestServerJavaCodegenRunner.java +++ b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/server/TestServerJavaCodegenRunner.java @@ -8,7 +8,9 @@ import java.nio.file.Paths; import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.build.PluginContext; +import software.amazon.smithy.java.codegen.JavaCodegenPlugin; import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.node.ArrayNode; import software.amazon.smithy.model.node.ObjectNode; /** @@ -20,7 +22,7 @@ private TestServerJavaCodegenRunner() { } public static void main(String[] args) { - JavaServerCodegenPlugin plugin = new JavaServerCodegenPlugin(); + JavaCodegenPlugin plugin = new JavaCodegenPlugin(); Model model = Model.assembler(TestServerJavaCodegenRunner.class.getClassLoader()) .discoverModels(TestServerJavaCodegenRunner.class.getClassLoader()) .assemble() @@ -29,8 +31,9 @@ public static void main(String[] args) { .fileManifest(FileManifest.create(Paths.get(System.getenv("output")))) .settings( ObjectNode.builder() - .withMember("service", "smithy.java.codegen.server.test#TestService") - .withMember("namespace", "smithy.java.codegen.server.test") + .withMember("service", "smithy.java.codegen.server.only.test#TestService") + .withMember("namespace", "smithy.java.codegen.server.only.test") + .withMember("modes", ArrayNode.fromStrings("server")) .build()) .model(model) .build(); diff --git a/codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/CodegenTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/CodegenTest.java similarity index 90% rename from codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/CodegenTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/CodegenTest.java index f2fe70d1f..2c334b9b1 100644 --- a/codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/CodegenTest.java +++ b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/CodegenTest.java @@ -27,7 +27,7 @@ public class CodegenTest { .assemble() .unwrap(); - private final SmithyBuildPlugin plugin = new JavaTypeCodegenPlugin(); + private final SmithyBuildPlugin plugin = new software.amazon.smithy.java.codegen.JavaCodegenPlugin(); private MockManifest manifest; private PluginContext.Builder contextBuilder; private ObjectNode.Builder settingsBuilder; @@ -39,7 +39,8 @@ public void setup() { .fileManifest(manifest) .model(model); settingsBuilder = ObjectNode.builder() - .withMember("namespace", "test.smithy.codegen.types.test"); + .withMember("namespace", "test.smithy.codegen.types.test") + .withMember("modes", ArrayNode.fromStrings("types")); } @Test @@ -48,7 +49,7 @@ void expectedFilesExist() { var context = contextBuilder.settings(settings).build(); plugin.execute(context); assertThat(manifest.getFiles()) - .hasSize(9) + .hasSize(8) .containsExactlyInAnyOrder( Path.of("/test/smithy/codegen/types/test/model/EnumShape.java"), Path.of("/test/smithy/codegen/types/test/model/IntEnumShape.java"), @@ -57,7 +58,6 @@ void expectedFilesExist() { Path.of("/test/smithy/codegen/types/test/model/StructureShape.java"), Path.of("/test/smithy/codegen/types/test/model/UnionShape.java"), Path.of("/test/smithy/codegen/types/test/model/GeneratedSchemaIndex.java"), - Path.of("/META-INF/smithy-java/type-mappings.properties"), Path.of("/META-INF/services/software.amazon.smithy.java.core.schema.SchemaIndex")); } @@ -69,13 +69,12 @@ void respectsSelector() { var context = contextBuilder.settings(settings).build(); plugin.execute(context); assertThat(manifest.getFiles()) - .hasSize(6) + .hasSize(5) .containsExactlyInAnyOrder( Path.of("/test/smithy/codegen/types/test/model/Schemas.java"), Path.of("/test/smithy/codegen/types/test/model/SharedSerde.java"), Path.of("/test/smithy/codegen/types/test/model/StructureShape.java"), Path.of("/test/smithy/codegen/types/test/model/GeneratedSchemaIndex.java"), - Path.of("/META-INF/smithy-java/type-mappings.properties"), Path.of("/META-INF/services/software.amazon.smithy.java.core.schema.SchemaIndex")); } @@ -87,16 +86,15 @@ void specificShapesAdded() { .build(); var context = contextBuilder.settings(settings).build(); plugin.execute(context); - assertEquals(7, manifest.getFiles().size()); + assertEquals(6, manifest.getFiles().size()); assertThat(manifest.getFiles()) - .hasSize(7) + .hasSize(6) .containsExactlyInAnyOrder( Path.of("/test/smithy/codegen/types/test/model/Schemas.java"), Path.of("/test/smithy/codegen/types/test/model/SharedSerde.java"), Path.of("/test/smithy/codegen/types/test/model/StructureShape.java"), Path.of("/test/smithy/codegen/types/test/model/UnionShape.java"), Path.of("/test/smithy/codegen/types/test/model/GeneratedSchemaIndex.java"), - Path.of("/META-INF/smithy-java/type-mappings.properties"), Path.of("/META-INF/services/software.amazon.smithy.java.core.schema.SchemaIndex")); } diff --git a/codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/TestJavaTypeCodegenRunner.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/TestJavaTypeCodegenRunner.java similarity index 71% rename from codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/TestJavaTypeCodegenRunner.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/TestJavaTypeCodegenRunner.java index 274035863..6e9c053d3 100644 --- a/codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/TestJavaTypeCodegenRunner.java +++ b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/TestJavaTypeCodegenRunner.java @@ -8,7 +8,9 @@ import java.nio.file.Paths; import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.build.PluginContext; +import software.amazon.smithy.java.codegen.JavaCodegenPlugin; import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.node.ArrayNode; import software.amazon.smithy.model.node.ObjectNode; /** @@ -20,7 +22,7 @@ private TestJavaTypeCodegenRunner() { } public static void main(String[] args) { - JavaTypeCodegenPlugin plugin = new JavaTypeCodegenPlugin(); + JavaCodegenPlugin plugin = new JavaCodegenPlugin(); Model model = Model.assembler(TestJavaTypeCodegenRunner.class.getClassLoader()) .discoverModels(TestJavaTypeCodegenRunner.class.getClassLoader()) .assemble() @@ -29,7 +31,11 @@ public static void main(String[] args) { .fileManifest(FileManifest.create(Paths.get(System.getenv("output")))) .settings( ObjectNode.builder() - .withMember("namespace", "smithy.java.codegen.server.test") + .withMember("namespace", "smithy.java.codegen.types.test") + .withMember("modes", ArrayNode.fromStrings("types")) + .withMember("selector", + ":is(structure, union, enum, intEnum)" + + "[id|namespace ^= 'smithy.java.codegen.types']") .build()) .model(model) .build(); diff --git a/codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/TypesCodegenPluginTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/TypesCodegenPluginTest.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/java/software/amazon/smithy/java/codegen/types/TypesCodegenPluginTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/types/TypesCodegenPluginTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/utils/AbstractCodegenFileTest.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/utils/AbstractCodegenFileTest.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/utils/AbstractCodegenFileTest.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/utils/AbstractCodegenFileTest.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenPlugin.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenPlugin.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenPlugin.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenPlugin.java diff --git a/codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenRunner.java b/codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenRunner.java similarity index 100% rename from codegen/codegen-core/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenRunner.java rename to codegen/codegen-plugin/src/test/java/software/amazon/smithy/java/codegen/utils/TestJavaCodegenRunner.java diff --git a/codegen/plugins/client-codegen/src/test/resources/META-INF/services/software.amazon.smithy.java.client.core.auth.scheme.AuthSchemeFactory b/codegen/codegen-plugin/src/test/resources/META-INF/services/software.amazon.smithy.java.client.core.auth.scheme.AuthSchemeFactory similarity index 100% rename from codegen/plugins/client-codegen/src/test/resources/META-INF/services/software.amazon.smithy.java.client.core.auth.scheme.AuthSchemeFactory rename to codegen/codegen-plugin/src/test/resources/META-INF/services/software.amazon.smithy.java.client.core.auth.scheme.AuthSchemeFactory diff --git a/codegen/codegen-plugin/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService b/codegen/codegen-plugin/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService new file mode 100644 index 000000000..0562885ab --- /dev/null +++ b/codegen/codegen-plugin/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService @@ -0,0 +1,2 @@ +software.amazon.smithy.java.codegen.CodegenContextTest$SelectedTrait$Provider +software.amazon.smithy.java.codegen.client.TestAuthSchemeTrait$Provider diff --git a/codegen/plugins/client-codegen/src/test/resources/software/amazon/smithy/java/codegen/client/integrations/javadoc/javadoc-examples.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/client/integrations/javadoc/javadoc-examples.smithy similarity index 100% rename from codegen/plugins/client-codegen/src/test/resources/software/amazon/smithy/java/codegen/client/integrations/javadoc/javadoc-examples.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/client/integrations/javadoc/javadoc-examples.smithy diff --git a/codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/codegen-context-test.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/codegen-context-test.smithy similarity index 100% rename from codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/codegen-context-test.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/codegen-context-test.smithy diff --git a/codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/generators/snippet-test.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/generators/snippet-test.smithy similarity index 100% rename from codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/generators/snippet-test.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/generators/snippet-test.smithy diff --git a/codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/integrations/core/prelude-trait-initializer-test.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/integrations/core/prelude-trait-initializer-test.smithy similarity index 100% rename from codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/integrations/core/prelude-trait-initializer-test.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/integrations/core/prelude-trait-initializer-test.smithy diff --git a/codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/integrations/javadoc/javadoc-test.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/integrations/javadoc/javadoc-test.smithy similarity index 100% rename from codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/integrations/javadoc/javadoc-test.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/integrations/javadoc/javadoc-test.smithy diff --git a/codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/naming-test.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/naming-test.smithy similarity index 100% rename from codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/naming-test.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/naming-test.smithy diff --git a/codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/null-annotation-test.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/null-annotation-test.smithy similarity index 100% rename from codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/null-annotation-test.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/null-annotation-test.smithy diff --git a/codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/relative-deprecated-test.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/relative-deprecated-test.smithy similarity index 100% rename from codegen/codegen-core/src/test/resources/software/amazon/smithy/java/codegen/relative-deprecated-test.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/relative-deprecated-test.smithy diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/expected/DefaultStructure.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/expected/DefaultStructure.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/expected/DefaultStructure.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/expected/DefaultStructure.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/model/defaults.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/model/defaults.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/model/defaults.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/model/defaults.smithy diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/smithy-build.json b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/smithy-build.json similarity index 69% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/smithy-build.json rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/smithy-build.json index 3dbf5a644..8ed09b6b4 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/smithy-build.json +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/defaults/smithy-build.json @@ -1,8 +1,9 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { - "namespace": "software.amazon.smithy.java.example.defaults" + "java-codegen": { + "namespace": "software.amazon.smithy.java.example.defaults", + "modes": ["types"] } } } diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/EnumType.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/EnumType.java similarity index 98% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/EnumType.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/EnumType.java index 7acc24266..e73bd548d 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/EnumType.java +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/EnumType.java @@ -20,7 +20,7 @@ public sealed interface EnumType extends SerializableShape { List $TYPES = List.of(OPTION_ONE, OPTION_TWO); Schema $SCHEMA = Schema.createEnum(ShapeId.from("smithy.java.codegen.types.naming#EnumType"), - Set.of(OPTION_ONE.getValue(), OPTION_TWO.getValue()) + Set.of(OPTION_ONE.getValue(), OPTION_TWO.getValue()), EnumType.class ); ShapeId $ID = $SCHEMA.id(); diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/IntEnumType.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/IntEnumType.java similarity index 99% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/IntEnumType.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/IntEnumType.java index df7a09550..ee8cba429 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/IntEnumType.java +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/IntEnumType.java @@ -20,7 +20,7 @@ public sealed interface IntEnumType extends SerializableShape { List $TYPES = List.of(FIRST, SECOND, FIFTH); Schema $SCHEMA = Schema.createIntEnum(ShapeId.from("smithy.java.codegen.types.naming#IntEnumType"), - Set.of(FIRST.getValue(), SECOND.getValue(), FIFTH.getValue()) + Set.of(FIRST.getValue(), SECOND.getValue(), FIFTH.getValue()), IntEnumType.class ); ShapeId $ID = $SCHEMA.id(); diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/TextType.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/TextType.java similarity index 98% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/TextType.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/TextType.java index f89d34eb0..33fc537dc 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/TextType.java +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/expected/TextType.java @@ -19,7 +19,7 @@ public sealed interface TextType extends SerializableShape { List $TYPES = List.of(TEXT); Schema $SCHEMA = Schema.createEnum(ShapeId.from("smithy.java.codegen.types.naming#TextType"), - Set.of(TEXT.getValue()) + Set.of(TEXT.getValue()), TextType.class ); ShapeId $ID = $SCHEMA.id(); diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/model/main.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/model/main.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/model/main.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/model/main.smithy diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/smithy-build.json b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/smithy-build.json similarity index 68% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/smithy-build.json rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/smithy-build.json index 18f2e820d..133b86fc3 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/smithy-build.json +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/smithy-build.json @@ -1,8 +1,9 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { - "namespace": "software.amazon.smithy.java.example.standalone" + "java-codegen": { + "namespace": "software.amazon.smithy.java.example.standalone", + "modes": ["types"] } } } diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/BuilderShape.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/BuilderShape.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/BuilderShape.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/BuilderShape.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/List.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/List.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/List.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/List.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Map.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Map.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Map.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Map.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/NamingStruct.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/NamingStruct.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/NamingStruct.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/NamingStruct.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/ObjectShape.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/ObjectShape.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/ObjectShape.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/ObjectShape.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Type.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Type.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Type.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/Type.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/UnionWithTypeMember.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/UnionWithTypeMember.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/UnionWithTypeMember.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/expected/UnionWithTypeMember.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/model/main.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/model/main.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/model/main.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/model/main.smithy diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/smithy-build.json b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/smithy-build.json similarity index 68% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/smithy-build.json rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/smithy-build.json index 18f2e820d..133b86fc3 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/enums/smithy-build.json +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/smithy-build.json @@ -1,8 +1,9 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { - "namespace": "software.amazon.smithy.java.example.standalone" + "java-codegen": { + "namespace": "software.amazon.smithy.java.example.standalone", + "modes": ["types"] } } } diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNotNullable.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNotNullable.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNotNullable.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNotNullable.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNullable.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNullable.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNullable.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/expected/PrimitivesNullable.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/model/main.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/model/main.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/model/main.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/model/main.smithy diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/smithy-build.json b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/smithy-build.json similarity index 68% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/smithy-build.json rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/smithy-build.json index 18f2e820d..133b86fc3 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/naming-conflict/smithy-build.json +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/smithy-build.json @@ -1,8 +1,9 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { - "namespace": "software.amazon.smithy.java.example.standalone" + "java-codegen": { + "namespace": "software.amazon.smithy.java.example.standalone", + "modes": ["types"] } } } diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/expected/UnionType.java b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/expected/UnionType.java similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/expected/UnionType.java rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/expected/UnionType.java diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/model/main.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/model/main.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/model/main.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/model/main.smithy diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/smithy-build.json b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/smithy-build.json similarity index 68% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/smithy-build.json rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/smithy-build.json index 18f2e820d..133b86fc3 100644 --- a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/primitive-types/smithy-build.json +++ b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/test-cases/union-type/smithy-build.json @@ -1,8 +1,9 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { - "namespace": "software.amazon.smithy.java.example.standalone" + "java-codegen": { + "namespace": "software.amazon.smithy.java.example.standalone", + "modes": ["types"] } } } diff --git a/codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/types.smithy b/codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/types.smithy similarity index 100% rename from codegen/plugins/types-codegen/src/test/resources/software/amazon/smithy/java/codegen/types/types.smithy rename to codegen/codegen-plugin/src/test/resources/software/amazon/smithy/java/codegen/types/types.smithy diff --git a/codegen/integrations/waiters-codegen/README.md b/codegen/integrations/waiters-codegen/README.md deleted file mode 100644 index 4da56f015..000000000 --- a/codegen/integrations/waiters-codegen/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## waiters-codegen -Codegen integration to generate pre-defined waiters based on -[waitable](https://smithy.io/2.0/additional-specs/waiters.html#smithy-waiters-waitable-trait) traits in the service model. - -### Usage -```kotlin -dependencies { - // Add codegen integration as a smithy-build dependency, so it can be - // discovered by the client codegen plugin - smithyBuild("software.amazon.smithy.java.codegen:waiters:") - - // Add waiters core package as a runtime dependency - implementation("software.amazon.smithy.java:waiters:") -} -``` - diff --git a/codegen/integrations/waiters-codegen/build.gradle.kts b/codegen/integrations/waiters-codegen/build.gradle.kts deleted file mode 100644 index d64a579f9..000000000 --- a/codegen/integrations/waiters-codegen/build.gradle.kts +++ /dev/null @@ -1,13 +0,0 @@ -plugins { - id("smithy-java.module-conventions") -} - -description = "This module provides the Smithy Java Waiter codegen integration" - -extra["displayName"] = "Smithy :: Java :: Codegen :: Waiters" -extra["moduleName"] = "software.amazon.smithy.java.codegen.waiters" - -dependencies { - implementation(project(":client:client-waiters")) - implementation(project(":codegen:plugins:client-codegen")) -} diff --git a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterClientImplMethodInterceptor.java b/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterClientImplMethodInterceptor.java deleted file mode 100644 index 34208edd2..000000000 --- a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterClientImplMethodInterceptor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client.waiters; - -import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.client.sections.ClientImplAdditionalMethodsSection; -import software.amazon.smithy.java.codegen.writer.JavaWriter; -import software.amazon.smithy.utils.CodeInterceptor; - -record WaiterClientImplMethodInterceptor(SymbolProvider symbolProvider, JavaCodegenSettings settings) - implements CodeInterceptor.Prepender { - @Override - public Class sectionType() { - return ClientImplAdditionalMethodsSection.class; - } - - @Override - public void prepend(JavaWriter writer, ClientImplAdditionalMethodsSection section) { - var clientSymbol = symbolProvider.toSymbol(section.client()); - writer.pushState(); - writer.putContext("container", WaiterCodegenUtils.getWaiterSymbol(clientSymbol, settings)); - writer.write(""" - @Override - public ${container:T} waiter() { - return new ${container:T}(this); - } - """); - writer.popState(); - } -} diff --git a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterClientInterfaceMethodInterceptor.java b/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterClientInterfaceMethodInterceptor.java deleted file mode 100644 index fab49185f..000000000 --- a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterClientInterfaceMethodInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client.waiters; - -import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.client.sections.ClientInterfaceAdditionalMethodsSection; -import software.amazon.smithy.java.codegen.writer.JavaWriter; -import software.amazon.smithy.utils.CodeInterceptor; - -record WaiterClientInterfaceMethodInterceptor(SymbolProvider symbolProvider, JavaCodegenSettings settings) - implements CodeInterceptor.Prepender { - @Override - public Class sectionType() { - return ClientInterfaceAdditionalMethodsSection.class; - } - - @Override - public void prepend(JavaWriter writer, ClientInterfaceAdditionalMethodsSection section) { - var clientSymbol = symbolProvider.toSymbol(section.client()); - writer.pushState(); - writer.putContext("container", WaiterCodegenUtils.getWaiterSymbol(clientSymbol, settings)); - writer.write(""" - /** - * Create a new {@link CoffeeShopWaiter} instance that uses this client for polling. - * - * @return new {@link ${container:T}} instance. - */ - ${container:T} waiter(); - """); - writer.popState(); - } -} diff --git a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenIntegration.java b/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenIntegration.java deleted file mode 100644 index 9374366c6..000000000 --- a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterCodegenIntegration.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client.waiters; - -import java.util.List; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.writer.JavaWriter; -import software.amazon.smithy.utils.CodeInterceptor; -import software.amazon.smithy.utils.CodeSection; -import software.amazon.smithy.utils.SmithyInternalApi; - -@SmithyInternalApi -public final class WaiterCodegenIntegration implements JavaCodegenIntegration { - @Override - public String name() { - return "waiters"; - } - - @Override - public List> interceptors( - CodeGenerationContext context - ) { - return List.of( - new WaiterClientInterfaceMethodInterceptor(context.symbolProvider(), context.settings()), - new WaiterClientImplMethodInterceptor(context.symbolProvider(), context.settings()), - new WaiterDocumentationInterceptor()); - } - - @Override - public void customize(CodeGenerationContext context) { - new WaiterContainerGenerator().accept(context); - } -} diff --git a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterDocumentationInterceptor.java b/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterDocumentationInterceptor.java deleted file mode 100644 index 519637cab..000000000 --- a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterDocumentationInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client.waiters; - -import software.amazon.smithy.java.codegen.sections.JavadocSection; -import software.amazon.smithy.java.codegen.writer.JavaWriter; -import software.amazon.smithy.utils.CodeInterceptor; - -/** - * Adds Javadoc documentation for waiter methods. - */ -final class WaiterDocumentationInterceptor implements CodeInterceptor.Appender { - - @Override - public void append(JavaWriter writer, JavadocSection section) { - if (section.parent() instanceof WaiterSection ws) { - ws.waiter().getDocumentation().ifPresent(writer::writeWithNoFormatting); - if (ws.waiter().isDeprecated()) { - writer.write("@deprecated Waiter is deprecated"); - } - } - } - - @Override - public Class sectionType() { - return JavadocSection.class; - } - - @Override - public boolean isIntercepted(JavadocSection section) { - return section.parent() instanceof WaiterSection; - } -} diff --git a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterSection.java b/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterSection.java deleted file mode 100644 index 407a0ebe6..000000000 --- a/codegen/integrations/waiters-codegen/src/main/java/software/amazon/smithy/java/codegen/client/waiters/WaiterSection.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client.waiters; - -import software.amazon.smithy.java.codegen.sections.DocumentedSection; -import software.amazon.smithy.model.shapes.Shape; -import software.amazon.smithy.utils.CodeSection; -import software.amazon.smithy.waiters.Waiter; - -/** - * Contains a waiter method. - * - * @param waiter waiter method definition contained by this section - */ -record WaiterSection(Waiter waiter) implements CodeSection, DocumentedSection { - @Override - public Shape targetedShape() { - // Never targets a shape. - return null; - } -} diff --git a/codegen/integrations/waiters-codegen/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration b/codegen/integrations/waiters-codegen/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration deleted file mode 100644 index 747fbb517..000000000 --- a/codegen/integrations/waiters-codegen/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration +++ /dev/null @@ -1 +0,0 @@ -software.amazon.smithy.java.codegen.client.waiters.WaiterCodegenIntegration diff --git a/codegen/plugins/build.gradle.kts b/codegen/plugins/build.gradle.kts deleted file mode 100644 index a4900bbc6..000000000 --- a/codegen/plugins/build.gradle.kts +++ /dev/null @@ -1,13 +0,0 @@ -plugins { - id("smithy-java.module-conventions") - id("smithy-java.publishing-conventions") -} - -description = "This module provides java code generation plugins for Smithy" - -extra["displayName"] = "Smithy :: Java :: Codegen :: Plugins" -extra["moduleName"] = "software.amazon.smithy.java.codegen.plugins" - -dependencies { - subprojects.forEach { api(project(it.path)) } -} diff --git a/codegen/plugins/client-codegen/README.md b/codegen/plugins/client-codegen/README.md deleted file mode 100644 index b6516c622..000000000 --- a/codegen/plugins/client-codegen/README.md +++ /dev/null @@ -1,2 +0,0 @@ -### codegen-client -Codegen plugin to generate a Java client from a Smithy model. diff --git a/codegen/plugins/client-codegen/build.gradle.kts b/codegen/plugins/client-codegen/build.gradle.kts deleted file mode 100644 index 5d321aae3..000000000 --- a/codegen/plugins/client-codegen/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -plugins { - id("smithy-java.codegen-plugin-conventions") -} - -description = "This module provides the codegen plugin for Smithy java client codegen" - -extra["displayName"] = "Smithy :: Java :: Codegen :: Client" -extra["moduleName"] = "software.amazon.smithy.java.codegen.client" - -dependencies { - api(project(":client:client-core")) - api(project(":client:client-rulesengine")) - testImplementation(project(":aws:client:aws-client-restjson")) - testImplementation(libs.smithy.aws.traits) - testImplementation(libs.smithy.rules) - itImplementation(project(":aws:client:aws-client-restjson")) -} - -addGenerateSrcsTask("software.amazon.smithy.java.codegen.client.TestServerJavaClientCodegenRunner") - -tasks.test { - failOnNoDiscoveredTests = false -} - -sourceSets { - it { - // Add test plugin to classpath - compileClasspath += sourceSets["test"].output - resources.srcDir("${layout.buildDirectory.get()}/generated-src/resources") - } -} - -tasks.named("processItResources") { - dependsOn("generateSources") -} diff --git a/codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/manifest b/codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/manifest deleted file mode 100644 index 3d59a94b6..000000000 --- a/codegen/plugins/client-codegen/src/it/resources/META-INF/smithy/manifest +++ /dev/null @@ -1,3 +0,0 @@ -main.smithy -test-auth-scheme.smithy -bdd-test.smithy \ No newline at end of file diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/ClientJavaSymbolProvider.java b/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/ClientJavaSymbolProvider.java deleted file mode 100644 index 92555edee..000000000 --- a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/ClientJavaSymbolProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client; - -import static java.lang.String.format; - -import software.amazon.smithy.codegen.core.Symbol; -import software.amazon.smithy.java.codegen.CodegenUtils; -import software.amazon.smithy.java.codegen.JavaSymbolProvider; -import software.amazon.smithy.java.codegen.SymbolProperties; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.shapes.ServiceShape; - -/** - * Maps Smithy types to Java Symbols for Client code generation. - */ -final class ClientJavaSymbolProvider extends JavaSymbolProvider { - private final String serviceName; - - public ClientJavaSymbolProvider(Model model, ServiceShape service, String packageNamespace, String serviceName) { - super(model, service, packageNamespace); - this.serviceName = serviceName; - } - - @Override - public Symbol serviceShape(ServiceShape serviceShape) { - return getSymbolFromName() - .toBuilder() - .putProperty(SymbolProperties.SERVICE_EXCEPTION, - CodegenUtils.getServiceExceptionSymbol(packageNamespace(), serviceName)) - .putProperty(SymbolProperties.SERVICE_API_SERVICE, - CodegenUtils.getServiceApiSymbol(packageNamespace(), serviceName)) - .build(); - } - - private Symbol getSymbolFromName() { - var name = serviceName + "Client"; - var symbol = Symbol.builder() - .name(name) - .putProperty(SymbolProperties.IS_PRIMITIVE, false) - .namespace(format("%s.client", packageNamespace()), ".") - .definitionFile(format("./%s/client/%s.java", packageNamespace().replace(".", "/"), name)) - .build(); - - return symbol.toBuilder() - .putProperty( - ClientSymbolProperties.CLIENT_IMPL, - symbol.toBuilder() - .name(name + "Impl") - .definitionFile( - format("./%s/client/%sImpl.java", packageNamespace().replace(".", "/"), name)) - .build()) - .build(); - } -} diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/DirectedJavaClientCodegen.java b/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/DirectedJavaClientCodegen.java deleted file mode 100644 index c02e5cc0a..000000000 --- a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/DirectedJavaClientCodegen.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client; - -import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.codegen.core.directed.*; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.client.generators.BddFileGenerator; -import software.amazon.smithy.java.codegen.client.generators.ClientImplementationGenerator; -import software.amazon.smithy.java.codegen.client.generators.ClientInterfaceGenerator; -import software.amazon.smithy.java.codegen.generators.ApiServiceGenerator; -import software.amazon.smithy.java.codegen.generators.EnumGenerator; -import software.amazon.smithy.java.codegen.generators.ListGenerator; -import software.amazon.smithy.java.codegen.generators.MapGenerator; -import software.amazon.smithy.java.codegen.generators.OperationGenerator; -import software.amazon.smithy.java.codegen.generators.ResourceGenerator; -import software.amazon.smithy.java.codegen.generators.SchemaIndexGenerator; -import software.amazon.smithy.java.codegen.generators.SchemasGenerator; -import software.amazon.smithy.java.codegen.generators.ServiceExceptionGenerator; -import software.amazon.smithy.java.codegen.generators.SharedSerdeGenerator; -import software.amazon.smithy.java.codegen.generators.StructureGenerator; -import software.amazon.smithy.java.codegen.generators.UnionGenerator; -import software.amazon.smithy.rulesengine.traits.EndpointBddTrait; -import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait; -import software.amazon.smithy.utils.SmithyUnstableApi; - -@SmithyUnstableApi -final class DirectedJavaClientCodegen - implements DirectedCodegen { - - @Override - public SymbolProvider createSymbolProvider( - CreateSymbolProviderDirective directive - ) { - return new ClientJavaSymbolProvider( - directive.model(), - directive.service(), - directive.settings().packageNamespace(), - directive.settings().name()); - } - - @Override - public CodeGenerationContext createContext( - CreateContextDirective directive - ) { - return new CodeGenerationContext( - directive, - "client"); - } - - @Override - public void generateStructure(GenerateStructureDirective directive) { - if (!directive.settings().useExternalTypes()) { - new StructureGenerator<>().accept(directive); - } - } - - @Override - public void generateError(GenerateErrorDirective directive) { - if (!directive.settings().useExternalTypes()) { - new StructureGenerator<>().accept(directive); - } - } - - @Override - public void generateUnion(GenerateUnionDirective directive) { - if (!directive.settings().useExternalTypes()) { - new UnionGenerator().accept(directive); - } - } - - @Override - public void generateList(GenerateListDirective directive) { - if (!directive.settings().useExternalTypes()) { - new ListGenerator().accept(directive); - } - } - - @Override - public void generateMap(GenerateMapDirective directive) { - if (!directive.settings().useExternalTypes()) { - new MapGenerator().accept(directive); - } - } - - @Override - public void generateEnumShape(GenerateEnumDirective directive) { - if (!directive.settings().useExternalTypes()) { - new EnumGenerator<>().accept(directive); - } - } - - @Override - public void generateIntEnumShape(GenerateIntEnumDirective directive) { - if (!directive.settings().useExternalTypes()) { - new EnumGenerator<>().accept(directive); - } - } - - @Override - public void generateOperation(GenerateOperationDirective directive) { - if (!directive.settings().useExternalTypes()) { - new OperationGenerator().accept(directive); - } - } - - @Override - public void generateService(GenerateServiceDirective directive) { - new ClientInterfaceGenerator().accept(directive); - new ClientImplementationGenerator().accept(directive); - - if (!directive.context().settings().useExternalTypes()) { - new ApiServiceGenerator().accept(directive); - new ServiceExceptionGenerator<>().accept(directive); - } - - var service = directive.service(); - if (service.hasTrait(EndpointBddTrait.ID) || service.hasTrait(EndpointRuleSetTrait.ID)) { - new BddFileGenerator().accept(directive); - } - } - - @Override - public void generateResource(GenerateResourceDirective directive) { - if (!directive.settings().useExternalTypes()) { - new ResourceGenerator().accept(directive); - } - } - - @Override - public void customizeBeforeIntegrations(CustomizeDirective directive) { - if (!directive.settings().useExternalTypes()) { - new SchemasGenerator().accept(directive); - new SharedSerdeGenerator().accept(directive); - new SchemaIndexGenerator().accept(directive); - } - } -} diff --git a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/JavaClientCodegenPlugin.java b/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/JavaClientCodegenPlugin.java deleted file mode 100644 index c7504f470..000000000 --- a/codegen/plugins/client-codegen/src/main/java/software/amazon/smithy/java/codegen/client/JavaClientCodegenPlugin.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.client; - -import software.amazon.smithy.build.PluginContext; -import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.codegen.core.directed.CodegenDirector; -import software.amazon.smithy.framework.transform.AddFrameworkErrorsTransform; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.DefaultTransforms; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.writer.JavaWriter; -import software.amazon.smithy.java.logging.InternalLogger; -import software.amazon.smithy.model.transform.ModelTransformer; -import software.amazon.smithy.utils.SmithyInternalApi; - -/** - * Plugin to execute Java client code generation. - */ -@SmithyInternalApi -public final class JavaClientCodegenPlugin implements SmithyBuildPlugin { - private static final InternalLogger LOGGER = InternalLogger.getLogger(JavaClientCodegenPlugin.class); - - @Override - public String getName() { - return "java-client-codegen"; - } - - @Override - public void execute(PluginContext context) { - CodegenDirector runner = - new CodegenDirector<>(); - var settings = JavaCodegenSettings.fromNode(context.getSettings()); - runner.settings(settings); - runner.directedCodegen(new DirectedJavaClientCodegen()); - runner.fileManifest(context.getFileManifest()); - runner.service(settings.service()); - // TODO: use built-in once this has been upstreamed - var model = AddFrameworkErrorsTransform.transform(ModelTransformer.create(), context.getModel()); - runner.model(model); - runner.integrationClass(JavaCodegenIntegration.class); - DefaultTransforms.apply(runner, settings); - runner.run(); - LOGGER.info("Smithy-Java client code generation complete"); - } -} diff --git a/codegen/plugins/client-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin b/codegen/plugins/client-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin deleted file mode 100644 index 176cd3a6f..000000000 --- a/codegen/plugins/client-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin +++ /dev/null @@ -1 +0,0 @@ -software.amazon.smithy.java.codegen.client.JavaClientCodegenPlugin diff --git a/codegen/plugins/client-codegen/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration b/codegen/plugins/client-codegen/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration deleted file mode 100644 index c820c760d..000000000 --- a/codegen/plugins/client-codegen/src/main/resources/META-INF/services/software.amazon.smithy.java.codegen.JavaCodegenIntegration +++ /dev/null @@ -1 +0,0 @@ -software.amazon.smithy.java.codegen.client.integrations.javadoc.ClientJavadocExamplesIntegration diff --git a/codegen/plugins/client-codegen/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService b/codegen/plugins/client-codegen/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService deleted file mode 100644 index fb203a03e..000000000 --- a/codegen/plugins/client-codegen/src/test/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService +++ /dev/null @@ -1 +0,0 @@ -software.amazon.smithy.java.codegen.client.TestAuthSchemeTrait$Provider diff --git a/codegen/plugins/server-codegen/README.md b/codegen/plugins/server-codegen/README.md deleted file mode 100644 index e93e5b442..000000000 --- a/codegen/plugins/server-codegen/README.md +++ /dev/null @@ -1,2 +0,0 @@ -### codegen-server -Codegen plugin to generate Java server stubs from a Smithy model. diff --git a/codegen/plugins/server-codegen/build.gradle.kts b/codegen/plugins/server-codegen/build.gradle.kts deleted file mode 100644 index ce4198535..000000000 --- a/codegen/plugins/server-codegen/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("smithy-java.codegen-plugin-conventions") -} - -description = "This module provides the codegen plugin for Smithy java server codegen" - -extra["displayName"] = "Smithy :: Java :: Codegen :: Server" -extra["moduleName"] = "software.amazon.smithy.java.codegen.server" - -dependencies { - implementation(project(":server:server-core")) -} - -tasks.test { - failOnNoDiscoveredTests = false -} - -addGenerateSrcsTask("software.amazon.smithy.java.codegen.server.TestServerJavaCodegenRunner") diff --git a/codegen/plugins/server-codegen/src/it/resources/META-INF/smithy/manifest b/codegen/plugins/server-codegen/src/it/resources/META-INF/smithy/manifest deleted file mode 100644 index 4ca2fadcf..000000000 --- a/codegen/plugins/server-codegen/src/it/resources/META-INF/smithy/manifest +++ /dev/null @@ -1 +0,0 @@ -main.smithy diff --git a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/JavaServerCodegenPlugin.java b/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/JavaServerCodegenPlugin.java deleted file mode 100644 index ea12a56f6..000000000 --- a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/JavaServerCodegenPlugin.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.server; - -import software.amazon.smithy.build.PluginContext; -import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.codegen.core.directed.CodegenDirector; -import software.amazon.smithy.framework.transform.AddFrameworkErrorsTransform; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.DefaultTransforms; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.writer.JavaWriter; -import software.amazon.smithy.java.logging.InternalLogger; -import software.amazon.smithy.model.transform.ModelTransformer; -import software.amazon.smithy.utils.SmithyInternalApi; - -/** - * Plugin to execute Java server code generation. - */ -@SmithyInternalApi -public final class JavaServerCodegenPlugin implements SmithyBuildPlugin { - private static final InternalLogger LOGGER = InternalLogger.getLogger(JavaServerCodegenPlugin.class); - - @Override - public String getName() { - return "java-server-codegen"; - } - - @Override - public void execute(PluginContext context) { - CodegenDirector runner = - new CodegenDirector<>(); - - var settings = JavaCodegenSettings.fromNode(context.getSettings()); - LOGGER.info("Generating Smithy-Java server for service [{}]...", settings.service()); - runner.settings(settings); - runner.directedCodegen(new DirectedJavaServerCodegen()); - runner.fileManifest(context.getFileManifest()); - runner.service(settings.service()); - // TODO: use built-in once this has been upstreamed - var model = AddFrameworkErrorsTransform.transform(ModelTransformer.create(), context.getModel()); - runner.model(model); - runner.integrationClass(JavaCodegenIntegration.class); - DefaultTransforms.apply(runner, settings); - runner.run(); - LOGGER.info("Smithy-Java server code generation complete"); - } -} diff --git a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/ServiceJavaSymbolProvider.java b/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/ServiceJavaSymbolProvider.java deleted file mode 100644 index c36787d6b..000000000 --- a/codegen/plugins/server-codegen/src/main/java/software/amazon/smithy/java/codegen/server/ServiceJavaSymbolProvider.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.server; - -import static java.lang.String.format; - -import software.amazon.smithy.codegen.core.Symbol; -import software.amazon.smithy.java.codegen.CodegenUtils; -import software.amazon.smithy.java.codegen.JavaSymbolProvider; -import software.amazon.smithy.java.codegen.SymbolProperties; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.shapes.OperationShape; -import software.amazon.smithy.model.shapes.ServiceShape; -import software.amazon.smithy.utils.SmithyInternalApi; -import software.amazon.smithy.utils.StringUtils; - -/** - * Maps Smithy types to Java Symbols for server code generation. - */ -@SmithyInternalApi -public final class ServiceJavaSymbolProvider extends JavaSymbolProvider { - private final String serviceName; - - public ServiceJavaSymbolProvider(Model model, ServiceShape service, String packageNamespace, String serviceName) { - super(model, service, packageNamespace); - this.serviceName = serviceName; - } - - @Override - public Symbol operationShape(OperationShape operationShape) { - var baseSymbol = super.operationShape(operationShape); - String stubName = baseSymbol.getName() + "Operation"; - String asyncStubName = stubName + "Async"; - String operationFieldName = StringUtils.uncapitalize(baseSymbol.getName()); - var stubSymbol = Symbol.builder() - .name(stubName) - .putProperty(SymbolProperties.IS_PRIMITIVE, false) - .namespace(format("%s.service", packageNamespace()), ".") - .declarationFile(format("./%s/service/%s.java", packageNamespace().replace(".", "/"), stubName)) - .build(); - var asyncStubSymbol = Symbol.builder() - .name(asyncStubName) - .putProperty(SymbolProperties.IS_PRIMITIVE, false) - .namespace(format("%s.service", packageNamespace()), ".") - .declarationFile(format("./%s/service/%s.java", packageNamespace().replace(".", "/"), asyncStubName)) - .build(); - var apiOperationSymbol = super.operationShape(operationShape); - return baseSymbol.toBuilder() - .putProperty(SymbolProperties.IS_PRIMITIVE, false) - .putProperty(ServerSymbolProperties.OPERATION_FIELD_NAME, operationFieldName) - .putProperty(ServerSymbolProperties.ASYNC_STUB_OPERATION, asyncStubSymbol) - .putProperty(ServerSymbolProperties.STUB_OPERATION, stubSymbol) - .putProperty(ServerSymbolProperties.API_OPERATION, apiOperationSymbol) - .build(); - } - - @Override - public Symbol serviceShape(ServiceShape serviceShape) { - return getServerJavaClassSymbol(); - } - - private Symbol getServerJavaClassSymbol() { - return Symbol.builder() - .name(serviceName) - .putProperty(SymbolProperties.IS_PRIMITIVE, false) - .putProperty(SymbolProperties.SERVICE_EXCEPTION, - CodegenUtils.getServiceExceptionSymbol(packageNamespace(), serviceName)) - .putProperty(SymbolProperties.SERVICE_API_SERVICE, - CodegenUtils.getServiceApiSymbol(packageNamespace(), serviceName)) - .putProperty(ServerSymbolProperties.TYPES_NAMESPACE, format("%s.model", packageNamespace())) - .namespace(format("%s.service", packageNamespace()), ".") - .declarationFile(format("./%s/service/%s.java", packageNamespace().replace(".", "/"), serviceName)) - .build(); - } -} diff --git a/codegen/plugins/server-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin b/codegen/plugins/server-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin deleted file mode 100644 index 2193f7168..000000000 --- a/codegen/plugins/server-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin +++ /dev/null @@ -1 +0,0 @@ -software.amazon.smithy.java.codegen.server.JavaServerCodegenPlugin diff --git a/codegen/plugins/types-codegen/README.md b/codegen/plugins/types-codegen/README.md deleted file mode 100644 index f64c8a2d3..000000000 --- a/codegen/plugins/types-codegen/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### codegen-types -Codegen plugin to generate standalone "plain old Java objects" (POJOs) -from a Smithy model. diff --git a/codegen/plugins/types-codegen/build.gradle.kts b/codegen/plugins/types-codegen/build.gradle.kts deleted file mode 100644 index f4d3b0e25..000000000 --- a/codegen/plugins/types-codegen/build.gradle.kts +++ /dev/null @@ -1,14 +0,0 @@ -plugins { - id("smithy-java.codegen-plugin-conventions") -} - -description = "This module provides the codegen plugin for Smithy java type codegen" - -extra["displayName"] = "Smithy :: Java :: Codegen :: Types" -extra["moduleName"] = "software.amazon.smithy.java.codegen.types" - -dependencies { - testImplementation(project(":codegen:test-utils")) -} - -addGenerateSrcsTask("software.amazon.smithy.java.codegen.types.TestJavaTypeCodegenRunner") diff --git a/codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/manifest b/codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/manifest deleted file mode 100644 index 5884def3f..000000000 --- a/codegen/plugins/types-codegen/src/it/resources/META-INF/smithy/manifest +++ /dev/null @@ -1,3 +0,0 @@ -a.smithy -b.smithy -nested/c.smithy diff --git a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/DirectedJavaTypeCodegen.java b/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/DirectedJavaTypeCodegen.java deleted file mode 100644 index 87b8f0b4b..000000000 --- a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/DirectedJavaTypeCodegen.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.types; - -import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.codegen.core.directed.CreateContextDirective; -import software.amazon.smithy.codegen.core.directed.CreateSymbolProviderDirective; -import software.amazon.smithy.codegen.core.directed.CustomizeDirective; -import software.amazon.smithy.codegen.core.directed.DirectedCodegen; -import software.amazon.smithy.codegen.core.directed.GenerateEnumDirective; -import software.amazon.smithy.codegen.core.directed.GenerateErrorDirective; -import software.amazon.smithy.codegen.core.directed.GenerateIntEnumDirective; -import software.amazon.smithy.codegen.core.directed.GenerateListDirective; -import software.amazon.smithy.codegen.core.directed.GenerateMapDirective; -import software.amazon.smithy.codegen.core.directed.GenerateServiceDirective; -import software.amazon.smithy.codegen.core.directed.GenerateStructureDirective; -import software.amazon.smithy.codegen.core.directed.GenerateUnionDirective; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.JavaSymbolProvider; -import software.amazon.smithy.java.codegen.generators.EnumGenerator; -import software.amazon.smithy.java.codegen.generators.ListGenerator; -import software.amazon.smithy.java.codegen.generators.MapGenerator; -import software.amazon.smithy.java.codegen.generators.SchemaIndexGenerator; -import software.amazon.smithy.java.codegen.generators.SchemasGenerator; -import software.amazon.smithy.java.codegen.generators.SharedSerdeGenerator; -import software.amazon.smithy.java.codegen.generators.StructureGenerator; -import software.amazon.smithy.java.codegen.generators.UnionGenerator; -import software.amazon.smithy.java.codegen.types.generators.TypeMappingGenerator; -import software.amazon.smithy.java.logging.InternalLogger; -import software.amazon.smithy.model.shapes.Shape; -import software.amazon.smithy.utils.SmithyUnstableApi; - -@SmithyUnstableApi -final class DirectedJavaTypeCodegen - implements DirectedCodegen { - private static final InternalLogger LOGGER = InternalLogger.getLogger(DirectedJavaTypeCodegen.class); - - @Override - public CodeGenerationContext createContext( - CreateContextDirective directive - ) { - return new CodeGenerationContext(directive, "type"); - } - - @Override - public SymbolProvider createSymbolProvider(CreateSymbolProviderDirective directive) { - return new JavaSymbolProvider( - directive.model(), - directive.service(), - directive.settings().packageNamespace()); - } - - @Override - public void generateService(GenerateServiceDirective directive) { - // Type codegen does not generate a service. - } - - @Override - public void generateStructure(GenerateStructureDirective directive) { - if (!isSynthetic(directive.shape())) { - LOGGER.debug("Generating Java Class for structure: {}", directive.shape()); - new StructureGenerator<>().accept(directive); - } - } - - @Override - public void generateError(GenerateErrorDirective directive) { - new StructureGenerator<>().accept(directive); - } - - @Override - public void generateUnion(GenerateUnionDirective directive) { - new UnionGenerator().accept(directive); - } - - @Override - public void generateList(GenerateListDirective directive) { - new ListGenerator().accept(directive); - } - - @Override - public void generateMap(GenerateMapDirective directive) { - new MapGenerator().accept(directive); - } - - @Override - public void generateEnumShape(GenerateEnumDirective directive) { - new EnumGenerator<>().accept(directive); - } - - @Override - public void generateIntEnumShape(GenerateIntEnumDirective directive) { - new EnumGenerator<>().accept(directive); - } - - @Override - public void customizeBeforeIntegrations(CustomizeDirective directive) { - new SharedSerdeGenerator().accept(directive); - new SchemasGenerator().accept(directive); - new SchemaIndexGenerator().accept(directive); - } - - @Override - public void customizeAfterIntegrations(CustomizeDirective directive) { - new TypeMappingGenerator().accept(directive); - } - - private static boolean isSynthetic(Shape shape) { - return shape.getId().getNamespace().equals(SyntheticServiceTransform.SYNTHETIC_NAMESPACE); - } -} diff --git a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/JavaTypeCodegenPlugin.java b/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/JavaTypeCodegenPlugin.java deleted file mode 100644 index c012ce6cb..000000000 --- a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/JavaTypeCodegenPlugin.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.types; - -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; -import software.amazon.smithy.build.PluginContext; -import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.codegen.core.CodegenException; -import software.amazon.smithy.codegen.core.directed.CodegenDirector; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.DefaultTransforms; -import software.amazon.smithy.java.codegen.JavaCodegenIntegration; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.writer.JavaWriter; -import software.amazon.smithy.java.logging.InternalLogger; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.loader.Prelude; -import software.amazon.smithy.model.neighbor.Walker; -import software.amazon.smithy.model.shapes.Shape; -import software.amazon.smithy.utils.SmithyInternalApi; - -/** - * Plugin to execute Java type code generation. - */ -@SmithyInternalApi -public final class JavaTypeCodegenPlugin implements SmithyBuildPlugin { - private static final InternalLogger LOGGER = InternalLogger.getLogger(JavaTypeCodegenPlugin.class); - - @Override - public String getName() { - return "java-type-codegen"; - } - - @Override - public void execute(PluginContext context) { - LOGGER.info("Generating Java types from smithy model."); - CodegenDirector runner = - new CodegenDirector<>(); - - var settings = TypeCodegenSettings.fromNode(context.getSettings()); - var codegenSettings = settings.codegenSettings(); - runner.settings(codegenSettings); - runner.directedCodegen(new DirectedJavaTypeCodegen()); - runner.fileManifest(context.getFileManifest()); - runner.service(codegenSettings.service()); - - // Add the synthetic service to the model - var closure = getClosure(context.getModel(), settings); - LOGGER.info("Found {} shapes in generation closure", closure.size()); - var model = SyntheticServiceTransform.transform(context.getModel(), closure, settings.renames()); - runner.model(model); - runner.integrationClass(JavaCodegenIntegration.class); - DefaultTransforms.apply(runner, codegenSettings); - runner.run(); - LOGGER.info("Successfully generated Java class files."); - } - - private static Set getClosure(Model model, TypeCodegenSettings settings) { - Set closure = new HashSet<>(); - settings.shapes() - .stream() - .map(model::expectShape) - .forEach(closure::add); - settings.selector() - .shapes(model) - .filter(s -> !s.isMemberShape()) - .filter(s -> !Prelude.isPreludeShape(s)) - .forEach(closure::add); - - // Filter out any shapes from this closure that are contained by any other shapes in the closure - Walker walker = new Walker(model); - Set nested = new HashSet<>(); - for (Shape shape : closure) { - nested.addAll( - walker.walkShapes(shape) - .stream() - .filter(s -> !shape.equals(s)) - .filter(s -> !s.isMemberShape()) - .filter(s -> !Prelude.isPreludeShape(s)) - .filter(nested::contains) - .collect(Collectors.toSet())); - } - closure.removeAll(nested); - if (closure.isEmpty()) { - throw new CodegenException("Could not generate types. No shapes found in closure"); - } - LOGGER.info("Found {} shapes in generation closure.", closure.size()); - - return closure; - } -} diff --git a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/SyntheticServiceTransform.java b/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/SyntheticServiceTransform.java deleted file mode 100644 index 307cf7f86..000000000 --- a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/SyntheticServiceTransform.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.types; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import software.amazon.smithy.java.codegen.generators.SyntheticTrait; -import software.amazon.smithy.java.logging.InternalLogger; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.shapes.OperationShape; -import software.amazon.smithy.model.shapes.ServiceShape; -import software.amazon.smithy.model.shapes.Shape; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.shapes.StructureShape; -import software.amazon.smithy.model.traits.ErrorTrait; -import software.amazon.smithy.model.traits.PrivateTrait; -import software.amazon.smithy.model.transform.ModelTransformer; - -/** - * Generates a synthetic service for a set of shapes. - * - *

Adds a set of shapes to the closure of a synthetic service shape. Operations shapes are added directly - * to the service shape while all other shapes are added to the service via synthetic operations with synthetic inputs. - * - *

Directed codegen requires a root service shape to use for generating types. This service shape also - * provides renames for a set of shapes as well as the list of protocols the shapes should support. This - * transform creates a synthetic service that Directed codegen can use to generate the provided set of shapes. - */ -final class SyntheticServiceTransform { - private static final InternalLogger LOGGER = InternalLogger.getLogger(SyntheticServiceTransform.class); - static final String SYNTHETIC_NAMESPACE = "smithy.synthetic"; - static final ShapeId SYNTHETIC_SERVICE_ID = ShapeId.fromParts(SYNTHETIC_NAMESPACE, "TypesGenService"); - - static Model transform(Model model, Set closure, Map renames) { - - Set shapesToAdd = new HashSet<>(); - - ServiceShape.Builder serviceBuilder = ServiceShape.builder() - .id(SYNTHETIC_SERVICE_ID) - .addTrait(new SyntheticTrait()); - serviceBuilder.rename(renames); - - for (Shape shape : closure) { - switch (shape.getType()) { - case SERVICE, RESOURCE -> LOGGER.debug( - "Skipping service-associated shape {} for type codegen...", - shape); - case OPERATION -> serviceBuilder.addOperation(shape.asOperationShape().orElseThrow()); - case STRUCTURE, ENUM, INT_ENUM, UNION -> { - var syntheticInput = createSyntheticWrapper(shape, "Input"); - var syntheticOutput = createSyntheticWrapper(shape, "Output"); - shapesToAdd.add(syntheticInput); - shapesToAdd.add(syntheticOutput); - var syntheticOperation = createSyntheticOperation(syntheticInput, syntheticOutput); - shapesToAdd.add(syntheticOperation); - serviceBuilder.addOperation(syntheticOperation); - } - default -> { - // All other shapes are skipped with no logging as they should be - // implicitly added by aggregate shapes. - } - } - } - shapesToAdd.add(serviceBuilder.build()); - - return ModelTransformer.create().replaceShapes(model, shapesToAdd); - } - - private static OperationShape createSyntheticOperation(Shape shape, Shape syntheticOutput) { - var id = ShapeId.fromParts(SYNTHETIC_NAMESPACE, shape.getId().getName() + "Operation"); - var operationBuilder = OperationShape.builder() - .id(id) - .addTrait(new SyntheticTrait()) - .addTrait(new PrivateTrait()); - if (shape.hasTrait(ErrorTrait.class)) { - operationBuilder.addError(shape.toShapeId()); - } else { - operationBuilder.input(shape.toShapeId()); - } - operationBuilder.output(syntheticOutput.toShapeId()); - return operationBuilder.build(); - } - - private static StructureShape createSyntheticWrapper(Shape shape, String suffix) { - var id = ShapeId.fromParts(SYNTHETIC_NAMESPACE, shape.getId().getName() + suffix); - return StructureShape.builder() - .id(id) - .addTrait(new SyntheticTrait()) - .addMember("syntheticMember", shape.getId()) - .build(); - } -} diff --git a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/generators/TypeMappingGenerator.java b/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/generators/TypeMappingGenerator.java deleted file mode 100644 index bb4421345..000000000 --- a/codegen/plugins/types-codegen/src/main/java/software/amazon/smithy/java/codegen/types/generators/TypeMappingGenerator.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.codegen.types.generators; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; -import software.amazon.smithy.codegen.core.Symbol; -import software.amazon.smithy.codegen.core.directed.CustomizeDirective; -import software.amazon.smithy.java.codegen.CodeGenerationContext; -import software.amazon.smithy.java.codegen.JavaCodegenSettings; -import software.amazon.smithy.java.codegen.SymbolProperties; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.shapes.ShapeType; -import software.amazon.smithy.utils.SmithyInternalApi; - -@SmithyInternalApi -public final class TypeMappingGenerator - implements Consumer> { - private static final String PROPERTY_FILE = "META-INF/smithy-java/type-mappings.properties"; - private static final Set EXCLUDED_NAMESPACE = Set.of("smithy.synthetic", "smithy.api"); - private static final EnumSet GENERATED_TYPES = EnumSet.of( - ShapeType.STRUCTURE, - ShapeType.UNION, - ShapeType.ENUM, - ShapeType.INT_ENUM); - - @Override - public void accept(CustomizeDirective directive) { - Map symbolMap = new HashMap<>(); - - // Add all types within the synthetic service closure - for (var shape : directive.connectedShapes().values()) { - var shapeId = shape.getId(); - // only add mappings for shapes that generate a class - if (GENERATED_TYPES.contains(shape.getType()) && !EXCLUDED_NAMESPACE.contains(shapeId.getNamespace())) { - var symbol = directive.symbolProvider().toSymbol(shape); - // Skip any external types used in this package - if (symbol.getProperty(SymbolProperties.EXTERNAL_TYPE).isPresent()) { - continue; - } - symbolMap.put(shapeId, symbol); - } - } - - if (symbolMap.isEmpty()) { - return; - } - - directive.context().writerDelegator().useFileWriter(PROPERTY_FILE, writer -> { - // Add a helpful header - writer.writeWithNoFormatting(""" - # This file maps Smithy shape ID's to concrete java class implementations - # WARNING: This file is code generated. Do not modify by hand. - """); - for (var entry : symbolMap.entrySet()) { - writer.write("$L=$L", entry.getKey(), entry.getValue()); - } - }); - } -} diff --git a/codegen/plugins/types-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin b/codegen/plugins/types-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin deleted file mode 100644 index 92fdf5add..000000000 --- a/codegen/plugins/types-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin +++ /dev/null @@ -1 +0,0 @@ -software.amazon.smithy.java.codegen.types.JavaTypeCodegenPlugin diff --git a/core/src/main/java/software/amazon/smithy/java/core/schema/DeferredRootSchema.java b/core/src/main/java/software/amazon/smithy/java/core/schema/DeferredRootSchema.java index 854de4aee..9bd2048ba 100644 --- a/core/src/main/java/software/amazon/smithy/java/core/schema/DeferredRootSchema.java +++ b/core/src/main/java/software/amazon/smithy/java/core/schema/DeferredRootSchema.java @@ -33,9 +33,10 @@ final class DeferredRootSchema extends Schema { Set stringEnumValues, Set intEnumValues, Supplier> builderSupplier, - SchemaBuilder schemaBuilder + SchemaBuilder schemaBuilder, + Class shapeClass ) { - super(type, id, traits, memberBuilders, stringEnumValues, builderSupplier); + super(type, id, traits, memberBuilders, stringEnumValues, builderSupplier, shapeClass); this.stringEnumValues = Collections.unmodifiableSet(stringEnumValues); this.intEnumValues = Collections.unmodifiableSet(intEnumValues); this.memberBuilders = memberBuilders; diff --git a/core/src/main/java/software/amazon/smithy/java/core/schema/ResolvedRootSchema.java b/core/src/main/java/software/amazon/smithy/java/core/schema/ResolvedRootSchema.java index b54b5821a..283455e13 100644 --- a/core/src/main/java/software/amazon/smithy/java/core/schema/ResolvedRootSchema.java +++ b/core/src/main/java/software/amazon/smithy/java/core/schema/ResolvedRootSchema.java @@ -26,7 +26,8 @@ final class ResolvedRootSchema extends Schema { deferredRootSchema.traits, deferredRootSchema.memberBuilders, deferredRootSchema.stringEnumValues, - deferredRootSchema.shapeBuilder); + deferredRootSchema.shapeBuilder, + deferredRootSchema.shapeClass); var resolvedMembers = deferredRootSchema.resolvedMembers(); this.memberList = resolvedMembers.memberList(); this.requiredMemberCount = resolvedMembers.requiredMemberCount(); diff --git a/core/src/main/java/software/amazon/smithy/java/core/schema/RootSchema.java b/core/src/main/java/software/amazon/smithy/java/core/schema/RootSchema.java index e7f694e0b..f6665f1eb 100644 --- a/core/src/main/java/software/amazon/smithy/java/core/schema/RootSchema.java +++ b/core/src/main/java/software/amazon/smithy/java/core/schema/RootSchema.java @@ -49,9 +49,10 @@ private static Set detectEnumTraitValues(ShapeType type, TraitMap traits List memberBuilders, Set stringEnumValues, Set intEnumValues, - Supplier> builderSupplier + Supplier> builderSupplier, + Class shapeClass ) { - super(type, id, traits, memberBuilders, stringEnumValues, builderSupplier); + super(type, id, traits, memberBuilders, stringEnumValues, builderSupplier, shapeClass); this.stringEnumValues = Collections.unmodifiableSet(stringEnumValues); this.intEnumValues = Collections.unmodifiableSet(intEnumValues); @@ -74,6 +75,18 @@ private static Set detectEnumTraitValues(ShapeType type, TraitMap traits } } + RootSchema( + ShapeType type, + ShapeId id, + TraitMap traits, + List memberBuilders, + Set stringEnumValues, + Set intEnumValues, + Supplier> builderSupplier + ) { + this(type, id, traits, memberBuilders, stringEnumValues, intEnumValues, builderSupplier, null); + } + RootSchema( ShapeType type, ShapeId id, @@ -82,7 +95,7 @@ private static Set detectEnumTraitValues(ShapeType type, TraitMap traits Set stringEnumValues, Set intEnumValues ) { - this(type, id, traits, memberBuilders, stringEnumValues, intEnumValues, null); + this(type, id, traits, memberBuilders, stringEnumValues, intEnumValues, null, null); } @Override diff --git a/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java b/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java index f52af6228..0bf34de4a 100644 --- a/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java +++ b/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java @@ -64,6 +64,8 @@ public abstract sealed class Schema implements MemberLookup final Supplier> shapeBuilder; + final Class shapeClass; + private final int hash; Schema( @@ -72,13 +74,15 @@ public abstract sealed class Schema implements MemberLookup TraitMap traits, List members, Set stringEnumValues, - Supplier> shapeBuilder + Supplier> shapeBuilder, + Class shapeClass ) { this.type = type; this.id = id; this.traits = traits; this.memberName = null; this.shapeBuilder = shapeBuilder; + this.shapeClass = shapeClass; // Structure shapes need to sort members so that required members come before optional members. if (type == ShapeType.STRUCTURE) { @@ -118,7 +122,7 @@ public abstract sealed class Schema implements MemberLookup List members, Set stringEnumValues ) { - this(type, id, traits, members, stringEnumValues, null); + this(type, id, traits, members, stringEnumValues, null, null); } Schema(MemberSchemaBuilder builder) { @@ -129,6 +133,7 @@ public abstract sealed class Schema implements MemberLookup this.memberIndex = builder.memberIndex; this.isRequiredByValidation = builder.isRequiredByValidation; this.shapeBuilder = null; + this.shapeClass = null; this.minLengthConstraint = builder.validationState.minLengthConstraint(); this.maxLengthConstraint = builder.validationState.maxLengthConstraint(); @@ -180,6 +185,18 @@ public static Schema createIntEnum(ShapeId id, Set values, Trait... tra values); } + public static Schema createIntEnum(ShapeId id, Set values, Class shapeClass, Trait... traits) { + return new RootSchema( + ShapeType.INT_ENUM, + id, + TraitMap.create(traits), + Collections.emptyList(), + Collections.emptySet(), + values, + null, + shapeClass); + } + public static Schema createLong(ShapeId id, Trait... traits) { return new RootSchema(ShapeType.LONG, id, TraitMap.create(traits)); } @@ -214,6 +231,18 @@ public static Schema createEnum(ShapeId id, Set values, Trait... traits) Collections.emptySet()); } + public static Schema createEnum(ShapeId id, Set values, Class shapeClass, Trait... traits) { + return new RootSchema( + ShapeType.ENUM, + id, + TraitMap.create(traits), + Collections.emptyList(), + values, + Collections.emptySet(), + null, + shapeClass); + } + public static Schema createBlob(ShapeId id, Trait... traits) { return new RootSchema(ShapeType.BLOB, id, TraitMap.create(traits)); } @@ -481,13 +510,22 @@ public final Schema mapValueMember() { * * @return A new shape builder for this schema. */ - public final ShapeBuilder shapeBuilder() { + public final ShapeBuilder shapeBuilder() { if (shapeBuilder == null) { throw new IllegalStateException("Schema does not have a shape builder"); } return shapeBuilder.get(); } + /** + * Get the Java class associated with this schema, if any. + * + * @return the shape class, or null if not set. + */ + public final Class shapeClass() { + return shapeClass; + } + /** * Get the allowed values of the string. * diff --git a/core/src/main/java/software/amazon/smithy/java/core/schema/SchemaBuilder.java b/core/src/main/java/software/amazon/smithy/java/core/schema/SchemaBuilder.java index eaa7febe7..cb1d61e01 100644 --- a/core/src/main/java/software/amazon/smithy/java/core/schema/SchemaBuilder.java +++ b/core/src/main/java/software/amazon/smithy/java/core/schema/SchemaBuilder.java @@ -35,6 +35,7 @@ public final class SchemaBuilder { final TraitMap traits; final List members; private Supplier> builderSupplier; + private Class shapeClass; private Schema builtShape; SchemaBuilder(ShapeId id, ShapeType type, Trait... traits) { @@ -86,6 +87,17 @@ public SchemaBuilder builderSupplier(Supplier> builderSupplier) return this; } + /** + * Sets the Java class associated with this schema's shape. + * + * @param shapeClass The class for this schema's shape. + * @return the builder. + */ + public SchemaBuilder shapeClass(Class shapeClass) { + this.shapeClass = shapeClass; + return this; + } + private SchemaBuilder putMember(String name, MemberSchemaBuilder builder) { if (builtShape != null) { throw new IllegalStateException("Cannot add a member to an already built builder"); @@ -155,7 +167,8 @@ public Schema build() { Set.of(), Set.of(), builderSupplier, - this); + this, + shapeClass); } else { builtShape = new RootSchema( type, @@ -164,7 +177,8 @@ public Schema build() { new ArrayList<>(members), Set.of(), Set.of(), - builderSupplier); + builderSupplier, + shapeClass); } return builtShape; diff --git a/examples/basic-server/build.gradle.kts b/examples/basic-server/build.gradle.kts index 9d5b6e67a..7e2b7ff85 100644 --- a/examples/basic-server/build.gradle.kts +++ b/examples/basic-server/build.gradle.kts @@ -7,7 +7,8 @@ plugins { dependencies { val smithyJavaVersion: String by project - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:server-api:$smithyJavaVersion") implementation("software.amazon.smithy.java:server-netty:$smithyJavaVersion") implementation("software.amazon.smithy.java:aws-server-restjson:$smithyJavaVersion") @@ -20,7 +21,7 @@ application { // Add generated Java files to the main sourceSet afterEvaluate { - val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen") + val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/examples/basic-server/smithy-build.json b/examples/basic-server/smithy-build.json index d9eb81ee5..8324c36e9 100644 --- a/examples/basic-server/smithy-build.json +++ b/examples/basic-server/smithy-build.json @@ -1,10 +1,11 @@ { "version": "1.0", "plugins": { - "java-server-codegen": { + "java-codegen": { "service": "smithy.example#BeerService", "namespace": "software.amazon.smithy.java.server.example", - "headerFile": "license.txt" + "headerFile": "license.txt", + "modes": ["server"] } } } diff --git a/examples/dynamodb-client/build.gradle.kts b/examples/dynamodb-client/build.gradle.kts index f5c311e54..1eff25ffb 100644 --- a/examples/dynamodb-client/build.gradle.kts +++ b/examples/dynamodb-client/build.gradle.kts @@ -7,7 +7,8 @@ plugins { dependencies { val smithyJavaVersion: String by project - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:client-api:$smithyJavaVersion") implementation("software.amazon.smithy.java:aws-client-awsjson:$smithyJavaVersion") implementation("software.amazon.smithy.java:client-core:$smithyJavaVersion") @@ -16,7 +17,7 @@ dependencies { // Add generated Java sources to the main sourceset afterEvaluate { - val clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-client-codegen") + val clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets.main.get().java.srcDir(clientPath) } diff --git a/examples/dynamodb-client/smithy-build.json b/examples/dynamodb-client/smithy-build.json index 101b3fa46..fab3cb0fa 100644 --- a/examples/dynamodb-client/smithy-build.json +++ b/examples/dynamodb-client/smithy-build.json @@ -1,7 +1,7 @@ { "version": "1.0", "plugins": { - "java-client-codegen": { + "java-codegen": { "service": "com.amazonaws.dynamodb#DynamoDB_20120810", "name": "DynamoDB", "namespace": "software.amazon.smithy.java.example.dynamodb", @@ -11,7 +11,8 @@ ], "transport": { "http-java": {} - } + }, + "modes": ["client"] } } } diff --git a/examples/end-to-end/build.gradle.kts b/examples/end-to-end/build.gradle.kts index 6e28437af..f8475240b 100644 --- a/examples/end-to-end/build.gradle.kts +++ b/examples/end-to-end/build.gradle.kts @@ -11,7 +11,9 @@ application { dependencies { val smithyJavaVersion: String by project - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:client-api:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:server-api:$smithyJavaVersion") // Server dependencies implementation("software.amazon.smithy.java:server-netty:$smithyJavaVersion") @@ -28,13 +30,11 @@ dependencies { // Add generated Java sources to the main sourceset afterEvaluate { - val clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-client-codegen") - val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen") + val codegenPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { - srcDir(clientPath) - srcDir(serverPath) + srcDir(codegenPath) } } create("it") { diff --git a/examples/end-to-end/smithy-build.json b/examples/end-to-end/smithy-build.json index 4d19eae1c..208425952 100644 --- a/examples/end-to-end/smithy-build.json +++ b/examples/end-to-end/smithy-build.json @@ -1,17 +1,12 @@ { "version": "1.0", "plugins": { - "java-client-codegen": { + "java-codegen": { "service": "com.example#CoffeeShop", "namespace": "software.amazon.smithy.java.example.etoe", "headerFile": "license.txt", - "protocol": "aws.protocols#restJson1" - }, - "java-server-codegen": { - "service": "com.example#CoffeeShop", - "namespace": "software.amazon.smithy.java.example.etoe", - "headerFile": "license.txt", - "useExternalTypes": true + "protocol": "aws.protocols#restJson1", + "modes": ["client", "server"] } } } diff --git a/examples/event-streaming-client/build.gradle.kts b/examples/event-streaming-client/build.gradle.kts index 65954ca27..69ead6e69 100644 --- a/examples/event-streaming-client/build.gradle.kts +++ b/examples/event-streaming-client/build.gradle.kts @@ -7,7 +7,8 @@ plugins { dependencies { val smithyJavaVersion: String by project - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:client-api:$smithyJavaVersion") implementation("software.amazon.smithy.java:aws-client-restjson:$smithyJavaVersion") implementation("software.amazon.smithy.java:client-core:$smithyJavaVersion") implementation("software.amazon.smithy.java:client-rpcv2-cbor:${smithyJavaVersion}") @@ -20,7 +21,7 @@ dependencies { // Add generated Java sources to the main sourceset afterEvaluate { - val clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-client-codegen") + val clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/examples/event-streaming-client/smithy-build.json b/examples/event-streaming-client/smithy-build.json index f1fba2422..b2da347a7 100644 --- a/examples/event-streaming-client/smithy-build.json +++ b/examples/event-streaming-client/smithy-build.json @@ -1,10 +1,11 @@ { "version": "1.0", "plugins": { - "java-client-codegen": { + "java-codegen": { "service": "smithy.example.eventstreaming#FizzBuzzService", "namespace": "software.amazon.smithy.java.example.eventstreaming", - "protocol": "aws.protocols#restJson1" + "protocol": "aws.protocols#restJson1", + "modes": ["client"] } } } diff --git a/examples/lambda/build.gradle.kts b/examples/lambda/build.gradle.kts index ea1567fd3..e96975755 100644 --- a/examples/lambda/build.gradle.kts +++ b/examples/lambda/build.gradle.kts @@ -9,7 +9,8 @@ dependencies { annotationProcessor("com.google.auto.service:auto-service:1.1.1") compileOnly("com.google.auto.service:auto-service:1.1.1") - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:server-api:$smithyJavaVersion") implementation("software.amazon.smithy.java:aws-lambda-endpoint:$smithyJavaVersion") implementation("software.amazon.smithy.java:server-api:$smithyJavaVersion") @@ -36,7 +37,7 @@ tasks { // Add generated Java files to the main sourceSet afterEvaluate { - val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen") + val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/examples/lambda/smithy-build.json b/examples/lambda/smithy-build.json index 21a2c41c2..9cb39d3c3 100644 --- a/examples/lambda/smithy-build.json +++ b/examples/lambda/smithy-build.json @@ -1,9 +1,10 @@ { "version": "1.0", "plugins": { - "java-server-codegen": { + "java-codegen": { "service": "smithy.example#BeerService", - "namespace": "software.amazon.smithy.java.example.lambda" + "namespace": "software.amazon.smithy.java.example.lambda", + "modes": ["server"] } } } diff --git a/examples/mcp-server/build.gradle.kts b/examples/mcp-server/build.gradle.kts index 8a6da9bdb..1a4133d48 100644 --- a/examples/mcp-server/build.gradle.kts +++ b/examples/mcp-server/build.gradle.kts @@ -9,7 +9,8 @@ plugins { dependencies { val smithyJavaVersion: String by project - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:server-api:$smithyJavaVersion") implementation("software.amazon.smithy.java:smithy-ai-traits:$smithyJavaVersion") implementation("software.amazon.smithy.java:mcp-server:$smithyJavaVersion") implementation("software.amazon.smithy.java:server-proxy:$smithyJavaVersion") @@ -18,12 +19,11 @@ dependencies { implementation("software.amazon.smithy.java:aws-client-restjson:$smithyJavaVersion") implementation("software.amazon.smithy.java:aws-client-awsjson:$smithyJavaVersion") implementation("software.amazon.smithy.java:aws-service-bundle:$smithyJavaVersion") - implementation("software.amazon.smithy.java:mcp-bundle-api:$smithyJavaVersion") } // Add generated Java files to the main sourceSet afterEvaluate { - val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen") + val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/examples/mcp-server/smithy-build.json b/examples/mcp-server/smithy-build.json index e85439ec0..cffa8acce 100644 --- a/examples/mcp-server/smithy-build.json +++ b/examples/mcp-server/smithy-build.json @@ -2,11 +2,12 @@ "version": "1.0", "sources" : ["src/main/resources/software/amazon/smithy/java/example/server/mcp"], "plugins": { - "java-server-codegen": { + "java-codegen": { "service": "smithy.example.mcp#EmployeeService", "namespace": "software.amazon.smithy.java.example.server.mcp", "headerFile": "license.txt", - "runtimeTraits": ["smithy.api#documentation", "smithy.api#examples", "smithy.ai#prompts" ] + "runtimeTraits": ["smithy.api#documentation", "smithy.api#examples", "smithy.ai#prompts" ], + "modes": ["server"] } } } diff --git a/examples/mcp-server/src/main/java/software/amazon/smithy/java/example/server/mcp/BundleMCPServerExample.java b/examples/mcp-server/src/main/java/software/amazon/smithy/java/example/server/mcp/BundleMCPServerExample.java deleted file mode 100644 index 9223fdfaf..000000000 --- a/examples/mcp-server/src/main/java/software/amazon/smithy/java/example/server/mcp/BundleMCPServerExample.java +++ /dev/null @@ -1,41 +0,0 @@ -package software.amazon.smithy.java.example.server.mcp; - -import software.amazon.smithy.java.json.JsonCodec; -import software.amazon.smithy.java.mcp.server.McpServer; -import software.amazon.smithy.mcp.bundle.api.model.Bundle; -import software.amazon.smithy.mcp.bundle.api.McpBundles; - -import java.util.Objects; - -public final class BundleMCPServerExample { - public static void main(String[] args) throws Exception { - try { - var bundle = loadBundle("dynamodb.json"); - var mcpServer = McpServer.builder() - .stdio() - .name("smithy-mcp-server") - .addService("dynamodb-mcp", McpBundles.getService(bundle.getValue())) - .build(); - - mcpServer.start(); - - try { - Thread.currentThread().join(); - } catch (InterruptedException e) { - mcpServer.shutdown().join(); - } - } catch (Throwable t) { - t.printStackTrace(); - System.exit(1); - } - } - - private static Bundle loadBundle(String name) throws Exception { - var codec = JsonCodec.builder().build(); - var payload = Objects.requireNonNull(BundleMCPServerExample.class.getResourceAsStream(name), - "no bundle named " + name).readAllBytes(); - try (var reader = codec.createDeserializer(payload)) { - return Bundle.builder().deserialize(reader).build(); - } - } -} \ No newline at end of file diff --git a/examples/mcp-traits-example/build.gradle.kts b/examples/mcp-traits-example/build.gradle.kts index 86bb0177c..742febb90 100644 --- a/examples/mcp-traits-example/build.gradle.kts +++ b/examples/mcp-traits-example/build.gradle.kts @@ -11,7 +11,7 @@ dependencies { implementation(project(":smithy-ai-traits")) // Standard Smithy dependencies - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") implementation("software.amazon.smithy:smithy-model:$smithyVersion") } diff --git a/examples/restjson-client/build.gradle.kts b/examples/restjson-client/build.gradle.kts index e708045fc..25ca8468b 100644 --- a/examples/restjson-client/build.gradle.kts +++ b/examples/restjson-client/build.gradle.kts @@ -8,7 +8,8 @@ plugins { dependencies { val smithyJavaVersion: String by project - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:client-api:$smithyJavaVersion") implementation("software.amazon.smithy.java:client-core:$smithyJavaVersion") api("software.amazon.smithy.java:aws-client-restjson:$smithyJavaVersion") @@ -24,7 +25,7 @@ application { // Add generated Java sources to the main sourceset afterEvaluate { - val clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-client-codegen") + val clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/examples/restjson-client/smithy-build.json b/examples/restjson-client/smithy-build.json index 39f1580d1..b5f934167 100644 --- a/examples/restjson-client/smithy-build.json +++ b/examples/restjson-client/smithy-build.json @@ -1,14 +1,15 @@ { "version": "1.0", "plugins": { - "java-client-codegen": { + "java-codegen": { "service": "smithy.example#PersonDirectory", "namespace": "software.amazon.smithy.java.example.restjson", "headerFile": "license.txt", "protocol": "aws.protocols#restJson1", "transport": { "http-java": {} - } + }, + "modes": ["client"] } } } diff --git a/examples/standalone-types/build.gradle.kts b/examples/standalone-types/build.gradle.kts index e6f635715..6ade3faf1 100644 --- a/examples/standalone-types/build.gradle.kts +++ b/examples/standalone-types/build.gradle.kts @@ -7,7 +7,7 @@ plugins { dependencies { val smithyJavaVersion: String by project - smithyBuild("software.amazon.smithy.java:plugins:$smithyJavaVersion") + smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion") api("software.amazon.smithy.java:core:$smithyJavaVersion") api("software.amazon.smithy.java:framework-errors:$smithyJavaVersion") @@ -18,7 +18,7 @@ dependencies { } afterEvaluate { - val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-type-codegen") + val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/examples/standalone-types/smithy-build.json b/examples/standalone-types/smithy-build.json index e25ec31df..c28581d8e 100644 --- a/examples/standalone-types/smithy-build.json +++ b/examples/standalone-types/smithy-build.json @@ -1,9 +1,10 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { + "java-codegen": { "namespace": "software.amazon.smithy.java.example.standalone", - "headerFile": "license.txt" + "headerFile": "license.txt", + "modes": ["types"] } } } diff --git a/framework-errors/build.gradle.kts b/framework-errors/build.gradle.kts index 8d880d220..e46475d70 100644 --- a/framework-errors/build.gradle.kts +++ b/framework-errors/build.gradle.kts @@ -9,7 +9,7 @@ extra["displayName"] = "Smithy :: Framework Errors" extra["moduleName"] = "software.amazon.smithy.framework" dependencies { - smithyBuild(project(":codegen:plugins:types-codegen")) + smithyBuild(project(":codegen:codegen-plugin")) api(project(":core")) // Validation error is imported separately, b/c it is used a bit uniquely in protocol tests. @@ -21,7 +21,7 @@ dependencies { // Add generated Java sources to the main sourceSet afterEvaluate { - val typesPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-type-codegen") + val typesPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/framework-errors/smithy-build.json b/framework-errors/smithy-build.json index a8ac36012..3192fe94d 100644 --- a/framework-errors/smithy-build.json +++ b/framework-errors/smithy-build.json @@ -1,13 +1,14 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { + "java-codegen": { "namespace": "software.amazon.smithy.java.framework", "selector": "[id|namespace = 'smithy.framework']", // Include all traits in generated models as we do not know which // protocol will be used. This will not add any additional dependencies // as all traits on framework errors are prelude traits. - "runtimeTraitsSelector": "*" + "runtimeTraitsSelector": "*", + "modes": ["types"] } } } diff --git a/fuzz-test-harness/build.gradle.kts b/fuzz-test-harness/build.gradle.kts index 01a79497f..6eeb6ee21 100644 --- a/fuzz-test-harness/build.gradle.kts +++ b/fuzz-test-harness/build.gradle.kts @@ -9,7 +9,7 @@ extra["displayName"] = "Smithy :: Java :: Fuzz Test Harness" extra["moduleName"] = "software.amazon.smithy.java.fuzz" dependencies { - smithyBuild(project(":codegen:plugins:types-codegen")) + smithyBuild(project(":codegen:codegen-plugin")) implementation(project(":core")) implementation(project(":logging")) @@ -28,7 +28,7 @@ dependencies { } afterEvaluate { - val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-type-codegen") + val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/fuzz-test-harness/smithy-build.json b/fuzz-test-harness/smithy-build.json index 10ec710a7..1310ce1be 100644 --- a/fuzz-test-harness/smithy-build.json +++ b/fuzz-test-harness/smithy-build.json @@ -1,9 +1,10 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { + "java-codegen": { "namespace": "software.smithy.fuzz.test", - "useExternalTypes": true + "useExternalTypes": true, + "modes": ["types"] } } } diff --git a/mcp/mcp-schemas/build.gradle.kts b/mcp/mcp-schemas/build.gradle.kts index 43f782811..ac62e146d 100644 --- a/mcp/mcp-schemas/build.gradle.kts +++ b/mcp/mcp-schemas/build.gradle.kts @@ -12,9 +12,10 @@ dependencies { api(project(":core")) api(libs.smithy.model) api(project(":server:server-api")) + api(project(":framework-errors")) api(project(":smithy-ai-traits")) - smithyBuild(project(":codegen:plugins:types-codegen")) - smithyBuild(project(":codegen:plugins:server-codegen")) + smithyBuild(project(":codegen:codegen-plugin")) + smithyBuild(project(":server:server-api")) smithyBuild(libs.smithy.traitcodegen) } @@ -27,20 +28,17 @@ sourceSets { } afterEvaluate { - val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-type-codegen") - val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen") + val codegenPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") val traitsPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "trait-codegen") sourceSets { main { java { - srcDir(typePath) - srcDir(serverPath) + srcDir(codegenPath) srcDir(traitsPath) include("software/**") } resources { - srcDir(typePath) - srcDir(serverPath) + srcDir(codegenPath) srcDir(traitsPath) exclude("**/*.java") exclude("META-INF/services/**") // Exclude original service files, use merged ones instead @@ -71,8 +69,7 @@ val serviceFilesMerger = // Use hardcoded paths because of https://docs.gradle.org/8.14.3/userguide/configuration_cache.html#config_cache:requirements:disallowed_types val sourceServiceDirs = listOf( - File(projectDir, "build/smithyprojections/mcp-schemas/source/java-type-codegen/META-INF/services"), - File(projectDir, "build/smithyprojections/mcp-schemas/source/java-server-codegen/META-INF/services"), + File(projectDir, "build/smithyprojections/mcp-schemas/source/java-codegen/META-INF/services"), File(projectDir, "build/smithyprojections/mcp-schemas/source/trait-codegen/META-INF/services"), ) diff --git a/mcp/mcp-schemas/smithy-build.json b/mcp/mcp-schemas/smithy-build.json index 2c876495e..e53ed9bd7 100644 --- a/mcp/mcp-schemas/smithy-build.json +++ b/mcp/mcp-schemas/smithy-build.json @@ -2,16 +2,12 @@ "version": "1.0", "sources": ["model"], "plugins": { - "java-type-codegen": { - "namespace": "software.amazon.smithy.java.mcp", - "headerFile": "license.txt", - "runtimeTraits": ["smithy.api#documentation", "smithy.api#examples", "smithy.mcp#oneOf" ] - }, - "java-server-codegen": { + "java-codegen": { "service": "smithy.mcp.toolassistant#ToolAssistant", - "namespace": "software.amazon.smithy.java.mcp.toolassistant", + "namespace": "software.amazon.smithy.java.mcp", "headerFile": "license.txt", - "runtimeTraits": ["smithy.api#documentation", "smithy.api#examples", "smithy.ai#prompts", "smithy.mcp#oneOf" ] + "runtimeTraits": ["smithy.api#documentation", "smithy.api#examples", "smithy.ai#prompts", "smithy.mcp#oneOf" ], + "modes": ["server", "types"] }, "trait-codegen": { "package": "software.amazon.smithy.java.mcp", diff --git a/mcp/mcp-server/build.gradle.kts b/mcp/mcp-server/build.gradle.kts index f57ec5f0e..4d760994b 100644 --- a/mcp/mcp-server/build.gradle.kts +++ b/mcp/mcp-server/build.gradle.kts @@ -23,7 +23,7 @@ dependencies { testRuntimeOnly(project(":aws:client:aws-client-awsjson")) testImplementation(project(":server:server-proxy")) - testImplementation(project(":codegen:plugins:server-codegen")) + testImplementation(project(":codegen:codegen-plugin")) testImplementation(libs.json.schema.validator) } diff --git a/mcp/mcp-server/src/test/java/software/amazon/smithy/java/mcp/server/utils/TestJavaCodegenRunner.java b/mcp/mcp-server/src/test/java/software/amazon/smithy/java/mcp/server/utils/TestJavaCodegenRunner.java index 0422359cb..429a929a8 100644 --- a/mcp/mcp-server/src/test/java/software/amazon/smithy/java/mcp/server/utils/TestJavaCodegenRunner.java +++ b/mcp/mcp-server/src/test/java/software/amazon/smithy/java/mcp/server/utils/TestJavaCodegenRunner.java @@ -15,8 +15,9 @@ import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.build.PluginContext; import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.java.codegen.server.JavaServerCodegenPlugin; +import software.amazon.smithy.java.codegen.JavaCodegenPlugin; import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.node.ArrayNode; import software.amazon.smithy.model.node.ObjectNode; /** @@ -28,7 +29,7 @@ private TestJavaCodegenRunner() { } public static void main(String[] args) { - SmithyBuildPlugin plugin = new JavaServerCodegenPlugin(); + SmithyBuildPlugin plugin = new JavaCodegenPlugin(); Model model = Model.assembler(TestJavaCodegenRunner.class.getClassLoader()) .discoverModels(TestJavaCodegenRunner.class.getClassLoader()) .assemble() @@ -39,6 +40,7 @@ public static void main(String[] args) { ObjectNode.builder() .withMember("service", "smithy.java.mcp.test#TestService") .withMember("namespace", "software.amazon.smithy.java.mcp.test") + .withMember("modes", ArrayNode.fromStrings("server")) .withMember("runtimeTraits", fromStrings("smithy.api#documentation", "smithy.api#examples", diff --git a/model-bundle/model-bundle-api/build.gradle.kts b/model-bundle/model-bundle-api/build.gradle.kts index 4ae3f2d54..0b1848ba9 100644 --- a/model-bundle/model-bundle-api/build.gradle.kts +++ b/model-bundle/model-bundle-api/build.gradle.kts @@ -10,7 +10,7 @@ extra["displayName"] = "Smithy :: Java :: Model Bundle" extra["moduleName"] = "software.amazon.smithy.java.modelbundle.api" dependencies { - smithyBuild(project(":codegen:plugins:types-codegen")) + smithyBuild(project(":codegen:codegen-plugin")) implementation(project(":core")) implementation(project(":logging")) @@ -23,7 +23,7 @@ dependencies { } afterEvaluate { - val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-type-codegen") + val typePath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen") sourceSets { main { java { diff --git a/model-bundle/model-bundle-api/smithy-build.json b/model-bundle/model-bundle-api/smithy-build.json index 5a78c012c..6b0627b1c 100644 --- a/model-bundle/model-bundle-api/smithy-build.json +++ b/model-bundle/model-bundle-api/smithy-build.json @@ -1,9 +1,10 @@ { "version": "1.0", "plugins": { - "java-type-codegen": { + "java-codegen": { "namespace": "software.amazon.smithy.modelbundle.api", - "headerFile": "license.txt" + "headerFile": "license.txt", + "modes": ["types"] } } } \ No newline at end of file diff --git a/protocol-test-harness/build.gradle.kts b/protocol-test-harness/build.gradle.kts index b160d7c45..bf35d7522 100644 --- a/protocol-test-harness/build.gradle.kts +++ b/protocol-test-harness/build.gradle.kts @@ -11,8 +11,7 @@ extra["moduleName"] = "software.amazon.smithy.java.protocoltests" dependencies { implementation(project(":logging")) - implementation(project(":codegen:plugins")) - implementation(project(":codegen:codegen-core")) + implementation(project(":codegen:codegen-plugin")) implementation(libs.smithy.codegen) implementation(project(":client:client-core")) implementation(libs.smithy.protocol.test.traits) diff --git a/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/generators/ProtocolTestGenerator.java b/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/generators/ProtocolTestGenerator.java index 81ce894db..e29da4a24 100644 --- a/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/generators/ProtocolTestGenerator.java +++ b/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/generators/ProtocolTestGenerator.java @@ -10,9 +10,9 @@ import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.build.PluginContext; import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.java.codegen.client.JavaClientCodegenPlugin; -import software.amazon.smithy.java.codegen.server.JavaServerCodegenPlugin; +import software.amazon.smithy.java.codegen.JavaCodegenPlugin; import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.node.ArrayNode; import software.amazon.smithy.model.node.ObjectNode; import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.utils.SmithyInternalApi; @@ -21,11 +21,7 @@ public final class ProtocolTestGenerator { public static void main(String[] args) { String mode = Objects.requireNonNull(System.getenv("mode")); - SmithyBuildPlugin plugin = switch (mode) { - case "client" -> new JavaClientCodegenPlugin(); - case "server" -> new JavaServerCodegenPlugin(); - default -> throw new IllegalStateException("Unknown mode '" + mode + "'. Expect 'client' or 'server'."); - }; + SmithyBuildPlugin plugin = new JavaCodegenPlugin(); Model model = Model.assembler(ProtocolTestGenerator.class.getClassLoader()) .discoverModels(ProtocolTestGenerator.class.getClassLoader()) .assemble() @@ -37,6 +33,7 @@ public static void main(String[] args) { ObjectNode.builder() .withMember("service", serviceId.toString()) .withMember("namespace", serviceId.getNamespace()) + .withMember("modes", ArrayNode.fromStrings(mode)) .build()) .model(model) .build(); diff --git a/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestExtension.java b/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestExtension.java index 3873ad0df..c5a9e94d4 100644 --- a/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestExtension.java +++ b/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestExtension.java @@ -21,10 +21,10 @@ import software.amazon.smithy.java.client.core.ProtocolSettings; import software.amazon.smithy.java.client.core.auth.scheme.AuthScheme; import software.amazon.smithy.java.client.core.auth.scheme.AuthSchemeFactory; +import software.amazon.smithy.java.codegen.CodegenMode; import software.amazon.smithy.java.codegen.CodegenUtils; import software.amazon.smithy.java.codegen.JavaSymbolProvider; -import software.amazon.smithy.java.codegen.server.ServerSymbolProperties; -import software.amazon.smithy.java.codegen.server.ServiceJavaSymbolProvider; +import software.amazon.smithy.java.codegen.ServerSymbolProperties; import software.amazon.smithy.java.core.error.ModeledException; import software.amazon.smithy.java.core.schema.ApiOperation; import software.amazon.smithy.java.core.schema.SerializableStruct; @@ -120,10 +120,11 @@ public void beforeAll(ExtensionContext context) throws Exception { } case SERVER -> { var symbolProvider = SymbolProvider.cache( - new ServiceJavaSymbolProvider(serviceModel, + new JavaSymbolProvider(serviceModel, service, serviceId.getNamespace(), - serviceId.getName())); + serviceId.getName(), + java.util.Set.of(CodegenMode.SERVER))); Map, MockOperation> mockOperationMap = new HashMap<>(); var serverTestOperations = new ArrayList(); for (var testOperation : testOperations) { @@ -294,7 +295,12 @@ private static List getTestOperations( .map(ap -> ap.equals(testType.appliesTo)) .orElse(true); - var symbolProvider = new JavaSymbolProvider(serviceModel, service, service.toShapeId().getNamespace()); + var symbolProvider = new JavaSymbolProvider( + serviceModel, + service, + service.toShapeId().getNamespace(), + service.toShapeId().getName(), + Set.of()); for (var operationId : service.getOperations()) { var operationShape = serviceModel.getShape(operationId); if (operationShape.isPresent() && operationShape.get().isOperationShape()) { diff --git a/server/server-api/build.gradle.kts b/server/server-api/build.gradle.kts index d66735821..79216afee 100644 --- a/server/server-api/build.gradle.kts +++ b/server/server-api/build.gradle.kts @@ -10,5 +10,4 @@ extra["moduleName"] = "software.amazon.smithy.java.server.api" dependencies { implementation(project(":logging")) implementation(project(":core")) - api(project(":framework-errors")) } diff --git a/server/server-core/build.gradle.kts b/server/server-core/build.gradle.kts index 3fab65c95..410306a7f 100644 --- a/server/server-core/build.gradle.kts +++ b/server/server-core/build.gradle.kts @@ -9,6 +9,7 @@ extra["moduleName"] = "software.amazon.smithy.java.server.core" dependencies { api(project(":server:server-api")) + api(project(":framework-errors")) api(project(":http:http-api")) api(project(":core")) api(project(":context")) diff --git a/server/server-api/src/main/java/software/amazon/smithy/java/server/FilteredService.java b/server/server-core/src/main/java/software/amazon/smithy/java/server/FilteredService.java similarity index 100% rename from server/server-api/src/main/java/software/amazon/smithy/java/server/FilteredService.java rename to server/server-core/src/main/java/software/amazon/smithy/java/server/FilteredService.java diff --git a/server/server-api/src/test/java/software/amazon/smithy/java/server/FilteredServiceTest.java b/server/server-core/src/test/java/software/amazon/smithy/java/server/FilteredServiceTest.java similarity index 98% rename from server/server-api/src/test/java/software/amazon/smithy/java/server/FilteredServiceTest.java rename to server/server-core/src/test/java/software/amazon/smithy/java/server/FilteredServiceTest.java index 8a4429539..97e16b31a 100644 --- a/server/server-api/src/test/java/software/amazon/smithy/java/server/FilteredServiceTest.java +++ b/server/server-core/src/test/java/software/amazon/smithy/java/server/FilteredServiceTest.java @@ -8,7 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertSame; -import static software.amazon.smithy.java.server.TestStructs.createMockOperation; +import static software.amazon.smithy.java.server.core.TestStructs.createMockOperation; import java.util.ArrayList; import java.util.List; @@ -23,7 +23,7 @@ import software.amazon.smithy.java.core.schema.SerializableStruct; import software.amazon.smithy.java.core.serde.TypeRegistry; import software.amazon.smithy.java.framework.model.UnknownOperationException; -import software.amazon.smithy.java.server.TestStructs.MockStruct; +import software.amazon.smithy.java.server.core.TestStructs.MockStruct; import software.amazon.smithy.model.shapes.ShapeId; /** diff --git a/server/server-core/src/test/java/software/amazon/smithy/java/server/core/TestStructs.java b/server/server-core/src/test/java/software/amazon/smithy/java/server/core/TestStructs.java index e5103801c..21170a8dd 100644 --- a/server/server-core/src/test/java/software/amazon/smithy/java/server/core/TestStructs.java +++ b/server/server-core/src/test/java/software/amazon/smithy/java/server/core/TestStructs.java @@ -24,6 +24,46 @@ import software.amazon.smithy.model.shapes.ShapeId; public class TestStructs { + public static class MockStruct implements SerializableStruct { + @Override + public Schema schema() { + return Schema.createString(ShapeId.from("smithy.api#String")); + } + + @Override + public void serializeMembers(ShapeSerializer serializer) {} + + @Override + public T getMemberValue(Schema member) { + return null; + } + } + + @SuppressWarnings("unchecked") + public static Operation createMockOperation(String name) { + var apiOp = new TestApiOperation() { + @Override + public Schema schema() { + return Schema.createOperation(ShapeId.from("test.mock#" + name)); + } + + @Override + public Schema inputSchema() { + return Schema.createString(ShapeId.from("test.mock#" + name + "Input")); + } + + @Override + public Schema outputSchema() { + return Schema.createString(ShapeId.from("test.mock#" + name + "Output")); + } + }; + return Operation.of( + name, + (input, ctx) -> input, + apiOp, + null); + } + public static abstract class TestInput implements SerializableStruct { @Override public Schema schema() { diff --git a/settings.gradle.kts b/settings.gradle.kts index 35e2acaba..05feda801 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -37,6 +37,7 @@ include(":codecs:json-codec") include(":codecs:xml-codec") // Client +include(":client:client-api") include(":client:client-core") include(":client:client-auth-api") include(":client:client-http") @@ -56,12 +57,7 @@ include(":server:server-rpcv2-cbor") include(":server:server-proxy") // Codegen -include(":codegen:codegen-core") -include(":codegen:integrations:waiters-codegen") -include(":codegen:plugins") -include(":codegen:plugins:client-codegen") -include(":codegen:plugins:server-codegen") -include(":codegen:plugins:types-codegen") +include(":codegen:codegen-plugin") include(":codegen:test-utils") // Utilities