Skip to content

Commit

Permalink
fix(core): Check if path exists before walking it. Fixes #1108
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 15, 2022
1 parent a1a9ee9 commit efe9a90
Showing 1 changed file with 10 additions and 2 deletions.
Expand Up @@ -87,6 +87,10 @@ public static Map<String, TemplateResource> resolveTemplates(String distribution
}
Path actualTemplateDirectory = directory;

if (!Files.exists(actualTemplateDirectory)) {
return templates;
}

try {
Files.walkFileTree(actualTemplateDirectory, new SimpleFileVisitor<Path>() {
@Override
Expand All @@ -99,7 +103,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
} catch (IOException e) {
String distributionTypeName = distributionType.toLowerCase(Locale.ENGLISH).replace('_', '-');
throw new JReleaserException(RB.$("ERROR_unexpected_reading_templates_distribution",
distributionTypeName, toolName, actualTemplateDirectory.toAbsolutePath()));
distributionTypeName, toolName, actualTemplateDirectory.toAbsolutePath()), e);
}

return templates;
Expand All @@ -108,6 +112,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
public static Map<String, TemplateResource> resolveTemplates(Path templateDirectory) {
Map<String, TemplateResource> templates = new LinkedHashMap<>();

if (!Files.exists(templateDirectory)) {
return templates;
}

try {
Files.walkFileTree(templateDirectory, new SimpleFileVisitor<Path>() {
@Override
Expand All @@ -118,7 +126,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
}
});
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_unexpected_reading_templates_from", templateDirectory.toAbsolutePath()));
throw new JReleaserException(RB.$("ERROR_unexpected_reading_templates_from", templateDirectory.toAbsolutePath()), e);
}

return templates;
Expand Down

0 comments on commit efe9a90

Please sign in to comment.