Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE: Chore: standarize Protobuf import paths #723

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -416,7 +417,7 @@ private Map<String, ProtoFile> 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)
Expand All @@ -426,6 +427,27 @@ private Map<String, ProtoFile> loadFilesWithLocations() {
}
return filesByLocations;
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we keep this until the issue is resolved on wire side? Or is this a different issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what issue you are referring to

I noticed this problem locally when I ran these tests manually

* Replaces backslashes in the given file path with forward slashes if the operating system is Windows.
*
* <p>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.</p>
*
* <p>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</p>
*
* @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;
}
}

}
Loading