Skip to content

Commit 41a627b

Browse files
author
Alexey Semenyuk
committedNov 17, 2024
8343876: Enhancements to jpackage test lib
Reviewed-by: almatvee
1 parent aa10ec7 commit 41a627b

File tree

13 files changed

+1462
-337
lines changed

13 files changed

+1462
-337
lines changed
 

‎test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/AnnotationsTest.java

+408
Large diffs are not rendered by default.

‎test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Annotations.java

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, 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
@@ -27,6 +27,7 @@
2727
import java.lang.annotation.Retention;
2828
import java.lang.annotation.RetentionPolicy;
2929
import java.lang.annotation.Target;
30+
import jdk.internal.util.OperatingSystem;
3031

3132
public class Annotations {
3233

@@ -43,6 +44,14 @@ public class Annotations {
4344
@Retention(RetentionPolicy.RUNTIME)
4445
@Target(ElementType.METHOD)
4546
public @interface Test {
47+
48+
OperatingSystem[] ifOS() default {
49+
OperatingSystem.LINUX,
50+
OperatingSystem.WINDOWS,
51+
OperatingSystem.MACOS
52+
};
53+
54+
OperatingSystem[] ifNotOS() default {};
4655
}
4756

4857
@Retention(RetentionPolicy.RUNTIME)
@@ -51,6 +60,14 @@ public class Annotations {
5160
public @interface Parameter {
5261

5362
String[] value();
63+
64+
OperatingSystem[] ifOS() default {
65+
OperatingSystem.LINUX,
66+
OperatingSystem.WINDOWS,
67+
OperatingSystem.MACOS
68+
};
69+
70+
OperatingSystem[] ifNotOS() default {};
5471
}
5572

5673
@Retention(RetentionPolicy.RUNTIME)
@@ -60,8 +77,39 @@ public class Annotations {
6077
Parameter[] value();
6178
}
6279

80+
@Retention(RetentionPolicy.RUNTIME)
81+
@Target(ElementType.METHOD)
82+
@Repeatable(ParameterSupplierGroup.class)
83+
public @interface ParameterSupplier {
84+
85+
String value();
86+
87+
OperatingSystem[] ifOS() default {
88+
OperatingSystem.LINUX,
89+
OperatingSystem.WINDOWS,
90+
OperatingSystem.MACOS
91+
};
92+
93+
OperatingSystem[] ifNotOS() default {};
94+
}
95+
96+
@Retention(RetentionPolicy.RUNTIME)
97+
@Target(ElementType.METHOD)
98+
public @interface ParameterSupplierGroup {
99+
100+
ParameterSupplier[] value();
101+
}
102+
63103
@Retention(RetentionPolicy.RUNTIME)
64104
@Target(ElementType.METHOD)
65105
public @interface Parameters {
106+
107+
OperatingSystem[] ifOS() default {
108+
OperatingSystem.LINUX,
109+
OperatingSystem.WINDOWS,
110+
OperatingSystem.MACOS
111+
};
112+
113+
OperatingSystem[] ifNotOS() default {};
66114
}
67115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package jdk.jpackage.test;
24+
25+
import java.util.HashSet;
26+
import java.util.Set;
27+
28+
record Comm<T>(Set<T> common, Set<T> unique1, Set<T> unique2) {
29+
30+
static <T> Comm<T> compare(Set<T> a, Set<T> b) {
31+
Set<T> common = new HashSet<>(a);
32+
common.retainAll(b);
33+
Set<T> unique1 = new HashSet<>(a);
34+
unique1.removeAll(common);
35+
Set<T> unique2 = new HashSet<>(b);
36+
unique2.removeAll(common);
37+
return new Comm(common, unique1, unique2);
38+
}
39+
}

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

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, 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
@@ -40,6 +40,7 @@
4040
import java.util.regex.Pattern;
4141
import java.util.stream.Collectors;
4242
import java.util.stream.Stream;
43+
import jdk.jpackage.internal.ApplicationLayout;
4344
import jdk.jpackage.internal.IOUtils;
4445
import jdk.jpackage.test.Functional.ThrowingConsumer;
4546
import jdk.jpackage.test.PackageTest.PackageHandlers;
@@ -399,6 +400,15 @@ static void addBundleDesktopIntegrationVerifier(PackageTest test,
399400
private static void verifyDesktopFile(JPackageCommand cmd, Path desktopFile)
400401
throws IOException {
401402
TKit.trace(String.format("Check [%s] file BEGIN", desktopFile));
403+
404+
var launcherName = Stream.of(List.of(cmd.name()), cmd.addLauncherNames()).flatMap(List::stream).filter(name -> {
405+
return getDesktopFile(cmd, name).equals(desktopFile);
406+
}).findAny();
407+
if (!cmd.hasArgument("--app-image")) {
408+
TKit.assertTrue(launcherName.isPresent(),
409+
"Check the desktop file corresponds to one of app launchers");
410+
}
411+
402412
List<String> lines = Files.readAllLines(desktopFile);
403413
TKit.assertEquals("[Desktop Entry]", lines.get(0), "Check file header");
404414

@@ -428,7 +438,7 @@ private static void verifyDesktopFile(JPackageCommand cmd, Path desktopFile)
428438
"Check value of [%s] key", key));
429439
}
430440

431-
// Verify value of `Exec` property in .desktop files are escaped if required
441+
// Verify the value of `Exec` key is escaped if required
432442
String launcherPath = data.get("Exec");
433443
if (Pattern.compile("\\s").matcher(launcherPath).find()) {
434444
TKit.assertTrue(launcherPath.startsWith("\"")
@@ -437,10 +447,25 @@ private static void verifyDesktopFile(JPackageCommand cmd, Path desktopFile)
437447
launcherPath = launcherPath.substring(1, launcherPath.length() - 1);
438448
}
439449

440-
Stream.of(launcherPath, data.get("Icon"))
441-
.map(Path::of)
442-
.map(cmd::pathToUnpackedPackageFile)
443-
.forEach(TKit::assertFileExists);
450+
if (launcherName.isPresent()) {
451+
TKit.assertEquals(launcherPath, cmd.pathToPackageFile(
452+
cmd.appLauncherPath(launcherName.get())).toString(),
453+
String.format(
454+
"Check the value of [Exec] key references [%s] app launcher",
455+
launcherName.get()));
456+
}
457+
458+
for (var e : List.<Map.Entry<Map.Entry<String, Optional<String>>, Function<ApplicationLayout, Path>>>of(
459+
Map.entry(Map.entry("Exec", Optional.of(launcherPath)), ApplicationLayout::launchersDirectory),
460+
Map.entry(Map.entry("Icon", Optional.empty()), ApplicationLayout::destktopIntegrationDirectory))) {
461+
var path = e.getKey().getValue().or(() -> Optional.of(data.get(
462+
e.getKey().getKey()))).map(Path::of).get();
463+
TKit.assertFileExists(cmd.pathToUnpackedPackageFile(path));
464+
Path expectedDir = cmd.pathToPackageFile(e.getValue().apply(cmd.appLayout()));
465+
TKit.assertTrue(path.getParent().equals(expectedDir), String.format(
466+
"Check the value of [%s] key references a file in [%s] folder",
467+
e.getKey().getKey(), expectedDir));
468+
}
444469

445470
TKit.trace(String.format("Check [%s] file END", desktopFile));
446471
}
@@ -725,10 +750,10 @@ private static Method initGetServiceUnitFileName() {
725750

726751
private static Map<PackageType, String> archs;
727752

728-
private final static Pattern XDG_CMD_ICON_SIZE_PATTERN = Pattern.compile("\\s--size\\s+(\\d+)\\b");
753+
private static final Pattern XDG_CMD_ICON_SIZE_PATTERN = Pattern.compile("\\s--size\\s+(\\d+)\\b");
729754

730755
// Values grabbed from https://linux.die.net/man/1/xdg-icon-resource
731-
private final static Set<Integer> XDG_CMD_VALID_ICON_SIZES = Set.of(16, 22, 32, 48, 64, 128);
756+
private static final Set<Integer> XDG_CMD_VALID_ICON_SIZES = Set.of(16, 22, 32, 48, 64, 128);
732757

733-
private final static Method getServiceUnitFileName = initGetServiceUnitFileName();
758+
private static final Method getServiceUnitFileName = initGetServiceUnitFileName();
734759
}

‎test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Main.java

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, 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
@@ -23,11 +23,17 @@
2323

2424
package jdk.jpackage.test;
2525

26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.util.ArrayDeque;
2629
import java.util.ArrayList;
30+
import java.util.Comparator;
31+
import java.util.Deque;
2732
import java.util.List;
2833
import java.util.function.Function;
2934
import java.util.function.Predicate;
30-
import java.util.stream.Collectors;
35+
import static java.util.stream.Collectors.toCollection;
36+
import java.util.stream.Stream;
3137
import static jdk.jpackage.test.TestBuilder.CMDLINE_ARG_PREFIX;
3238

3339

@@ -36,14 +42,39 @@ public static void main(String args[]) throws Throwable {
3642
boolean listTests = false;
3743
List<TestInstance> tests = new ArrayList<>();
3844
try (TestBuilder testBuilder = new TestBuilder(tests::add)) {
39-
for (var arg : args) {
45+
Deque<String> argsAsList = new ArrayDeque<>(List.of(args));
46+
while (!argsAsList.isEmpty()) {
47+
var arg = argsAsList.pop();
4048
TestBuilder.trace(String.format("Parsing [%s]...", arg));
4149

4250
if ((CMDLINE_ARG_PREFIX + "list").equals(arg)) {
4351
listTests = true;
4452
continue;
4553
}
4654

55+
if (arg.startsWith("@")) {
56+
// Command file
57+
// @=args will read arguments from the "args" file, one argument per line
58+
// @args will read arguments from the "args" file, splitting lines into arguments at whitespaces
59+
arg = arg.substring(1);
60+
var oneArgPerLine = arg.startsWith("=");
61+
if (oneArgPerLine) {
62+
arg = arg.substring(1);
63+
}
64+
65+
var newArgsStream = Files.readAllLines(Path.of(arg)).stream();
66+
if (!oneArgPerLine) {
67+
newArgsStream.map(line -> {
68+
return Stream.of(line.split("\\s+"));
69+
}).flatMap(x -> x);
70+
}
71+
72+
var newArgs = newArgsStream.collect(toCollection(ArrayDeque::new));
73+
newArgs.addAll(argsAsList);
74+
argsAsList = newArgs;
75+
continue;
76+
}
77+
4778
boolean success = false;
4879
try {
4980
testBuilder.processCmdLineArg(arg);
@@ -62,12 +93,11 @@ public static void main(String args[]) throws Throwable {
6293

6394
// Order tests by their full names to have stable test sequence.
6495
List<TestInstance> orderedTests = tests.stream()
65-
.sorted((a, b) -> a.fullName().compareTo(b.fullName()))
66-
.collect(Collectors.toList());
96+
.sorted(Comparator.comparing(TestInstance::fullName)).toList();
6797

6898
if (listTests) {
6999
// Just list the tests
70-
orderedTests.stream().forEach(test -> System.out.println(String.format(
100+
orderedTests.forEach(test -> System.out.println(String.format(
71101
"%s; workDir=[%s]", test.fullName(), test.workDir())));
72102
return;
73103
}

0 commit comments

Comments
 (0)
Please sign in to comment.