4545import  java .util .Set ;
4646import  java .util .TreeMap ;
4747import  java .util .TreeSet ;
48+ import  java .util .function .Consumer ;
4849import  java .util .function .Function ;
4950import  java .util .function .Predicate ;
5051import  java .util .regex .Matcher ;
@@ -90,9 +91,7 @@ public static Path getDesktopFile(JPackageCommand cmd) {
9091
9192    public  static  Path  getDesktopFile (JPackageCommand  cmd , String  launcherName ) {
9293        cmd .verifyIsOfType (PackageType .LINUX );
93-         String  desktopFileName  = String .format ("%s-%s.desktop" , getPackageName (
94-                 cmd ), Optional .ofNullable (launcherName ).orElseGet (
95-                         () -> cmd .name ()).replaceAll ("\\ s+" , "_" ));
94+         var  desktopFileName  = getLauncherDesktopFileName (cmd , launcherName );
9695        return  cmd .appLayout ().desktopIntegrationDirectory ().resolve (
9796                desktopFileName );
9897    }
@@ -204,6 +203,20 @@ public static String getBundleProperty(JPackageCommand cmd,
204203        }
205204    }
206205
206+     private  static  Path  getFaIconFileName (JPackageCommand  cmd , String  mimeType ) {
207+         return  Path .of (mimeType .replace ('/' , '-' ) + ".png" );
208+     }
209+ 
210+     static  Path  getLauncherDesktopFileName (JPackageCommand  cmd , String  launcherName ) {
211+         return  Path .of (String .format ("%s-%s.desktop" , getPackageName (cmd ),
212+                 Optional .ofNullable (launcherName ).orElseGet (cmd ::name ).replaceAll ("\\ s+" , "_" )));
213+     }
214+ 
215+     static  Path  getLauncherIconFileName (JPackageCommand  cmd , String  launcherName ) {
216+         return  Path .of (String .format ("%s.png" ,
217+                 Optional .ofNullable (launcherName ).orElseGet (cmd ::name ).replaceAll ("\\ s+" , "_" )));
218+     }
219+ 
207220    static  PackageHandlers  createDebPackageHandlers () {
208221        return  new  PackageHandlers (LinuxHelper ::installDeb , LinuxHelper ::uninstallDeb , LinuxHelper ::unpackDeb );
209222    }
@@ -423,7 +436,12 @@ static void addBundleDesktopIntegrationVerifier(PackageTest test, boolean integr
423436        });
424437    }
425438
426-     static  void  verifyDesktopFiles (JPackageCommand  cmd , boolean  installed ) {
439+     static  void  verifyDesktopIntegrationFiles (JPackageCommand  cmd , boolean  installed ) {
440+         verifyDesktopFiles (cmd , installed );
441+         verifyAllIconsReferenced (cmd );
442+     }
443+ 
444+     private  static  void  verifyDesktopFiles (JPackageCommand  cmd , boolean  installed ) {
427445        final  var  desktopFiles  = getDesktopFiles (cmd );
428446        try  {
429447            if  (installed ) {
@@ -451,8 +469,6 @@ static void verifyDesktopFiles(JPackageCommand cmd, boolean installed) {
451469        } catch  (IOException  ex ) {
452470            throw  new  UncheckedIOException (ex );
453471        }
454- 
455-         verifyIcons (cmd );
456472    }
457473
458474    private  static  Collection <Path > getDesktopFiles (JPackageCommand  cmd ) {
@@ -481,7 +497,7 @@ private static Stream<Path> relativePackageFilesInSubdirectory(
481497        }).map (packageDir ::relativize );
482498    }
483499
484-     private  static  void  verifyIcons (JPackageCommand  cmd ) {
500+     private  static  void  verifyAllIconsReferenced (JPackageCommand  cmd ) {
485501
486502        var  installCmd  = Optional .ofNullable (cmd .unpackedPackageDirectory ()).map (_  -> {
487503            return  cmd .createMutableCopy ().setUnpackedPackageLocation (null );
@@ -495,8 +511,18 @@ private static void verifyIcons(JPackageCommand cmd) {
495511        }).map (installCmd .appLayout ().desktopIntegrationDirectory ()::resolve ).collect (toSet ());
496512
497513        var  referencedIcons  = getDesktopFiles (cmd ).stream ().map (path  -> {
498-             return  new  DesktopFile (path , false ).findQuotedValue ("Icon" );
499-         }).filter (Optional ::isPresent ).map (Optional ::get ).map (Path ::of ).collect (toSet ());
514+             return  new  DesktopFile (path , false );
515+         }).<Path >mapMulti ((desktopFile , sink ) -> {
516+             desktopFile .findQuotedValue ("Icon" ).map (Path ::of ).ifPresent (sink );
517+             desktopFile .find ("MimeType" ).ifPresent (str  -> {
518+                 Stream .of (str .split (";" ))
519+                         .map (mimeType  -> {
520+                             return  getFaIconFileName (cmd , mimeType );
521+                         })
522+                         .map (installCmd .appLayout ().desktopIntegrationDirectory ()::resolve )
523+                         .forEach (sink );
524+             });
525+         }).collect (toSet ());
500526
501527        var  unreferencedIconFiles  = Comm .compare (installedIconFiles , referencedIcons ).unique1 ().stream ().sorted ().toList ();
502528
@@ -686,16 +712,19 @@ static void addFileAssociationsVerifier(PackageTest test, FileAssociations fa) {
686712        });
687713
688714        test .addBundleVerifier (cmd  -> {
689-             final  Path  mimeTypeIconFileName  = fa .getLinuxIconFileName ();
690-             if  (mimeTypeIconFileName  != null ) {
691-                 // Verify there are xdg registration commands for mime icon file. 
692-                 Path  mimeTypeIcon  = cmd .appLayout ().desktopIntegrationDirectory ().resolve (
693-                         mimeTypeIconFileName );
694- 
695-                 Map <Scriptlet , List <String >> scriptlets  = getScriptlets (cmd );
696-                 scriptlets .entrySet ().stream ().forEach (e  -> verifyIconInScriptlet (
697-                         e .getKey (), e .getValue (), mimeTypeIcon ));
698-             }
715+             Optional .of (fa ).filter (FileAssociations ::hasIcon )
716+                     .map (FileAssociations ::getMime )
717+                     .map (mimeType  -> {
718+                         return  getFaIconFileName (cmd , mimeType );
719+                     }).ifPresent (mimeTypeIconFileName  -> {
720+                         // Verify there are xdg registration commands for mime icon file. 
721+                         Path  mimeTypeIcon  = cmd .appLayout ().desktopIntegrationDirectory ().resolve (
722+                                 mimeTypeIconFileName );
723+ 
724+                         Map <Scriptlet , List <String >> scriptlets  = getScriptlets (cmd );
725+                         scriptlets .entrySet ().stream ().forEach (e  -> verifyIconInScriptlet (
726+                                 e .getKey (), e .getValue (), mimeTypeIcon ));
727+                     });
699728        });
700729    }
701730
0 commit comments