Skip to content

Commit 52ff67b

Browse files
committed
generate service mapping vm file during build time
1 parent b510c1f commit 52ff67b

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

archetypes/archetype-lambda/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
3636
</properties>
3737

38+
<dependencies>
39+
<!-- Depends on the artifacts of all services to generate serviceMapping.vm -->
40+
<dependency>
41+
<groupId>software.amazon.awssdk</groupId>
42+
<artifactId>aws-sdk-java</artifactId>
43+
<version>${awsjavasdk.version}</version>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
3847
<build>
3948
<!-- Filtering the resource properties to get ${project.version} from archetype metadata.
4049
See https://stackoverflow.com/a/22300149 -->
@@ -63,6 +72,23 @@
6372
</extensions>
6473

6574
<plugins>
75+
<plugin>
76+
<artifactId>exec-maven-plugin</artifactId>
77+
<groupId>org.codehaus.mojo</groupId>
78+
<version>${exec-maven-plugin.version}</version>
79+
<executions>
80+
<execution>
81+
<id>map-service-to-client-prefix</id>
82+
<phase>generate-resources</phase>
83+
<goals>
84+
<goal>exec</goal>
85+
</goals>
86+
<configuration>
87+
<executable>${basedir}/src/main/resources/map-service-to-client-prefix</executable>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
6692
<plugin>
6793
<artifactId>maven-archetype-plugin</artifactId>
6894
<version>${maven.archetype.version}</version>
@@ -81,6 +107,16 @@
81107
</execution>
82108
</executions>
83109
</plugin>
110+
111+
<!-- Skip dependency analysis because it's unnecessary for this module -->
112+
<plugin>
113+
<groupId>org.apache.maven.plugins</groupId>
114+
<artifactId>maven-dependency-plugin</artifactId>
115+
<version>${maven-dependency-plugin.version}</version>
116+
<configuration>
117+
<skip>true</skip>
118+
</configuration>
119+
</plugin>
84120
</plugins>
85121
</build>
86122
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
3+
import json
4+
import os
5+
import string
6+
7+
MAPPING_FILE_NAME = 'serviceMapping.vm'
8+
RESOURCES_ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)))
9+
ARCHETYPE_LAMBDA_ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(os.path.join(RESOURCES_ROOT_DIR, "../"))))
10+
SERVICE_DIR = os.path.join(
11+
os.path.dirname(os.path.dirname(os.path.abspath(os.path.join(__file__, "../../../../")))),
12+
'services'
13+
)
14+
15+
def load_all_service_modules():
16+
service_mapping = {}
17+
for f in [f for f in os.listdir(SERVICE_DIR) if os.path.isdir(os.path.join(SERVICE_DIR, f)) & os.path.exists(os.path.join(SERVICE_DIR, f, 'target'))]:
18+
for s in [s for s in os.listdir(os.path.join(SERVICE_DIR, f, 'target', 'generated-sources/sdk/software/amazon/awssdk/services', f)) if s.endswith('AsyncClient.java') & s.startswith('Default')]:
19+
service_mapping[f] = find_client_prefix(s)
20+
return service_mapping
21+
22+
def find_client_prefix(d):
23+
index = d.find('AsyncClient.java')
24+
return d[7:index]
25+
26+
def write_to_vm_file(service_mapping):
27+
target = os.path.join(ARCHETYPE_LAMBDA_ROOT_DIR, 'target', 'classes')
28+
29+
if not os.path.exists(target):
30+
os.mkdir(target)
31+
32+
filename = os.path.join(target, MAPPING_FILE_NAME)
33+
34+
with open(filename, 'w') as f:
35+
f.write('#set ( $serviceMapping =')
36+
f.write(json.dumps(service_mapping))
37+
f.write(')')
38+
return filename
39+
40+
def main():
41+
service_mapping = load_all_service_modules()
42+
write_to_vm_file(service_mapping)
43+
44+
if __name__ == '__main__':
45+
main()

archetypes/archetype-lambda/src/main/resources/serviceMapping.vm

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)