Skip to content

Commit

Permalink
8345185: Update jpackage to not include service bindings by default
Browse files Browse the repository at this point in the history
Backport-of: 85ed78c
  • Loading branch information
jerboaa committed Feb 5, 2025
1 parent f90566a commit ba7b3c2
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jdk.internal.module.ModulePath;


Expand Down Expand Up @@ -99,8 +100,10 @@ private static Set<String> getDefaultModules(

ModuleFinder finder = createModuleFinder(paths);

// Don't perform service bindings by default as outlined by JEP 343
// and JEP 392
return Configuration.empty()
.resolveAndBind(finder, ModuleFinder.of(), roots)
.resolve(finder, ModuleFinder.of(), roots)
.modules()
.stream()
.map(ResolvedModule::name)
Expand Down
3 changes: 2 additions & 1 deletion test/jdk/tools/jpackage/TEST.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ exclusiveAccess.dirs=share windows
modules=jdk.jpackage/jdk.jpackage.internal:+open \
jdk.jpackage/jdk.jpackage.internal.util \
jdk.jpackage/jdk.jpackage.internal.util.function \
java.base/jdk.internal.util
java.base/jdk.internal.util \
jdk.jlink/jdk.tools.jlink.internal
41 changes: 33 additions & 8 deletions test/jdk/tools/jpackage/share/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.nio.file.Path;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
Expand All @@ -41,7 +43,9 @@
import jdk.jpackage.test.JavaTool;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.Annotations.Parameter;
import jdk.jpackage.test.Annotations.ParameterSupplier;
import jdk.jpackage.internal.util.function.ThrowingConsumer;
import jdk.tools.jlink.internal.LinkableRuntimeImage;
import static jdk.jpackage.test.RunnablePackageTest.Action.CREATE_AND_UNPACK;

/*
Expand All @@ -55,6 +59,32 @@
*/

public final class BasicTest {

public static Collection addModulesParams() {
List<Object[][]> params = new ArrayList<>();
params.add(new Object[][] { new String[] { "--add-modules", "ALL-DEFAULT" } });
params.add(new Object[][] { new String[] { "--add-modules", "java.desktop" } });
params.add(new Object[][] { new String[] { "--add-modules", "java.desktop,jdk.jartool" } });
params.add(new Object[][] { new String[] { "--add-modules", "java.desktop", "--add-modules", "jdk.jartool" } });
if (isAllModulePathCapable()) {
final Path jmods = Path.of(System.getProperty("java.home"), "jmods");
params.add(new Object[][] { new String[] { "--add-modules", "ALL-MODULE-PATH",
// Since JDK-8345259 ALL-MODULE-PATH requires --module-path arg
"--module-path", jmods.toString() } });
}
return Collections.unmodifiableList(params);
}

private static boolean isAllModulePathCapable() {
Path jmods = Path.of(System.getProperty("java.home"), "jmods");
boolean noJmods = Files.notExists(jmods);
if (LinkableRuntimeImage.isLinkableRuntime() && noJmods) {
TKit.trace("ALL-MODULE-PATH test skipped for linkable run-time image");
return false;
}
return true;
}

@Test
public void testNoArgs() {
List<String> output =
Expand Down Expand Up @@ -306,17 +336,12 @@ public void testNoOutputDir(boolean appImage) throws Throwable {
}

@Test
@Parameter("ALL-MODULE-PATH")
@Parameter("ALL-DEFAULT")
@Parameter("java.desktop")
@Parameter("java.desktop,jdk.jartool")
@Parameter({ "java.desktop", "jdk.jartool" })
public void testAddModules(String... addModulesArg) {
@ParameterSupplier("addModulesParams")
public void testAddModules(String[] addModulesArg) {
JPackageCommand cmd = JPackageCommand
.helloAppImage("goodbye.jar:com.other/com.other.Hello")
.ignoreDefaultRuntime(true); // because of --add-modules
Stream.of(addModulesArg).map(v -> Stream.of("--add-modules", v)).flatMap(
s -> s).forEachOrdered(cmd::addArgument);
Stream.of(addModulesArg).forEachOrdered(cmd::addArgument);
cmd.executeAndAssertHelloAppImageCreated();
}

Expand Down
12 changes: 7 additions & 5 deletions test/jdk/tools/jpackage/share/JLinkOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,26 @@ public static Collection input() {
"--jlink-options",
"--strip-debug --no-man-pages --no-header-files",
"--jlink-options",
"--bind-services",
"--verbose --bind-services --limit-modules java.smartcardio,jdk.crypto.cryptoki,java.desktop",
},
// with bind-services should have some services
// with limit-modules and bind-services should have them in the result
new String[]{"java.smartcardio", "jdk.crypto.cryptoki"},
null,
},
// bind-services
{"Hello", new String[]{
"--jlink-options", "--bind-services",
"--jlink-options",
"--bind-services --limit-modules jdk.jartool,jdk.unsupported,java.desktop",
},
// non modular should have everything
// non modular should have at least the module limits
new String[]{"jdk.jartool", "jdk.unsupported"},
null,
},

// jlink-options --bind-services
{"com.other/com.other.Hello", new String[]{
"--jlink-options", "--bind-services",
"--jlink-options",
"--bind-services --limit-modules java.smartcardio,jdk.crypto.cryptoki,java.desktop",
},
// with bind-services should have some services
new String[]{"java.smartcardio", "jdk.crypto.cryptoki"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class RuntimeImageSymbolicLinksTest {

@Test
public static void test() throws Exception {
final Path jmods = Path.of(System.getProperty("java.home"), "jmods");
final Path workDir = TKit.createTempDirectory("runtime").resolve("data");
final Path jlinkOutputDir = workDir.resolve("temp.runtime");
Files.createDirectories(jlinkOutputDir.getParent());
Expand All @@ -61,8 +60,7 @@ public static void test() throws Exception {
.dumpOutput()
.addArguments(
"--output", jlinkOutputDir.toString(),
"--add-modules", "ALL-MODULE-PATH",
"--module-path", jmods.toString(),
"--add-modules", "java.desktop",
"--strip-debug",
"--no-header-files",
"--no-man-pages",
Expand Down
4 changes: 1 addition & 3 deletions test/jdk/tools/jpackage/share/RuntimeImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class RuntimeImageTest {

@Test
public static void test() throws Exception {
final Path jmods = Path.of(System.getProperty("java.home"), "jmods");
final Path workDir = TKit.createTempDirectory("runtime").resolve("data");
final Path jlinkOutputDir = workDir.resolve("temp.runtime");
Files.createDirectories(jlinkOutputDir.getParent());
Expand All @@ -54,8 +53,7 @@ public static void test() throws Exception {
.dumpOutput()
.addArguments(
"--output", jlinkOutputDir.toString(),
"--add-modules", "ALL-MODULE-PATH",
"--module-path", jmods.toString(),
"--add-modules", "java.desktop",
"--strip-debug",
"--no-header-files",
"--no-man-pages",
Expand Down
4 changes: 1 addition & 3 deletions test/jdk/tools/jpackage/share/RuntimePackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private static PackageTest init(Set<PackageType> types) {
.forTypes(types)
.addInitializer(cmd -> {
final Path runtimeImageDir;
final Path jmods = Path.of(System.getProperty("java.home"), "jmods");

if (JPackageCommand.DEFAULT_RUNTIME_IMAGE != null) {
runtimeImageDir = JPackageCommand.DEFAULT_RUNTIME_IMAGE;
Expand All @@ -113,8 +112,7 @@ private static PackageTest init(Set<PackageType> types) {
.dumpOutput()
.addArguments(
"--output", runtimeImageDir.toString(),
"--add-modules", "ALL-MODULE-PATH",
"--module-path", jmods.toString(),
"--add-modules", "java.desktop",
"--strip-debug",
"--no-header-files",
"--no-man-pages")
Expand Down

0 comments on commit ba7b3c2

Please sign in to comment.