Skip to content

Commit 6fb9f9c

Browse files
committed
U dmg image generation enhanced
1 parent e2d48f1 commit 6fb9f9c

File tree

4 files changed

+151
-5
lines changed

4 files changed

+151
-5
lines changed

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<connection>scm:git:git://github.com/fvarrui/JavaPackager.git</connection>
3636
<developerConnection>scm:git:git@github.com:fvarrui/fvarrui.git</developerConnection>
3737
<url>https://github.com/fvarrui/JavaPackager</url>
38-
<tag>v0.9.1</tag>
3938
</scm>
4039

4140
<dependencies>

src/main/java/io/github/fvarrui/javapackager/PackageMojo.java

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

131 KB
Loading
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
on run (volumeName)
2+
tell application "Finder"
3+
tell disk (volumeName as string)
4+
open
5+
6+
set theXOrigin to ${windowX}
7+
set theYOrigin to ${windowY}
8+
set theWidth to ${windowWidth}
9+
set theHeight to ${windowHeight}
10+
11+
set theBottomRightX to (theXOrigin + theWidth)
12+
set theBottomRightY to (theYOrigin + theHeight)
13+
set dsStore to "\"" & "/Volumes/" & volumeName & "/" & ".DS_STORE\""
14+
15+
tell container window
16+
set current view to icon view
17+
set toolbar visible to false
18+
set statusbar visible to false
19+
set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
20+
set statusbar visible to false
21+
set position of every item to {theBottomRightX + 100, 100}
22+
end tell
23+
24+
set opts to the icon view options of container window
25+
tell opts
26+
set icon size to ${iconSize}
27+
set text size to ${textSize}
28+
set arrangement to not arranged
29+
end tell
30+
set background picture of opts to file ".background:${background}"
31+
32+
-- Positioning
33+
set position of item "${file}" to {${fileX}, ${fileY}}
34+
35+
-- Hiding
36+
set the extension hidden of item "${file}" to true
37+
38+
-- Application
39+
set position of item "Applications" to {${appX}, ${appY}}
40+
41+
close
42+
open
43+
-- Force saving of the size
44+
delay 1
45+
46+
tell container window
47+
set statusbar visible to false
48+
set the bounds to {theXOrigin, theYOrigin, theBottomRightX - 10, theBottomRightY - 10}
49+
end tell
50+
end tell
51+
52+
delay 1
53+
54+
tell disk (volumeName as string)
55+
tell container window
56+
set statusbar visible to false
57+
set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
58+
end tell
59+
end tell
60+
61+
--give the finder some time to write the .DS_Store file
62+
delay 3
63+
64+
set waitTime to 0
65+
set ejectMe to false
66+
repeat while ejectMe is false
67+
delay 1
68+
set waitTime to waitTime + 1
69+
70+
if (do shell script "[ -f " & dsStore & " ]; echo $?") = "0" then set ejectMe to true
71+
end repeat
72+
log "waited " & waitTime & " seconds for .DS_STORE to be created."
73+
end tell
74+
end run

0 commit comments

Comments
 (0)