diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeVersionDetector.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeVersionDetector.java index ef88ad21b..e6d1796d1 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeVersionDetector.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeVersionDetector.java @@ -88,9 +88,7 @@ public static String recursivelyFindVersion(File directory) throws Exception { } private static String readNvmrcFile(File nvmrcFile, Path nvmrcFilePath, Logger logger) throws Exception { - if (!nvmrcFile.canRead()) { - throw new Exception("Tried to read the node version from the file, but giving up because it's possible to read" + nvmrcFile.getPath()); - } + assertNodeVersionFileIsReadable(nvmrcFile); List lines = Files.readAllLines(nvmrcFilePath); Optional version = readNvmrcFileLines(lines); @@ -134,9 +132,7 @@ static Optional readNvmrcFileLines(List lines) { } private static String readToolVersionsFile(File toolVersionsFile, Path toolVersionsFilePath, Logger logger) throws Exception { - if (!toolVersionsFile.canRead()) { - throw new Exception("Tried to read the node version from the file, but giving up because it's possible to read" + toolVersionsFile.getPath()); - } + assertNodeVersionFileIsReadable(toolVersionsFile); List lines = Files.readAllLines(toolVersionsFilePath); for (String line: lines) { @@ -157,4 +153,10 @@ private static String readToolVersionsFile(File toolVersionsFile, Path toolVersi } return null; } + + private static void assertNodeVersionFileIsReadable(File file) throws Exception { + if (!file.canRead()) { + throw new Exception("Tried to read the node version from the file, but giving up because it's not possible to read" + file.getPath()); + } + } }