in src/main/java/org/apache/maven/shared/utils/io/FileUtils.java [1528:1591]
private static void copyDirectoryStructure(
@Nonnull File sourceDirectory,
@Nonnull File destinationDirectory,
File rootDestinationDirectory,
boolean onlyModifiedFiles)
throws IOException {
//noinspection ConstantConditions
if (sourceDirectory == null) {
throw new IOException("source directory can't be null.");
}
//noinspection ConstantConditions
if (destinationDirectory == null) {
throw new IOException("destination directory can't be null.");
}
if (sourceDirectory.equals(destinationDirectory)) {
throw new IOException("source and destination are the same directory.");
}
if (!sourceDirectory.exists()) {
throw new IOException("Source directory doesn't exist (" + sourceDirectory.getAbsolutePath() + ").");
}
File[] files = sourceDirectory.listFiles();
if (files == null) {
return;
}
String sourcePath = sourceDirectory.getAbsolutePath();
for (File file : files) {
if (file.equals(rootDestinationDirectory)) {
// We don't copy the destination directory in itself
continue;
}
String dest = file.getAbsolutePath();
dest = dest.substring(sourcePath.length() + 1);
File destination = new File(destinationDirectory, dest);
if (file.isFile()) {
destination = destination.getParentFile();
if (onlyModifiedFiles) {
copyFileToDirectoryIfModified(file, destination);
} else {
copyFileToDirectory(file, destination);
}
} else if (file.isDirectory()) {
if (!destination.exists() && !destination.mkdirs()) {
throw new IOException(
"Could not create destination directory '" + destination.getAbsolutePath() + "'.");
}
copyDirectoryStructure(file, destination, rootDestinationDirectory, onlyModifiedFiles);
} else {
throw new IOException("Unknown file type: " + file.getAbsolutePath());
}
}
}