Skip to content

Commit f31ed63

Browse files
Use FileUtils.ensureDirectory instead of Files.createDirectories in stager plugin (#1011)
1 parent 818c396 commit f31ed63

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
2222

2323
import io.helidon.build.common.Maps;
2424

25+
import static io.helidon.build.common.FileUtils.ensureDirectory;
26+
2527
/**
2628
* Copy an artifact to a given target location.
2729
*/
@@ -54,7 +56,7 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
5456
ctx.logInfo("Copying %s to %s", resolvedGav, resolveTarget);
5557
Path artifact = ctx.resolve(resolvedGav);
5658
Path targetFile = dir.resolve(resolveTarget);
57-
Files.createDirectories(targetFile.getParent());
59+
ensureDirectory(targetFile.getParent());
5860
Files.copy(artifact, targetFile);
5961
}
6062

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import io.helidon.build.common.NetworkConnection;
2929
import io.helidon.build.common.Strings;
3030

31+
import static io.helidon.build.common.FileUtils.ensureDirectory;
3132
import static io.helidon.build.common.FileUtils.measuredSize;
3233

3334
/**
@@ -66,7 +67,7 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
6667
private void download(StagingContext ctx, Path dir, Map<String, String> vars) throws IOException {
6768
String path = resolveVar(target(), vars);
6869
Path file = dir.resolve(path).normalize();
69-
Files.createDirectories(file.getParent());
70+
ensureDirectory(file.getParent());
7071
URL url = new URL(resolveVar(this.url, vars));
7172
try (BufferedInputStream bis = new BufferedInputStream(open(url, ctx))) {
7273
try (OutputStream fos = Files.newOutputStream(file)) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25+
import static io.helidon.build.common.FileUtils.ensureDirectory;
26+
2527
/**
2628
* Generate or copy a file to a given target location.
2729
*/
@@ -68,7 +70,7 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
6870
String resolvedSource = resolveVar(source, vars);
6971
String resolvedContent = resolveVar(content, vars);
7072
Path targetFile = dir.resolve(resolvedTarget).normalize();
71-
Files.createDirectories(targetFile.getParent());
73+
ensureDirectory(targetFile.getParent());
7274
if (resolvedSource != null && !resolvedSource.isEmpty()) {
7375
Path sourceFile = ctx.resolve(resolvedSource);
7476
if (!Files.exists(sourceFile)) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,14 +15,14 @@
1515
*/
1616
package io.helidon.build.maven.stager;
1717

18-
import java.io.IOException;
19-
import java.nio.file.Files;
2018
import java.nio.file.Path;
2119
import java.util.List;
2220
import java.util.Map;
2321
import java.util.concurrent.CompletableFuture;
2422
import java.util.concurrent.CompletionStage;
2523

24+
import static io.helidon.build.common.FileUtils.ensureDirectory;
25+
2626
/**
2727
* Generate a directory using a set of actions.
2828
*/
@@ -39,8 +39,8 @@ public CompletionStage<Void> execute(StagingContext ctx, Path dir, Map<String, S
3939
Path targetDir = dir.resolve(target());
4040
ctx.logInfo("Staging %s", targetDir);
4141
try {
42-
Files.createDirectories(targetDir);
43-
} catch (IOException ex) {
42+
ensureDirectory(targetDir);
43+
} catch (Throwable ex) {
4444
return CompletableFuture.failedFuture(ex);
4545
}
4646
return super.execute(ctx, targetDir, vars);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
2222

2323
import io.helidon.build.common.Strings;
2424

25+
import static io.helidon.build.common.FileUtils.ensureDirectory;
26+
2527
/**
2628
* Create a symlink.
2729
*/
@@ -54,7 +56,7 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
5456
Path link = dir.resolve(resolveVar(target(), vars));
5557
Path linkTarget = link.getParent().relativize(dir.resolve(resolveVar(source, vars)));
5658
ctx.logInfo("Creating symlink source: %s, target: %s", link, linkTarget);
57-
Files.createDirectories(link.getParent());
59+
ensureDirectory(link.getParent());
5860
Files.createSymbolicLink(link, linkTarget);
5961
}
6062
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
import com.github.mustachejava.DefaultMustacheFactory;
3030
import com.github.mustachejava.util.DecoratedCollection;
3131

32+
import static io.helidon.build.common.FileUtils.ensureDirectory;
3233
import static java.util.stream.Collectors.toMap;
3334

3435
/**
@@ -74,7 +75,7 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
7475
throw new IllegalStateException(sourceFile + " does not exist");
7576
}
7677
Path targetFile = dir.resolve(resolvedTarget).normalize();
77-
Files.createDirectories(targetFile.getParent());
78+
ensureDirectory(targetFile.getParent());
7879
try (Reader reader = Files.newBufferedReader(sourceFile);
7980
Writer writer = Files.newBufferedWriter(targetFile,
8081
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,11 @@
1616
package io.helidon.build.maven.stager;
1717

1818
import java.io.IOException;
19-
import java.nio.file.Files;
2019
import java.nio.file.Path;
2120
import java.util.Map;
2221

22+
import static io.helidon.build.common.FileUtils.ensureDirectory;
23+
2324
/**
2425
* Unpack an artifact to a given target location.
2526
*/
@@ -73,7 +74,7 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
7374
Path artifact = ctx.resolve(resolvedGav);
7475
Path targetDir = dir.resolve(resolvedTarget).normalize();
7576
ctx.logInfo("Unpacking %s to %s", artifact, targetDir);
76-
Files.createDirectories(targetDir);
77+
ensureDirectory(targetDir);
7778
ctx.unpack(artifact, targetDir, excludes, includes);
7879
}
7980
}

0 commit comments

Comments
 (0)