diff --git a/common/common/src/main/java/io/helidon/build/common/FileUtils.java b/common/common/src/main/java/io/helidon/build/common/FileUtils.java index 2bb00edaa..2d02b5a9a 100644 --- a/common/common/src/main/java/io/helidon/build/common/FileUtils.java +++ b/common/common/src/main/java/io/helidon/build/common/FileUtils.java @@ -150,6 +150,11 @@ public static Path ensureDirectory(Path path, FileAttribute... attrs) { return requireDirectory(path); } else { try { + if (Files.isSymbolicLink(path)) { + // The File.exists check will follow symbolic links. If it returns false because + // path is a broken link, then we want to catch that here. + throw new IOException("Broken link: " + path); + } return Files.createDirectories(path, attrs); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/DownloadTask.java b/maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/DownloadTask.java index 07f7acce8..92dffa5d0 100644 --- a/maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/DownloadTask.java +++ b/maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/DownloadTask.java @@ -78,32 +78,33 @@ protected void doExecute(StagingContext ctx, Path dir, Map vars) static void download(StagingContext ctx, URL url, Path file) throws IOException { - try (BufferedInputStream bis = new BufferedInputStream(open(url, ctx))) { - try (OutputStream fos = Files.newOutputStream(file)) { - int n; - long startTime = System.currentTimeMillis(); - long progressTime = startTime; - long currentTime = startTime; - long totalSize = 0; - long totalTime = 1; - byte[] buffer = new byte[1024]; - while ((n = bis.read(buffer, 0, buffer.length)) >= 0) { - fos.write(buffer, 0, n); - totalSize += n; - currentTime = System.currentTimeMillis(); - if (currentTime - progressTime >= 1000) { - totalTime = (currentTime - startTime) / 1000; - progressTime = currentTime; - ctx.logInfo("Downloading %s to %s (%s at %s/s)", - url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime)); - } - } + try (BufferedInputStream bis = new BufferedInputStream(open(url, ctx)); + OutputStream fos = Files.newOutputStream(file)) { + int n; + long startTime = System.currentTimeMillis(); + long progressTime = startTime; + long currentTime = startTime; + long totalSize = 0; + long totalTime = 1; + byte[] buffer = new byte[1024]; + while ((n = bis.read(buffer, 0, buffer.length)) >= 0) { + fos.write(buffer, 0, n); + totalSize += n; + currentTime = System.currentTimeMillis(); if (currentTime - progressTime >= 1000) { totalTime = (currentTime - startTime) / 1000; + progressTime = currentTime; + ctx.logInfo("Downloading %s to %s (%s at %s/s)", + url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime)); } - ctx.logInfo("Downloaded %s to %s (%s at %s/s)", - url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime)); } + if (currentTime - progressTime >= 1000) { + totalTime = (currentTime - startTime) / 1000; + } + ctx.logInfo("Downloaded %s to %s (%s at %s/s)", + url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime)); + } catch (IOException ex) { + throw new IOException("Failed to download " + url + " to " + file, ex); } }