Skip to content

Commit e1e1912

Browse files
committed
Testing: add GitHub action for testing Java Module support
1 parent 078914c commit e1e1912

File tree

1 file changed

+249
-0
lines changed

1 file changed

+249
-0
lines changed
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
name: Java 9+ Module Support
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'moduleInfo', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
# Test Java 9+ module support (JPMS)
11+
# Verifies that module-info.java is properly compiled and the resulting
12+
# JAR can be used with jlink to create custom Java runtimes.
13+
module-test:
14+
strategy:
15+
matrix:
16+
os: [ 'ubuntu-latest' ]
17+
jdk_version: [ '11', '17', '21' ]
18+
runs-on: ${{ matrix.os }}
19+
name: Module Test (JDK ${{ matrix.jdk_version }})
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Cache JUnit dependencies
25+
uses: actions/cache@v4
26+
id: cache-junit
27+
with:
28+
path: junit
29+
key: junit-jars-v1
30+
31+
- name: Download junit-4.13.2.jar
32+
if: steps.cache-junit.outputs.cache-hit != 'true'
33+
run: wget --directory-prefix=$GITHUB_WORKSPACE/junit https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
34+
35+
- name: Download hamcrest-all-1.3.jar
36+
if: steps.cache-junit.outputs.cache-hit != 'true'
37+
run: wget --directory-prefix=$GITHUB_WORKSPACE/junit https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar
38+
39+
- name: Build native wolfSSL
40+
uses: wolfSSL/actions-build-autotools-project@v1
41+
with:
42+
repository: wolfSSL/wolfssl
43+
ref: master
44+
path: wolfssl
45+
configure: --enable-jni
46+
check: false
47+
install: true
48+
49+
- name: Setup Java
50+
uses: actions/setup-java@v4
51+
with:
52+
distribution: 'zulu'
53+
java-version: ${{ matrix.jdk_version }}
54+
55+
- name: Set JUNIT_HOME
56+
run: |
57+
echo "JUNIT_HOME=$GITHUB_WORKSPACE/junit" >> "$GITHUB_ENV"
58+
59+
- name: Set LD_LIBRARY_PATH
60+
run: |
61+
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
62+
63+
- name: Copy makefile
64+
run: cp makefile.linux makefile
65+
66+
- name: Build JNI library
67+
run: PREFIX=$GITHUB_WORKSPACE/build-dir make
68+
69+
- name: Build JAR with module support (ant)
70+
run: ant build-jce-release
71+
72+
- name: Verify module-info.class exists in JAR
73+
run: |
74+
echo "Checking for module-info.class in wolfcrypt-jni.jar..."
75+
if jar tf lib/wolfcrypt-jni.jar | grep -q "module-info.class"; then
76+
echo "SUCCESS: module-info.class found in JAR"
77+
else
78+
echo "FAILURE: module-info.class not found in JAR"
79+
echo "JAR contents:"
80+
jar tf lib/wolfcrypt-jni.jar | head -20
81+
exit 1
82+
fi
83+
84+
- name: Verify module descriptor with jar --describe-module
85+
run: |
86+
echo "Describing module in wolfcrypt-jni.jar..."
87+
jar --describe-module --file=lib/wolfcrypt-jni.jar
88+
echo ""
89+
echo "Verifying module name is 'com.wolfssl.wolfcrypt'..."
90+
MODULE_NAME=$(jar --describe-module --file=lib/wolfcrypt-jni.jar 2>&1 | head -1 | cut -d' ' -f1)
91+
if [ "$MODULE_NAME" = "com.wolfssl.wolfcrypt" ]; then
92+
echo "SUCCESS: Module name is correct: $MODULE_NAME"
93+
else
94+
echo "FAILURE: Expected module name 'com.wolfssl.wolfcrypt', got '$MODULE_NAME'"
95+
exit 1
96+
fi
97+
98+
- name: Verify module exports correct packages
99+
run: |
100+
echo "Verifying module exports..."
101+
EXPORTS=$(jar --describe-module --file=lib/wolfcrypt-jni.jar 2>&1)
102+
echo "$EXPORTS"
103+
echo ""
104+
if echo "$EXPORTS" | grep -q "exports com.wolfssl.wolfcrypt"; then
105+
echo "SUCCESS: exports com.wolfssl.wolfcrypt"
106+
else
107+
echo "FAILURE: missing 'exports com.wolfssl.wolfcrypt'"
108+
exit 1
109+
fi
110+
if echo "$EXPORTS" | grep -q "exports com.wolfssl.provider.jce"; then
111+
echo "SUCCESS: exports com.wolfssl.provider.jce"
112+
else
113+
echo "FAILURE: missing 'exports com.wolfssl.provider.jce'"
114+
exit 1
115+
fi
116+
117+
- name: Test jlink can create runtime with module
118+
run: |
119+
echo "Testing jlink integration..."
120+
jlink \
121+
--module-path lib/wolfcrypt-jni.jar \
122+
--add-modules com.wolfssl.wolfcrypt \
123+
--output test-jlink-runtime \
124+
--no-header-files \
125+
--no-man-pages
126+
echo ""
127+
echo "SUCCESS: jlink created custom runtime"
128+
echo "Runtime modules:"
129+
./test-jlink-runtime/bin/java --list-modules
130+
echo ""
131+
echo "Verifying com.wolfssl.wolfcrypt module is present..."
132+
if ./test-jlink-runtime/bin/java --list-modules | grep -q "com.wolfssl.wolfcrypt"; then
133+
echo "SUCCESS: com.wolfssl.wolfcrypt module found in custom runtime"
134+
else
135+
echo "FAILURE: com.wolfssl.wolfcrypt module not found in custom runtime"
136+
exit 1
137+
fi
138+
139+
- name: Clean up jlink test runtime
140+
run: rm -rf test-jlink-runtime
141+
142+
- name: Run standard tests to verify module doesn't break functionality
143+
run: ant test
144+
145+
- name: Clean ant build for Maven test
146+
run: ant clean
147+
148+
- name: Maven build and verify module-info in JAR
149+
run: |
150+
echo "Building with Maven..."
151+
mvn package -DskipTests -q
152+
echo ""
153+
MAVEN_JAR=$(ls target/wolfcrypt-jni-*.jar)
154+
echo "Maven JAR: $MAVEN_JAR"
155+
echo ""
156+
echo "Checking for module-info.class in Maven-built JAR..."
157+
if jar tf "$MAVEN_JAR" | grep -q "module-info.class"; then
158+
echo "SUCCESS: module-info.class found in Maven JAR"
159+
else
160+
echo "FAILURE: module-info.class not found in Maven JAR"
161+
jar tf "$MAVEN_JAR" | head -20
162+
exit 1
163+
fi
164+
echo ""
165+
echo "Verifying Maven JAR module descriptor..."
166+
jar --describe-module --file="$MAVEN_JAR"
167+
168+
- name: Clean Maven build
169+
run: mvn clean -q
170+
171+
- name: Show logs on failure
172+
if: failure() || cancelled()
173+
run: |
174+
cat build/reports/*.txt 2>/dev/null || echo "No test reports found"
175+
176+
# Verify Java 8 builds do NOT include module-info.class
177+
# This ensures the conditional compilation works correctly for Java 8 users
178+
java8-no-module-test:
179+
runs-on: ubuntu-latest
180+
name: Java 8 No Module Test
181+
182+
steps:
183+
- uses: actions/checkout@v4
184+
185+
- name: Cache JUnit dependencies
186+
uses: actions/cache@v4
187+
id: cache-junit
188+
with:
189+
path: junit
190+
key: junit-jars-v1
191+
192+
- name: Download junit-4.13.2.jar
193+
if: steps.cache-junit.outputs.cache-hit != 'true'
194+
run: wget --directory-prefix=$GITHUB_WORKSPACE/junit https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
195+
196+
- name: Download hamcrest-all-1.3.jar
197+
if: steps.cache-junit.outputs.cache-hit != 'true'
198+
run: wget --directory-prefix=$GITHUB_WORKSPACE/junit https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar
199+
200+
- name: Build native wolfSSL
201+
uses: wolfSSL/actions-build-autotools-project@v1
202+
with:
203+
repository: wolfSSL/wolfssl
204+
ref: master
205+
path: wolfssl
206+
configure: --enable-jni
207+
check: false
208+
install: true
209+
210+
- name: Setup Java 8
211+
uses: actions/setup-java@v4
212+
with:
213+
distribution: 'zulu'
214+
java-version: '8'
215+
216+
- name: Set JUNIT_HOME
217+
run: |
218+
echo "JUNIT_HOME=$GITHUB_WORKSPACE/junit" >> "$GITHUB_ENV"
219+
220+
- name: Set LD_LIBRARY_PATH
221+
run: |
222+
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
223+
224+
- name: Copy makefile
225+
run: cp makefile.linux makefile
226+
227+
- name: Build JNI library
228+
run: PREFIX=$GITHUB_WORKSPACE/build-dir make
229+
230+
- name: Build JAR with Java 8 (ant)
231+
run: ant build-jce-release
232+
233+
- name: Verify module-info.class is NOT in JAR (Java 8)
234+
run: |
235+
echo "Checking that module-info.class is NOT in wolfcrypt-jni.jar (Java 8 build)..."
236+
if jar tf lib/wolfcrypt-jni.jar | grep -q "module-info.class"; then
237+
echo "FAILURE: module-info.class should NOT be in Java 8 JAR"
238+
exit 1
239+
else
240+
echo "SUCCESS: module-info.class correctly absent from Java 8 JAR"
241+
fi
242+
243+
- name: Run standard tests to verify Java 8 compatibility
244+
run: ant test
245+
246+
- name: Show logs on failure
247+
if: failure() || cancelled()
248+
run: |
249+
cat build/reports/*.txt 2>/dev/null || echo "No test reports found"

0 commit comments

Comments
 (0)