// Most of this method was copied from org.codehaus.plexus.archiver.tar.TarArchiver
// and modified to store files in a directory, not a tar archive.
final ResourceIterator iter = getResources();
if ( !iter.hasNext() )
{
throw new ArchiverException( "You must set at least one file." );
}
final File destDirectory = getDestFile();
if ( destDirectory == null )
{
throw new ArchiverException( "You must set the destination directory." );
}
if ( destDirectory.exists() && !destDirectory.isDirectory() )
{
throw new ArchiverException( destDirectory + " is not a directory." );
}
if ( destDirectory.exists() && !destDirectory.canWrite() )
{
throw new ArchiverException( destDirectory + " is not writable." );
}
getLogger().info( "Copying files to " + destDirectory.getAbsolutePath() );
try
{
while ( iter.hasNext() )
{
final ArchiveEntry f = iter.next();
// Check if we don't add directory file in itself
if ( ResourceUtils.isSame( f.getResource(), destDirectory ) )
{
throw new ArchiverException( "The destination directory cannot include itself." );
}
String fileName = f.getName();
final String destDir = destDirectory.getCanonicalPath();
fileName = destDir + File.separator + fileName;
copyFile( f, fileName );
}
}
catch ( final IOException ioe )
{
final String message = "Problem copying files : " + ioe.getMessage();
throw new ArchiverException( message, ioe );
}
}