@@ -498,6 +498,8 @@ private void generateRpmPackage() throws MojoExecutionException {
498498 element ("needarch" , "true" ),
499499 element ("defaultDirmode" , "755" ),
500500 element ("defaultFilemode" , "644" ),
501+ element ("defaultUsername" , "root" ),
502+ element ("defaultGroupname" , "root" ),
501503 element ("copyTo" , rpmFile .getAbsolutePath ()),
502504 element ("mappings" ,
503505 /* app folder files, except executable file and jre/bin/java */
@@ -847,15 +849,86 @@ private void generateDmgImage() throws MojoExecutionException {
847849
848850 getLog ().info ("Generating DMG disk image file" );
849851
852+ // final dmg file
853+ File dmgFile = new File (outputDirectory , name + "_" + version + ".dmg" );
854+
855+ // temp dmg file
856+ File tempDmgFile = new File (assetsFolder , name + "_" + version + ".dmg" );
857+
858+ // volumen name
859+ String volumeName = name ;
860+
861+ // mount dir
862+ File mountFolder = new File ("/Volumes/" + volumeName );
863+
850864 // creates a symlink to Applications folder
851865 File targetFolder = new File ("/Applications" );
852866 File linkFile = new File (appFolder , "Applications" );
853867 FileUtils .createSymlink (linkFile , targetFolder );
854868
855- // creates the DMG file including app folder's content
856- getLog ().info ("Generating the Disk Image file" );
857- File diskImageFile = new File (outputDirectory , name + "_" + version + ".dmg" );
858- CommandUtils .execute ("hdiutil" , "create" , "-srcfolder" , appFolder , "-volname" , name , diskImageFile );
869+ // copies background file
870+ getLog ().info ("Copying background image" );
871+ File backgroundFolder = FileUtils .mkdir (appFolder , ".background" );
872+ File backgroundFile = new File (backgroundFolder , "background.png" );
873+ FileUtils .copyResourceToFile ("/assets/mac/background.png" , backgroundFile );
874+
875+ // copies volume icon
876+ getLog ().info ("Copying icon file: " + iconFile .getAbsolutePath ());
877+ FileUtils .copyFileToFile (iconFile , new File (appFolder , ".VolumeIcon.icns" ));
878+
879+ // creates image
880+ getLog ().info ("Creating image: " + tempDmgFile .getAbsolutePath ());
881+ CommandUtils .execute ("hdiutil" , "create" , "-srcfolder" , appFolder , "-volname" , volumeName , "-fs" , "HFS+" , "-fsargs" , "-c c=64,a=16,e=16" , "-format" , "UDRW" , tempDmgFile );
882+
883+ // mounts image
884+ getLog ().info ("Mounting image: " + tempDmgFile .getAbsolutePath ());
885+ String result = CommandUtils .execute ("hdiutil" , "attach" , "-readwrite" , "-noverify" , "-noautoopen" , tempDmgFile );
886+ String deviceName = Arrays .asList (result .split ("\n " )).stream ().filter (s -> s .startsWith ("/dev/" )).findFirst ().get ();
887+ getLog ().info ("- Device name: " + deviceName );
888+
889+ // rendering applescript
890+ Map <String , Object > params = new HashMap <>();
891+ params .put ("windowX" , "value" );
892+ params .put ("windowY" , "value" );
893+ params .put ("windowWidth" , "value" );
894+ params .put ("windowHeight" , "value" );
895+ params .put ("iconSize" , 128 );
896+ params .put ("textSize" , 16 );
897+ params .put ("background" , backgroundFile .getParentFile ().getName () + "/" + backgroundFile .getName ());
898+ params .put ("file" , name );
899+ params .put ("fileX" , 20 );
900+ params .put ("fileY" , 20 );
901+ params .put ("appX" , 100 );
902+ params .put ("appY" , 20 );
903+ File applescript = new File (assetsFolder , "customize-dmg.applescript" );
904+ getLog ().info ("Rendering applescript: " + applescript .getAbsolutePath ());
905+ VelocityUtils .render ("/mac/customize-dmg.applescript.vtl" , applescript , params );
906+
907+ // rendering applescript
908+ getLog ().info ("Running applescript" );
909+ CommandUtils .execute ("/usr/bin/osascript" , applescript , volumeName );
910+
911+ // make sure it's not world writeable
912+ getLog ().info ("Fixing permissions..." );
913+ CommandUtils .execute ("chmod" , "-Rf" , "go-w" , mountFolder );
914+
915+ // make the top window open itself on mount:
916+ getLog ().info ("Blessing ..." );
917+ CommandUtils .execute ("bless" , "--folder" , mountFolder , "--openfolder" , mountFolder );
918+
919+ // tell the volume that it has a special file attribute
920+ CommandUtils .execute ("SetFile" , "-a" , "C" , mountFolder );
921+
922+ // unmount
923+ getLog ().info ("Unmounting disk image..." );
924+ CommandUtils .execute ("hdiutil" , "detach" , deviceName );
925+
926+ // compress image
927+ getLog ().info ("Compressing disk image..." );
928+ CommandUtils .execute ("hdiutil" , "convert" , tempDmgFile , "-format" , "UDZO" , "zlib-level=9" , "-o" , dmgFile );
929+ tempDmgFile .delete ();
930+
931+ getLog ().info ("DMG disk image file generated!" );
859932
860933 }
861934
0 commit comments