You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2023/01/30 20:06:59 UTC
[logging-log4j-tools] branch windows-fixes updated: Trying `File.listRoots()`
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch windows-fixes
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
The following commit(s) were added to refs/heads/windows-fixes by this push:
new 158322d Trying `File.listRoots()`
158322d is described below
commit 158322d40c350261cb03b17437ef4ec56c2b58ac
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Mon Jan 30 21:08:18 2023 +0100
Trying `File.listRoots()`
---
.../log4j/changelog/exporter/FreeMarkerUtils.java | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java
index 0426818..116421b 100644
--- a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java
+++ b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java
@@ -25,8 +25,6 @@ import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
-import javax.swing.filechooser.FileSystemView;
-
import org.apache.logging.log4j.changelog.util.CharsetUtils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -58,17 +56,19 @@ final class FreeMarkerUtils {
return configuration;
}
- @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
private static TemplateLoader createTemplateLoader() {
- if (File.separatorChar == '/') {
- return createFileTemplateLoader(new File("/"));
+ final File[] roots = File.listRoots();
+ if (roots.length == 0) {
+ throw new RuntimeException("could not find any filesystem roots");
+ } else if (roots.length == 1) {
+ return createFileTemplateLoader(roots[0]);
+ } else {
+ final TemplateLoader[] templateLoaders = Arrays
+ .stream(roots)
+ .map(FreeMarkerUtils::createFileTemplateLoader)
+ .toArray(TemplateLoader[]::new);
+ return new MultiTemplateLoader(templateLoaders);
}
- final File[] roots = FileSystemView.getFileSystemView().getRoots();
- final TemplateLoader[] templateLoaders = Arrays
- .stream(roots)
- .map(FreeMarkerUtils::createFileTemplateLoader)
- .toArray(TemplateLoader[]::new);
- return new MultiTemplateLoader(templateLoaders);
}
private static FileTemplateLoader createFileTemplateLoader(final File baseDir) {