// Locate the destination folder, and make sure it exists
final FileObject destFolder = resolveFile(destDirUrl);
destFolder.createFolder();
// Locate the source files, and make sure they exist
FileName srcDirName = null;
if (srcDirUrl != null)
{
srcDirName = resolveFile(srcDirUrl).getName();
}
final ArrayList<FileObject> srcs = new ArrayList<FileObject>();
for (int i = 0; i < srcFiles.size(); i++)
{
// Locate the source file, and make sure it exists
final SourceInfo src = srcFiles.get(i);
final FileObject srcFile = resolveFile(src.file);
if (!srcFile.exists())
{
final String message =
Messages.getString("vfs.tasks/sync.src-file-no-exist.warn", srcFile);
logOrDie(message, Project.MSG_WARN);
}
else
{
srcs.add(srcFile);
}
}
// Scan the source files
final Set<FileObject> destFiles = new HashSet<FileObject>();
for (int i = 0; i < srcs.size(); i++)
{
final FileObject rootFile = srcs.get(i);
final FileName rootName = rootFile.getName();
if (rootFile.getType() == FileType.FILE)
{
// Build the destination file name
String relName = null;
if (srcDirName == null || !srcDirIsBase)
{
relName = rootName.getBaseName();
}
else
{
relName = srcDirName.getRelativeName(rootName);
}
final FileObject destFile = destFolder.resolveFile(relName, NameScope.DESCENDENT);
// Do the copy
handleFile(destFiles, rootFile, destFile);
}
else
{
// Find matching files
// If srcDirIsBase is true, select also the sub-directories
final FileObject[] files = rootFile.findFiles(srcDirIsBase
? Selectors.SELECT_ALL : Selectors.SELECT_FILES);
for (int j = 0; j < files.length; j++)
{
final FileObject srcFile = files[j];
// Build the destination file name
String relName = null;
if (srcDirName == null || !srcDirIsBase)
{
relName = rootName.getRelativeName(srcFile.getName());
}
else
{
relName = srcDirName.getRelativeName(srcFile.getName());
}