throw new MojoFailureException( "Failed to copy PKG resources files." );
}
// Generating the PKG
log.info( "Generating Mac OS X PKG Installer" );
Execute createPkgTask = new Execute();
String[] cmd = new String[]
{ packageMakerUtility.getAbsolutePath(), "--root", "root/", "--resources", "Resources/", "--info",
"Info.plist", "--title", "Apache Directory Server " + target.getApplication().getVersion(),
"--version", target.getApplication().getVersion(), "--scripts", "scripts", "--out",
"Apache Directory Server Installer.pkg" };
createPkgTask.setCommandline( cmd );
createPkgTask.setSpawn( true );
createPkgTask.setWorkingDirectory( pkgDirectory );
try
{
createPkgTask.execute();
}
catch ( IOException e )
{
log.error( e.getMessage() );
throw new MojoFailureException( "Failed while trying to generate the PKG: " + e.getMessage() );
}
log.info( "Mac OS X PKG Installer generated at "
+ new File( pkgDirectory, "Apache Directory Server Installer.pkg" ) );
log.info( "Creating Mac OS X DMG..." );
// Creating the disc image directory
File dmgDirectory = new File( imagesDirectory, target.getId() + "-dmg" );
dmgDirectory.mkdirs();
log.info( "Copying DMG files" );
// Create dmg directory and its sub-directory
File dmgDmgBackgroundDirectory = new File( dmgDirectory, "dmg/.background" );
dmgDmgBackgroundDirectory.mkdirs();
// Copying the files
try
{
MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "dmg-background.png" ), new File(
dmgDirectory, "dmg/.background/background.png" ) );
MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "DS_Store" ), new File( dmgDirectory,
"dmg/.DS_Store" ) );
MojoHelperUtils.copyFiles( new File( pkgDirectory, "Apache Directory Server Installer.pkg" ), new File(
dmgDirectory, "dmg/Apache Directory Server Installer.pkg" ) );
}
catch ( IOException e )
{
log.error( e.getMessage() );
throw new MojoFailureException( "Failed to copy DMG resources files." );
}
// Setting execution permission to the postflight script
// (unfortunately, the execution permission has been lost after the
// copy of the PKG to the dmg folder)
MojoHelperUtils.exec( new String[]
{
"chmod",
"755",
new File( dmgDirectory, "dmg/Apache Directory Server Installer.pkg/Contents/Resources/postflight" )
.toString() }, dmgDirectory, false );
// Generating the DMG
log.info( "Generating Mac OS X DMG Installer" );
String finalName = target.getFinalName();
if ( !finalName.endsWith( ".dmg" ) )
{
finalName = finalName + ".dmg";
}
try
{
Execute createDmgTask = new Execute();
createDmgTask.setCommandline( new String[]
{ hdiutilUtility.getAbsolutePath(), "makehybrid", "-hfs", "-hfs-volume-name",
"Apache Directory Server Installer", "-hfs-openfolder", "dmg/", "dmg/", "-o", "TMP.dmg" } );
createDmgTask.setSpawn( true );
createDmgTask.setWorkingDirectory( dmgDirectory );
createDmgTask.execute();
createDmgTask.setCommandline( new String[]
{ hdiutilUtility.getAbsolutePath(), "convert", "-format", "UDZO", "TMP.dmg", "-o", "../" + finalName } );
createDmgTask.execute();
}
catch ( IOException e )
{
log.error( e.getMessage() );