Repository navigation
Expand file tree
/
Copy pathnative-image.sh
More file actions
executable file
·189 lines (156 loc) · 4.47 KB
/
Copy pathnative-image.sh
File metadata and controls
executable file
·189 lines (156 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT"
IMAGE="ghcr.io/graalvm/native-image-community:25"
MODULES=(watsonx-ai-core watsonx-ai-jackson2 watsonx-ai-jackson3)
REFLECTION_DENY_PREFIXES_JSON='[
"com.github.jknack.handlebars",
"com.google.common",
"com.google.gson",
"com.jayway.jsonpath",
"com.squareup.moshi",
"com.sun.management.internal",
"com.sun.org.apache.xalan",
"com.sun.org.apache.xerces",
"com.sun.security",
"jakarta.servlet",
"javax.servlet",
"jdk.internal",
"jdk.management",
"net.javacrumbs.jsonunit",
"org.apache.commons",
"org.apache.johnzon",
"org.apache.logging",
"org.apiguardian",
"org.jcp.xml.dsig",
"org.json",
"org.jspecify",
"org.osgi",
"org.junit",
"sun.instrument",
"sun.invoke.util",
"sun.management.spi",
"sun.net.spi",
"sun.reflect",
"uk.org.webcompere"
]'
RESOURCE_ALLOW_PREFIXES_JSON='[
"META-INF/services/com.fasterxml.",
"META-INF/services/com.ibm.watsonx.",
"META-INF/services/java.",
"META-INF/services/javax.",
"META-INF/services/org.slf4j."
]'
if ! command -v native-image-configure >/dev/null 2>&1; then
command -v podman >/dev/null 2>&1 || {
echo "ERROR: GraalVM and podman are not available." >&2
exit 1
}
echo "==> Running inside $IMAGE"
exec podman run --rm \
--security-opt label=disable \
-e LC_ALL=C \
-e LANG=C \
-e LC_CTYPE=C \
--entrypoint bash \
-v "$ROOT:/workspace" \
-v "$HOME/.m2:/root/.m2" \
-w /workspace \
"$IMAGE" \
-c "./native-image.sh"
fi
if ! command -v jq >/dev/null 2>&1; then
echo "==> Installing jq"
microdnf install -y jq >/dev/null
fi
echo "==> Installing parent POM"
./mvnw install -N -B -ntp -q
echo "==> Installing watsonx-ai-core"
./mvnw install \
-pl modules/watsonx-ai-core \
-B -ntp -q \
-DskipTests
echo "==> Installing watsonx-ai"
./mvnw install \
-pl modules/watsonx-ai \
-B -ntp -q \
-DskipTests
clean_metadata() {
local file="$1"
echo "==> [$(basename "$(dirname "$file")")] Cleaning metadata: $file"
local tmp
tmp="$(mktemp)"
jq \
--argjson deny "$REFLECTION_DENY_PREFIXES_JSON" \
--argjson allow "$RESOURCE_ALLOW_PREFIXES_JSON" \
'
def denied_type:
. as $t |
(type == "string") and (any($deny[]; . as $p | $t | startswith($p)));
def denied_entry:
. as $e |
if ($e.type | type) == "string" then ($e.type | denied_type)
elif ($e.type | type) == "object" then
if ($e.type | has("lambda")) then ($e.type.lambda.declaringClass | denied_type)
elif ($e.type | has("proxy")) then ($e.type.proxy | map(denied_type) | any)
else false
end
else false
end;
def allowed_resource:
. as $r |
([$r.glob, $r.bundle, $r.module] | map(select(. != null))[0] // "") as $v |
any($allow[]; . as $p | $v | startswith($p));
.reflection |= map(select(denied_entry | not)) |
.resources |= map(select(allowed_resource))
' "$file" > "$tmp"
mv "$tmp" "$file"
}
generate_metadata() {
local module="$1"
local module_dir="modules/$module"
local agent_dir="$module_dir/target/native/agent-output/test"
local output_dir="$module_dir/src/main/resources/META-INF/native-image/com.ibm.watsonx/$module"
echo "==> [$module] Running tracing agent"
./mvnw -Pnative-agent clean test -pl "$module_dir" -B -ntp
mapfile -t input_dirs < <(
find "$agent_dir" \
-name reachability-metadata.json \
-exec dirname {} \; |
sort -u
)
if [[ ${#input_dirs[@]} -eq 0 ]]; then
echo "ERROR: [$module] No reachability metadata generated." >&2
exit 1
fi
local args=()
for dir in "${input_dirs[@]}"; do
args+=("--input-dir=$dir")
done
echo "==> [$module] Generating metadata"
native-image-configure generate \
"${args[@]}" \
"--output-dir=$output_dir"
echo "==> [$module] Cleaning generated metadata"
clean_metadata "$output_dir/reachability-metadata.json"
echo "==> [$module] Reinstalling with refreshed metadata"
./mvnw install \
-pl "$module_dir" \
-B -ntp -q \
-DskipTests
}
run_native_tests() {
local module="$1"
echo "==> [$module] Running native tests"
./mvnw -Pnative clean test -pl "modules/$module" -B -ntp
}
echo "==> Generating reachability metadata"
for module in "${MODULES[@]}"; do
generate_metadata "$module"
done
echo "==> Running native tests"
for module in "${MODULES[@]}"; do
run_native_tests "$module"
done
echo "==> Done"