From c62d11b803f1b3aca772ac4bab5d6c269f7e3cfb Mon Sep 17 00:00:00 2001
From: yeikel
Date: Mon, 23 Dec 2024 12:18:16 -0500
Subject: [PATCH 1/4] BE: standarize import paths
---
.../ui/serdes/builtin/ProtobufFileSerde.java | 21 ++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
index 723474cae..4d8194780 100644
--- a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
+++ b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
@@ -64,6 +64,7 @@
import javax.annotation.Nullable;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.SystemUtils;
import org.jetbrains.annotations.NotNull;
@Slf4j
@@ -416,7 +417,7 @@ private Map loadFilesWithLocations() {
files.filter(p -> !Files.isDirectory(p) && p.toString().endsWith(".proto"))
.forEach(path -> {
// relative path will be used as "import" statement
- String relativePath = baseLocation.relativize(path).toString();
+ String relativePath = removeBackSlashes(baseLocation.relativize(path).toString());
var protoFileElement = ProtoParser.Companion.parse(
Location.get(baseLocation.toString(), relativePath),
readFileAsString(path)
@@ -426,6 +427,24 @@ private Map loadFilesWithLocations() {
}
return filesByLocations;
}
+
+ /**
+ * Replaces backslashes in the given file path with forward slashes if the operating system is Windows.
+ *
+ * This method is designed to standardize file paths by converting Windows-style backslashes (`\`)
+ * to Linux/Unix-style forward slashes (`/`) when the application is running on a Windows OS.
+ * On other operating systems, the input path is returned unchanged.
+ * This is needed because imports in Protobuf use forward slashes (`/`) for the imports
+ *
+ * @param path the file path to standardize; must not be {@code null}.
+ * @return the standardized file path with forward slashes if running on Windows, or the original path otherwise.
+ */
+ private @NotNull String removeBackSlashes(@NotNull final String path) {
+ if (SystemUtils.IS_OS_WINDOWS) {
+ return path.replace("\\", "/");
+ }
+ return path;
+ }
}
}
From 330b7c7bc5eb47fe6342e9755ce7256e2dc6c2cc Mon Sep 17 00:00:00 2001
From: yeikel
Date: Mon, 23 Dec 2024 12:32:01 -0500
Subject: [PATCH 2/4] extend docs
---
.../main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
index 4d8194780..87f3567c3 100644
--- a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
+++ b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
@@ -435,6 +435,7 @@ private Map loadFilesWithLocations() {
* to Linux/Unix-style forward slashes (`/`) when the application is running on a Windows OS.
* On other operating systems, the input path is returned unchanged.
* This is needed because imports in Protobuf use forward slashes (`/`) for the imports
+ * which causes a conflict with Windows paths. Ie: `language/language.proto` is converted to `language\language.proto`
*
* @param path the file path to standardize; must not be {@code null}.
* @return the standardized file path with forward slashes if running on Windows, or the original path otherwise.
From b38da7c1ad6d5ffdcef86208e03960bfe5bcb124 Mon Sep 17 00:00:00 2001
From: yeikel
Date: Mon, 23 Dec 2024 12:32:45 -0500
Subject: [PATCH 3/4] reformat
---
.../java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
index 87f3567c3..9955438bb 100644
--- a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
+++ b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
@@ -434,8 +434,9 @@ private Map loadFilesWithLocations() {
* This method is designed to standardize file paths by converting Windows-style backslashes (`\`)
* to Linux/Unix-style forward slashes (`/`) when the application is running on a Windows OS.
* On other operating systems, the input path is returned unchanged.
- * This is needed because imports in Protobuf use forward slashes (`/`) for the imports
- * which causes a conflict with Windows paths. Ie: `language/language.proto` is converted to `language\language.proto`
+ *
+ * This is needed because imports in Protobuf use forward slashes (`/`) for the imports
+ * which causes a conflict with Windows paths. Ie: `language/language.proto` is converted to `language\language.proto`
*
* @param path the file path to standardize; must not be {@code null}.
* @return the standardized file path with forward slashes if running on Windows, or the original path otherwise.
From dc790f4b62cc9e962f97530eac343e66314f71ac Mon Sep 17 00:00:00 2001
From: yeikel
Date: Mon, 23 Dec 2024 12:34:12 -0500
Subject: [PATCH 4/4] reword
---
.../java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
index 9955438bb..2c0939c03 100644
--- a/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
+++ b/api/src/main/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerde.java
@@ -435,8 +435,9 @@ private Map loadFilesWithLocations() {
* to Linux/Unix-style forward slashes (`/`) when the application is running on a Windows OS.
* On other operating systems, the input path is returned unchanged.
*
- * This is needed because imports in Protobuf use forward slashes (`/`) for the imports
- * which causes a conflict with Windows paths. Ie: `language/language.proto` is converted to `language\language.proto`
+ * This is needed because imports in Protobuf use forward slashes (`/`)
+ * which causes a conflict with Windows paths. For example,`language/language.proto`
+ * would be converted to `language\language.proto` in Windows causing a resolution exception
*
* @param path the file path to standardize; must not be {@code null}.
* @return the standardized file path with forward slashes if running on Windows, or the original path otherwise.