{
outputDirectory = "";
}
else if ( "..".equals( outputDirectory ) )
{
throw new ArchiveCreationException( "Cannot add source directory: " + directory + " to archive-path: "
+ outputDirectory + ". All paths must be within the archive root directory." );
}
final int oldDirMode = archiver.getOverrideDirectoryMode();
final int oldFileMode = archiver.getOverrideFileMode();
boolean fileModeSet = false;
boolean dirModeSet = false;
try
{
if ( directoryMode != -1 )
{
archiver.setDirectoryMode( directoryMode );
dirModeSet = true;
}
if ( fileMode != -1 )
{
archiver.setFileMode( fileMode );
fileModeSet = true;
}
if ( directory.exists() )
{
List<String> directoryExcludes;
if ( excludes != null && !excludes.isEmpty() )
{
directoryExcludes = new ArrayList<String>( excludes );
}
else
{
directoryExcludes = new ArrayList<String>();
}
try
{
String[] includesArray = null;
if ( includes != null && !includes.isEmpty() )
{
includesArray = new String[includes.size()];
int i = 0;
for ( String include : includes )
{
includesArray[i++] = normalize( include );
}
}
// this one is guaranteed to be non-null by code above.
final String[] excludesArray = new String[directoryExcludes.size()];
int i = 0;
for ( String directoryExclude : directoryExcludes )
{
excludesArray[i++] = normalize( directoryExclude );
}
final DefaultFileSet fs = new DefaultFileSet();
fs.setUsingDefaultExcludes( useDefaultExcludes );
fs.setPrefix( outputDirectory );
fs.setDirectory( directory );
fs.setIncludes( includesArray );
fs.setExcludes( excludesArray );
if (transformer != null){
fs.setStreamTransformer( transformer );
}
archiver.addFileSet( fs );
}
catch ( final ArchiverException e )
{
throw new ArchiveCreationException( "Error adding directory to archive: " + e.getMessage(), e );
}
}
}
finally
{