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
2222 */
2323
2424
25+ import java .nio .file .Path ;
2526import java .util .Collection ;
2627import 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 ;
2832import jdk .jpackage .test .Annotations .Test ;
33+ import jdk .jpackage .test .Comm ;
34+ import jdk .jpackage .test .HelloApp ;
2935import jdk .jpackage .test .JPackageCommand ;
3036import jdk .jpackage .test .TKit ;
3137
4147
4248public 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