You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "CrazyHZM (via GitHub)" <gi...@apache.org> on 2023/05/04 05:27:17 UTC

[GitHub] [maven] CrazyHZM commented on a diff in pull request #1098: [MNG-7774] Maven config and command line interpolation (take two)

CrazyHZM commented on code in PR #1098:
URL: https://github.com/apache/maven/pull/1098#discussion_r1184555983


##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -309,6 +320,47 @@ void initialize(CliRequest cliRequest) throws ExitException {
             }
         }
 
+        // We need to locate the top level project which may be pointed at using
+        // the -f/--file option.  However, the command line isn't parsed yet, so
+        // we need to iterate through the args to find it and act upon it.
+        Path topDirectory = Paths.get(cliRequest.workingDirectory);
+        boolean isAltFile = false;
+        for (String arg : cliRequest.args) {
+            if (isAltFile) {
+                // this is the argument following -f/--file
+                Path path = topDirectory.resolve(arg);
+                if (Files.isDirectory(path)) {
+                    topDirectory = path;
+                } else if (Files.isRegularFile(path)) {
+                    topDirectory = path.getParent();
+                    if (!Files.isDirectory(topDirectory)) {
+                        System.err.println("Directory " + topDirectory
+                                + " extracted from the -f/--file command-line argument " + arg + " does not exist");
+                        throw new ExitException(1);
+                    }
+                } else {
+                    System.err.println(
+                            "POM file " + arg + " specified with the -f/--file command line argument does not exist");
+                    throw new ExitException(1);
+                }
+                break;
+            } else {
+                // Check if this is the -f/--file option
+                isAltFile = arg.equals(String.valueOf(CLIManager.ALTERNATE_POM_FILE)) || arg.equals("file");
+            }
+        }
+        try {
+            topDirectory = topDirectory.toAbsolutePath().toRealPath();
+        } catch (IOException e) {
+            System.err.println("Error computing real path from " + topDirectory);

Review Comment:
   Would it be easier to troubleshoot the problem if the exception information was printed out here?



-- 
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-unsubscribe@maven.apache.org

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