Skip to content

Commit 2093bb7

Browse files
author
Alexey Semenyuk
committed
8346434: Add test for non-automatic service binding
Reviewed-by: almatvee
1 parent dd8720e commit 2093bb7

File tree

3 files changed

+60
-21
lines changed

3 files changed

+60
-21
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -21,8 +21,12 @@
2121
* questions.
2222
*/
2323

24-
import java.util.List;
24+
import java.lang.module.ModuleDescriptor;
25+
import java.lang.module.ModuleFinder;
26+
import java.lang.module.ModuleReference;
2527
import java.util.ArrayList;
28+
import java.util.List;
29+
import java.util.stream.Collectors;
2630

2731
public class PrintEnv {
2832

@@ -41,6 +45,11 @@ private static List<String> printArgs(String[] args) {
4145
} else if (arg.startsWith(PRINT_SYS_PROP)) {
4246
String name = arg.substring(PRINT_SYS_PROP.length());
4347
lines.add(name + "=" + System.getProperty(name));
48+
} else if (arg.startsWith(PRINT_MODULES)) {
49+
lines.add(ModuleFinder.ofSystem().findAll().stream()
50+
.map(ModuleReference::descriptor)
51+
.map(ModuleDescriptor::name)
52+
.collect(Collectors.joining(",")));
4453
} else {
4554
throw new IllegalArgumentException();
4655
}
@@ -51,4 +60,5 @@ private static List<String> printArgs(String[] args) {
5160

5261
private final static String PRINT_ENV_VAR = "--print-env-var=";
5362
private final static String PRINT_SYS_PROP = "--print-sys-prop=";
63+
private final static String PRINT_MODULES = "--print-modules";
5464
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 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
@@ -25,9 +25,9 @@
2525
import java.util.HashSet;
2626
import java.util.Set;
2727

28-
record Comm<T>(Set<T> common, Set<T> unique1, Set<T> unique2) {
28+
public record Comm<T>(Set<T> common, Set<T> unique1, Set<T> unique2) {
2929

30-
static <T> Comm<T> compare(Set<T> a, Set<T> b) {
30+
public static <T> Comm<T> compare(Set<T> a, Set<T> b) {
3131
Set<T> common = new HashSet<>(a);
3232
common.retainAll(b);
3333
Set<T> unique1 = new HashSet<>(a);

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

Lines changed: 45 additions & 16 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
@@ -22,10 +22,16 @@
2222
*/
2323

2424

25+
import java.nio.file.Path;
2526
import java.util.Collection;
2627
import java.util.List;
27-
import jdk.jpackage.test.Annotations.Parameters;
28+
import java.util.Set;
29+
import java.util.stream.Collectors;
30+
import java.util.stream.Stream;
31+
import jdk.jpackage.test.Annotations.ParameterSupplier;
2832
import jdk.jpackage.test.Annotations.Test;
33+
import jdk.jpackage.test.Comm;
34+
import jdk.jpackage.test.HelloApp;
2935
import jdk.jpackage.test.JPackageCommand;
3036
import jdk.jpackage.test.TKit;
3137

@@ -41,7 +47,6 @@
4147

4248
public final class JLinkOptionsTest {
4349

44-
@Parameters
4550
public static Collection input() {
4651
return List.of(new Object[][]{
4752
// default but with strip-native-commands removed
@@ -111,17 +116,11 @@ public static Collection input() {
111116
});
112117
}
113118

114-
public JLinkOptionsTest(String javaAppDesc, String[] jpackageArgs, String[] required, String[] prohibited) {
115-
this.required = required;
116-
this.prohibited = prohibited;
117-
cmd = JPackageCommand
118-
.helloAppImage(javaAppDesc)
119-
.ignoreDefaultRuntime(true)
120-
.addArguments(jpackageArgs);
121-
}
122-
123119
@Test
124-
public void test() {
120+
@ParameterSupplier("input")
121+
public void test(String javaAppDesc, String[] jpackageArgs, String[] required, String[] prohibited) {
122+
final var cmd = createJPackageCommand(javaAppDesc).addArguments(jpackageArgs);
123+
125124
cmd.executeAndAssertHelloAppImageCreated();
126125

127126
List<String> release = cmd.readRuntimeReleaseFile();
@@ -138,7 +137,37 @@ public void test() {
138137
}
139138
}
140139

141-
private final String[] required;
142-
private final String[] prohibited;
143-
private final JPackageCommand cmd;
140+
@Test
141+
public void testNoBindServicesByDefault() {
142+
final var defaultModules = getModulesInRuntime();
143+
final var modulesWithBindServices = getModulesInRuntime("--bind-services");
144+
145+
final var moduleComm = Comm.compare(defaultModules, modulesWithBindServices);
146+
147+
TKit.assertStringListEquals(List.of(), moduleComm.unique1().stream().toList(),
148+
"Check '--bind-services' option doesn't remove modules");
149+
TKit.assertNotEquals("", moduleComm.unique2().stream().sorted().collect(Collectors.joining(",")),
150+
"Check '--bind-services' option adds modules");
151+
}
152+
153+
private final JPackageCommand createJPackageCommand(String javaAppDesc) {
154+
return JPackageCommand.helloAppImage(javaAppDesc).ignoreDefaultRuntime(true);
155+
}
156+
157+
private final Set<String> getModulesInRuntime(String ... jlinkOptions) {
158+
final var cmd = createJPackageCommand(PRINT_ENV_APP + "*");
159+
if (jlinkOptions.length != 0) {
160+
cmd.addArguments("--jlink-options");
161+
cmd.addArguments(jlinkOptions);
162+
}
163+
164+
cmd.executeAndAssertImageCreated();
165+
166+
final var output = HelloApp.assertApp(cmd.appLauncherPath())
167+
.saveOutput(true).execute("--print-modules").getFirstLineOfOutput();
168+
169+
return Stream.of(output.split(",")).collect(Collectors.toSet());
170+
}
171+
172+
private static final Path PRINT_ENV_APP = TKit.TEST_SRC_ROOT.resolve("apps/PrintEnv.java");
144173
}

0 commit comments

Comments
 (0)