diff --git a/.changes/next-release/feature-AWSSDKforJavav2-0b9a472.json b/.changes/next-release/feature-AWSSDKforJavav2-0b9a472.json new file mode 100644 index 000000000000..6deebfd096b4 --- /dev/null +++ b/.changes/next-release/feature-AWSSDKforJavav2-0b9a472.json @@ -0,0 +1,6 @@ +{ + "type": "feature", + "category": "AWS SDK for Java v2", + "contributor": "", + "description": "Don't generate the unused files for the service endpoint provider when compiled endpoint rules are enabled (the default behavior). This lowers the overall size of the built JAR." +} diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/EndpointProviderTasks.java b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/EndpointProviderTasks.java index 6b64bd61f743..e54f964e4d04 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/EndpointProviderTasks.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/EndpointProviderTasks.java @@ -53,7 +53,7 @@ protected List createTasks() throws Exception { tasks.add(generateParams()); if (shouldGenerateCompiledEndpointRules()) { tasks.add(generateDefaultProvider2()); - tasks.add(new RulesEngineRuntimeGeneratorTask(generatorTaskParams)); + tasks.add(new RulesEngineRuntimeLiteGeneratorTask(generatorTaskParams)); tasks.add(new RulesEngineRuntimeGeneratorTask2(generatorTaskParams)); } else { tasks.add(generateDefaultProvider()); diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeGeneratorTask.java b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeGeneratorTask.java index beaa1a3bb0d7..38c956695a14 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeGeneratorTask.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeGeneratorTask.java @@ -30,7 +30,7 @@ import software.amazon.awssdk.utils.StringUtils; import software.amazon.awssdk.utils.Validate; -public final class RulesEngineRuntimeGeneratorTask extends BaseGeneratorTasks { +public class RulesEngineRuntimeGeneratorTask extends BaseGeneratorTasks { public static final String RUNTIME_CLASS_NAME = "WaitersRuntime"; private final String engineInternalClassDir; @@ -63,7 +63,7 @@ protected List createTasks() throws Exception { return copyTasks; } - private List rulesEngineJavaFilePaths(Collection runtimeEngineFiles) { + protected List rulesEngineJavaFilePaths(Collection runtimeEngineFiles) { return runtimeEngineFiles.stream() .filter(e -> e.endsWith(".java.resource")) .collect(Collectors.toList()); diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeLiteGeneratorTask.java b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeLiteGeneratorTask.java new file mode 100644 index 000000000000..d223f2d6ace9 --- /dev/null +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeLiteGeneratorTask.java @@ -0,0 +1,57 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.codegen.emitters.tasks; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams; +import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig; + +/** A version of {@link software.amazon.awssdk.codegen.emitters.tasks.RulesEngineRuntimeGeneratorTask} that copies a minimal + * set of the interpreter related classes. This set represents the only classes that need to be copied when compiled rules are + * enabled. + * + * @see CustomizationConfig#isEnableGenerateCompiledEndpointRules() + */ +public final class RulesEngineRuntimeLiteGeneratorTask extends RulesEngineRuntimeGeneratorTask { + // Note: leading slashes are important to disambiguate between files that share the same suffix + private static final List FILES_TO_COPY = Stream.of("/Outputs.java.resource", + "/RegionOverride.java.resource", + "/Partition.java.resource", + "/PartitionDataProvider.java.resource", + "/AwsEndpointProviderUtils.java.resource", + "/Arn.java.resource", + "/Value.java.resource", + "/Identifier.java.resource", + "/EndpointAuthSchemeStrategy.java.resource", + "/EndpointAttributeProvider.java.resource", + "/EndpointAuthSchemeStrategyFactory.java.resource", + "/DefaultEndpointAuthSchemeStrategy.java.resource") + .collect(Collectors.toList()); + + public RulesEngineRuntimeLiteGeneratorTask(GeneratorTaskParams generatorTaskParams) { + super(generatorTaskParams); + } + + protected List rulesEngineJavaFilePaths(Collection runtimeEngineFiles) { + return super.rulesEngineJavaFilePaths(runtimeEngineFiles) + .stream() + .filter(e -> FILES_TO_COPY.stream().anyMatch(e::endsWith)) + .collect(Collectors.toList()); + } +}