@@ -150,16 +150,7 @@ private void createBinary( List<File> filesToPackage ) throws Throwable {
150150 // pyinstaller --onefile --target-architecture universal2 dmgbuild
151151
152152 task .getProject ().getLogger ().lifecycle ( "\t Extracting dmgbuild" );
153- File dmgbuild = ResourceUtils .extract ( getClass (), "template/dmgbuild/dmgbuild" , tempPath .get ( "dmgbuild" ).toFile () );
154- Set <PosixFilePermission > perms = new HashSet <PosixFilePermission >();
155- perms .add ( PosixFilePermission .OWNER_READ );
156- perms .add ( PosixFilePermission .OWNER_WRITE );
157- perms .add ( PosixFilePermission .GROUP_READ );
158- perms .add ( PosixFilePermission .OTHERS_READ );
159- perms .add ( PosixFilePermission .OWNER_EXECUTE );
160- perms .add ( PosixFilePermission .GROUP_EXECUTE );
161- perms .add ( PosixFilePermission .OTHERS_EXECUTE );
162- Files .setPosixFilePermissions ( dmgbuild .toPath (), perms );
153+ File dmgbuild = extractExecutableFile ( "template/dmgbuild/dmgbuild" , tempPath .get ( "dmgbuild" ).toFile () );
163154
164155 Path settingsFile = tempPath .getTempFile ( "dmgbuild" , "settings.py" ).toPath ();
165156
@@ -201,6 +192,27 @@ private void createBinary( List<File> filesToPackage ) throws Throwable {
201192 codesignFinalImage ();
202193 }
203194
195+ /**
196+ * Extract an executable resource and set file permissions accordingly
197+ * @param source the source, relative to the current class
198+ * @param destination the destination file
199+ * @return the actual file it was extracted to
200+ * @throws IOException in case of errors
201+ */
202+ private File extractExecutableFile ( String source , File destination ) throws IOException {
203+ File dmgbuild = ResourceUtils .extract ( getClass (), source , destination );
204+ Set <PosixFilePermission > perms = new HashSet <PosixFilePermission >();
205+ perms .add ( PosixFilePermission .OWNER_READ );
206+ perms .add ( PosixFilePermission .OWNER_WRITE );
207+ perms .add ( PosixFilePermission .GROUP_READ );
208+ perms .add ( PosixFilePermission .OTHERS_READ );
209+ perms .add ( PosixFilePermission .OWNER_EXECUTE );
210+ perms .add ( PosixFilePermission .GROUP_EXECUTE );
211+ perms .add ( PosixFilePermission .OTHERS_EXECUTE );
212+ Files .setPosixFilePermissions ( dmgbuild .toPath (), perms );
213+ return dmgbuild ;
214+ }
215+
204216 /**
205217 * Create the service files and the pre- and post installer scripts
206218 * @throws IOException in case of errors
@@ -304,9 +316,9 @@ private File createPackageFromApp() throws Throwable {
304316 task .getCodeSign ().signProduct ( resultingPackage );
305317 }
306318
307- // packageApplescript();
308319 File packageFile = new File ( setup .getDestinationDir (), "/" + setup .getApplication () + ".pkg" );
309320 Files .copy ( resultingPackage .toPath (), packageFile .toPath (), java .nio .file .StandardCopyOption .REPLACE_EXISTING );
321+ setIconForPackage ( packageFile );
310322 return packageFile ;
311323 }
312324
@@ -531,7 +543,7 @@ private OSXScriptBuilder iconLocations( boolean requiresApplicationsLink ) throw
531543 int yPos = (windowHeight - iconSize ) / 3 * 2 ;
532544
533545 String appLocation = "" ;
534- if ( ! requiresApplicationsLink ) {
546+ if ( requiresApplicationsLink ) {
535547 // Only set the symlinks for applications if required.
536548 settings .setPlaceholder ( "symlinks" , "\" Applications\" : \" /Applications\" " );
537549
@@ -575,25 +587,23 @@ private File prepareBackgroundImage() throws IOException {
575587 * run a Script for the Package.
576588 * @throws IOException exception
577589 */
578- /*
579- private void packageApplescript() throws IOException {
590+ private void setIconForPackage ( File packageFile ) throws IOException {
580591
581- Template applescript = new Template( "dmg/template/package.applescript.txt" );
582- applescript.setPlaceholder( "icon", ImageFactory.getImageFile( task.getProject(), task.getSetupIcon(), buildDir, "icns" ).getAbsolutePath() );
583- applescript.setPlaceholder( "package", new File( imageSourceRoot, setup.getApplication() + ".pkg" ).getAbsolutePath() );
592+ task .getProject ().getLogger ().lifecycle ( "\t Extracting setIcon.sh" );
593+ File setIcon = extractExecutableFile ( "template/dmgbuild/setIcon.sh" , tempPath .get ( "setIcon.sh" ).toFile () );
584594
585595 ArrayList <String > command = new ArrayList <>();
586- command.add( "/usr/bin/osascript" );
596+ command .add ( setIcon .getAbsolutePath () );
597+ command .add ( ImageFactory .getImageFile ( task .getProject (), task .getSetupIcon (), buildDir , "icns" ).getAbsolutePath () );
598+ command .add ( packageFile .getAbsolutePath () );
587599
588600 task .getProject ().getLogger ().lifecycle ( "\t Setting display options for package." );
589- task.getProject().getLogger().debug( applescript.toString() );
590601
591602 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
592- exec( command, new ByteArrayInputStream( applescript.toString().getBytes( StandardCharsets.UTF_8 ) ), baos, true );
603+ exec ( true , baos , command . toArray ( new String [ command . size ()] ) );
593604 task .getProject ().getLogger ().lifecycle ( "\t Done Setting DMG display options for package. Ignoring errors if there were any" );
594605 task .getProject ().getLogger ().lifecycle ( "\t " + baos .toString () );
595606 }
596- */
597607
598608 /**
599609 * Run the code signing if applicable
0 commit comments