|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 4 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | +# |
| 6 | +# This code is free software; you can redistribute it and/or modify it |
| 7 | +# under the terms of the GNU General Public License version 2 only, as |
| 8 | +# published by the Free Software Foundation. |
| 9 | +# |
| 10 | +# This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | +# version 2 for more details (a copy is included in the LICENSE file that |
| 14 | +# accompanied this code). |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License version |
| 17 | +# 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | +# |
| 20 | +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | +# or visit www.oracle.com if you need additional information or have any |
| 22 | +# questions. |
| 23 | + |
| 24 | +# |
| 25 | +# Filters output produced by running jpackage with "jpackage.test.stash-root=<PATH>" property. |
| 26 | +# |
| 27 | + |
| 28 | +set -e |
| 29 | +set -o pipefail |
| 30 | + |
| 31 | + |
| 32 | +declare -a stash_dirs |
| 33 | +if [ $# -eq 0 ]; then |
| 34 | + stash_dirs=(${0%/*}) |
| 35 | +else |
| 36 | + stash_dirs=($@) |
| 37 | +fi |
| 38 | + |
| 39 | + |
| 40 | +sed_inplace_option=-i |
| 41 | +sed_version_string=$(sed --version 2>&1 | head -1 || true) |
| 42 | +if [ "${sed_version_string#sed (GNU sed)}" != "$sed_version_string" ]; then |
| 43 | + # GNU sed, the default |
| 44 | + : |
| 45 | +elif [ "${sed_version_string#sed: illegal option}" != "$sed_version_string" ]; then |
| 46 | + # Macos sed |
| 47 | + sed_inplace_option="-i ''" |
| 48 | +else |
| 49 | + echo 'WARNING: Unknown sed variant, assume it is GNU compatible' |
| 50 | +fi |
| 51 | + |
| 52 | + |
| 53 | +winActions=' |
| 54 | +' |
| 55 | +winMsiActions=' |
| 56 | + winMsiRmDotPackage |
| 57 | + winMsiFilterAppImageListing |
| 58 | + winMsiFilterUiWxf |
| 59 | + winMsiFilterBundleWxf |
| 60 | +' |
| 61 | +winAllActions="${winActions} ${winMsiActions}" |
| 62 | + |
| 63 | +macActions=' |
| 64 | + macFormatInfoPlist |
| 65 | + macFormatEntitlements |
| 66 | +' |
| 67 | +macPkgActions=' |
| 68 | + macPkgFormatCplPlist |
| 69 | +' |
| 70 | +macDmgActions=' |
| 71 | + macDmgFilterScpt |
| 72 | +' |
| 73 | +macAllActions="${macActions} ${macDmgActions} ${macPkgActions}" |
| 74 | + |
| 75 | +linuxActions= |
| 76 | +linuxRpmActions= |
| 77 | +linuxDebActions= |
| 78 | +linuxAllActions="${linuxActions} ${linuxRpmActions} ${linuxDebActions}" |
| 79 | + |
| 80 | +actions=' |
| 81 | + rmPostImageScript |
| 82 | + sortAppImageListing |
| 83 | +' |
| 84 | +allActions="${actions} ${winAllActions} ${macAllActions} ${linuxAllActions}" |
| 85 | + |
| 86 | + |
| 87 | +rmPostImageScript() { |
| 88 | + # Remove post-image scripts |
| 89 | + find "$stash_dir" '(' -name '*-post-image.sh' -o -name '*-post-image.wsf' ')' -type f -exec rm -f {} \; |
| 90 | +} |
| 91 | + |
| 92 | +sortAppImageListing() { |
| 93 | + # Sort app image listings |
| 94 | + find "$stash_dir" -name 'app-image-listing.txt' -type f -exec sort -o {} {} \; |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | +# |
| 99 | +# MAC: |
| 100 | +# |
| 101 | + |
| 102 | +macFormatInfoPlist() { |
| 103 | + # Info.plist |
| 104 | + # - Format |
| 105 | + find "$stash_dir" -name 'Info.plist' -type f -exec xmllint --output '{}' --format '{}' \; |
| 106 | +} |
| 107 | + |
| 108 | +macFormatEntitlements() { |
| 109 | + # *.entitlements |
| 110 | + # - Format |
| 111 | + find "$stash_dir" -name '*.entitlements' -type f -exec xmllint --output '{}' --format '{}' \; |
| 112 | +} |
| 113 | + |
| 114 | +# |
| 115 | +# DMG: |
| 116 | +# |
| 117 | + |
| 118 | +macDmgFilterScpt() { |
| 119 | + # *.scpt |
| 120 | + # - Trim random absolute temp path |
| 121 | + # - Replace "/dmg-workdir/" (new) with "/images/" (old) |
| 122 | + find "$stash_dir" -name '*.scpt' -type f | xargs -I {} sed $sed_inplace_option \ |
| 123 | + -e 's|"/.*/jdk.jpackage[0-9]\{1,\}/|"/jdk.jpackage/|' \ |
| 124 | + -e 's|"file:///.*/jdk.jpackage[0-9]\{1,\}/|"file:///jdk.jpackage/|' \ |
| 125 | + -e 's|/dmg-workdir/|/images/|' \ |
| 126 | + '{}' |
| 127 | +} |
| 128 | + |
| 129 | +# |
| 130 | +# PKG: |
| 131 | +# |
| 132 | + |
| 133 | +macPkgFormatCplPlist() { |
| 134 | + # cpl.plist: |
| 135 | + # - Format and strip <!DOCTYPE ...> (old) |
| 136 | + find "$stash_dir" -name 'cpl.plist' -type f -exec xmllint --output '{}' --dropdtd --format '{}' \; |
| 137 | +} |
| 138 | + |
| 139 | + |
| 140 | +# |
| 141 | +# WIN: |
| 142 | +# |
| 143 | + |
| 144 | +# |
| 145 | +# MSI: |
| 146 | +# |
| 147 | + |
| 148 | +winMsiRmDotPackage() { |
| 149 | + # .package |
| 150 | + # - Strip it. Old jpackage created this file in the app image. |
| 151 | + # New jpackage creates it in the "config" directory. |
| 152 | + # Value is verified in tests, can ignore it here. |
| 153 | + find "$stash_dir" -name '.package' -type f -exec rm -f {} \; |
| 154 | +} |
| 155 | + |
| 156 | +winMsiFilterAppImageListing() { |
| 157 | + # app-image-listing.txt: |
| 158 | + # - Remove "app\.jpackage.xml" and "app\.package" entries. The new jpackage doesn't create them in the app image |
| 159 | + find "$stash_dir" -path '*msi/*/app-image-listing.txt' -type f | xargs -I {} sed $sed_inplace_option \ |
| 160 | + -e '/^app\\\.package[\r]\{0,\}$/d' \ |
| 161 | + -e '/^app\\\.jpackage\.xml[\r]\{0,\}$/d' \ |
| 162 | + '{}' |
| 163 | +} |
| 164 | + |
| 165 | +winMsiFilterUiWxf() { |
| 166 | + # ui.wxf: |
| 167 | + # - Order of namespaces is undefined, strip them for simplicity |
| 168 | + find "$stash_dir" -name 'ui.wxf' -type f | xargs -I {} sed $sed_inplace_option \ |
| 169 | + -e 's|^<Wix[^>]*>|<Wix>|' \ |
| 170 | + '{}' |
| 171 | +} |
| 172 | + |
| 173 | +winMsiFilterBundleWxf() { |
| 174 | + # bundle.wxf: |
| 175 | + # - Order of namespaces is undefined, strip them for simplicity (same as with ui.wxf) |
| 176 | + # - Trim paths down to file names in "Source" attributes. |
| 177 | + # They all are different because the new jpackage doesn't copy app images. |
| 178 | + # - Order of files and directories is undefined, sort xml. |
| 179 | + # It turns the file into garbage, but all that matters is that the |
| 180 | + # old and the new jpackage variants should produce the same "garbage" |
| 181 | + find "$stash_dir" -name 'bundle.wxf' -type f | xargs -I {} sed $sed_inplace_option \ |
| 182 | + -e 's|^<Wix[^>]*>|<Wix>|' \ |
| 183 | + -e 's|Source=".*\\\([^\\]\{1,\}\)"|Source="\1"|' \ |
| 184 | + -e 's|Source="\\jdk.jpackage\\images\\win-msi.image\\.*\\app\\\.package"|Source="\\jdk.jpackage\\config\\\.package"|' \ |
| 185 | + '{}' |
| 186 | + find "$stash_dir" -name 'bundle.wxf' -type f -exec sort -o {} {} \; |
| 187 | +} |
| 188 | + |
| 189 | + |
| 190 | +for stash_dir in "${stash_dirs[@]}"; do |
| 191 | + printf "In %s:\n" "$stash_dir" |
| 192 | + for a in ${allActions}; do |
| 193 | + echo " $a..." |
| 194 | + $a |
| 195 | + done |
| 196 | +done |
0 commit comments