Skip to content

Commit 8adeaa7

Browse files
committed
wip: attepting to untangle AI
1 parent 41f0ea6 commit 8adeaa7

30 files changed

+193
-3426
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ __pycache__/
1414
local.properties
1515

1616
# ignore generated files
17-
services/*/generated-src
17+
**/generated-src
1818
services/*/build.gradle.kts
1919
services/*/API.md
2020
services/*/OVERVIEW.md
2121
.kotest/
2222
.kotlin/
2323
*.klib
24-
tests/codegen/smoke-tests/services/*/generated-src
2524
tests/codegen/smoke-tests/services/*/build.gradle.kts

aws-custom-sdk-build-plugin/build.gradle.kts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ repositories {
2121
dependencies {
2222
// Gradle API - use explicit Kotlin version matching parent project
2323
implementation(kotlin("gradle-plugin", version = "2.1.0"))
24-
25-
// Kotlin reflection for constants registry
26-
implementation(kotlin("reflect", version = "2.1.0"))
27-
24+
2825
// JSON processing for Smithy build configuration
2926
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
3027

3128
// Smithy dependencies for model processing - use versions matching parent project
3229
implementation("software.amazon.smithy:smithy-model:1.60.2")
3330
implementation("software.amazon.smithy:smithy-aws-traits:1.60.2")
3431
implementation("software.amazon.smithy:smithy-protocol-traits:1.60.2")
35-
32+
33+
implementation(libs.plugins.aws.kotlin.repo.tools.smithybuild)
34+
3635
// Smithy CLI for real build execution
3736
implementation("software.amazon.smithy:smithy-cli:1.60.2")
3837

@@ -45,6 +44,14 @@ dependencies {
4544
testImplementation("io.mockk:mockk:1.13.13")
4645
}
4746

47+
kotlin {
48+
sourceSets {
49+
main {
50+
kotlin.srcDir("generated-src/main/kotlin")
51+
}
52+
}
53+
}
54+
4855
gradlePlugin {
4956
plugins {
5057
create("awsCustomSdkBuild") {

aws-custom-sdk-build-plugin/src/main/kotlin/aws/sdk/kotlin/gradle/customsdk/AwsCustomSdkBuildExtension.kt

Lines changed: 17 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -6,203 +6,43 @@
66
package aws.sdk.kotlin.gradle.customsdk
77

88
import org.gradle.api.Project
9+
import org.gradle.api.artifacts.Dependency
910
import org.gradle.api.provider.Property
11+
import org.gradle.api.provider.Provider
1012

1113
/**
1214
* Extension for configuring the AWS Custom SDK Build plugin.
1315
*
1416
* Provides a type-safe DSL for specifying which AWS services and operations
1517
* to include in the custom SDK build.
1618
*/
17-
abstract class AwsCustomSdkBuildExtension(private val project: Project) {
18-
19-
/**
20-
* AWS region for the generated clients (optional, defaults to us-east-1)
21-
*/
22-
abstract val region: Property<String>
23-
19+
abstract class AwsCustomSdkBuildExtension(internal val project: Project) {
2420
/**
25-
* Output directory for generated clients (optional, defaults to build/generated/aws-custom-sdk)
21+
* Output directory for generated clients. Defaults to `${project.layout.buildDirectory}/generated-src/aws-sdk`.
2622
*/
2723
abstract val outputDirectory: Property<String>
2824

2925
/**
30-
* Package name for generated clients (optional, defaults to aws.sdk.kotlin.custom)
31-
*/
32-
abstract val packageName: Property<String>
33-
34-
/**
35-
* Enable strict validation of operations against generated constants (default: true)
26+
* Package name for generated clients. Defaults to `aws.sdk.kotlin.services`.
3627
*/
37-
abstract val strictValidation: Property<Boolean>
38-
28+
abstract val packageNamePrefix: Property<String>
29+
3930
/**
4031
* Set of selected services with their operations
4132
*/
42-
private val selectedServices = mutableMapOf<String, MutableSet<String>>()
43-
33+
internal val selectedServices = mutableMapOf<String, Set<String>>()
34+
4435
init {
4536
// Set default values
46-
region.convention("us-east-1")
47-
outputDirectory.convention("${project.buildDir}/generated/aws-custom-sdk")
48-
packageName.convention("aws.sdk.kotlin.custom")
49-
strictValidation.convention(true)
37+
outputDirectory.convention("${project.layout.buildDirectory}/generated-src/aws-sdk")
38+
packageNamePrefix.convention("aws.sdk.kotlin.services")
5039
}
51-
52-
/**
53-
* Configure a service with selected operations using type-safe constants
54-
*
55-
* Example with type-safe constants:
56-
* ```
57-
* service("lambda") {
58-
* operations(
59-
* LambdaOperations.CreateFunction,
60-
* LambdaOperations.InvokeFunction,
61-
* LambdaOperations.DeleteFunction
62-
* )
63-
* }
64-
* ```
65-
*
66-
* Example with string literals (backward compatibility):
67-
* ```
68-
* service("s3") {
69-
* operations("GetObject", "PutObject")
70-
* }
71-
* ```
72-
*/
73-
fun service(serviceName: String, configure: ServiceConfiguration.() -> Unit) {
74-
val serviceConfig = ServiceConfiguration(serviceName, project)
75-
serviceConfig.configure()
76-
77-
val operations = serviceConfig.getOperations()
78-
79-
// Validate operations if strict validation is enabled
80-
if (strictValidation.get()) {
81-
val validationResult = ConstantsRegistry.validateOperations(serviceName, operations)
82-
if (!validationResult.isValid) {
83-
project.logger.warn("AWS Custom SDK: ${validationResult.message}")
84-
if (validationResult.invalidOperations.isNotEmpty()) {
85-
project.logger.warn("Available operations for $serviceName: ${ConstantsRegistry.getServiceOperations(serviceName).sorted().joinToString(", ")}")
86-
}
87-
}
88-
}
89-
90-
selectedServices[serviceName] = operations.toMutableSet()
91-
}
92-
93-
/**
94-
* Configure multiple services using a DSL block
95-
*
96-
* Example:
97-
* ```
98-
* services {
99-
* lambda {
100-
* operations(LambdaOperations.CreateFunction, LambdaOperations.InvokeFunction)
101-
* }
102-
* s3 {
103-
* operations(S3Operations.GetObject, S3Operations.PutObject)
104-
* }
105-
* }
106-
* ```
107-
*/
108-
fun services(configure: ServicesConfiguration.() -> Unit) {
109-
val servicesConfig = ServicesConfiguration(this)
110-
servicesConfig.configure()
111-
}
112-
113-
/**
114-
* Get all selected services and their operations
115-
*/
116-
fun getSelectedServices(): Map<String, Set<String>> = selectedServices.toMap()
117-
118-
/**
119-
* Get validation summary for all configured services
120-
*/
121-
fun getValidationSummary(): Map<String, ConstantsRegistry.ValidationResult> {
122-
return selectedServices.mapValues { (serviceName, operations) ->
123-
ConstantsRegistry.validateOperations(serviceName, operations)
124-
}
125-
}
126-
127-
/**
128-
* Configuration block for multiple services
129-
*/
130-
class ServicesConfiguration(private val extension: AwsCustomSdkBuildExtension) {
131-
132-
fun lambda(configure: ServiceConfiguration.() -> Unit) {
133-
extension.service("lambda", configure)
134-
}
135-
136-
fun s3(configure: ServiceConfiguration.() -> Unit) {
137-
extension.service("s3", configure)
138-
}
139-
140-
fun dynamodb(configure: ServiceConfiguration.() -> Unit) {
141-
extension.service("dynamodb", configure)
142-
}
143-
144-
fun apigateway(configure: ServiceConfiguration.() -> Unit) {
145-
extension.service("apigateway", configure)
146-
}
147-
148-
/**
149-
* Generic service configuration for services not explicitly defined
150-
*/
151-
fun service(serviceName: String, configure: ServiceConfiguration.() -> Unit) {
152-
extension.service(serviceName, configure)
153-
}
154-
}
155-
156-
/**
157-
* Configuration block for a specific service
158-
*/
159-
class ServiceConfiguration(private val serviceName: String, private val project: Project) {
160-
private val operations = mutableSetOf<String>()
161-
162-
/**
163-
* Add operations using type-safe constants or string literals
164-
*
165-
* Examples:
166-
* ```
167-
* operations(LambdaOperations.CreateFunction, LambdaOperations.InvokeFunction)
168-
* operations("CreateFunction", "InvokeFunction")
169-
* ```
170-
*/
171-
fun operations(vararg operationConstants: String) {
172-
operations.addAll(operationConstants)
173-
}
174-
175-
/**
176-
* Add operations using a collection of constants
177-
*/
178-
fun operations(operationConstants: Collection<String>) {
179-
operations.addAll(operationConstants)
180-
}
181-
182-
/**
183-
* Add all available operations for this service
184-
*/
185-
fun allOperations() {
186-
val availableOps = ConstantsRegistry.getServiceOperations(serviceName)
187-
if (availableOps.isNotEmpty()) {
188-
operations.addAll(availableOps)
189-
project.logger.info("Added all ${availableOps.size} operations for $serviceName service")
190-
} else {
191-
project.logger.warn("No operation constants available for $serviceName service")
192-
}
193-
}
194-
195-
/**
196-
* Add operations matching a pattern (regex)
197-
*/
198-
fun operationsMatching(pattern: String) {
199-
val regex = Regex(pattern)
200-
val availableOps = ConstantsRegistry.getServiceOperations(serviceName)
201-
val matchingOps = availableOps.filter { regex.matches(it) }
202-
operations.addAll(matchingOps)
203-
project.logger.info("Added ${matchingOps.size} operations matching '$pattern' for $serviceName service")
40+
41+
internal fun service(serviceName: String, operationNames: Set<String>): Provider<Dependency> {
42+
check(serviceName !in selectedServices) {
43+
"Service $serviceName configured multiple times. All service configuration should be in a single DSL block."
20444
}
205-
206-
internal fun getOperations(): Set<String> = operations.toSet()
45+
46+
selectedServices[serviceName] = operationNames
20747
}
20848
}

aws-custom-sdk-build-plugin/src/main/kotlin/aws/sdk/kotlin/gradle/customsdk/AwsCustomSdkBuildPlugin.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@ import org.gradle.api.Project
1616
* operation constants for configuration.
1717
*/
1818
class AwsCustomSdkBuildPlugin : Plugin<Project> {
19-
2019
companion object {
2120
const val EXTENSION_NAME = "awsCustomSdk"
2221
const val GENERATE_CLIENTS_TASK_NAME = "generateAwsCustomClients"
2322
}
2423

2524
override fun apply(project: Project) {
2625
// Create the extension for DSL configuration
27-
val extension = project.extensions.create(
28-
EXTENSION_NAME,
29-
AwsCustomSdkBuildExtension::class.java,
30-
project
31-
)
26+
val extension = project.extensions.create(EXTENSION_NAME, AwsCustomSdkBuildExtension::class.java, project)
3227

3328
// Register the main task for generating custom clients
3429
project.tasks.register(GENERATE_CLIENTS_TASK_NAME, GenerateCustomClientsTask::class.java)

0 commit comments

Comments
 (0)