{
Map archiveEntries = getFiles();
if ( archiveEntries == null || archiveEntries.size() == 0 )
{
throw new ArchiverException( "You must set at least one file." );
}
File tarFile = getDestFile();
if ( tarFile == null )
{
throw new ArchiverException( "You must set the destination tar file." );
}
if ( tarFile.exists() && !tarFile.isFile() )
{
throw new ArchiverException( tarFile + " isn't a file." );
}
if ( tarFile.exists() && !tarFile.canWrite() )
{
throw new ArchiverException( tarFile + " is read-only." );
}
// Check if we don't add tar file in inself
if ( containsFile( tarFile, archiveEntries.values() ) )
{
throw new ArchiverException( "A tar file cannot include itself." );
}
getLogger().info( "Building tar : " + tarFile.getAbsolutePath() );
TarOutputStream tOut = null;
try
{
tOut = new TarOutputStream(
compression.compress( new BufferedOutputStream( new FileOutputStream( tarFile ) ) ) );
tOut.setDebug( true );
if ( longFileMode.isTruncateMode() )
{
tOut.setLongFileMode( TarOutputStream.LONGFILE_TRUNCATE );
}
else if ( longFileMode.isFailMode() || longFileMode.isOmitMode() )
{
tOut.setLongFileMode( TarOutputStream.LONGFILE_ERROR );
}
else
{
// warn or GNU
tOut.setLongFileMode( TarOutputStream.LONGFILE_GNU );
}
longWarningGiven = false;
for ( Iterator iter = archiveEntries.keySet().iterator(); iter.hasNext(); )
{
String fileName = (String) iter.next();
String name = StringUtils.replace( fileName, File.separatorChar, '/' );
ArchiveEntry entry = (ArchiveEntry) archiveEntries.get( fileName );
tarFile( entry, tOut, name );
}
}
catch ( IOException ioe )
{
String message = "Problem creating TAR : " + ioe.getMessage();
throw new ArchiverException( message, ioe );
}
finally
{
if ( tOut != null )
{