|  | 
| 21 | 21 |  * questions. | 
| 22 | 22 |  */ | 
| 23 | 23 | 
 | 
| 24 |  | -import java.nio.file.Path; | 
| 25 |  | -import java.util.Map; | 
| 26 | 24 | import java.lang.invoke.MethodHandles; | 
| 27 |  | -import jdk.jpackage.test.PackageTest; | 
| 28 |  | -import jdk.jpackage.test.FileAssociations; | 
|  | 25 | +import java.nio.file.Path; | 
|  | 26 | +import java.util.function.Consumer; | 
|  | 27 | +import jdk.internal.util.OperatingSystem; | 
| 29 | 28 | import jdk.jpackage.test.AdditionalLauncher; | 
|  | 29 | +import jdk.jpackage.test.Annotations.Parameter; | 
|  | 30 | +import jdk.jpackage.test.Annotations.Test; | 
|  | 31 | +import jdk.jpackage.test.CfgFile; | 
|  | 32 | +import jdk.jpackage.test.ConfigurationTarget; | 
|  | 33 | +import jdk.jpackage.test.FileAssociations; | 
| 30 | 34 | import jdk.jpackage.test.JPackageCommand; | 
| 31 | 35 | import jdk.jpackage.test.JavaAppDesc; | 
|  | 36 | +import jdk.jpackage.test.PackageTest; | 
|  | 37 | +import jdk.jpackage.test.PackageType; | 
|  | 38 | +import jdk.jpackage.test.RunnablePackageTest.Action; | 
| 32 | 39 | import jdk.jpackage.test.TKit; | 
| 33 |  | -import jdk.jpackage.test.Annotations.Test; | 
| 34 |  | -import jdk.jpackage.test.Annotations.Parameter; | 
| 35 |  | -import jdk.jpackage.test.CfgFile; | 
| 36 | 40 | 
 | 
| 37 | 41 | /** | 
| 38 | 42 |  * Test --add-launcher parameter. Output of the test should be | 
| @@ -233,6 +237,61 @@ public void testMainLauncherIsModular(boolean mainLauncherIsModular) { | 
| 233 | 237 |                 "Check app.classpath value in ModularAppLauncher cfg file"); | 
| 234 | 238 |     } | 
| 235 | 239 | 
 | 
|  | 240 | +    /** | 
|  | 241 | +     * Test --description option | 
|  | 242 | +     */ | 
|  | 243 | +    @Test(ifNotOS = OperatingSystem.MACOS) // Don't run on macOS as launcher description is ignored on this platform | 
|  | 244 | +    @Parameter("true") | 
|  | 245 | +    @Parameter("fase") | 
|  | 246 | +    public void testDescription(boolean withPredefinedAppImage) { | 
|  | 247 | + | 
|  | 248 | +        ConfigurationTarget target; | 
|  | 249 | +        if (TKit.isWindows() || withPredefinedAppImage) { | 
|  | 250 | +            target = new ConfigurationTarget(JPackageCommand.helloAppImage()); | 
|  | 251 | +        } else { | 
|  | 252 | +            target = new ConfigurationTarget(new PackageTest().configureHelloApp()); | 
|  | 253 | +        } | 
|  | 254 | + | 
|  | 255 | +        target.addInitializer(cmd -> { | 
|  | 256 | +            cmd.setArgumentValue("--name", "Foo").setArgumentValue("--description", "Hello"); | 
|  | 257 | +            cmd.setFakeRuntime(); | 
|  | 258 | +            cmd.setStandardAsserts(JPackageCommand.StandardAssert.MAIN_LAUNCHER_DESCRIPTION); | 
|  | 259 | +        }); | 
|  | 260 | + | 
|  | 261 | +        target.add(new AdditionalLauncher("x")); | 
|  | 262 | +        target.add(new AdditionalLauncher("bye").setProperty("description", "Bye")); | 
|  | 263 | + | 
|  | 264 | +        target.test().ifPresent(test -> { | 
|  | 265 | +            // Make all launchers have shortcuts and thus .desktop files. | 
|  | 266 | +            // Launcher description is recorded in a desktop file and verified automatically. | 
|  | 267 | +            test.mutate(addLinuxShortcuts()); | 
|  | 268 | +        }); | 
|  | 269 | + | 
|  | 270 | +        target.cmd().ifPresent(withPredefinedAppImage ? JPackageCommand::execute : JPackageCommand::executeAndAssertImageCreated); | 
|  | 271 | +        target.test().ifPresent(test -> { | 
|  | 272 | +            test.run(Action.CREATE_AND_UNPACK); | 
|  | 273 | +        }); | 
|  | 274 | + | 
|  | 275 | +        if (withPredefinedAppImage) { | 
|  | 276 | +            new PackageTest().addInitializer(cmd -> { | 
|  | 277 | +                cmd.setArgumentValue("--name", "Bar"); | 
|  | 278 | +                // Should not have impact of launcher descriptions, but it does. | 
|  | 279 | +                cmd.setArgumentValue("--description", "Installer"); | 
|  | 280 | +                cmd.removeArgumentWithValue("--input").setArgumentValue("--app-image", target.cmd().orElseThrow().outputBundle()); | 
|  | 281 | +            }).mutate(addLinuxShortcuts()).run(Action.CREATE_AND_UNPACK); | 
|  | 282 | +        } | 
|  | 283 | +    } | 
|  | 284 | + | 
|  | 285 | +    private static Consumer<PackageTest> addLinuxShortcuts() { | 
|  | 286 | +        return test -> { | 
|  | 287 | +            test.forTypes(PackageType.LINUX, () -> { | 
|  | 288 | +                test.addInitializer(cmd -> { | 
|  | 289 | +                    cmd.addArgument("--linux-shortcut"); | 
|  | 290 | +                }); | 
|  | 291 | +            }); | 
|  | 292 | +        }; | 
|  | 293 | +    } | 
|  | 294 | + | 
| 236 | 295 |     private static final Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of( | 
| 237 | 296 |             "resources", "icon" + TKit.ICON_SUFFIX)); | 
| 238 | 297 | } | 
0 commit comments