diff --git a/CHANGELOG.md b/CHANGELOG.md index b24916d2b..b7131bc2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Last public release: [![Maven Central](https://maven-badges.herokuapp.com/maven- ## Changelog +### 1.7.6 + +* Fix #670: Plugin will no longer fail to install node.exe if node.exe already exists + ### 1.5 * Revert support for the maven.frontend.failOnError flag ([#572](https://github.com/eirslett/frontend-maven-plugin/pull/572)), due to diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java index 302f691a2..474fce183 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java @@ -3,6 +3,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.Arrays; import org.apache.commons.io.FileUtils; @@ -151,7 +153,12 @@ private void installNodeDefault() throws InstallationException { File destination = new File(destinationDirectory, "node"); this.logger.info("Copying node binary from {} to {}", nodeBinary, destination); - if (!nodeBinary.renameTo(destination)) { + if (destination.exists() && !destination.delete()) { + throw new InstallationException("Could not install Node: Was not allowed to delete " + destination); + } + try { + Files.move(nodeBinary.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { throw new InstallationException("Could not install Node: Was not allowed to rename " + nodeBinary + " to " + destination); } @@ -219,7 +226,9 @@ private void installNodeWithNpmForWindows() throws InstallationException { File destination = new File(destinationDirectory, "node.exe"); this.logger.info("Copying node binary from {} to {}", nodeBinary, destination); - if (!nodeBinary.renameTo(destination)) { + try { + Files.move(nodeBinary.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { throw new InstallationException("Could not install Node: Was not allowed to rename " + nodeBinary + " to " + destination); }