Skip to content

Commit 1dad467

Browse files
authored
4.x: improve exception messages in stager plugin (#1081)
* Detect files that are broken links for better ex message * Add additional exception info in DownloadTask.download
1 parent 5980e9a commit 1dad467

File tree

2 files changed

+28
-22
lines changed
  • common/common/src/main/java/io/helidon/build/common
  • maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager

2 files changed

+28
-22
lines changed

common/common/src/main/java/io/helidon/build/common/FileUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public static Path ensureDirectory(Path path, FileAttribute<?>... attrs) {
150150
return requireDirectory(path);
151151
} else {
152152
try {
153+
if (Files.isSymbolicLink(path)) {
154+
// The File.exists check will follow symbolic links. If it returns false because
155+
// path is a broken link, then we want to catch that here.
156+
throw new IOException("Broken link: " + path);
157+
}
153158
return Files.createDirectories(path, attrs);
154159
} catch (IOException e) {
155160
throw new UncheckedIOException(e);

maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/DownloadTask.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,33 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
7878
static void download(StagingContext ctx, URL url, Path file)
7979
throws IOException {
8080

81-
try (BufferedInputStream bis = new BufferedInputStream(open(url, ctx))) {
82-
try (OutputStream fos = Files.newOutputStream(file)) {
83-
int n;
84-
long startTime = System.currentTimeMillis();
85-
long progressTime = startTime;
86-
long currentTime = startTime;
87-
long totalSize = 0;
88-
long totalTime = 1;
89-
byte[] buffer = new byte[1024];
90-
while ((n = bis.read(buffer, 0, buffer.length)) >= 0) {
91-
fos.write(buffer, 0, n);
92-
totalSize += n;
93-
currentTime = System.currentTimeMillis();
94-
if (currentTime - progressTime >= 1000) {
95-
totalTime = (currentTime - startTime) / 1000;
96-
progressTime = currentTime;
97-
ctx.logInfo("Downloading %s to %s (%s at %s/s)",
98-
url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime));
99-
}
100-
}
81+
try (BufferedInputStream bis = new BufferedInputStream(open(url, ctx));
82+
OutputStream fos = Files.newOutputStream(file)) {
83+
int n;
84+
long startTime = System.currentTimeMillis();
85+
long progressTime = startTime;
86+
long currentTime = startTime;
87+
long totalSize = 0;
88+
long totalTime = 1;
89+
byte[] buffer = new byte[1024];
90+
while ((n = bis.read(buffer, 0, buffer.length)) >= 0) {
91+
fos.write(buffer, 0, n);
92+
totalSize += n;
93+
currentTime = System.currentTimeMillis();
10194
if (currentTime - progressTime >= 1000) {
10295
totalTime = (currentTime - startTime) / 1000;
96+
progressTime = currentTime;
97+
ctx.logInfo("Downloading %s to %s (%s at %s/s)",
98+
url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime));
10399
}
104-
ctx.logInfo("Downloaded %s to %s (%s at %s/s)",
105-
url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime));
106100
}
101+
if (currentTime - progressTime >= 1000) {
102+
totalTime = (currentTime - startTime) / 1000;
103+
}
104+
ctx.logInfo("Downloaded %s to %s (%s at %s/s)",
105+
url, file, measuredSize(totalSize), measuredSize(totalSize / totalTime));
106+
} catch (IOException ex) {
107+
throw new IOException("Failed to download " + url + " to " + file, ex);
107108
}
108109
}
109110

0 commit comments

Comments
 (0)