1
1
/*
2
- * Copyright (c) 2019, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
40
40
import java .util .regex .Pattern ;
41
41
import java .util .stream .Collectors ;
42
42
import java .util .stream .Stream ;
43
+ import jdk .jpackage .internal .ApplicationLayout ;
43
44
import jdk .jpackage .internal .IOUtils ;
44
45
import jdk .jpackage .test .Functional .ThrowingConsumer ;
45
46
import jdk .jpackage .test .PackageTest .PackageHandlers ;
@@ -399,6 +400,15 @@ static void addBundleDesktopIntegrationVerifier(PackageTest test,
399
400
private static void verifyDesktopFile (JPackageCommand cmd , Path desktopFile )
400
401
throws IOException {
401
402
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
+
402
412
List <String > lines = Files .readAllLines (desktopFile );
403
413
TKit .assertEquals ("[Desktop Entry]" , lines .get (0 ), "Check file header" );
404
414
@@ -428,7 +438,7 @@ private static void verifyDesktopFile(JPackageCommand cmd, Path desktopFile)
428
438
"Check value of [%s] key" , key ));
429
439
}
430
440
431
- // Verify value of `Exec` property in .desktop files are escaped if required
441
+ // Verify the value of `Exec` key is escaped if required
432
442
String launcherPath = data .get ("Exec" );
433
443
if (Pattern .compile ("\\ s" ).matcher (launcherPath ).find ()) {
434
444
TKit .assertTrue (launcherPath .startsWith ("\" " )
@@ -437,10 +447,25 @@ private static void verifyDesktopFile(JPackageCommand cmd, Path desktopFile)
437
447
launcherPath = launcherPath .substring (1 , launcherPath .length () - 1 );
438
448
}
439
449
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
+ }
444
469
445
470
TKit .trace (String .format ("Check [%s] file END" , desktopFile ));
446
471
}
@@ -725,10 +750,10 @@ private static Method initGetServiceUnitFileName() {
725
750
726
751
private static Map <PackageType , String > archs ;
727
752
728
- private final static Pattern XDG_CMD_ICON_SIZE_PATTERN = Pattern .compile ("\\ s--size\\ s+(\\ d+)\\ b" );
753
+ private static final Pattern XDG_CMD_ICON_SIZE_PATTERN = Pattern .compile ("\\ s--size\\ s+(\\ d+)\\ b" );
729
754
730
755
// Values grabbed from https://linux.die.net/man/1/xdg-icon-resource
731
- private final static Set <Integer > XDG_CMD_VALID_ICON_SIZES = Set .of (16 , 22 , 32 , 48 , 64 , 128 );
756
+ private static final Set <Integer > XDG_CMD_VALID_ICON_SIZES = Set .of (16 , 22 , 32 , 48 , 64 , 128 );
732
757
733
- private final static Method getServiceUnitFileName = initGetServiceUnitFileName ();
758
+ private static final Method getServiceUnitFileName = initGetServiceUnitFileName ();
734
759
}
0 commit comments