File dest = config.getDestination();
try {
if ( source == null || !source.exists() ) {
throw new UtilityException( "Source archive doesn't exist." );
}
if ( source.isDirectory() ) {
throw new UtilityException( "Source archive is a directory." );
}
if ( performInPlaceAssembly( config ) ) {
if ( LOG.isDebugEnabled() ) {
LOG.debug( "Performing in-place assembly of " + config.getSource().getAbsolutePath() );
}
dest = File.createTempFile( source.getName(), ".tmp" );
config.setDestination( dest );
assembleInternal( config );
// renameTo() is impl-specific
boolean success = dest.renameTo( source );
if (! success ) {
// do it the old-fashioned way
FileUtils.copyFile( dest, source );
}
} else {
if ( LOG.isDebugEnabled() ) {
LOG.debug( "Performing assembly of " + config.getSource().getAbsolutePath() + " to " +
config.getDestination().getAbsolutePath() );
}
File destFile = dest;
// if the destination is a directory, ensure that parent
// directories have been created and set the destination
// file to the file in the direcotory.
if ( dest.isDirectory() ) {
dest.mkdirs();
destFile = new File( dest, source.getName() );
}
config.setDestination( destFile );
assembleInternal( config );
}
} catch ( IOException e ) {
LOG.error( "Assembly failed: "+ e.getMessage() );
throw new UtilityException( e.getMessage(), e );
}
}