Repository navigation
287 lines (252 loc) · 11.1 KB
/
Copy pathjava-module-test.yml
File metadata and controls
287 lines (252 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
name: Java 9+ Module Support
on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]
# Cancel superseded in-progress runs for the same PR. In-progress
# push runs are never cancelled, though a still-queued push run may
# be superseded by a newer queued one.
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.
module-test:
strategy:
matrix:
os: [ 'ubuntu-latest' ]
jdk_version: [ '11', '15', '17', '21' ]
runs-on: ${{ matrix.os }}
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: Build native wolfSSL (cached)
uses: ./.github/actions/build-wolfssl-cached
with:
configure: '--enable-jni'
- 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: Copy makefile
run: cp makefile.linux makefile
- name: Build JNI library
run: PREFIX=$GITHUB_WORKSPACE/build-dir make
- name: Build JAR with module support (ant)
run: ant build-jce-release
- name: Verify module-info.class exists in JAR
run: |
echo "Checking for module-info.class in wolfcrypt-jni.jar..."
if jar tf lib/wolfcrypt-jni.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/wolfcrypt-jni.jar | head -20
exit 1
fi
- name: Verify EdDSA multi-release overlay layout
env:
JAVA_MAJOR: ${{ matrix.jdk_version }}
run: |
MR=$(unzip -p lib/wolfcrypt-jni.jar META-INF/MANIFEST.MF | tr -d '\r' | grep -c '^Multi-Release: true' || true)
OVERLAY=$(jar tf lib/wolfcrypt-jni.jar | grep -c 'META-INF/versions/15/com/wolfssl/provider/jce/WolfCryptEdDSA' || true)
echo "Multi-Release manifest entries: $MR, overlay classes: $OVERLAY"
if [ "$JAVA_MAJOR" -ge 15 ]; then
if [ "$MR" -ne 1 ] || [ "$OVERLAY" -lt 3 ]; then
echo "FAILURE: JDK $JAVA_MAJOR build must contain the META-INF/versions/15 EdDSA overlay"
exit 1
fi
if [ "$JAVA_MAJOR" -ge 17 ]; then
# jar --validate: absent on JDK 11, present from 17, 15 and 16
# unverified
echo "Validating multi-release JAR structure (jar --validate)..."
jar --validate --file lib/wolfcrypt-jni.jar
fi
echo "SUCCESS: JDK 15+ EdDSA overlay present"
else
if [ "$MR" -ne 0 ] || [ "$OVERLAY" -ne 0 ]; then
echo "FAILURE: JDK $JAVA_MAJOR build must not be marked Multi-Release or contain the versions/15 overlay"
exit 1
fi
echo "SUCCESS: no overlay on JDK $JAVA_MAJOR (base classes only)"
fi
- name: Verify module descriptor with jar --describe-module
run: |
echo "Describing module in wolfcrypt-jni.jar..."
jar --describe-module --file=lib/wolfcrypt-jni.jar
echo ""
echo "Verifying module name is 'com.wolfssl.wolfcrypt'..."
MODULE_NAME=$(jar --describe-module --file=lib/wolfcrypt-jni.jar 2>&1 | head -1 | cut -d' ' -f1)
if [ "$MODULE_NAME" = "com.wolfssl.wolfcrypt" ]; then
echo "SUCCESS: Module name is correct: $MODULE_NAME"
else
echo "FAILURE: Expected module name 'com.wolfssl.wolfcrypt', got '$MODULE_NAME'"
exit 1
fi
- name: Verify module exports correct packages
run: |
echo "Verifying module exports..."
EXPORTS=$(jar --describe-module --file=lib/wolfcrypt-jni.jar 2>&1)
echo "$EXPORTS"
echo ""
if echo "$EXPORTS" | grep -q "exports com.wolfssl.wolfcrypt"; then
echo "SUCCESS: exports com.wolfssl.wolfcrypt"
else
echo "FAILURE: missing 'exports com.wolfssl.wolfcrypt'"
exit 1
fi
if echo "$EXPORTS" | grep -q "exports com.wolfssl.provider.jce"; then
echo "SUCCESS: exports com.wolfssl.provider.jce"
else
echo "FAILURE: missing 'exports com.wolfssl.provider.jce'"
exit 1
fi
- name: Test jlink can create runtime with module
run: |
echo "Testing jlink integration..."
jlink \
--module-path lib/wolfcrypt-jni.jar:$JAVA_HOME/jmods \
--add-modules com.wolfssl.wolfcrypt \
--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.wolfcrypt module is present..."
if ./test-jlink-runtime/bin/java --list-modules | grep -q "com.wolfssl.wolfcrypt"; then
echo "SUCCESS: com.wolfssl.wolfcrypt module found in custom runtime"
else
echo "FAILURE: com.wolfssl.wolfcrypt 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
env:
JAVA_MAJOR: ${{ matrix.jdk_version }}
run: |
echo "Building with Maven..."
./mvnw package -DskipTests -q
echo ""
# Exclude the filtered-providers classified jar, also built by
# 'mvn package' on JDK 9+
MAVEN_JAR=$(ls target/wolfcrypt-jni-*.jar | grep -v filtered-providers)
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"
echo ""
echo "Checking the filtered providers stay out of the Maven JAR..."
if jar tf "$MAVEN_JAR" | grep -q '^com/wolfssl/security/providers/'; then
echo "FAILURE: filtered providers leaked into the main Maven JAR"
exit 1
fi
echo ""
echo "Verifying Maven JAR EdDSA multi-release overlay layout..."
MR=$(unzip -p "$MAVEN_JAR" META-INF/MANIFEST.MF | tr -d '\r' | grep -c '^Multi-Release: true' || true)
OVERLAY=$(jar tf "$MAVEN_JAR" | grep -c 'META-INF/versions/15/com/wolfssl/provider/jce/WolfCryptEdDSA' || true)
if [ "$JAVA_MAJOR" -ge 15 ]; then
if [ "$MR" -ne 1 ] || [ "$OVERLAY" -lt 3 ]; then
echo "FAILURE: Maven JDK $JAVA_MAJOR build must contain the META-INF/versions/15 EdDSA overlay"
exit 1
fi
if [ "$JAVA_MAJOR" -ge 17 ]; then
# jar --validate: absent on JDK 11, present from 17, 15 and 16
# unverified
echo "Validating Maven multi-release JAR structure (jar --validate)..."
jar --validate --file "$MAVEN_JAR"
fi
elif [ "$MR" -ne 0 ] || [ "$OVERLAY" -ne 0 ]; then
echo "FAILURE: Maven JDK $JAVA_MAJOR build must not be marked Multi-Release or contain the overlay"
exit 1
fi
echo "SUCCESS: Maven JAR overlay layout matches JDK $JAVA_MAJOR"
- name: Clean Maven build
run: ./mvnw 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
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: Build native wolfSSL (cached)
uses: ./.github/actions/build-wolfssl-cached
with:
configure: '--enable-jni'
- 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: Copy makefile
run: cp makefile.linux makefile
- name: Build JNI library
run: PREFIX=$GITHUB_WORKSPACE/build-dir make
- name: Build JAR with Java 8 (ant)
run: ant build-jce-release
- name: Verify module-info.class is NOT in JAR (Java 8)
run: |
echo "Checking that module-info.class is NOT in wolfcrypt-jni.jar (Java 8 build)..."
if jar tf lib/wolfcrypt-jni.jar | grep -q "module-info.class"; then
echo "FAILURE: module-info.class should NOT be in Java 8 JAR"
exit 1
else
echo "SUCCESS: module-info.class correctly absent from Java 8 JAR"
fi
- name: Verify no multi-release overlay in JAR (Java 8)
run: |
MR=$(unzip -p lib/wolfcrypt-jni.jar META-INF/MANIFEST.MF | tr -d '\r' | grep -c '^Multi-Release: true' || true)
OVERLAY=$(jar tf lib/wolfcrypt-jni.jar | grep -c 'META-INF/versions/15/' || true)
if [ "$MR" -ne 0 ] || [ "$OVERLAY" -ne 0 ]; then
echo "FAILURE: Java 8 build must not be marked Multi-Release or contain the versions/15 overlay"
exit 1
fi
echo "SUCCESS: no multi-release overlay in Java 8 JAR"
- name: Run standard tests to verify Java 8 compatibility
run: ant test
- name: Show logs on failure
if: failure() || cancelled()
run: |
cat build/reports/*.txt 2>/dev/null || echo "No test reports found"