11package io .github .fvarrui .javapackager .packagers ;
22
33import static org .apache .commons .lang3 .StringUtils .defaultIfBlank ;
4+ import static io .github .fvarrui .javapackager .utils .CommandUtils .execute ;
45
56import java .io .File ;
67import java .util .Arrays ;
78
89import org .apache .commons .lang3 .StringUtils ;
910
1011import io .github .fvarrui .javapackager .model .MacConfig ;
11- import io .github .fvarrui .javapackager .utils .CommandUtils ;
1212import io .github .fvarrui .javapackager .utils .FileUtils ;
1313import io .github .fvarrui .javapackager .utils .Logger ;
1414import io .github .fvarrui .javapackager .utils .ThreadUtils ;
@@ -81,11 +81,14 @@ public File apply(Packager packager) throws Exception {
8181
8282 // creates image
8383 Logger .info ("Creating image: " + tempDmgFile .getAbsolutePath ());
84- CommandUtils .execute ("hdiutil" , "create" , "-srcfolder" , appFolder , "-volname" , volumeName , "-ov" , "-fs" , "HFS+" , "-format" , "UDRW" , tempDmgFile );
84+ execute ("hdiutil" , "create" , "-srcfolder" , appFolder , "-volname" , volumeName , "-ov" , "-fs" , "HFS+" , "-format" , "UDRW" , tempDmgFile );
85+
86+ Logger .info ("Unmounting disk image (if mounted)..." );
87+ execute ("hdiutil" , "detach" , volumeName );
8588
8689 // mounts image
8790 Logger .info ("Mounting image: " + tempDmgFile .getAbsolutePath ());
88- String result = CommandUtils . execute ("hdiutil" , "attach" , "-readwrite" , "-noverify" , "-noautoopen" , tempDmgFile );
91+ String result = execute ("hdiutil" , "attach" , "-readwrite" , "-noverify" , "-noautoopen" , tempDmgFile );
8992 String deviceName = Arrays .asList (result .split ("\n " ))
9093 .stream ()
9194 .filter (s -> s .contains (mountFolder .getAbsolutePath ()))
@@ -106,26 +109,26 @@ public File apply(Packager packager) throws Exception {
106109
107110 // runs applescript
108111 Logger .info ("Running applescript" );
109- CommandUtils . execute ("/usr/bin/osascript" , applescriptFile , volumeName );
112+ execute ("/usr/bin/osascript" , applescriptFile , volumeName );
110113
111114 // makes sure it's not world writeable and user readable
112115 Logger .info ("Fixing permissions..." );
113- CommandUtils . execute ("chmod" , "-Rf" , "u+r,go-w" , mountFolder );
116+ execute ("chmod" , "-Rf" , "u+r,go-w" , mountFolder );
114117
115118 // makes the top window open itself on mount:
116119 Logger .info ("Blessing ..." );
117- CommandUtils . execute ("bless" , "--folder" , mountFolder , "--openfolder" , mountFolder );
120+ execute ("bless" , "--folder" , mountFolder , "--openfolder" , mountFolder );
118121
119122 // tells the volume that it has a special file attribute
120- CommandUtils . execute ("SetFile" , "-a" , "C" , mountFolder );
123+ execute ("SetFile" , "-a" , "C" , mountFolder );
121124
122125 // unmounts
123126 Logger .info ("Unmounting disk image..." );
124- CommandUtils . execute ("hdiutil" , "detach" , deviceName );
127+ execute ("hdiutil" , "detach" , volumeName );
125128
126129 // compress image
127130 Logger .info ("Compressing disk image..." );
128- CommandUtils . execute ("hdiutil" , "convert" , tempDmgFile , "-format" , "UDZO" , "-imagekey" , "zlib-level=9" , "-o" , dmgFile );
131+ execute ("hdiutil" , "convert" , tempDmgFile , "-format" , "UDZO" , "-imagekey" , "zlib-level=9" , "-o" , dmgFile );
129132 tempDmgFile .delete ();
130133
131134 // checks if dmg file was created
0 commit comments