6464import javax .annotation .Nullable ;
6565import lombok .SneakyThrows ;
6666import lombok .extern .slf4j .Slf4j ;
67+ import org .apache .commons .lang3 .SystemUtils ;
6768import org .jetbrains .annotations .NotNull ;
6869
6970@ Slf4j
@@ -416,7 +417,7 @@ private Map<String, ProtoFile> loadFilesWithLocations() {
416417 files .filter (p -> !Files .isDirectory (p ) && p .toString ().endsWith (".proto" ))
417418 .forEach (path -> {
418419 // relative path will be used as "import" statement
419- String relativePath = baseLocation .relativize (path ).toString ();
420+ String relativePath = removeBackSlashes ( baseLocation .relativize (path ).toString () );
420421 var protoFileElement = ProtoParser .Companion .parse (
421422 Location .get (baseLocation .toString (), relativePath ),
422423 readFileAsString (path )
@@ -426,6 +427,24 @@ private Map<String, ProtoFile> loadFilesWithLocations() {
426427 }
427428 return filesByLocations ;
428429 }
430+
431+ /**
432+ * Replaces backslashes in the given file path with forward slashes if the operating system is Windows.
433+ *
434+ * <p>This method is designed to standardize file paths by converting Windows-style backslashes (`\`)
435+ * to Linux/Unix-style forward slashes (`/`) when the application is running on a Windows OS.
436+ * On other operating systems, the input path is returned unchanged.</p>
437+ * This is needed because imports in Protobuf use forward slashes (`/`) for the imports
438+ *
439+ * @param path the file path to standardize; must not be {@code null}.
440+ * @return the standardized file path with forward slashes if running on Windows, or the original path otherwise.
441+ */
442+ private @ NotNull String removeBackSlashes (@ NotNull final String path ) {
443+ if (SystemUtils .IS_OS_WINDOWS ) {
444+ return path .replace ("\\ " , "/" );
445+ }
446+ return path ;
447+ }
429448 }
430449
431450}
0 commit comments