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 11:55:20 UTC

[logging-log4j-tools] branch windows-fixes updated: Fix FreeMarker integration on Windows

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 18d9a9d  Fix FreeMarker integration on Windows
18d9a9d is described below

commit 18d9a9d3950e42b6ca81f54b493a3f91ed57a079
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Mon Jan 30 12:56:40 2023 +0100

    Fix FreeMarker integration on Windows
---
 CHANGELOG.adoc                                                      | 2 ++
 .../apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java    | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 1026fcf..41693ae 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -17,6 +17,8 @@ limitations under the License.
 
 == Unreleased
 
+* Fixed Windows compatibility (for https://github.com/apache/logging-log4j-tools/issues/19[#19] by Volkan Yazıcı)
+
 * Fixed unreleased directory order in `ChangelogExporter` (for https://github.com/apache/logging-log4j-tools/issues/17[#17] by Volkan Yazıcı)
 
 * Removed `security` as a change type from `log4j-changelog` (for https://github.com/apache/logging-log4j-tools/issues/14[#14] by Ralph Goers, Volkan Yazıcı)
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 9deafcd..aca4cc9 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
@@ -59,8 +59,12 @@ final class FreeMarkerUtils {
 
     @SuppressFBWarnings("TEMPLATE_INJECTION_FREEMARKER")
     static void render(final Path templateFile, final Object templateData, final Path outputFile) {
+        // Since we are using `FileTemplateLoader`, template names refer to actual file paths.
+        // On Windows, this causes failures; FreeMarker doesn't allow backslashes in the template name.
+        // As a workaround, we are replacing backslashes with slashes.
+        final String templateName = templateFile.toAbsolutePath().toString().replace('\\', '/');
         try {
-            final Template template = CONFIGURATION.getTemplate(templateFile.toAbsolutePath().toString());
+            final Template template = CONFIGURATION.getTemplate(templateName);
             final Path outputFileParent = outputFile.getParent();
             if (outputFileParent != null) {
                 Files.createDirectories(outputFileParent);