in src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java [828:861]
private void replaceFile(File oldFile, File newFile) throws MojoExecutionException {
getLog().debug("Replacing " + oldFile + " with " + newFile);
File origFile = new File(outputDirectory, "original-" + oldFile.getName());
if (oldFile.exists() && !oldFile.renameTo(origFile)) {
// try a gc to see if an unclosed stream needs garbage collecting
System.gc();
System.gc();
if (!oldFile.renameTo(origFile)) {
// Still didn't work. We'll do a copy
try {
copyFiles(oldFile, origFile);
} catch (IOException ex) {
// kind of ignorable here. We're just trying to save the original
getLog().warn(ex);
}
}
}
if (!newFile.renameTo(oldFile)) {
// try a gc to see if an unclosed stream needs garbage collecting
System.gc();
System.gc();
if (!newFile.renameTo(oldFile)) {
// Still didn't work. We'll do a copy
try {
copyFiles(newFile, oldFile);
} catch (IOException ex) {
throw new MojoExecutionException("Could not replace original artifact with shaded artifact!", ex);
}
}
}
}