JBR-8046 repack java.base.jmod with correct module hashes after signing

This commit is contained in:
Sergey Shelomentsev
2025-01-24 18:51:47 +02:00
committed by jbrbot
parent 6933c868a0
commit 21d6f5e725

View File

@@ -55,8 +55,10 @@ done
log "Signing jmod files"
JMODS_DIR="$APPLICATION_PATH/Contents/Home/jmods"
JMOD_EXE="$APPLICATION_PATH/Contents/Home/bin/jmod"
JMOD_EXE="$BOOT_JDK/bin/jmod"
if [ -d "$JMODS_DIR" ]; then
log "processing jmods"
for jmod_file in "$JMODS_DIR"/*.jmod; do
log "Processing $jmod_file"
@@ -64,16 +66,16 @@ if [ -d "$JMODS_DIR" ]; then
rm -rf "$TMP_DIR"
mkdir "$TMP_DIR"
log "Unzipping $jmod_file"
log "Unzipping $jmod_file"
$JMOD_EXE extract --dir "$TMP_DIR" "$jmod_file" >/dev/null
log "Removing $jmod_file"
rm -f "$jmod_file"
log "Signing dylibs in $TMP_DIR"
find "$TMP_DIR" \
-type f \( -name "*.dylib" -o -name "*.so"-o -perm +111 -o -name jarsigner -o -name jnativescan -o -name jdeps -o -name jpackageapplauncher -o -name jspawnhelper -o -name jar -o -name javap -o -name jdeprscan -o -name jfr -o -name rmiregistry -o -name java -o -name jhsdb -o -name jstatd -o -name jstatd -o -name jpackage -o -name keytool -o -name jmod -o -name jlink -o -name jimage -o -name jstack -o -name jcmd -o -name jps -o -name jmap -o -name jstat -o -name jinfo -o -name jshell -o -name jwebserver -o -name javac -o -name serialver -o -name jrunscript -o -name jdb -o -name jconsole -o -name javadoc \) \
-exec sh -c '"$1" --timestamp -v -s "$2" --options=runtime --force --entitlements "$3" "$4" || exit 1' sh "$SIGN_UTILITY" "$JB_DEVELOPER_CERT" "$SCRIPT_DIR/entitlements.xml" {} \;
log "Removing $jmod_file"
rm -f "$jmod_file"
cmd="$JMOD_EXE create --class-path $TMP_DIR/classes"
# Check each directory and add to the command if it exists
@@ -84,6 +86,8 @@ if [ -d "$JMODS_DIR" ]; then
[ -d "$TMP_DIR/legal" ] && cmd="$cmd --legal-notices $TMP_DIR/legal"
[ -d "$TMP_DIR/man" ] && cmd="$cmd --man-pages $TMP_DIR/man"
log "Creating jmod file"
log "$cmd"
# Add the output file
cmd="$cmd $jmod_file"
@@ -93,6 +97,41 @@ if [ -d "$JMODS_DIR" ]; then
log "Removing $TMP_DIR"
rm -rf "$TMP_DIR"
done
log "Repack java.base.jmod with new hashes of modules"
hash_modules=$($JMOD_EXE describe $JMODS_DIR/java.base.jmod | grep hashes | awk '{print $2}' | tr '\n' '|' | sed s/\|$//) || exit $?
TMP_DIR="$JMODS_DIR/tmp"
rm -rf "$TMP_DIR"
mkdir "$TMP_DIR"
jmod_file="$JMODS_DIR/java.base.jmod"
log "Unzipping $jmod_file"
$JMOD_EXE extract --dir "$TMP_DIR" "$jmod_file" >/dev/null
log "Removing java.base.jmod"
rm -f "$jmod_file"
cmd="$JMOD_EXE create --class-path $TMP_DIR/classes --hash-modules \"$hash_modules\" --module-path $JMODS_DIR"
# Check each directory and add to the command if it exists
[ -d "$TMP_DIR/bin" ] && cmd="$cmd --cmds $TMP_DIR/bin"
[ -d "$TMP_DIR/conf" ] && cmd="$cmd --config $TMP_DIR/conf"
[ -d "$TMP_DIR/lib" ] && cmd="$cmd --libs $TMP_DIR/lib"
[ -d "$TMP_DIR/include" ] && cmd="$cmd --header-files $TMP_DIR/include"
[ -d "$TMP_DIR/legal" ] && cmd="$cmd --legal-notices $TMP_DIR/legal"
[ -d "$TMP_DIR/man" ] && cmd="$cmd --man-pages $TMP_DIR/man"
log "Creating jmod file"
log "$cmd"
# Add the output file
cmd="$cmd $jmod_file"
# Execute the command
eval $cmd
log "Removing $TMP_DIR"
rm -rf "$TMP_DIR"
else
echo "Directory '$JMODS_DIR' does not exist. Skipping signing of jmod files."
fi