18
18
*/
19
19
package org .apache .maven .impl .model .rootlocator ;
20
20
21
+ import java .io .IOException ;
22
+ import java .nio .file .Files ;
21
23
import java .nio .file .Path ;
22
24
import java .nio .file .Paths ;
23
25
import java .util .List ;
24
- import java .util .Objects ;
25
26
import java .util .Optional ;
26
27
import java .util .ServiceLoader ;
27
28
@@ -47,7 +48,7 @@ public DefaultRootLocator() {
47
48
}
48
49
49
50
@ Override
50
- public Path findRoot (Path basedir ) {
51
+ public Path findRoot (@ Nonnull Path basedir ) {
51
52
requireNonNull (basedir , getNoRootMessage ());
52
53
Path rootDirectory = basedir ;
53
54
while (rootDirectory != null && !isRootDirectory (rootDirectory )) {
@@ -64,8 +65,14 @@ public Path findMandatoryRoot(@Nonnull Path basedir) {
64
65
rootDirectory = rdf .orElseThrow (() -> new IllegalStateException (getNoRootMessage ()));
65
66
logger .warn (getNoRootMessage ());
66
67
} 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
+ }
69
76
}
70
77
}
71
78
return rootDirectory ;
@@ -84,8 +91,16 @@ protected boolean isRootDirectory(Path dir) {
84
91
protected Optional <Path > getRootDirectoryFallback () {
85
92
String mmpd = System .getProperty ("maven.multiModuleProjectDirectory" );
86
93
if (mmpd != null ) {
87
- return Optional .of (Paths .get (mmpd ));
94
+ return Optional .of (getCanonicalPath ( Paths .get (mmpd ) ));
88
95
}
89
96
return Optional .empty ();
90
97
}
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
+ }
91
106
}
0 commit comments