Skip to content

Commit 7e484e2

Browse files
author
Alexey Semenyuk
committed
8334238: Enhance AddLShortcutTest jpackage test
Reviewed-by: almatvee
1 parent f95af74 commit 7e484e2

23 files changed

+2331
-730
lines changed

test/jdk/tools/jpackage/apps/PrintEnv.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,38 @@
2121
* questions.
2222
*/
2323

24+
import java.io.IOException;
25+
import java.io.UncheckedIOException;
2426
import java.lang.module.ModuleDescriptor;
2527
import java.lang.module.ModuleFinder;
2628
import java.lang.module.ModuleReference;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
2731
import java.util.ArrayList;
2832
import java.util.List;
33+
import java.util.Optional;
2934
import java.util.stream.Collectors;
3035

3136
public class PrintEnv {
3237

3338
public static void main(String[] args) {
3439
List<String> lines = printArgs(args);
35-
lines.forEach(System.out::println);
40+
Optional.ofNullable(System.getProperty("jpackage.test.appOutput")).map(Path::of).ifPresentOrElse(outputFilePath -> {
41+
Optional.ofNullable(outputFilePath.getParent()).ifPresent(dir -> {
42+
try {
43+
Files.createDirectories(dir);
44+
} catch (IOException ex) {
45+
throw new UncheckedIOException(ex);
46+
}
47+
});
48+
try {
49+
Files.write(outputFilePath, lines);
50+
} catch (IOException ex) {
51+
throw new UncheckedIOException(ex);
52+
}
53+
}, () -> {
54+
lines.forEach(System.out::println);
55+
});
3656
}
3757

3858
private static List<String> printArgs(String[] args) {
@@ -45,11 +65,13 @@ private static List<String> printArgs(String[] args) {
4565
} else if (arg.startsWith(PRINT_SYS_PROP)) {
4666
String name = arg.substring(PRINT_SYS_PROP.length());
4767
lines.add(name + "=" + System.getProperty(name));
48-
} else if (arg.startsWith(PRINT_MODULES)) {
68+
} else if (arg.equals(PRINT_MODULES)) {
4969
lines.add(ModuleFinder.ofSystem().findAll().stream()
5070
.map(ModuleReference::descriptor)
5171
.map(ModuleDescriptor::name)
5272
.collect(Collectors.joining(",")));
73+
} else if (arg.equals(PRINT_WORK_DIR)) {
74+
lines.add("$CD=" + Path.of("").toAbsolutePath());
5375
} else {
5476
throw new IllegalArgumentException();
5577
}
@@ -58,7 +80,8 @@ private static List<String> printArgs(String[] args) {
5880
return lines;
5981
}
6082

61-
private final static String PRINT_ENV_VAR = "--print-env-var=";
62-
private final static String PRINT_SYS_PROP = "--print-sys-prop=";
63-
private final static String PRINT_MODULES = "--print-modules";
83+
private static final String PRINT_ENV_VAR = "--print-env-var=";
84+
private static final String PRINT_SYS_PROP = "--print-sys-prop=";
85+
private static final String PRINT_MODULES = "--print-modules";
86+
private static final String PRINT_WORK_DIR = "--print-workdir";
6487
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 test(s).
26+
#
27+
28+
set -eu
29+
set -o pipefail
30+
31+
32+
sed_inplace_option=-i
33+
sed_version_string=$(sed --version 2>&1 | head -1 || true)
34+
if [ "${sed_version_string#sed (GNU sed)}" != "$sed_version_string" ]; then
35+
# GNU sed, the default
36+
:
37+
elif [ "${sed_version_string#sed: illegal option}" != "$sed_version_string" ]; then
38+
# Macos sed
39+
sed_inplace_option="-i ''"
40+
else
41+
echo 'WARNING: Unknown sed variant, assume it is GNU compatible'
42+
fi
43+
44+
45+
filterFile () {
46+
local expressions=(
47+
# Strip leading log message timestamp `[19:33:44.713] `
48+
-e 's/^\[[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\.[0-9]\{3\}\] //'
49+
50+
# Strip log message timestamps `[19:33:44.713]`
51+
-e 's/\[[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\.[0-9]\{3\}\]//g'
52+
53+
# Convert variable part of R/O directory path timestamp `#2025-07-24T16:38:13.3589878Z`
54+
-e 's/#[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\.[0-9]\{1,\}Z/#<ts>Z/'
55+
56+
# Strip variable part of temporary directory name `jdk.jpackage5060841750457404688`
57+
-e 's|\([\/]\)jdk\.jpackage[0-9]\{1,\}\b|\1jdk.jpackage|g'
58+
59+
# Convert PID value `[PID: 131561]`
60+
-e 's/\[PID: [0-9]\{1,\}\]/[PID: <pid>]/'
61+
62+
# Strip a warning message `Windows Defender may prevent jpackage from functioning`
63+
-e '/Windows Defender may prevent jpackage from functioning/d'
64+
65+
# Convert variable part of test output directory `out-6268`
66+
-e 's|\bout-[0-9]\{1,\}\b|out-N|g'
67+
68+
# Convert variable part of test summary `[ OK ] IconTest(AppImage, ResourceDirIcon, DefaultIcon).test; checks=39`
69+
-e 's/^\(.*\bchecks=\)[0-9]\{1,\}\(\r\{0,1\}\)$/\1N\2/'
70+
71+
# Convert variable part of ldd output `libdl.so.2 => /lib64/libdl.so.2 (0x00007fbf63c81000)`
72+
-e 's/(0x[[:xdigit:]]\{1,\})$/(0xHEX)/'
73+
74+
# Convert variable part of rpmbuild output `Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.CMO6a9`
75+
-e 's|/rpm-tmp\...*$|/rpm-tmp.V|'
76+
77+
# Convert variable part of stack trace entry `at jdk.jpackage.test.JPackageCommand.execute(JPackageCommand.java:863)`
78+
-e 's/^\(.*\b\.java:\)[0-9]\{1,\}\()\r\{0,1\}\)$/\1N\2/'
79+
)
80+
81+
sed $sed_inplace_option "$1" "${expressions[@]}"
82+
}
83+
84+
85+
for f in "$@"; do
86+
filterFile "$f"
87+
done

0 commit comments

Comments
 (0)