Skip to content

Commit 142f0c0

Browse files
Add clean_stashed_files.sh
1 parent 1e14e0d commit 142f0c0

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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+
stash_dir=${1:-${0%/*}}
33+
34+
35+
sed_inplace_option=-i
36+
sed_version_string=$(sed --version 2>&1 | head -1 || true)
37+
if [ "${sed_version_string#sed (GNU sed)}" != "$sed_version_string" ]; then
38+
# GNU sed, the default
39+
:
40+
elif [ "${sed_version_string#sed: illegal option}" != "$sed_version_string" ]; then
41+
# Macos sed
42+
sed_inplace_option="-i ''"
43+
else
44+
echo 'WARNING: Unknown sed variant, assume it is GNU compatible'
45+
fi
46+
47+
48+
winActions='
49+
'
50+
winMsiActions='
51+
winMsiRmDotPackage
52+
winMsiFilterAppImageListing
53+
winMsiFilterUiWxf
54+
winMsiFilterBundleWxf
55+
'
56+
winAllActions="${winActions} ${winMsiActions}"
57+
58+
macActions='
59+
macFormatInfoPlist
60+
'
61+
macPkgActions='
62+
macPkgFormatCplPlist
63+
'
64+
macDmgActions='
65+
macDmgFilterScpt
66+
'
67+
macAllActions="${macActions} ${macDmgActions} ${macPkgActions}"
68+
69+
linuxActions=
70+
linuxRpmActions=
71+
linuxDebActions=
72+
linuxAllActions="${linuxActions} ${linuxRpmActions} ${linuxDebActions}"
73+
74+
actions='
75+
rmPostImageScript
76+
sortAppImageListing
77+
'
78+
allActions="${actions} ${winAllActions} ${macAllActions} ${linuxAllActions}"
79+
80+
81+
rmPostImageScript() {
82+
# Remove post-image scripts
83+
find "$stash_dir" '(' -name '*-post-image.sh' -o -name '*-post-image.wsf' ')' -type f -exec rm -f {} \;
84+
}
85+
86+
sortAppImageListing() {
87+
# Sort app image listings
88+
find "$stash_dir" -name 'app-image-listing.txt' -type f -exec sort -o {} {} \;
89+
}
90+
91+
92+
#
93+
# MAC:
94+
#
95+
96+
macFormatInfoPlist() {
97+
# Info.plist
98+
# - Format
99+
find "$stash_dir" -name 'Info.plist' -type f -exec xmllint --output '{}' --format '{}' \;
100+
}
101+
102+
#
103+
# DMG:
104+
#
105+
106+
macDmgFilterScpt() {
107+
# *.scpt
108+
# - Trim random absolute temp path
109+
# - Replace "/dmg-workdir/" (new) with "/images/" (old)
110+
find "$stash_dir" -name '*.scpt' -type f | xargs -I {} sed $sed_inplace_option \
111+
-e 's|"/.*/jdk.jpackage[0-9]\{1,\}/|"/jdk.jpackage/|' \
112+
-e 's|"file:///.*/jdk.jpackage[0-9]\{1,\}/|"file:///jdk.jpackage/|' \
113+
-e 's|/dmg-workdir/|/images/|' \
114+
'{}'
115+
}
116+
117+
#
118+
# PKG:
119+
#
120+
121+
macPkgFormatCplPlist() {
122+
# cpl.plist:
123+
# - Format and strip <!DOCTYPE ...> (old)
124+
find "$stash_dir" -name 'cpl.plist' -type f -exec xmllint --output '{}' --dropdtd --format '{}' \;
125+
}
126+
127+
128+
#
129+
# WIN:
130+
#
131+
132+
#
133+
# MSI:
134+
#
135+
136+
winMsiRmDotPackage() {
137+
# .package
138+
# - Strip it. Old jpackage created this file in the app image.
139+
# New jpackage creates it in the "config" directory.
140+
# Value is verified in tests, can ignore it here.
141+
find "$stash_dir" -name '.package' -type f -exec rm -f {} \;
142+
}
143+
144+
winMsiFilterAppImageListing() {
145+
# app-image-listing.txt:
146+
# - Remove "app\.jpackage.xml" and "app\.package" entries. The new jpackage doesn't create them in the app image
147+
find "$stash_dir" -path '*msi/*/app-image-listing.txt' -type f | xargs -I {} sed $sed_inplace_option \
148+
-e '/^app\\\.package[\r]\{0,\}$/d' \
149+
-e '/^app\\\.jpackage\.xml[\r]\{0,\}$/d' \
150+
'{}'
151+
}
152+
153+
winMsiFilterUiWxf() {
154+
# ui.wxf:
155+
# - Order of namespaces is undefined, strip them for simplicity
156+
find "$stash_dir" -name 'ui.wxf' -type f | xargs -I {} sed $sed_inplace_option \
157+
-e 's|^<Wix[^>]*>|<Wix>|' \
158+
'{}'
159+
}
160+
161+
winMsiFilterBundleWxf() {
162+
# bundle.wxf:
163+
# - Order of namespaces is undefined, strip them for simplicity (same as with ui.wxf)
164+
# - Trim paths down to file names in "Source" attributes.
165+
# They all are different because the new jpackage doesn't copy app images.
166+
# - Order of files and directories is undefined, sort xml.
167+
# It turns the file into garbage, but all that matters is that the
168+
# old and the new jpackage variants should produce the same "garbage"
169+
find "$stash_dir" -name 'bundle.wxf' -type f | xargs -I {} sed $sed_inplace_option \
170+
-e 's|^<Wix[^>]*>|<Wix>|' \
171+
-e 's|Source=".*\\\([^\\]\{1,\}\)"|Source="\1"|' \
172+
-e 's|Source="\\jdk.jpackage\\images\\win-msi.image\\.*\\app\\\.package"|Source="\\jdk.jpackage\\config\\\.package"|' \
173+
'{}'
174+
find "$stash_dir" -name 'bundle.wxf' -type f -exec sort -o {} {} \;
175+
}
176+
177+
178+
for a in ${allActions}; do
179+
echo "$a..."
180+
$a
181+
done

0 commit comments

Comments
 (0)