+ "' encoding to copy filtered resources." );
}
for ( Iterator i = mavenResourcesExecution.getResources().iterator(); i.hasNext(); )
{
Resource resource = (Resource) i.next();
if ( getLogger().isDebugEnabled() )
{
String ls = System.getProperty( "line.separator" );
StringBuffer debugMessage = new StringBuffer( "resource with targetPath " + resource.getTargetPath() )
.append( ls );
debugMessage.append( "directory " + resource.getDirectory() ).append( ls );
debugMessage.append(
"excludes "
+ ( resource.getExcludes() == null ? " empty " : resource.getExcludes()
.toString() ) ).append( ls );
debugMessage.append( "includes "
+ ( resource.getIncludes() == null ? " empty " : resource.getIncludes().toString() ) );
getLogger().debug( debugMessage.toString() );
}
String targetPath = resource.getTargetPath();
File resourceDirectory = new File( resource.getDirectory() );
if ( !resourceDirectory.isAbsolute() )
{
resourceDirectory = new File( mavenResourcesExecution.getResourcesBaseDirectory(), resourceDirectory
.getPath() );
}
if ( !resourceDirectory.exists() )
{
getLogger().info( "skip non existing resourceDirectory " + resourceDirectory.getPath() );
continue;
}
// this part is required in case the user specified "../something" as destination
// see MNG-1345
File outputDirectory = mavenResourcesExecution.getOutputDirectory();
boolean outputExists = outputDirectory.exists();
if ( !outputExists && !outputDirectory.mkdirs() )
{
throw new MavenFilteringException( "Cannot create resource output directory: " + outputDirectory );
}
boolean ignoreDelta =
!outputExists || buildContext.hasDelta( mavenResourcesExecution.getFileFilters() )
|| buildContext.hasDelta( getRelativeOutputDirectory( mavenResourcesExecution ) );
getLogger().debug( "ignoreDelta " + ignoreDelta );
Scanner scanner = buildContext.newScanner( resourceDirectory, ignoreDelta );
setupScanner( resource, scanner );
scanner.scan();
if ( mavenResourcesExecution.isIncludeEmptyDirs() )
{
try
{
File targetDirectory = targetPath == null ? outputDirectory
: new File( outputDirectory, targetPath );
copyDirectoryLayout( resourceDirectory, targetDirectory, scanner );
}
catch ( IOException e )
{
throw new MavenFilteringException( "Cannot copy directory structure from "
+ resourceDirectory.getPath() + " to " + outputDirectory.getPath() );
}
}
List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
getLogger().info(
"Copying " + includedFiles.size() + " resource" + ( includedFiles.size() > 1 ? "s" : "" )
+ ( targetPath == null ? "" : " to " + targetPath ) );
for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
{
String name = (String) j.next();
File source = new File( resourceDirectory, name );
//File destinationFile = new File( outputDirectory, destination );
File destinationFile = getDestinationFile( outputDirectory, targetPath, name );
boolean filteredExt = filteredFileExtension( source.getName(), mavenResourcesExecution
.getNonFilteredFileExtensions() );
mavenFileFilter.copyFile( source, destinationFile, resource.isFiltering() && filteredExt,
mavenResourcesExecution.getFilterWrappers(), mavenResourcesExecution
.getEncoding(), mavenResourcesExecution.isOverwrite() );
}
// deal with deleted source files