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[]
{ mojo.getPackageMakerUtility().getAbsolutePath(), "--root", "root/", "--resources", "Resources/",
"--info", "Info.plist", "--title", "Apache Directory Server " + mojo.getProject().getVersion(),
"--version", mojo.getProject().getVersion(), "--scripts", "scripts", "--out",
"Apache Directory Server Installer.pkg" };
createPkgTask.setCommandline( cmd );
createPkgTask.setWorkingDirectory( targetDirectory );
try
{
createPkgTask.execute();
}
catch ( IOException e )
{
log.error( e.getMessage() );
throw new MojoFailureException( "Failed while trying to generate the PKG: " + e.getMessage() );
}
log.info( " Creating Mac OS X DMG..." );
// Creating the disc image directory
File dmgDirectory = new File( mojo.getOutputDirectory(), target.getId() + "-dmg" );
if ( !dmgDirectory.mkdirs() )
{
Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, dmgDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
log.info( " Copying DMG files" );
// Create dmg directory and its sub-directory
File dmgDmgBackgroundDirectory = new File( dmgDirectory, "dmg/.background" );
if ( !dmgDmgBackgroundDirectory.mkdirs() )
{
Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, dmgDmgBackgroundDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
// 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( targetDirectory, "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 preflight and postflight scripts
// (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/preflight" )
.toString() }, dmgDirectory, false );
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", "-quiet", "-hfs", "-hfs-volume-name",
"Apache Directory Server Installer", "-hfs-openfolder", "dmg/", "dmg/", "-o", "TMP.dmg" } );
createDmgTask.setWorkingDirectory( dmgDirectory );
createDmgTask.execute();
createDmgTask.setCommandline( new String[]
{
hdiutilUtility.getAbsolutePath(),
"convert",
"-quiet",
"-format",
"UDZO",
"TMP.dmg",
"-o",
"../" + finalName } );
createDmgTask.execute();
}
catch ( IOException e )
{
log.error( e.getMessage() );