{
FileUtils.copyFile( artifact.getFile(), tempArtifactFile );
}
catch ( final IOException e )
{
throw new ArchiveCreationException( "Error moving artifact file: '" + artifact.getFile()
+ "' to temporary location: " + tempArtifactFile + ". Reason: " + e.getMessage(), e );
}
artifact.setFile( tempArtifactFile );
}
String destDirectory = outputDirectory;
destDirectory =
AssemblyFormatUtils.getOutputDirectory( destDirectory, configSource.getProject(), moduleProject, project,
configSource.getFinalName(), configSource );
if ( unpack )
{
String outputLocation = destDirectory;
if ( ( outputLocation.length() > 0 ) && !outputLocation.endsWith( "/" ) )
{
outputLocation += "/";
}
String[] includesArray = TypeConversionUtils.toStringArray( includes );
if ( includesArray == null )
{
includesArray = DEFAULT_INCLUDES_ARRAY;
}
final String[] excludesArray = TypeConversionUtils.toStringArray( excludes );
final int oldDirMode = archiver.getOverrideDirectoryMode();
final int oldFileMode = archiver.getOverrideFileMode();
logger.debug( "Unpacking artifact: " + artifact.getId() + " to assembly location: " + outputLocation + "." );
boolean fileModeSet = false;
boolean dirModeSet = false;
try
{
if ( fileMode != -1 )
{
archiver.setFileMode( fileMode );
fileModeSet = true;
}
if ( directoryMode != -1 )
{
archiver.setDirectoryMode( directoryMode );
dirModeSet = true;
}
final File artifactFile = artifact.getFile();
if ( artifactFile == null )
{
logger.warn( "Skipping artifact: " + artifact.getId()
+ "; it does not have an associated file or directory." );
}
else if ( artifactFile.isDirectory() )
{
logger.debug( "Adding artifact directory contents for: " + artifact + " to: " + outputLocation );
archiver.addDirectory( artifactFile, outputLocation, includesArray, excludesArray );
}
else
{
logger.debug( "Unpacking artifact contents for: " + artifact + " to: " + outputLocation );
logger.debug( "includes:\n" + StringUtils.join( includesArray, "\n" ) + "\n" );
logger.debug( "excludes:\n"
+ ( excludesArray == null ? "none" : StringUtils.join( excludesArray, "\n" ) )
+ "\n" );
archiver.addArchivedFileSet( artifactFile, outputLocation, includesArray, excludesArray );
}
}
catch ( final ArchiverException e )
{
throw new ArchiveCreationException( "Error adding file-set for '" + artifact.getId() + "' to archive: "
+ e.getMessage(), e );
}
finally
{
if ( dirModeSet )
{
archiver.setDirectoryMode( oldDirMode );
}
if ( fileModeSet )
{
archiver.setFileMode( oldFileMode );
}
}
}
else
{
final String fileNameMapping =
AssemblyFormatUtils.evaluateFileNameMapping( outputFileNameMapping, artifact,
configSource.getProject(), moduleProject, moduleArtifact,
project, configSource );
final String outputLocation = destDirectory + fileNameMapping;
try
{
final File artifactFile = artifact.getFile();
logger.debug( "Adding artifact: " + artifact.getId() + " with file: " + artifactFile
+ " to assembly location: " + outputLocation + "." );
if ( fileMode != -1 )
{
archiver.addFile( artifactFile, outputLocation, fileMode );
}
else
{
archiver.addFile( artifactFile, outputLocation );
}
}
catch ( final ArchiverException e )
{
throw new ArchiveCreationException( "Error adding file '" + artifact.getId() + "' to archive: "
+ e.getMessage(), e );
}
}
}