diff --git a/CHANGELOG.md b/CHANGELOG.md index b7131bc2e..575bf7e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Last public release: [![Maven Central](https://maven-badges.herokuapp.com/maven- ### 1.7.6 * Fix #670: Plugin will no longer fail to install node.exe if node.exe already exists +* Fix #794: Plugin will self-repair if previous node/npm/yarn archive download was interrupted ### 1.5 diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java index 68ff346f3..d9c517e60 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java @@ -1,5 +1,6 @@ package com.github.eirslett.maven.plugins.frontend.lib; +import java.io.EOFException; import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -139,12 +140,28 @@ private void installNpm() throws InstallationException { this.logger.warn("Failed to delete existing NPM installation."); } - extractFile(archive, nodeModulesDirectory); + File packageDirectory = new File(nodeModulesDirectory, "package"); + try { + extractFile(archive, nodeModulesDirectory); + } catch (ArchiveExtractionException e) { + if (e.getCause() instanceof EOFException) { + // https://github.com/eirslett/frontend-maven-plugin/issues/794 + // The downloading was probably interrupted and archive file is incomplete: + // delete it to retry from scratch + this.logger.error("The archive file {} is corrupted and will be deleted. " + + "Please try the build again.", archive.getPath()); + archive.delete(); + if (packageDirectory.exists()) { + FileUtils.deleteDirectory(packageDirectory); + } + } + + throw e; + } // handles difference between old and new download root (nodejs.org/dist/npm and // registry.npmjs.org) // see https://github.com/eirslett/frontend-maven-plugin/issues/65#issuecomment-52024254 - File packageDirectory = new File(nodeModulesDirectory, "package"); if (packageDirectory.exists() && !npmDirectory.exists()) { if (!packageDirectory.renameTo(npmDirectory)) { this.logger.warn("Cannot rename NPM directory, making a copy."); 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 474fce183..0fa7fdf1d 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 @@ -1,5 +1,6 @@ package com.github.eirslett.maven.plugins.frontend.lib; +import java.io.EOFException; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -140,7 +141,21 @@ private void installNodeDefault() throws InstallationException { downloadFileIfMissing(downloadUrl, archive, this.userName, this.password); - extractFile(archive, tmpDirectory); + try { + extractFile(archive, tmpDirectory); + } catch (ArchiveExtractionException e) { + if (e.getCause() instanceof EOFException) { + // https://github.com/eirslett/frontend-maven-plugin/issues/794 + // The downloading was probably interrupted and archive file is incomplete: + // delete it to retry from scratch + this.logger.error("The archive file {} is corrupted and will be deleted. " + + "Please try the build again.", archive.getPath()); + archive.delete(); + FileUtils.deleteDirectory(tmpDirectory); + } + + throw e; + } // Search for the node binary File nodeBinary = diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java index 244e98b76..532439fb2 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java @@ -1,5 +1,6 @@ package com.github.eirslett.maven.plugins.frontend.lib; +import java.io.EOFException; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -122,7 +123,23 @@ private void installYarn() throws InstallationException { logger.warn("Failed to delete existing Yarn installation."); } - extractFile(archive, installDirectory); + try { + extractFile(archive, installDirectory); + } catch (ArchiveExtractionException e) { + if (e.getCause() instanceof EOFException) { + // https://github.com/eirslett/frontend-maven-plugin/issues/794 + // The downloading was probably interrupted and archive file is incomplete: + // delete it to retry from scratch + this.logger.error("The archive file {} is corrupted and will be deleted. " + + "Please try the build again.", archive.getPath()); + archive.delete(); + if (installDirectory.exists()) { + FileUtils.deleteDirectory(installDirectory); + } + } + + throw e; + } ensureCorrectYarnRootDirectory(installDirectory, yarnVersion);