gnodet-bot commented on code in PR #13538:
URL: https://github.com/apache/maven/pull/13538#discussion_r4280561996
##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java:
##########
@@ -216,10 +219,40 @@ public String getLocation() {
return source.getLocation();
}
+ /**
+ * Returns the POM which the relative path designates, for instance
the parent POM of the one of this source.
+ * The path is resolved against the directory which contains the file
of this source, like a
+ * {@code FileModelSource} does, and not against the file itself,
which {@link Source#resolve(String)} would do.
+ *
+ * @param relPath the path of the related POM, or of its directory,
relative to the directory of this source
+ * @return the related source, or {@code null} if this source is not
backed by a file, or if there is no
+ * readable POM at that path
+ */
@Override
public ModelSource2 getRelatedSource(String relPath) {
- Source rel = source.resolve(relPath);
- return rel != null ? new SourceWrapper(rel) : null;
+ Path path = source.getPath();
+ if (path == null || path.getParent() == null) {
+ // there is no directory to resolve a relative path against
+ return null;
+ }
+
+ Path related;
+ try {
+ related = path.getParent()
+ .resolve(relPath.replace('\\',
File.separatorChar).replace('/', File.separatorChar));
Review Comment:
💡 **Readability nit (non-blocking):** The double-replace
`relPath.replace('\\', File.separatorChar).replace('/', File.separatorChar)`
correctly normalises both Windows and Unix separators to the platform
separator. A brief inline comment — e.g. `// normalise both '\\' and '/' to the
platform separator` — would make the intent immediately obvious to future
readers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]