Skip to content

Commit 71cc5c9

Browse files
committed
Add validation for .brazil.json
This commit adds the `validate-brazil-config` script, which validates the .brazil.json file for correctness. It validates that all modules of the SDK are mapped to a package internally, or explicitly skipped. Additional, it ensures that all external dependencies are also mapped to internal packages. The buildspecs/validate-brazil-config.yml is so that this validation can run as PR build check.
1 parent 404dae2 commit 71cc5c9

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 0.2
2+
3+
phases:
4+
install:
5+
runtime-versions:
6+
java: "$JAVA_RUNTIME"
7+
python: 3.13
8+
9+
build:
10+
commands:
11+
- mvn clean install -P quick -T0.4C
12+
- mvn exec:exec -Dexec.executable=pwd -pl !:aws-sdk-java-pom,!:sdk-benchmarks,!:module-path-tests -q 2>&1 > modules.txt
13+
- mvn dependency:list -DexcludeTransitive=true -DincludeScope=runtime 2>&1 > deps.txt
14+
- scripts/validate-brazil-config modules.txt deps.txt

scripts/validate-brazil-config

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python3
2+
from pathlib import Path
3+
import json
4+
import sys
5+
import re
6+
7+
# This script validates that:
8+
# - All SDK modules are mapped or skipped for internal import
9+
# - All non-SDK dependencies of imported modules are mapped to internal
10+
# packages
11+
#
12+
# Usage: validate-brazil-config [module-paths-file] [dependencies-file]
13+
14+
# Generating module-paths-file:
15+
# mvn exec:exec -Dexec.executable=pwd -pl \!:aws-sdk-java-pom,\!:sdk-benchmarks,\!:module-path-tests -q 2>&1 > modules.txt
16+
#
17+
# Generates contents similar to:
18+
# /workspace/aws-sdk-java-v2/build-tools
19+
# /workspace/aws-sdk-java-v2/core
20+
# /workspace/aws-sdk-java-v2/core/annotations
21+
# /workspace/aws-sdk-java-v2/utils
22+
# /workspace/aws-sdk-java-v2/test/test-utils
23+
# /workspace/aws-sdk-java-v2/core/metrics-spi
24+
# /workspace/aws-sdk-java-v2/http-client-spi
25+
# /workspace/aws-sdk-java-v2/core/endpoints-spi
26+
# /workspace/aws-sdk-java-v2/core/identity-spi
27+
# /workspace/aws-sdk-java-v2/core/http-auth-spi
28+
# ...
29+
30+
# Generating dependencies-file:
31+
# mvn dependency:list -DexcludeTransitive=true -DincludeScope=runtime 2>&1 > deps.txt
32+
#
33+
# Generates content similar to:
34+
#
35+
# [INFO] -----------------< software.amazon.awssdk:test-utils >------------------
36+
# [INFO] Building AWS Java SDK :: Test :: Test Utils 2.31.61-SNAPSHOT [6/493]
37+
# [INFO] from test/test-utils/pom.xml
38+
# [INFO] --------------------------------[ jar ]---------------------------------
39+
# [INFO]
40+
# [INFO] --- dependency:3.1.1:list (default-cli) @ test-utils ---
41+
# [INFO]
42+
# [INFO] The following files have been resolved:
43+
# [INFO] org.slf4j:slf4j-api:jar:1.7.36:compile -- module org.slf4j [auto]
44+
# [INFO] org.junit.jupiter:junit-jupiter:jar:5.10.0:compile -- module org.junit.jupiter
45+
# [INFO] com.fasterxml.jackson.core:jackson-core:jar:2.15.2:compile -- module com.fasterxml.jackson.core
46+
# ...
47+
48+
brazil_import_config_path=".brazil.json"
49+
50+
with open(brazil_import_config_path) as f:
51+
brazil_import_config = json.loads(f.read())
52+
53+
modules_path=sys.argv[1]
54+
55+
p = Path(modules_path)
56+
57+
service_modules = set()
58+
core_modules = set()
59+
60+
with open(modules_path) as f:
61+
for l in f.readlines():
62+
l = l.strip()
63+
module_path = Path(l)
64+
name = module_path.name
65+
if module_path.parent.name == 'services':
66+
service_modules.add(name)
67+
else:
68+
core_modules.add(name)
69+
70+
# Ensure all 'core' modules are mapped. For the purposes of this validation, we
71+
# don't care if we map to a package name or skip import.
72+
config_modules = brazil_import_config['modules']
73+
for core_module in core_modules:
74+
if core_module not in config_modules:
75+
raise Exception(f"The module {core_module} is not mapped!")
76+
77+
78+
# Ensure all dependencies are mapped.
79+
current_module_pattern = re.compile(r"\[INFO\] --- .*:list \(default-cli\) @ (.*) ---")
80+
dependency_pattern = re.compile(r"\[INFO\] ([^: ]+:[^: ]+):jar:[^: ]+:(compile|runtime)")
81+
82+
deps_path=sys.argv[2]
83+
config_dependencies = brazil_import_config['dependencies']
84+
with open(deps_path) as f:
85+
for l in f.readlines():
86+
# Match a line that gives the name of the current module
87+
match = current_module_pattern.match(l)
88+
if match is not None:
89+
# Unless explicitly skipped, all modules are imported
90+
skipping_import = False
91+
current_module = match.group(1)
92+
93+
if current_module in config_modules:
94+
module_import = config_modules[current_module]
95+
96+
if 'skipImport' in module_import and module_import['skipImport']:
97+
print(f"Module import skipped for {current_module}")
98+
skipping_import = True
99+
100+
continue
101+
102+
# Match a line that gives a dependency of a given module
103+
match = dependency_pattern.match(l)
104+
if match is not None and \
105+
not skipping_import and \
106+
not match.group(1).startswith("software.amazon.awssdk:"):
107+
# The current module is being imported, and this dependency is not an SDK
108+
# module. Ensure that it's mapped
109+
dependency_name = match.group(1)
110+
if dependency_name not in config_dependencies:
111+
raise Exception(f"The dependency {dependency_name} is not mapped!")

0 commit comments

Comments
 (0)