Repository navigation
316 lines (277 loc) · 11.1 KB
/
Copy pathjava-module-test.yml
File metadata and controls
316 lines (277 loc) · 11.1 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
name: Java 9+ Module Support
on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]
# Cancel superseded in-progress runs for the same PR. Runs
# triggered by push events are never cancelled.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# Test Java 9+ module support (JPMS)
# Verifies that module-info.java is properly compiled and the resulting
# JAR can be used with jlink to create custom Java runtimes.
# See GitHub issue #85 for background.
module-test:
strategy:
matrix:
os: [ 'ubuntu-latest' ]
jdk_version: [ '11', '17', '21' ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
name: Module Test (JDK ${{ matrix.jdk_version }})
steps:
- uses: actions/checkout@v4
- name: Setup JUnit
uses: ./.github/actions/setup-junit
# Cache the installed wolfSSL build. The key matches the one built
# in linux-common.yml for the same configure flags, so this job
# shares the cache with the main CI matrix.
- name: Resolve wolfSSL cache key
id: wolfssl-key
env:
WOLFSSL_CONFIGURE: '--enable-jni'
run: |
SHA=$(git ls-remote https://github.com/wolfSSL/wolfssl.git \
refs/heads/master | cut -f1)
if [ -z "$SHA" ]; then
echo "Failed to resolve wolfSSL master SHA" >&2
exit 1
fi
CFG_HASH=$(printf '%s' "$WOLFSSL_CONFIGURE" | \
shasum -a 256 | cut -c1-16)
KEY="wolfssl-${{ runner.os }}-${{ runner.arch }}-$SHA-$CFG_HASH"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
echo "key=$KEY" >> "$GITHUB_OUTPUT"
- name: Restore cached wolfSSL install
id: cache-wolfssl
uses: actions/cache/restore@v4
with:
path: build-dir
key: ${{ steps.wolfssl-key.outputs.key }}
# Build the exact commit the cache key was computed from so the
# key and contents cannot drift if master advances mid-run.
- name: Build native wolfSSL
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
uses: wolfSSL/actions-build-autotools-project@v1
with:
repository: wolfSSL/wolfssl
ref: ${{ steps.wolfssl-key.outputs.sha }}
path: wolfssl
configure: --enable-jni
check: false
install: true
# Save right after building (not at job end) so a later test
# failure does not prevent the cache from being populated.
- name: Save wolfSSL install to cache
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: build-dir
key: ${{ steps.wolfssl-key.outputs.key }}
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: ${{ matrix.jdk_version }}
- name: Set LD_LIBRARY_PATH
run: |
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
- name: Build JNI library
run: ./java.sh $GITHUB_WORKSPACE/build-dir
- name: Build JAR with module support (ant)
run: ant
- name: Verify module-info.class exists in JAR
run: |
echo "Checking for module-info.class in wolfssl-jsse.jar..."
if jar tf lib/wolfssl-jsse.jar | grep -q "module-info.class"; then
echo "SUCCESS: module-info.class found in JAR"
else
echo "FAILURE: module-info.class not found in JAR"
echo "JAR contents:"
jar tf lib/wolfssl-jsse.jar | head -20
exit 1
fi
- name: Verify module descriptor with jar --describe-module
run: |
echo "Describing module in wolfssl-jsse.jar..."
jar --describe-module --file=lib/wolfssl-jsse.jar
echo ""
echo "Verifying module name is 'com.wolfssl'..."
MODULE_NAME=$(jar --describe-module --file=lib/wolfssl-jsse.jar 2>&1 | head -1 | cut -d' ' -f1)
if [ "$MODULE_NAME" = "com.wolfssl" ]; then
echo "SUCCESS: Module name is correct: $MODULE_NAME"
else
echo "FAILURE: Expected module name 'com.wolfssl', got '$MODULE_NAME'"
exit 1
fi
- name: Verify module exports correct packages
run: |
echo "Verifying module exports..."
EXPORTS=$(jar --describe-module --file=lib/wolfssl-jsse.jar 2>&1)
echo "$EXPORTS"
echo ""
if echo "$EXPORTS" | grep -q "exports com.wolfssl"; then
echo "SUCCESS: exports com.wolfssl"
else
echo "FAILURE: missing 'exports com.wolfssl'"
exit 1
fi
if echo "$EXPORTS" | grep -q "exports com.wolfssl.provider.jsse"; then
echo "SUCCESS: exports com.wolfssl.provider.jsse"
else
echo "FAILURE: missing 'exports com.wolfssl.provider.jsse'"
exit 1
fi
- name: Test jlink can create runtime with module
run: |
echo "Testing jlink integration..."
jlink \
--module-path lib/wolfssl-jsse.jar \
--add-modules com.wolfssl \
--output test-jlink-runtime \
--no-header-files \
--no-man-pages
echo ""
echo "SUCCESS: jlink created custom runtime"
echo "Runtime modules:"
./test-jlink-runtime/bin/java --list-modules
echo ""
echo "Verifying com.wolfssl module is present..."
if ./test-jlink-runtime/bin/java --list-modules | grep -q "com.wolfssl"; then
echo "SUCCESS: com.wolfssl module found in custom runtime"
else
echo "FAILURE: com.wolfssl module not found in custom runtime"
exit 1
fi
- name: Clean up jlink test runtime
run: rm -rf test-jlink-runtime
- name: Run standard tests to verify module doesn't break functionality
run: ant test
- name: Clean ant build for Maven test
run: ant clean
- name: Maven build and verify module-info in JAR
run: |
echo "Building with Maven..."
mvn package -DskipTests -q
echo ""
MAVEN_JAR=$(ls target/wolfssl-jsse-*.jar)
echo "Maven JAR: $MAVEN_JAR"
echo ""
echo "Checking for module-info.class in Maven-built JAR..."
if jar tf "$MAVEN_JAR" | grep -q "module-info.class"; then
echo "SUCCESS: module-info.class found in Maven JAR"
else
echo "FAILURE: module-info.class not found in Maven JAR"
jar tf "$MAVEN_JAR" | head -20
exit 1
fi
echo ""
echo "Verifying Maven JAR module descriptor..."
jar --describe-module --file="$MAVEN_JAR"
- name: Clean Maven build
run: mvn clean -q
- name: Show logs on failure
if: failure() || cancelled()
run: |
cat build/reports/*.txt 2>/dev/null || echo "No test reports found"
# Verify Java 8 builds do NOT include module-info.class
# This ensures the conditional compilation works correctly for Java 8 users
java8-no-module-test:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Java 8 No Module Test
steps:
- uses: actions/checkout@v4
- name: Setup JUnit
uses: ./.github/actions/setup-junit
# Cache the installed wolfSSL build. The key matches the one built
# in linux-common.yml for the same configure flags, so this job
# shares the cache with the main CI matrix.
- name: Resolve wolfSSL cache key
id: wolfssl-key
env:
WOLFSSL_CONFIGURE: '--enable-jni'
run: |
SHA=$(git ls-remote https://github.com/wolfSSL/wolfssl.git \
refs/heads/master | cut -f1)
if [ -z "$SHA" ]; then
echo "Failed to resolve wolfSSL master SHA" >&2
exit 1
fi
CFG_HASH=$(printf '%s' "$WOLFSSL_CONFIGURE" | \
shasum -a 256 | cut -c1-16)
KEY="wolfssl-${{ runner.os }}-${{ runner.arch }}-$SHA-$CFG_HASH"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
echo "key=$KEY" >> "$GITHUB_OUTPUT"
- name: Restore cached wolfSSL install
id: cache-wolfssl
uses: actions/cache/restore@v4
with:
path: build-dir
key: ${{ steps.wolfssl-key.outputs.key }}
# Build the exact commit the cache key was computed from so the
# key and contents cannot drift if master advances mid-run.
- name: Build native wolfSSL
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
uses: wolfSSL/actions-build-autotools-project@v1
with:
repository: wolfSSL/wolfssl
ref: ${{ steps.wolfssl-key.outputs.sha }}
path: wolfssl
configure: --enable-jni
check: false
install: true
# Save right after building (not at job end) so a later test
# failure does not prevent the cache from being populated.
- name: Save wolfSSL install to cache
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: build-dir
key: ${{ steps.wolfssl-key.outputs.key }}
- name: Setup Java 8
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '8'
- name: Set LD_LIBRARY_PATH
run: |
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
- name: Build JNI library
run: ./java.sh $GITHUB_WORKSPACE/build-dir
- name: Build JAR without module support (ant on Java 8)
run: ant
- name: Verify module-info.class is NOT in JAR (Java 8 build)
run: |
echo "Checking that module-info.class is NOT in wolfssl-jsse.jar (Java 8 build)..."
if jar tf lib/wolfssl-jsse.jar | grep -q "module-info.class"; then
echo "FAILURE: module-info.class should NOT be in JAR when built with Java 8"
exit 1
else
echo "SUCCESS: module-info.class correctly excluded from Java 8 build"
fi
- name: Run tests to verify Java 8 build works correctly
run: ant test
- name: Maven build and verify NO module-info in JAR (Java 8)
run: |
echo "Building with Maven on Java 8..."
mvn package -DskipTests -q
echo ""
MAVEN_JAR=$(ls target/wolfssl-jsse-*.jar)
echo "Maven JAR: $MAVEN_JAR"
echo ""
echo "Checking that module-info.class is NOT in Maven-built JAR..."
if jar tf "$MAVEN_JAR" | grep -q "module-info.class"; then
echo "FAILURE: module-info.class should NOT be in Maven JAR on Java 8"
exit 1
else
echo "SUCCESS: module-info.class correctly excluded from Maven Java 8 build"
fi
mvn clean -q
- name: Show logs on failure
if: failure() || cancelled()
run: |
cat build/reports/*.txt 2>/dev/null || echo "No test reports found"