11/*
2- * Copyright (c) 2019, 2022 , 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
4040import java .util .regex .Pattern ;
4141import java .util .stream .Collectors ;
4242import java .util .stream .Stream ;
43+ import jdk .jpackage .internal .ApplicationLayout ;
4344import jdk .jpackage .internal .IOUtils ;
4445import jdk .jpackage .test .Functional .ThrowingConsumer ;
4546import 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 }
@@ -720,10 +745,10 @@ private static Method initGetServiceUnitFileName() {
720745
721746 private static Map <PackageType , String > archs ;
722747
723- private final static Pattern XDG_CMD_ICON_SIZE_PATTERN = Pattern .compile ("\\ s--size\\ s+(\\ d+)\\ b" );
748+ private static final Pattern XDG_CMD_ICON_SIZE_PATTERN = Pattern .compile ("\\ s--size\\ s+(\\ d+)\\ b" );
724749
725750 // Values grabbed from https://linux.die.net/man/1/xdg-icon-resource
726- private final static Set <Integer > XDG_CMD_VALID_ICON_SIZES = Set .of (16 , 22 , 32 , 48 , 64 , 128 );
751+ private static final Set <Integer > XDG_CMD_VALID_ICON_SIZES = Set .of (16 , 22 , 32 , 48 , 64 , 128 );
727752
728- private final static Method getServiceUnitFileName = initGetServiceUnitFileName ();
753+ private static final Method getServiceUnitFileName = initGetServiceUnitFileName ();
729754}
0 commit comments