Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use code-generated endpoint rules for all services, and remove the customization. #5410

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import software.amazon.awssdk.codegen.poet.rules.EndpointResolverInterceptorSpec;
import software.amazon.awssdk.codegen.poet.rules.EndpointRulesClientTestSpec;
import software.amazon.awssdk.codegen.poet.rules.RequestEndpointInterceptorSpec;
import software.amazon.awssdk.codegen.poet.rules2.EndpointProviderSpec2;

public final class EndpointProviderTasks extends BaseGeneratorTasks {
private final GeneratorTaskParams generatorTaskParams;
Expand All @@ -51,14 +50,8 @@ protected List<GeneratorTask> createTasks() throws Exception {
List<GeneratorTask> tasks = new ArrayList<>();
tasks.add(generateInterface());
tasks.add(generateParams());
if (shouldGenerateCompiledEndpointRules()) {
tasks.add(generateDefaultProvider2());
tasks.add(new RulesEngineRuntimeGeneratorTask(generatorTaskParams));
tasks.add(new RulesEngineRuntimeGeneratorTask2(generatorTaskParams));
} else {
tasks.add(generateDefaultProvider());
tasks.add(new RulesEngineRuntimeGeneratorTask(generatorTaskParams));
}
tasks.add(generateDefaultProvider());
tasks.add(new RulesEngineRuntimeGeneratorTask(generatorTaskParams));
if (shouldGenerateJmesPathRuntime()) {
tasks.add(new JmesPathRuntimeGeneratorTask(generatorTaskParams));
}
Expand Down Expand Up @@ -88,20 +81,11 @@ private GeneratorTask generateDefaultProvider() {
return new PoetGeneratorTask(endpointRulesInternalDir(), model.getFileHeader(), new EndpointProviderSpec(model));
}

private GeneratorTask generateDefaultProvider2() {
return new PoetGeneratorTask(endpointRulesInternalDir(), model.getFileHeader(), new EndpointProviderSpec2(model));
}

private GeneratorTask generateDefaultPartitionsProvider() {
return new PoetGeneratorTask(endpointRulesInternalDir(), model.getFileHeader(),
new DefaultPartitionDataProviderSpec(model));
}

private boolean shouldGenerateCompiledEndpointRules() {
CustomizationConfig customizationConfig = generatorTaskParams.getModel().getCustomizationConfig();
return customizationConfig.isEnableGenerateCompiledEndpointRules();
}

private Collection<GeneratorTask> generateInterceptors() {
return Arrays.asList(
new PoetGeneratorTask(endpointRulesInternalDir(), model.getFileHeader(), new EndpointResolverInterceptorSpec(model)),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,6 @@ public class CustomizationConfig {

private boolean s3ExpressAuthSupport;

/**
* Set to true to enable compiled endpoint rules. Currently defaults to false.
*/
private boolean enableGenerateCompiledEndpointRules = false;

/**
* Customization related to auth scheme derived from endpoints.
*/
Expand Down Expand Up @@ -752,14 +747,6 @@ public void setUseS3ExpressSessionAuth(boolean useS3ExpressSessionAuth) {
this.useS3ExpressSessionAuth = useS3ExpressSessionAuth;
}

public boolean isEnableGenerateCompiledEndpointRules() {
return enableGenerateCompiledEndpointRules;
}

public void setEnableGenerateCompiledEndpointRules(boolean enableGenerateCompiledEndpointRules) {
this.enableGenerateCompiledEndpointRules = enableGenerateCompiledEndpointRules;
}

public Map<String, String> getSkipEndpointTests() {
return skipEndpointTests;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.lang.model.element.Modifier;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
Expand Down Expand Up @@ -123,11 +125,15 @@ private void addAccessorMethods(TypeSpec.Builder b) {
if (authSchemeSpecUtils.generateEndpointBasedParams()) {
parameters().forEach((name, model) -> {
if (authSchemeSpecUtils.includeParam(name)) {
MethodSpec accessor = endpointRulesSpecUtils.parameterInterfaceAccessorMethod(name, model);
List<MethodSpec> methods = endpointRulesSpecUtils.parameterInterfaceAccessorMethods(name, model);
if (model.getDocumentation() != null) {
accessor = accessor.toBuilder().addJavadoc(model.getDocumentation()).build();
methods = methods.stream()
.map(m -> m.toBuilder()
.addJavadoc(model.getDocumentation())
.build())
.collect(Collectors.toList());
}
b.addMethod(accessor);
b.addMethods(methods);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import java.util.Map;
import java.util.stream.Collectors;
import javax.lang.model.element.Modifier;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
Expand Down Expand Up @@ -185,10 +186,12 @@ private void addFieldsAndAccessors(TypeSpec.Builder b) {
parameters().forEach((name, model) -> {
if (authSchemeSpecUtils.includeParam(name)) {
b.addField(endpointRulesSpecUtils.parameterClassField(name, model));
b.addMethod(endpointRulesSpecUtils.parameterClassAccessorMethod(name, model)
.toBuilder()
.addAnnotation(Override.class)
.build());
b.addMethods(endpointRulesSpecUtils.parameterClassAccessorMethods(name, model)
.stream()
.map(m -> m.toBuilder()
.addAnnotation(Override.class)
.build())
.collect(Collectors.toList()));
}
});
ClassName endpointProvider = endpointRulesSpecUtils.providerInterfaceName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.rules2;
package software.amazon.awssdk.codegen.poet.rules;

/**
* Assigns an identifier to each rule then we use as a name for the generated method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.rules2;
package software.amazon.awssdk.codegen.poet.rules;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.rules2;
package software.amazon.awssdk.codegen.poet.rules;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.rules2;
package software.amazon.awssdk.codegen.poet.rules;

import java.util.Objects;
import software.amazon.awssdk.utils.Validate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.rules2;
package software.amazon.awssdk.codegen.poet.rules;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
Expand All @@ -25,6 +25,8 @@
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4AuthScheme;
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme;
import software.amazon.awssdk.codegen.model.config.customization.KeyTypePair;
import software.amazon.awssdk.codegen.model.rules.endpoints.BuiltInParameter;
import software.amazon.awssdk.codegen.poet.rules.RuleExpression.RuleExpressionKind;
import software.amazon.awssdk.endpoints.Endpoint;

public class CodeGeneratorVisitor extends WalkRuleExpressionVisitor {
Expand Down Expand Up @@ -141,10 +143,28 @@ public Void visitVariableReferenceExpression(VariableReferenceExpression e) {
@Override
public Void visitMemberAccessExpression(MemberAccessExpression e) {
e.source().accept(this);
builder.add(".$L()", e.name());
if (regionNeedsConversionToString(e)) {
builder.add(".$LId()", e.name());
} else {
builder.add(".$L()", e.name());
}
return null;
}

private boolean regionNeedsConversionToString(MemberAccessExpression e) {
// It's only a Region type if it's a parameter, so see if it's a parameter.
if (e.source().kind() != RuleExpressionKind.VARIABLE_REFERENCE) {
return false;
}

if (!symbolTable.isParam(e.name())) {
return false;
}

// It's a parameter. Is it a region type parameter? If so, we need to convert it.
return symbolTable.builtInParamType(e.name()) == BuiltInParameter.AWS_REGION;
}

@Override
public Void visitStringConcatExpression(StringConcatExpression e) {
boolean isFirst = true;
Expand Down Expand Up @@ -221,7 +241,7 @@ public Void visitLetExpression(LetExpression expr) {

private void conditionsPreamble(RuleSetExpression expr) {
for (RuleExpression condition : expr.conditions()) {
if (condition.kind() == RuleExpression.RuleExpressionKind.LET) {
if (condition.kind() == RuleExpressionKind.LET) {
condition.accept(this);
} else {
builder.add("if (");
Expand Down Expand Up @@ -332,7 +352,7 @@ private void addAuthSchemesBlock(RuleExpression e) {
}

private void addAuthSchemesBody(RuleExpression e) {
if (e.kind() != RuleExpression.RuleExpressionKind.PROPERTIES) {
if (e.kind() != RuleExpressionKind.PROPERTIES) {
throw new RuntimeException("Expecting properties, got: " + e);
}
PropertiesExpression expr = (PropertiesExpression) e;
Expand All @@ -349,7 +369,7 @@ private void addAuthSchemesBody(RuleExpression e) {
}

private String stringValueOf(RuleExpression e) {
if (e.kind() != RuleExpression.RuleExpressionKind.STRING_VALUE) {
if (e.kind() != RuleExpressionKind.STRING_VALUE) {
throw new RuntimeException("Expecting string value, got: " + e);
}
LiteralStringExpression expr = (LiteralStringExpression) e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.rules2;
package software.amazon.awssdk.codegen.poet.rules;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -59,10 +59,6 @@ public boolean isLocal(String name) {
return symbolTable.isLocal(name);
}

public String regionParamName() {
return symbolTable.regionParamName();
}

public Map<String, RuleType> locals() {
return symbolTable.locals();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.rules2;
package software.amazon.awssdk.codegen.poet.rules;

import java.util.Objects;
import software.amazon.awssdk.utils.Validate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TypeSpec poetSpec() {

parameters().forEach((name, model) -> {
b.addField(endpointRulesSpecUtils.parameterClassField(name, model));
b.addMethod(endpointRulesSpecUtils.parameterClassAccessorMethod(name, model));
b.addMethods(endpointRulesSpecUtils.parameterClassAccessorMethods(name, model));
});

b.addMethod(toBuilderMethod());
Expand Down
Loading
Loading