add fallback resource copying via steams if NIO-based approach fails (IDEA-201797)

This commit is contained in:
Eugene Zhuravlev
2018-11-07 13:12:53 +01:00
parent 9bdef9f0de
commit b339420b03
@@ -124,13 +124,23 @@ public class ResourcesBuilder extends TargetBuilder<ResourceRootDescriptor, Reso
final Path from = file.toPath();
final Path to = targetFile.toPath();
try {
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
}
catch (NoSuchFileException e) {
final File parent = targetFile.getParentFile();
if (parent != null && parent.mkdirs()) {
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); // repeat on successful target dir creation
try {
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
}
catch (NoSuchFileException e) {
final File parent = targetFile.getParentFile();
if (parent != null && parent.mkdirs()) {
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); // repeat on successful target dir creation
}
else {
throw e;
}
}
}
catch (IOException e) {
// fallback: trying 'classic' copying via streams
LOG.info("Error copying resource "+ file.getPath() + " to " + targetFile.getPath() + " with NIO API", e);
FileUtil.copyContent(file, targetFile);
}
outputConsumer.registerOutputFile(targetFile, Collections.singletonList(file.getPath()));
}