[MNG-6985] Use correct maven.multiModuleProjectDirectory in Embedded mode
diff --git a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
index 17d4d3d..abe02a3 100644
--- a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
+++ b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
@@ -29,8 +29,13 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -579,7 +584,8 @@
if ( matchesVersionRange( "(3.2.5,)" ) )
{
- verifier.getSystemProperties().put( "maven.multiModuleProjectDirectory", basedir );
+ String multiModuleProjectDirectory = findMultiModuleProjectDirectory( basedir );
+ verifier.getSystemProperties().put( "maven.multiModuleProjectDirectory", multiModuleProjectDirectory );
}
try
@@ -608,6 +614,36 @@
return verifier;
}
+ private boolean hasDotMvnSubfolder( Path path )
+ {
+ final Path probablySubfolder = path.resolve( ".mvn" );
+ return Files.exists( probablySubfolder ) && Files.isDirectory( probablySubfolder );
+ }
+
+ private String findMultiModuleProjectDirectory( String basedir )
+ {
+ Path path = Paths.get( basedir );
+ Path result = path;
+
+ Collection<Path> fileSystemRoots = new ArrayList<>();
+ for ( Path root : path.getFileSystem().getRootDirectories() )
+ {
+ fileSystemRoots.add( root );
+ }
+
+ while ( !fileSystemRoots.contains( path ) )
+ {
+ if ( hasDotMvnSubfolder( path ) )
+ {
+ result = path;
+ break;
+ }
+ path = path.getParent();
+ }
+
+ return result.toString();
+ }
+
public static void assertCanonicalFileEquals( String message, File expected, File actual )
throws IOException
{