Skip to content

Commit 0cdd257

Browse files
committed
Added Consumer<Builder> methods to many locations where they were previously missing.
1 parent 5405dec commit 0cdd257

File tree

18 files changed

+209
-77
lines changed

18 files changed

+209
-77
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"type": "feature",
4+
"description": "Added Consumer<Builder> methods to multiple locations where they were previously missing."
5+
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderInterface.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import com.squareup.javapoet.ClassName;
1919
import com.squareup.javapoet.CodeBlock;
2020
import com.squareup.javapoet.MethodSpec;
21+
import com.squareup.javapoet.ParameterizedTypeName;
22+
import com.squareup.javapoet.TypeName;
2123
import com.squareup.javapoet.TypeSpec;
2224
import com.squareup.javapoet.TypeVariableName;
25+
import java.util.function.Consumer;
2326
import javax.lang.model.element.Modifier;
2427
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
2528
import software.amazon.awssdk.codegen.poet.ClassSpec;
@@ -48,6 +51,7 @@ public TypeSpec poetSpec() {
4851

4952
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
5053
builder.addMethod(advancedConfigurationMethod());
54+
builder.addMethod(advancedConfigurationConsumerBuilderMethod());
5155
}
5256

5357
return builder.build();
@@ -62,14 +66,28 @@ private CodeBlock getJavadoc() {
6266

6367
private MethodSpec advancedConfigurationMethod() {
6468
ClassName advancedConfiguration = ClassName.get(basePackage,
65-
model.getCustomizationConfig().getServiceSpecificClientConfigClass());
69+
model.getCustomizationConfig().getServiceSpecificClientConfigClass());
6670
return MethodSpec.methodBuilder("advancedConfiguration")
6771
.addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC)
6872
.returns(TypeVariableName.get("B"))
6973
.addParameter(advancedConfiguration, "advancedConfiguration")
7074
.build();
7175
}
7276

77+
private MethodSpec advancedConfigurationConsumerBuilderMethod() {
78+
ClassName advancedConfiguration = ClassName.get(basePackage,
79+
model.getCustomizationConfig().getServiceSpecificClientConfigClass());
80+
TypeName consumerBuilder = ParameterizedTypeName.get(ClassName.get(Consumer.class),
81+
advancedConfiguration.nestedClass("Builder"));
82+
return MethodSpec.methodBuilder("advancedConfiguration")
83+
.addModifiers(Modifier.DEFAULT, Modifier.PUBLIC)
84+
.returns(TypeVariableName.get("B"))
85+
.addParameter(consumerBuilder, "advancedConfiguration")
86+
.addStatement("return advancedConfiguration($T.builder().apply(advancedConfiguration).build())",
87+
advancedConfiguration)
88+
.build();
89+
}
90+
7391
@Override
7492
public ClassName className() {
7593
return builderInterfaceName;

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-async-client-builder-class.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
*/
2424
@Generated("software.amazon.awssdk:codegen")
2525
@SdkInternalApi
26-
final class DefaultJsonAsyncClientBuilder extends DefaultJsonBaseClientBuilder<JsonAsyncClientBuilder, JsonAsyncClient>
27-
implements JsonAsyncClientBuilder {
26+
final class DefaultJsonAsyncClientBuilder extends DefaultJsonBaseClientBuilder<JsonAsyncClientBuilder, JsonAsyncClient> implements
27+
JsonAsyncClientBuilder {
2828
@Override
2929
protected final JsonAsyncClient buildClient() {
30-
return new DefaultJsonAsyncClient(super.asyncClientConfiguration());
30+
return new DefaultJsonAsyncClient(super.asyncClientConfiguration(), advancedConfiguration());
3131
}
3232
}
33+

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-class.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
@Generated("software.amazon.awssdk:codegen")
1717
@SdkInternalApi
1818
abstract class DefaultJsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C> extends DefaultClientBuilder<B, C> {
19+
private AdvancedConfiguration advancedConfiguration;
20+
1921
@Override
2022
protected final String serviceEndpointPrefix() {
2123
return "json-service";
@@ -24,8 +26,8 @@ protected final String serviceEndpointPrefix() {
2426
@Override
2527
protected final ClientConfigurationDefaults serviceDefaults() {
2628
return ServiceBuilderConfigurationDefaults.builder().defaultSignerProvider(this::defaultSignerProvider)
27-
.addRequestHandlerPath("software/amazon/awssdk/services/json/execution.interceptors")
28-
.crc32FromCompressedDataEnabled(false).build();
29+
.addRequestHandlerPath("software/amazon/awssdk/services/json/execution.interceptors")
30+
.crc32FromCompressedDataEnabled(false).build();
2931
}
3032

3133
private SignerProvider defaultSignerProvider() {
@@ -35,6 +37,19 @@ private SignerProvider defaultSignerProvider() {
3537
return StaticSignerProvider.create(signer);
3638
}
3739

40+
public B advancedConfiguration(AdvancedConfiguration advancedConfiguration) {
41+
this.advancedConfiguration = advancedConfiguration;
42+
return thisBuilder();
43+
}
44+
45+
protected AdvancedConfiguration advancedConfiguration() {
46+
return advancedConfiguration;
47+
}
48+
49+
public void setAdvancedConfiguration(AdvancedConfiguration advancedConfiguration) {
50+
advancedConfiguration(advancedConfiguration);
51+
}
52+
3853
@Override
3954
protected final AttributeMap serviceSpecificHttpConfig() {
4055
return MyServiceHttpConfig.CONFIG;

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-interface.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package software.amazon.awssdk.services.json;
1717

18+
import java.util.function.Consumer;
1819
import javax.annotation.Generated;
1920
import software.amazon.awssdk.core.client.builder.ClientBuilder;
2021

@@ -24,4 +25,9 @@
2425
*/
2526
@Generated("software.amazon.awssdk:codegen")
2627
public interface JsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C> extends ClientBuilder<B, C> {
28+
B advancedConfiguration(AdvancedConfiguration advancedConfiguration);
29+
30+
default B advancedConfiguration(Consumer<AdvancedConfiguration.Builder> advancedConfiguration) {
31+
return advancedConfiguration(AdvancedConfiguration.builder().apply(advancedConfiguration).build());
32+
}
2733
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-sync-client-builder-class.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
@Generated("software.amazon.awssdk:codegen")
2525
@SdkInternalApi
2626
final class DefaultJsonClientBuilder extends DefaultJsonBaseClientBuilder<JsonClientBuilder, JsonClient> implements
27-
JsonClientBuilder {
27+
JsonClientBuilder {
2828
@Override
2929
protected final JsonClient buildClient() {
30-
return new DefaultJsonClient(super.syncClientConfiguration());
30+
return new DefaultJsonClient(super.syncClientConfiguration(), advancedConfiguration());
3131
}
32-
}
32+
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/json/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"skip" : true
44
},
55
"presignersFqcn": "software.amazon.awssdk.services.acm.presign.AcmClientPresigners",
6-
"serviceSpecificHttpConfig": "MyServiceHttpConfig.CONFIG"
6+
"serviceSpecificHttpConfig": "MyServiceHttpConfig.CONFIG",
7+
"serviceSpecificClientConfigClass": "AdvancedConfiguration"
78
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-async-client-class.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ final class DefaultJsonAsyncClient implements JsonAsyncClient {
5858

5959
private final SdkJsonProtocolFactory protocolFactory;
6060

61-
protected DefaultJsonAsyncClient(AsyncClientConfiguration clientConfiguration) {
62-
this.clientHandler = new SdkAsyncClientHandler(clientConfiguration, null);
61+
protected DefaultJsonAsyncClient(AsyncClientConfiguration clientConfiguration, AdvancedConfiguration serviceConfiguration) {
62+
this.clientHandler = new SdkAsyncClientHandler(clientConfiguration, serviceConfiguration);
6363
this.protocolFactory = init();
6464
}
6565

@@ -96,8 +96,8 @@ public CompletableFuture<APostOperationResponse> aPostOperation(APostOperationRe
9696
HttpResponseHandler<SdkServiceException> errorResponseHandler = createErrorResponseHandler();
9797

9898
return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>()
99-
.withMarshaller(new APostOperationRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler)
100-
.withErrorResponseHandler(errorResponseHandler).withInput(aPostOperationRequest));
99+
.withMarshaller(new APostOperationRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler)
100+
.withErrorResponseHandler(errorResponseHandler).withInput(aPostOperationRequest));
101101
}
102102

103103
/**
@@ -135,9 +135,9 @@ public CompletableFuture<APostOperationWithOutputResponse> aPostOperationWithOut
135135

136136
return clientHandler
137137
.execute(new ClientExecutionParams<APostOperationWithOutputRequest, APostOperationWithOutputResponse>()
138-
.withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory))
139-
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
140-
.withInput(aPostOperationWithOutputRequest));
138+
.withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory))
139+
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
140+
.withInput(aPostOperationWithOutputRequest));
141141
}
142142

143143
/**
@@ -175,9 +175,9 @@ public CompletableFuture<GetWithoutRequiredMembersResponse> getWithoutRequiredMe
175175

176176
return clientHandler
177177
.execute(new ClientExecutionParams<GetWithoutRequiredMembersRequest, GetWithoutRequiredMembersResponse>()
178-
.withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory))
179-
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
180-
.withInput(getWithoutRequiredMembersRequest));
178+
.withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory))
179+
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
180+
.withInput(getWithoutRequiredMembersRequest));
181181
}
182182

183183
/**
@@ -212,9 +212,9 @@ public CompletableFuture<PaginatedOperationWithResultKeyResponse> paginatedOpera
212212

213213
return clientHandler
214214
.execute(new ClientExecutionParams<PaginatedOperationWithResultKeyRequest, PaginatedOperationWithResultKeyResponse>()
215-
.withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory))
216-
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
217-
.withInput(paginatedOperationWithResultKeyRequest));
215+
.withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory))
216+
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
217+
.withInput(paginatedOperationWithResultKeyRequest));
218218
}
219219

220220
/**
@@ -249,9 +249,9 @@ public CompletableFuture<PaginatedOperationWithoutResultKeyResponse> paginatedOp
249249

250250
return clientHandler
251251
.execute(new ClientExecutionParams<PaginatedOperationWithoutResultKeyRequest, PaginatedOperationWithoutResultKeyResponse>()
252-
.withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory))
253-
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
254-
.withInput(paginatedOperationWithoutResultKeyRequest));
252+
.withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory))
253+
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
254+
.withInput(paginatedOperationWithoutResultKeyRequest));
255255
}
256256

257257
/**
@@ -290,9 +290,9 @@ public CompletableFuture<StreamingInputOperationResponse> streamingInputOperatio
290290
HttpResponseHandler<SdkServiceException> errorResponseHandler = createErrorResponseHandler();
291291

292292
return clientHandler.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>()
293-
.withMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory))
294-
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
295-
.withAsyncRequestProvider(requestProvider).withInput(streamingInputOperationRequest));
293+
.withMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory))
294+
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
295+
.withAsyncRequestProvider(requestProvider).withInput(streamingInputOperationRequest));
296296
}
297297

298298
/**
@@ -344,13 +344,13 @@ public void close() {
344344

345345
private software.amazon.awssdk.core.protocol.json.SdkJsonProtocolFactory init() {
346346
return new SdkJsonProtocolFactory(new JsonClientMetadata()
347-
.withProtocolVersion("1.1")
348-
.withSupportsCbor(false)
349-
.withSupportsIon(false)
350-
.withBaseServiceExceptionClass(software.amazon.awssdk.services.json.model.JsonException.class)
351-
.withContentTypeOverride("")
352-
.addErrorMetadata(
353-
new JsonErrorShapeMetadata().withErrorCode("InvalidInput").withModeledClass(InvalidInputException.class)));
347+
.withProtocolVersion("1.1")
348+
.withSupportsCbor(false)
349+
.withSupportsIon(false)
350+
.withBaseServiceExceptionClass(software.amazon.awssdk.services.json.model.JsonException.class)
351+
.withContentTypeOverride("")
352+
.addErrorMetadata(
353+
new JsonErrorShapeMetadata().withErrorCode("InvalidInput").withModeledClass(InvalidInputException.class)));
354354
}
355355

356356
private HttpResponseHandler<SdkServiceException> createErrorResponseHandler() {

0 commit comments

Comments
 (0)