1818 */
1919package org .apache .maven .impl .model .rootlocator ;
2020
21+ import java .io .IOException ;
22+ import java .nio .file .Files ;
2123import java .nio .file .Path ;
2224import java .nio .file .Paths ;
2325import java .util .List ;
24- import java .util .Objects ;
2526import java .util .Optional ;
2627import java .util .ServiceLoader ;
2728
@@ -47,7 +48,7 @@ public DefaultRootLocator() {
4748 }
4849
4950 @ Override
50- public Path findRoot (Path basedir ) {
51+ public Path findRoot (@ Nonnull Path basedir ) {
5152 requireNonNull (basedir , getNoRootMessage ());
5253 Path rootDirectory = basedir ;
5354 while (rootDirectory != null && !isRootDirectory (rootDirectory )) {
@@ -64,8 +65,14 @@ public Path findMandatoryRoot(@Nonnull Path basedir) {
6465 rootDirectory = rdf .orElseThrow (() -> new IllegalStateException (getNoRootMessage ()));
6566 logger .warn (getNoRootMessage ());
6667 } else {
67- if (rdf .isPresent () && !Objects .equals (rootDirectory , rdf .get ())) {
68- logger .warn ("Project root directory and multiModuleProjectDirectory are not aligned" );
68+ if (rdf .isPresent ()) {
69+ try {
70+ if (!Files .isSameFile (rootDirectory , rdf .orElseThrow ())) {
71+ logger .warn ("Project root directory and multiModuleProjectDirectory are not aligned" );
72+ }
73+ } catch (IOException e ) {
74+ throw new IllegalStateException ("findMandatoryRoot failed" , e );
75+ }
6976 }
7077 }
7178 return rootDirectory ;
@@ -84,8 +91,16 @@ protected boolean isRootDirectory(Path dir) {
8491 protected Optional <Path > getRootDirectoryFallback () {
8592 String mmpd = System .getProperty ("maven.multiModuleProjectDirectory" );
8693 if (mmpd != null ) {
87- return Optional .of (Paths .get (mmpd ));
94+ return Optional .of (getCanonicalPath ( Paths .get (mmpd ) ));
8895 }
8996 return Optional .empty ();
9097 }
98+
99+ protected Path getCanonicalPath (Path path ) {
100+ try {
101+ return path .toRealPath ();
102+ } catch (IOException e ) {
103+ return getCanonicalPath (path .getParent ()).resolve (path .getFileName ());
104+ }
105+ }
91106}
0 commit comments