This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 6be7a126d5 [MNG-8720] Fix for symlinked project directory (#2289)
6be7a126d5 is described below
commit 6be7a126d5778e781102445658da0b54b97df0e2
Author: Tamas Cservenak <[email protected]>
AuthorDate: Wed May 7 11:04:26 2025 +0200
[MNG-8720] Fix for symlinked project directory (#2289)
Applied proposed fix and a bit more. Checked with provided reproducer at
https://github.com/hho/MNG-8720
Thanks!
---
https://issues.apache.org/jira/browse/MNG-8720
---
.../impl/model/rootlocator/DefaultRootLocator.java | 25 +++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
index 5e9859fadc..712d742998 100644
---
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
+++
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
@@ -18,10 +18,11 @@
*/
package org.apache.maven.impl.model.rootlocator;
+import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
-import java.util.Objects;
import java.util.Optional;
import java.util.ServiceLoader;
@@ -47,7 +48,7 @@ public DefaultRootLocator() {
}
@Override
- public Path findRoot(Path basedir) {
+ public Path findRoot(@Nonnull Path basedir) {
requireNonNull(basedir, getNoRootMessage());
Path rootDirectory = basedir;
while (rootDirectory != null && !isRootDirectory(rootDirectory)) {
@@ -64,8 +65,14 @@ public Path findMandatoryRoot(@Nonnull Path basedir) {
rootDirectory = rdf.orElseThrow(() -> new
IllegalStateException(getNoRootMessage()));
logger.warn(getNoRootMessage());
} else {
- if (rdf.isPresent() && !Objects.equals(rootDirectory, rdf.get())) {
- logger.warn("Project root directory and
multiModuleProjectDirectory are not aligned");
+ if (rdf.isPresent()) {
+ try {
+ if (!Files.isSameFile(rootDirectory, rdf.orElseThrow())) {
+ logger.warn("Project root directory and
multiModuleProjectDirectory are not aligned");
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("findMandatoryRoot
failed", e);
+ }
}
}
return rootDirectory;
@@ -84,8 +91,16 @@ protected boolean isRootDirectory(Path dir) {
protected Optional<Path> getRootDirectoryFallback() {
String mmpd = System.getProperty("maven.multiModuleProjectDirectory");
if (mmpd != null) {
- return Optional.of(Paths.get(mmpd));
+ return Optional.of(getCanonicalPath(Paths.get(mmpd)));
}
return Optional.empty();
}
+
+ protected Path getCanonicalPath(Path path) {
+ try {
+ return path.toRealPath();
+ } catch (IOException e) {
+ return
getCanonicalPath(path.getParent()).resolve(path.getFileName());
+ }
+ }
}