gnodet commented on code in PR #1810:
URL: https://github.com/apache/maven/pull/1810#discussion_r1803404996


##########
maven-cli/src/main/java/org/apache/maven/cling/invoker/Utils.java:
##########
@@ -144,4 +150,37 @@ public static int 
toPlexusLoggingLevel(Slf4jConfiguration.Level level) {
             case ERROR -> Logger.LEVEL_ERROR;
         };
     }
+
+    @Nullable
+    public static Path findRoot(Path topDirectory) throws ParserException {
+        requireNonNull(topDirectory, "topDirectory");
+        Path rootDirectory = null;
+        for (RootLocator rootLocator : 
ServiceLoader.load(RootLocator.class).stream()
+                .map(ServiceLoader.Provider::get)
+                .toList()) {
+            rootDirectory = rootLocator.findRoot(topDirectory);
+            if (rootDirectory != null) {
+                break;
+            }
+        }
+        if (rootDirectory != null) {
+            return getCanonicalPath(rootDirectory);
+        }
+        return null;
+    }
+
+    @Nonnull
+    public static Path findMandatoryRoot(Path topDirectory) throws 
ParserException {
+        requireNonNull(topDirectory, "topDirectory");
+        Path rootDirectory;
+        for (RootLocator rootLocator : 
ServiceLoader.load(RootLocator.class).stream()
+                .map(ServiceLoader.Provider::get)
+                .toList()) {
+            rootDirectory = rootLocator.findMandatoryRoot(topDirectory);

Review Comment:
   In this case, we'll take only the first `RootLocator`, because calling 
`findMandatoryRoot` should throw an exception if that `RootLocator` cannot find 
the root.  That's not really in line with the `findRoot` (not mandatory above).
   Should that be:
   ```
   return Optional.ofNullable(findMandatory(topDirectory)).orElseThrow();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to