in installers-maven-plugin/src/main/java/org/apache/directory/server/installers/archive/ArchiveInstallerCommand.java [153:300]
public void execute() throws MojoExecutionException, MojoFailureException
{
// Verifying the target
if ( !verifyTarget() )
{
return;
}
// Getting the archive type
String archiveType = target.getArchiveType();
log.info( " Creating " + archiveType + " archive..." );
// Creating the target directory, where we will store the files which
// will be packaged to form the installer
if ( !getTargetDirectory().mkdirs() )
{
Exception e = new IOException( I18n.err( I18n.ERR_00004_COULD_NOT_CREATE_DIRECTORY, getTargetDirectory() ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
log.info( " Copying archive files" );
try
{
// Creating the installation and instance layouts.
createLayouts( false );
// Copy bat and sh scripts to bin
MojoHelperUtils.copyAsciiFile( mojo, filterProperties, APACHE_BAT_FILE, getClass().getResourceAsStream(
APACHE_BAT_FILE ), new File( getInstallationLayout().getBinDirectory(), APACHE_BAT_FILE ), false );
MojoHelperUtils.copyAsciiFile( mojo, filterProperties, APACHE_SH_FILE, getClass().getResourceAsStream(
APACHE_SH_FILE ), new File( getInstallationLayout().getBinDirectory(), APACHE_SH_FILE ), false );
MojoHelperUtils.copyAsciiFile( mojo, filterProperties, CPAPPEND_BAT_FILE, getClass().getResourceAsStream(
CPAPPEND_BAT_FILE ), new File( getInstallationLayout().getBinDirectory(),
CPAPPEND_BAT_FILE ), false );
// Removing unnecessary directories and files
FileUtils.deleteDirectory( getInstallationLayout().getConfDirectory() );
File wrapperConf = new File( getInstanceLayout().getConfDirectory(), WRAPPER_INSTANCE_CONF_FILE );
if ( !wrapperConf.delete() )
{
throw new IOException( I18n.err( I18n.ERR_11000_COULD_NOT_DELETE_FILE_OR_DIRECTORY, wrapperConf ) );
}
}
catch ( Exception e )
{
log.error( e.getMessage() );
throw new MojoFailureException( "Failed to copy archive files." );
}
// Generating the archive
log.info( " Generating archive" );
// Creating the final file
String finalName = target.getFinalName();
if ( !finalName.endsWith( archiveType ) )
{
finalName = finalName + archiveType;
}
File finalFile = new File( mojo.getOutputDirectory(), finalName );
// Preparing the Ant project
Project project = new Project();
project.setBaseDir( mojo.getOutputDirectory() );
// ZIP Archive
ArchiveType type = ArchiveType.getType( archiveType );
switch ( type )
{
case ZIP:
// ZIP Archive
Zip zipTask = new Zip();
zipTask.setProject( project );
zipTask.setDestFile( finalFile );
zipTask.setBasedir( getTargetDirectory() );
zipTask.setIncludes( getArchiveDirectory().getName() + ALL_FILES );
zipTask.execute();
break;
case TAR:
// TAR Archive
createTarFile( project, finalFile );
break;
case TAR_GZ:
// TAR.GZ Archive
File tarFile = new File( mojo.getOutputDirectory(), target.getId() + DOT_TAR );
// First create the tar file that will be gzipped
createTarFile( project, tarFile );
// And gzip it
GZip gzipTask = new GZip();
gzipTask.setProject( project );
gzipTask.setDestfile( finalFile );
gzipTask.setSrc( tarFile );
gzipTask.execute();
if ( !tarFile.delete() )
{
Exception e = new IOException( I18n.err( I18n.ERR_11000_COULD_NOT_DELETE_FILE_OR_DIRECTORY, tarFile ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
break;
case TAR_BZ2:
// TAR.BZ2 Archive
tarFile = new File( mojo.getOutputDirectory(), target.getId() + DOT_TAR );
// First create the tar file that will be zipped
createTarFile( project, finalFile );
// And bzip it
BZip2 bzip2Task = new BZip2();
bzip2Task.setProject( project );
bzip2Task.setDestfile( finalFile );
bzip2Task.setSrc( tarFile );
bzip2Task.execute();
if ( !tarFile.delete() )
{
Exception e = new IOException( I18n.err( I18n.ERR_11000_COULD_NOT_DELETE_FILE_OR_DIRECTORY, tarFile ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
break;
default:
// Unkown archive type
Exception e = new IOException(
"Cannot determinate the archive type. Only \"tar\", \"tar.gz\", \"tar.bz2\" and \"zip\" are accepted : "
+ archiveType );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
log.info( "=> Archive Installer (" + archiveType + ") archive generated at "
+ finalFile );
}