Skip to content

Commit 881afd3

Browse files
authored
Copy only req extra files if using compiled rules (#6101)
* Copy only req extra files if using compiled rules When generating compiled endpoint rules, the majority of the classes used for the older intepreted rules don't need to be copied. To save on JAR space, only copy the files that are required. * Include Arn class * Include separator to disambiguate names * Additional files to copy * Add comment about leading slash
1 parent 475f914 commit 881afd3

4 files changed

Lines changed: 66 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"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."
6+
}

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/EndpointProviderTasks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected List<GeneratorTask> createTasks() throws Exception {
5353
tasks.add(generateParams());
5454
if (shouldGenerateCompiledEndpointRules()) {
5555
tasks.add(generateDefaultProvider2());
56-
tasks.add(new RulesEngineRuntimeGeneratorTask(generatorTaskParams));
56+
tasks.add(new RulesEngineRuntimeLiteGeneratorTask(generatorTaskParams));
5757
tasks.add(new RulesEngineRuntimeGeneratorTask2(generatorTaskParams));
5858
} else {
5959
tasks.add(generateDefaultProvider());

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/RulesEngineRuntimeGeneratorTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import software.amazon.awssdk.utils.StringUtils;
3131
import software.amazon.awssdk.utils.Validate;
3232

33-
public final class RulesEngineRuntimeGeneratorTask extends BaseGeneratorTasks {
33+
public class RulesEngineRuntimeGeneratorTask extends BaseGeneratorTasks {
3434
public static final String RUNTIME_CLASS_NAME = "WaitersRuntime";
3535

3636
private final String engineInternalClassDir;
@@ -63,7 +63,7 @@ protected List<GeneratorTask> createTasks() throws Exception {
6363
return copyTasks;
6464
}
6565

66-
private List<String> rulesEngineJavaFilePaths(Collection<String> runtimeEngineFiles) {
66+
protected List<String> rulesEngineJavaFilePaths(Collection<String> runtimeEngineFiles) {
6767
return runtimeEngineFiles.stream()
6868
.filter(e -> e.endsWith(".java.resource"))
6969
.collect(Collectors.toList());
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.emitters.tasks;
17+
18+
import java.util.Collection;
19+
import java.util.List;
20+
import java.util.stream.Collectors;
21+
import java.util.stream.Stream;
22+
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
23+
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
24+
25+
/** A version of {@link software.amazon.awssdk.codegen.emitters.tasks.RulesEngineRuntimeGeneratorTask} that copies a minimal
26+
* set of the interpreter related classes. This set represents the only classes that need to be copied when compiled rules are
27+
* enabled.
28+
*
29+
* @see CustomizationConfig#isEnableGenerateCompiledEndpointRules()
30+
*/
31+
public final class RulesEngineRuntimeLiteGeneratorTask extends RulesEngineRuntimeGeneratorTask {
32+
// Note: leading slashes are important to disambiguate between files that share the same suffix
33+
private static final List<String> FILES_TO_COPY = Stream.of("/Outputs.java.resource",
34+
"/RegionOverride.java.resource",
35+
"/Partition.java.resource",
36+
"/PartitionDataProvider.java.resource",
37+
"/AwsEndpointProviderUtils.java.resource",
38+
"/Arn.java.resource",
39+
"/Value.java.resource",
40+
"/Identifier.java.resource",
41+
"/EndpointAuthSchemeStrategy.java.resource",
42+
"/EndpointAttributeProvider.java.resource",
43+
"/EndpointAuthSchemeStrategyFactory.java.resource",
44+
"/DefaultEndpointAuthSchemeStrategy.java.resource")
45+
.collect(Collectors.toList());
46+
47+
public RulesEngineRuntimeLiteGeneratorTask(GeneratorTaskParams generatorTaskParams) {
48+
super(generatorTaskParams);
49+
}
50+
51+
protected List<String> rulesEngineJavaFilePaths(Collection<String> runtimeEngineFiles) {
52+
return super.rulesEngineJavaFilePaths(runtimeEngineFiles)
53+
.stream()
54+
.filter(e -> FILES_TO_COPY.stream().anyMatch(e::endsWith))
55+
.collect(Collectors.toList());
56+
}
57+
}

0 commit comments

Comments
 (0)