Skip to content

Commit c631c61

Browse files
authored
Add separate generated-resources directory (#2197)
1 parent 023adfb commit c631c61

File tree

9 files changed

+54
-12
lines changed

9 files changed

+54
-12
lines changed

codegen-maven-plugin/src/main/java/software/amazon/awssdk/codegen/maven/plugin/GenerationMojo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ public class GenerationMojo extends AbstractMojo {
6666
private MavenProject project;
6767

6868
private Path sourcesDirectory;
69+
private Path resourcesDirectory;
6970
private Path testsDirectory;
7071

7172
@Override
7273
public void execute() throws MojoExecutionException {
7374
this.sourcesDirectory = Paths.get(outputDirectory).resolve("generated-sources").resolve("sdk");
75+
this.resourcesDirectory = Paths.get(outputDirectory).resolve("generated-resources").resolve("sdk-resources");
7476
this.testsDirectory = Paths.get(outputDirectory).resolve("generated-test-sources").resolve("sdk-tests");
7577

7678
findModelRoots().forEach(p -> {
@@ -112,6 +114,7 @@ private void generateCode(C2jModels models) {
112114
CodeGenerator.builder()
113115
.models(models)
114116
.sourcesDirectory(sourcesDirectory.toFile().getAbsolutePath())
117+
.resourcesDirectory(resourcesDirectory.toFile().getAbsolutePath())
115118
.testsDirectory(testsDirectory.toFile().getAbsolutePath())
116119
.intermediateModelFileNamePrefix(intermediateModelFileNamePrefix(models))
117120
.build()

codegen/src/main/java/software/amazon/awssdk/codegen/CodeGenerator.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class CodeGenerator {
3333

3434
private final C2jModels models;
3535
private final String sourcesDirectory;
36+
private final String resourcesDirectory;
3637
private final String testsDirectory;
3738

3839
/**
@@ -51,6 +52,7 @@ public CodeGenerator(Builder builder) {
5152
this.models = builder.models;
5253
this.sourcesDirectory = builder.sourcesDirectory;
5354
this.testsDirectory = builder.testsDirectory;
55+
this.resourcesDirectory = builder.resourcesDirectory;
5456
this.fileNamePrefix = builder.fileNamePrefix;
5557
}
5658

@@ -124,7 +126,10 @@ private void emitCode(IntermediateModel intermediateModel) {
124126
}
125127

126128
private GeneratorTask createGeneratorTasks(IntermediateModel intermediateModel) {
127-
return new AwsGeneratorTasks(GeneratorTaskParams.create(intermediateModel, sourcesDirectory, testsDirectory));
129+
return new AwsGeneratorTasks(GeneratorTaskParams.create(intermediateModel,
130+
sourcesDirectory,
131+
testsDirectory,
132+
resourcesDirectory));
128133

129134
}
130135

@@ -135,6 +140,7 @@ public static final class Builder {
135140

136141
private C2jModels models;
137142
private String sourcesDirectory;
143+
private String resourcesDirectory;
138144
private String testsDirectory;
139145
private String fileNamePrefix;
140146

@@ -151,6 +157,11 @@ public Builder sourcesDirectory(String sourcesDirectory) {
151157
return this;
152158
}
153159

160+
public Builder resourcesDirectory(String resourcesDirectory) {
161+
this.resourcesDirectory = resourcesDirectory;
162+
return this;
163+
}
164+
154165
public Builder testsDirectory(String smokeTestsDirectory) {
155166
this.testsDirectory = smokeTestsDirectory;
156167
return this;

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/GeneratorPathProvider.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,25 @@ public class GeneratorPathProvider {
2525

2626
private final IntermediateModel model;
2727
private final String sourceDirectory;
28+
private final String resourcesDirectory;
2829
private final String testDirectory;
2930

30-
public GeneratorPathProvider(IntermediateModel model, String sourceDirectory, String testDirectory) {
31+
public GeneratorPathProvider(IntermediateModel model, String sourceDirectory, String testDirectory,
32+
String resourcesDirectory) {
3133
this.model = model;
3234
this.sourceDirectory = sourceDirectory;
35+
this.resourcesDirectory = resourcesDirectory;
3336
this.testDirectory = testDirectory;
3437
}
3538

3639
public String getSourceDirectory() {
3740
return sourceDirectory;
3841
}
3942

43+
public String getResourcesDirectory() {
44+
return resourcesDirectory;
45+
}
46+
4047
public String getTestDirectory() {
4148
return testDirectory;
4249
}
@@ -81,6 +88,10 @@ public String getEndpointRulesInternalDirectory() {
8188
return sourceDirectory + "/" + Utils.packageToDirectory(model.getMetadata().getFullInternalEndpointRulesPackageName());
8289
}
8390

91+
public String getEndpointRulesInternalResourcesDirectory() {
92+
return resourcesDirectory + "/" + Utils.packageToDirectory(model.getMetadata().getFullInternalEndpointRulesPackageName());
93+
}
94+
8495
public String getEndpointRulesTestDirectory() {
8596
return testDirectory + "/" + Utils.packageToDirectory(model.getMetadata().getFullEndpointRulesPackageName());
8697
}

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/GeneratorTaskParams.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ private GeneratorTaskParams(IntermediateModel model,
4040
this.poetExtensions = new PoetExtension(model);
4141
}
4242

43-
public static GeneratorTaskParams create(IntermediateModel model, String sourceDirectory, String testDirectory) {
44-
GeneratorPathProvider pathProvider = new GeneratorPathProvider(model, sourceDirectory, testDirectory);
43+
public static GeneratorTaskParams create(IntermediateModel model, String sourceDirectory, String testDirectory,
44+
String resourcesDirectory) {
45+
GeneratorPathProvider pathProvider = new GeneratorPathProvider(model, sourceDirectory, testDirectory, resourcesDirectory);
4546
GeneratorTaskParams params = new GeneratorTaskParams(model, pathProvider);
4647
TASK_PARAMS_VALIDATORS.accept(params);
4748
return params;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ public final class RulesEngineRuntimeGeneratorTask extends BaseGeneratorTasks {
3636
public static final String RUNTIME_CLASS_NAME = "WaitersRuntime";
3737

3838
private final String engineInternalClassDir;
39+
private final String engineInternalResourcesDir;
3940
private final String engineInternalPackageName;
4041
private final String fileHeader;
4142

4243
public RulesEngineRuntimeGeneratorTask(GeneratorTaskParams generatorTaskParams) {
4344
super(generatorTaskParams);
4445
this.engineInternalClassDir = generatorTaskParams.getPathProvider().getEndpointRulesInternalDirectory();
46+
this.engineInternalResourcesDir = generatorTaskParams.getPathProvider().getEndpointRulesInternalResourcesDirectory();
4547
this.engineInternalPackageName = generatorTaskParams.getModel().getMetadata().getFullInternalEndpointRulesPackageName();
4648
this.fileHeader = generatorTaskParams.getModel().getFileHeader();
4749
}
@@ -62,7 +64,7 @@ protected List<GeneratorTask> createTasks() throws Exception {
6264

6365
for (String path : rulesEngineJsonFilePaths(rulesEngineFiles)) {
6466
String newFileName = computeNewName(path);
65-
copyTasks.add(new SimpleGeneratorTask(engineInternalClassDir,
67+
copyTasks.add(new SimpleGeneratorTask(engineInternalResourcesDir,
6668
newFileName,
6769
".json",
6870
"",

codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/PoetClientFunctionalTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public void asyncClientClassXml() throws Exception {
8888
}
8989

9090
private SyncClientClass createSyncClientClass(IntermediateModel model) {
91-
return new SyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/"));
91+
return new SyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/", "resources/"));
9292
}
9393

9494
private AsyncClientClass createAsyncClientClass(IntermediateModel model) {
95-
return new AsyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/"));
95+
return new AsyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/", "resources/"));
9696
}
9797

9898
@Test
@@ -110,14 +110,14 @@ public void syncClientEndpointDiscovery() throws Exception {
110110
@Test
111111
public void asyncClientEndpointDiscovery() throws Exception {
112112
ClassSpec asyncClientEndpointDiscovery = new AsyncClientClass(
113-
GeneratorTaskParams.create(ClientTestModels.endpointDiscoveryModels(), "sources/", "tests/"));
113+
GeneratorTaskParams.create(ClientTestModels.endpointDiscoveryModels(), "sources/", "tests/", "resources/"));
114114
assertThat(asyncClientEndpointDiscovery, generatesTo("test-endpoint-discovery-async.java"));
115115
}
116116

117117
@Test
118118
public void asyncClientCustomServiceMetaData() throws Exception {
119119
ClassSpec asyncClientCustomServiceMetaData = new AsyncClientClass(
120-
GeneratorTaskParams.create(ClientTestModels.customContentTypeModels(), "sources/", "tests/"));
120+
GeneratorTaskParams.create(ClientTestModels.customContentTypeModels(), "sources/", "tests/", "resources/"));
121121
assertThat(asyncClientCustomServiceMetaData, generatesTo("test-customservicemetadata-async.java"));
122122
}
123123

codegen/src/test/java/software/amazon/awssdk/codegen/poet/endpointdiscovery/EndpointDiscoveryCacheLoaderGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public class EndpointDiscoveryCacheLoaderGeneratorTest {
2727
@Test
2828
public void syncEndpointDiscoveryCacheLoaderGenerator() {
2929
IntermediateModel model = ClientTestModels.endpointDiscoveryModels();
30-
GeneratorTaskParams dependencies = GeneratorTaskParams.create(model, "sources/", "tests/");
30+
GeneratorTaskParams dependencies = GeneratorTaskParams.create(model, "sources/", "tests/", "resources/");
3131
EndpointDiscoveryCacheLoaderGenerator cacheLoader = new EndpointDiscoveryCacheLoaderGenerator(dependencies);
3232
assertThat(cacheLoader, generatesTo("test-sync-cache-loader.java"));
3333
}
3434

3535
@Test
3636
public void asyncEndpointDiscoveryCacheLoaderGenerator() {
3737
IntermediateModel model = ClientTestModels.endpointDiscoveryModels();
38-
GeneratorTaskParams dependencies = GeneratorTaskParams.create(model, "sources/", "tests/");
38+
GeneratorTaskParams dependencies = GeneratorTaskParams.create(model, "sources/", "tests/", "resources/");
3939
EndpointDiscoveryAsyncCacheLoaderGenerator cacheLoader = new EndpointDiscoveryAsyncCacheLoaderGenerator(dependencies);
4040
assertThat(cacheLoader, generatesTo("test-async-cache-loader.java"));
4141
}

codegen/src/test/java/software/amazon/awssdk/codegen/poet/eventstream/EventStreamFunctionalTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void responseHandlerBuilder() throws Exception {
4646
private void runTest(BiFunction<GeneratorTaskParams, OperationModel, ClassSpec> specFactory,
4747
String expectedTestFile) {
4848
IntermediateModel model = ClientTestModels.restJsonServiceModels();
49-
GeneratorTaskParams dependencies = GeneratorTaskParams.create(model, "sources/", "tests/");
49+
GeneratorTaskParams dependencies = GeneratorTaskParams.create(model, "sources/", "tests/", "resources/");
5050
ClassSpec classSpec = specFactory.apply(dependencies, model.getOperation("EventStreamOperation"));
5151
assertThat(classSpec, generatesTo(expectedTestFile));
5252
}

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@
302302
</sources>
303303
</configuration>
304304
</execution>
305+
<execution>
306+
<id>add-generated-resources</id>
307+
<phase>generate-sources</phase>
308+
<goals>
309+
<goal>add-resource</goal>
310+
</goals>
311+
<configuration>
312+
<resources>
313+
<resource>
314+
<directory>${basedir}/target/generated-resources/sdk-resources</directory>
315+
</resource>
316+
</resources>
317+
</configuration>
318+
</execution>
305319
<execution>
306320
<id>add-license-notice</id>
307321
<phase>generate-sources</phase>

0 commit comments

Comments
 (0)