This is an automated email from the ASF dual-hosted git repository.

mthmulders pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git


The following commit(s) were added to refs/heads/master by this push:
     new 2dc4f0c  [MNG-6985] Use correct maven.multiModuleProjectDirectory in 
Embedded mode
2dc4f0c is described below

commit 2dc4f0cd187f4f464e94f183117e9797f634e99a
Author: Maarten Mulders <[email protected]>
AuthorDate: Thu Sep 10 16:50:19 2020 +0200

    [MNG-6985] Use correct maven.multiModuleProjectDirectory in Embedded mode
---
 .../maven/it/AbstractMavenIntegrationTestCase.java | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

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 org.apache.maven.shared.utils.io.FileUtils;
 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 @@ public abstract class AbstractMavenIntegrationTestCase
 
         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 @@ public abstract class AbstractMavenIntegrationTestCase
         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
     {

Reply via email to