Skip to content

Commit cbbab07

Browse files
author
Alexey Semenyuk
committed
8356309: Fix issues uncovered after running jpackage tests locally with installing test packages
Reviewed-by: almatvee
1 parent 9a23f72 commit cbbab07

File tree

7 files changed

+101
-58
lines changed

7 files changed

+101
-58
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static void addFileAssociationsVerifier(PackageTest test, FileAssociations fa) {
533533
TKit.assertEquals(fa.getMime(), mimeType, String.format(
534534
"Check mime type of [%s] file", testFile));
535535

536-
String desktopFileName = queryMimeTypeDefaultHandler(mimeType);
536+
String desktopFileName = queryMimeTypeDefaultHandler(mimeType).orElse(null);
537537

538538
Path systemDesktopFile = getSystemDesktopFilesFolder().resolve(
539539
desktopFileName);
@@ -557,7 +557,7 @@ static void addFileAssociationsVerifier(PackageTest test, FileAssociations fa) {
557557
TKit.assertNotEquals(fa.getMime(), mimeType, String.format(
558558
"Check mime type of [%s] file", testFile));
559559

560-
String desktopFileName = queryMimeTypeDefaultHandler(fa.getMime());
560+
String desktopFileName = queryMimeTypeDefaultHandler(fa.getMime()).orElse(null);
561561

562562
TKit.assertNull(desktopFileName, String.format(
563563
"Check there is no default handler for [%s] mime type",
@@ -584,9 +584,9 @@ private static String queryFileMimeType(Path file) {
584584
.executeAndGetFirstLineOfOutput();
585585
}
586586

587-
private static String queryMimeTypeDefaultHandler(String mimeType) {
587+
private static Optional<String> queryMimeTypeDefaultHandler(String mimeType) {
588588
return Executor.of("xdg-mime", "query", "default", mimeType)
589-
.executeAndGetFirstLineOfOutput();
589+
.discardStderr().saveFirstLineOfOutput().execute().findFirstLineOfOutput();
590590
}
591591

592592
private static void verifyIconInScriptlet(Scriptlet scriptletType,
@@ -708,7 +708,7 @@ private static enum Scriptlet {
708708

709709
static final Map<String, Scriptlet> RPM_MAP = Stream.of(values()).collect(
710710
Collectors.toMap(v -> v.rpm, v -> v));
711-
};
711+
}
712712

713713
public static String getDefaultPackageArch(PackageType type) {
714714
if (archs == null) {

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.util.HashMap;
4343
import java.util.HashSet;
4444
import java.util.List;
45-
import java.util.ListIterator;
4645
import java.util.Map;
4746
import java.util.Objects;
4847
import java.util.Optional;
@@ -365,27 +364,37 @@ public PackageTest addHelloAppInitializer(String javaAppDesc) {
365364

366365
public static class Group extends RunnablePackageTest {
367366
public Group(PackageTest... tests) {
368-
handlers = Stream.of(tests)
369-
.map(PackageTest::createPackageTypeHandlers)
370-
.flatMap(List<Consumer<Action>>::stream)
371-
.collect(Collectors.toUnmodifiableList());
367+
typeHandlers = Stream.of(PackageType.values()).map(type -> {
368+
return Map.entry(type, Stream.of(tests).map(test -> {
369+
return test.createPackageTypeHandler(type);
370+
}).filter(Optional::isPresent).map(Optional::orElseThrow).toList());
371+
}).filter(e -> {
372+
return !e.getValue().isEmpty();
373+
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
372374
}
373375

374376
@Override
375377
protected void runAction(Action... action) {
376-
if (Set.of(action).contains(Action.UNINSTALL)) {
377-
ListIterator<Consumer<Action>> listIterator = handlers.listIterator(
378-
handlers.size());
378+
typeHandlers.entrySet().stream()
379+
.sorted(Comparator.comparing(Map.Entry::getKey))
380+
.map(Map.Entry::getValue).forEachOrdered(handlers -> {
381+
runAction(handlers, List.of(action));
382+
});
383+
}
384+
385+
private static void runAction(List<Consumer<Action>> handlers, List<Action> actions) {
386+
if (actions.contains(Action.UNINSTALL)) {
387+
final var listIterator = handlers.listIterator(handlers.size());
379388
while (listIterator.hasPrevious()) {
380-
var handler = listIterator.previous();
381-
List.of(action).forEach(handler::accept);
389+
final var handler = listIterator.previous();
390+
actions.forEach(handler::accept);
382391
}
383392
} else {
384-
handlers.forEach(handler -> List.of(action).forEach(handler::accept));
393+
handlers.forEach(handler -> actions.forEach(handler::accept));
385394
}
386395
}
387396

388-
private final List<Consumer<Action>> handlers;
397+
private final Map<PackageType, List<Consumer<Action>>> typeHandlers;
389398
}
390399

391400
PackageTest packageHandlers(PackageHandlers v) {
@@ -455,16 +464,22 @@ protected void runAction(Action... action) {
455464
throw new UnsupportedOperationException();
456465
}
457466

467+
private Optional<Consumer<Action>> createPackageTypeHandler(PackageType type) {
468+
Objects.requireNonNull(type);
469+
return Optional.ofNullable(handlers.get(type)).filter(Predicate.not(Handler::isVoid)).map(h -> {
470+
return createPackageTypeHandler(type, h);
471+
});
472+
}
473+
458474
private List<Consumer<Action>> createPackageTypeHandlers() {
459475
if (handlers.keySet().stream().noneMatch(isPackageTypeEnabled)) {
460476
PackageType.throwSkippedExceptionIfNativePackagingUnavailable();
461477
}
462-
return handlers.entrySet().stream()
463-
.filter(entry -> !entry.getValue().isVoid())
464-
.sorted(Comparator.comparing(Map.Entry::getKey))
465-
.map(entry -> {
466-
return createPackageTypeHandler(entry.getKey(), entry.getValue());
467-
}).toList();
478+
return Stream.of(PackageType.values()).sorted()
479+
.map(this::createPackageTypeHandler)
480+
.filter(Optional::isPresent)
481+
.map(Optional::orElseThrow)
482+
.toList();
468483
}
469484

470485
private record PackageTypePipeline(PackageType type, int expectedJPackageExitCode,

test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/util/PListReaderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class PListReaderTest {
5151
enum QueryType {
5252
STRING(PListReader::queryValue),
5353
BOOLEAN(PListReader::queryBoolValue),
54-
STRING_ARRY(PListReader::queryArrayValue);
54+
STRING_ARRAY(PListReader::queryArrayValue);
5555

5656
QueryType(BiFunction<PListReader, String, ?> queryMethod) {
5757
this.queryMethod = Objects.requireNonNull(queryMethod);
@@ -98,7 +98,7 @@ Builder expectedValue(Object v) {
9898
} else if (v instanceof Boolean) {
9999
queryType(QueryType.BOOLEAN);
100100
} else if (v instanceof List<?>) {
101-
queryType(QueryType.STRING_ARRY);
101+
queryType(QueryType.STRING_ARRAY);
102102
}
103103
return this;
104104
}
@@ -196,7 +196,7 @@ public void testWrongValueType(QueryType queryType) {
196196
testSpecs.add(builder.keyName("string-key").create());
197197
testSpecs.add(builder.keyName("array-key").create());
198198
}
199-
case STRING_ARRY -> {
199+
case STRING_ARRAY -> {
200200
testSpecs.add(builder.keyName("string-key").create());
201201
testSpecs.add(builder.keyName("boolean-true-key").create());
202202
testSpecs.add(builder.keyName("boolean-false-key").create());
@@ -230,7 +230,7 @@ private static List<QueryValueTestSpec> testQueryValue() {
230230
testSpec(QueryType.BOOLEAN).xml("<key>foo</key><False/>").create(),
231231
testSpec().expectedValue(List.of("foo", "bar")).xml("<key>foo</key><array><string>foo</string><string>bar</string></array>").create(),
232232
testSpec().expectedValue(List.of()).xml("<key>foo</key><array/>").create(),
233-
testSpec(QueryType.STRING_ARRY).xml("<key>foo</key><Array/>").create(),
233+
testSpec(QueryType.STRING_ARRAY).xml("<key>foo</key><Array/>").create(),
234234
testSpec().expectedValue("A").xml("<key>foo</key><string>A</string><string>B</string>").create(),
235235
testSpec().expectedValue("A").xml("<key>foo</key><string>A</string><key>foo</key><string>B</string>").create()
236236
);

test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/util/PathGroupTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
public class PathGroupTest {
6262

63+
@Test
6364
public void testNullId() {
6465
assertThrowsExactly(NullPointerException.class, () -> new PathGroup(Map.of()).getPath(null));
6566
}

test/jdk/tools/jpackage/share/EmptyFolderTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -97,16 +97,21 @@ private static void createDirTree(JPackageCommand cmd) throws IOException {
9797
}
9898

9999
private static void validateDirTree(JPackageCommand cmd) {
100+
// When MSI package is unpacked and not installed, empty directories are not created.
101+
final boolean emptyDirSupported = !(PackageType.WINDOWS.contains(cmd.packageType()) && cmd.isPackageUnpacked());
102+
validateDirTree(cmd, emptyDirSupported);
103+
}
104+
105+
private static void validateDirTree(JPackageCommand cmd, boolean emptyDirSupported) {
100106
var outputBaseDir = cmd.appLayout().appDirectory();
101107
var inputBaseDir = cmd.inputDir();
102108
for (var path : DIR_STRUCT) {
103109
Path outputPath = outputBaseDir.resolve(path);
104110
if (isFile(outputPath)) {
105111
TKit.assertFileExists(outputPath);
106-
} else if (!PackageType.WINDOWS.contains(cmd.packageType())) {
112+
} else if (emptyDirSupported) {
107113
TKit.assertDirectoryExists(outputPath);
108114
} else if (inputBaseDir.resolve(path).toFile().list().length == 0) {
109-
// MSI packages don't support empty folders
110115
TKit.assertPathExists(outputPath, false);
111116
} else {
112117
TKit.assertDirectoryNotEmpty(outputPath);

test/jdk/tools/jpackage/share/RuntimeImageTest.java

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
* questions.
2222
*/
2323

24+
import java.io.IOException;
2425
import java.nio.file.Files;
2526
import java.nio.file.Path;
26-
import jdk.jpackage.test.TKit;
2727
import jdk.jpackage.test.Annotations.Test;
28+
import jdk.jpackage.test.Executor;
2829
import jdk.jpackage.test.JPackageCommand;
2930
import jdk.jpackage.test.JavaTool;
30-
import jdk.jpackage.test.Executor;
31+
import jdk.jpackage.test.TKit;
3132

3233
/*
3334
* @test
@@ -43,27 +44,49 @@
4344
public class RuntimeImageTest {
4445

4546
@Test
46-
public static void test() throws Exception {
47-
final Path workDir = TKit.createTempDirectory("runtime").resolve("data");
48-
final Path jlinkOutputDir = workDir.resolve("temp.runtime");
49-
Files.createDirectories(jlinkOutputDir.getParent());
47+
public static void test() throws IOException {
48+
49+
JPackageCommand cmd = JPackageCommand.helloAppImage();
50+
51+
if (JPackageCommand.DEFAULT_RUNTIME_IMAGE == null) {
52+
final Path workDir = TKit.createTempDirectory("runtime").resolve("data");
53+
final Path jlinkOutputDir = workDir.resolve("temp.runtime");
54+
Files.createDirectories(jlinkOutputDir.getParent());
5055

51-
new Executor()
52-
.setToolProvider(JavaTool.JLINK)
53-
.dumpOutput()
54-
.addArguments(
55-
"--output", jlinkOutputDir.toString(),
56-
"--add-modules", "java.desktop",
57-
"--strip-debug",
58-
"--no-header-files",
59-
"--no-man-pages",
60-
"--strip-native-commands")
61-
.execute();
56+
new Executor()
57+
.setToolProvider(JavaTool.JLINK)
58+
.dumpOutput()
59+
.addArguments(
60+
"--output", jlinkOutputDir.toString(),
61+
"--add-modules", "java.desktop",
62+
"--strip-debug",
63+
"--no-header-files",
64+
"--no-man-pages",
65+
"--strip-native-commands")
66+
.execute();
6267

63-
JPackageCommand cmd = JPackageCommand.helloAppImage()
64-
.setArgumentValue("--runtime-image", jlinkOutputDir.toString());
68+
cmd.setArgumentValue("--runtime-image", jlinkOutputDir.toString());
69+
}
6570

6671
cmd.executeAndAssertHelloAppImageCreated();
6772
}
6873

74+
@Test
75+
public static void testStrippedFiles() throws IOException {
76+
final var cmd = JPackageCommand.helloAppImage().setFakeRuntime();
77+
78+
final var runtimePath = Path.of(cmd.executePrerequisiteActions().getArgumentValue("--runtime-image"));
79+
80+
Files.createDirectories(runtimePath.resolve("jmods"));
81+
Files.createDirectories(runtimePath.resolve("lib"));
82+
Files.createFile(runtimePath.resolve("lib/src.zip"));
83+
Files.createFile(runtimePath.resolve("src.zip"));
84+
85+
(new JPackageCommand()).addArguments(cmd.getAllArguments()).executeAndAssertHelloAppImageCreated();
86+
87+
final var appRuntimeDir = cmd.appLayout().runtimeHomeDirectory();
88+
TKit.assertPathExists(appRuntimeDir.resolve("jmods"), false);
89+
TKit.assertPathExists(appRuntimeDir.resolve("lib/src.zip"), false);
90+
TKit.assertPathExists(appRuntimeDir.resolve("src.zip"), false);
91+
}
6992
}

test/jdk/tools/jpackage/share/RuntimePackageTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import jdk.jpackage.test.LinuxHelper;
4141
import static jdk.jpackage.test.TKit.assertTrue;
4242
import static jdk.jpackage.test.TKit.assertFalse;
43+
import static jdk.internal.util.OperatingSystem.LINUX;
4344

4445
/**
4546
* Test --runtime-image parameter.
@@ -81,22 +82,22 @@ public class RuntimePackageTest {
8182

8283
@Test
8384
public static void test() {
84-
init(PackageType.NATIVE).run();
85+
init().run();
8586
}
8687

87-
@Test
88+
@Test(ifOS = LINUX)
8889
@Parameter("/usr")
8990
@Parameter("/usr/lib/Java")
9091
public static void testUsrInstallDir(String installDir) {
91-
init(PackageType.LINUX)
92-
.addInitializer(cmd -> cmd.addArguments("--install-dir", "/usr"))
92+
init()
93+
.addInitializer(cmd -> cmd.addArguments("--install-dir", installDir))
9394
.run();
9495
}
9596

9697
@Test
9798
public static void testName() {
9899
// Test that jpackage can derive package name from the path to runtime image.
99-
init(PackageType.NATIVE)
100+
init()
100101
.addInitializer(cmd -> cmd.removeArgumentWithValue("--name"))
101102
// Don't attempt to install this package as it may have an odd name derived from
102103
// the runtime image path. Say, on Linux for `--runtime-image foo/bar/sed`
@@ -105,9 +106,8 @@ public static void testName() {
105106
.run(Action.CREATE_AND_UNPACK);
106107
}
107108

108-
private static PackageTest init(Set<PackageType> types) {
109+
private static PackageTest init() {
109110
return new PackageTest()
110-
.forTypes(types)
111111
.addInitializer(cmd -> {
112112
final Path runtimeImageDir;
113113

@@ -166,8 +166,7 @@ private static PackageTest init(Set<PackageType> types) {
166166
"Check the package doesn't deliver [%s] copyright file",
167167
copyright));
168168
}
169-
})
170-
.forTypes(types);
169+
});
171170
}
172171

173172
private static Set<Path> listFiles(Path root) throws IOException {

0 commit comments

Comments
 (0)