diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index cefb2c3fe6f7..5e5930ca964b 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -19,6 +19,7 @@ package org.apache.maven.execution; import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -162,6 +163,10 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest { private Map data; + private Path topDirectory; + + private Path rootDirectory; + public DefaultMavenExecutionRequest() {} public static MavenExecutionRequest copy(MavenExecutionRequest original) { @@ -204,6 +209,10 @@ public static MavenExecutionRequest copy(MavenExecutionRequest original) { copy.setExecutionListener(original.getExecutionListener()); copy.setUseLegacyLocalRepository(original.isUseLegacyLocalRepository()); copy.setBuilderId(original.getBuilderId()); + + copy.setTopDirectory(original.getTopDirectory()); + copy.setRootDirectory(original.getRootDirectory()); + return copy; } @@ -1097,4 +1106,26 @@ public Map getData() { return data; } + + @Override + public Path getTopDirectory() { + return topDirectory; + } + + @Override + public MavenExecutionRequest setTopDirectory(Path topDirectory) { + this.topDirectory = topDirectory; + return this; + } + + @Override + public Path getRootDirectory() { + return rootDirectory; + } + + @Override + public MavenExecutionRequest setRootDirectory(Path rootDirectory) { + this.rootDirectory = rootDirectory; + return this; + } } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index b074eea348de..41da25035268 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -19,6 +19,7 @@ package org.apache.maven.execution; import java.io.File; +import java.nio.file.Path; import java.util.Date; import java.util.List; import java.util.Map; @@ -455,4 +456,24 @@ public interface MavenExecutionRequest { * @since 3.3.0 */ Map getData(); + + /** + * @since 3.10.0 + */ + Path getTopDirectory(); + + /** + * @since 3.10.0 + */ + MavenExecutionRequest setTopDirectory(Path topDirectory); + + /** + * @since 3.10.0 + */ + Path getRootDirectory(); + + /** + * @since 3.10.0 + */ + MavenExecutionRequest setRootDirectory(Path rootDirectory); } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index b08bef9f6e27..ac968f7afb2e 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -163,6 +163,24 @@ public MavenExecutionResult getResult() { return result; } + /** + * Returns top directory if discovered or {@code null}. + * + * @since 3.10.0 + */ + public File getTopDirectory() { + return request.getTopDirectory() != null ? request.getTopDirectory().toFile() : null; + } + + /** + * Returns root directory if discovered or {@code null}. + * + * @since 3.10.0 + */ + public File getRootDirectory() { + return request.getRootDirectory() != null ? request.getRootDirectory().toFile() : null; + } + // Backward compat public Map getPluginContext(PluginDescriptor plugin, MavenProject project) { diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java b/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java index 4c48de3925a3..15439def8dfc 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java @@ -19,7 +19,6 @@ package org.apache.maven.cli; import java.io.File; -import java.nio.file.Path; import java.util.Properties; import org.apache.commons.cli.CommandLine; @@ -41,10 +40,6 @@ public class CliRequest { File multiModuleProjectDirectory; - Path rootDirectory; - - Path topDirectory; - boolean debug; boolean quiet; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index e0ed45c3a424..2c9c568111c1 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -352,11 +352,11 @@ void initialize(CliRequest cliRequest) throws ExitException { } } topDirectory = getCanonicalPath(topDirectory); - cliRequest.topDirectory = topDirectory; + cliRequest.request.setTopDirectory(topDirectory); // We're very early in the process and we don't have the container set up yet, // so we on searchAcceptableRootDirectory method to find us acceptable directory. // The method may return null if nothing acceptable found. - cliRequest.rootDirectory = searchAcceptableRootDirectory(topDirectory); + cliRequest.request.setRootDirectory(searchAcceptableRootDirectory(topDirectory)); // // Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative @@ -613,7 +613,7 @@ void properties(CliRequest cliRequest) throws ExitException { } catch (IllegalUseOfUndefinedProperty e) { String message = "ERROR: Illegal use of undefined property: " + e.property; System.err.println(message); - if (cliRequest.rootDirectory == null) { + if (cliRequest.request.getRootDirectory() == null) { System.err.println(); System.err.println(UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); } @@ -1577,14 +1577,14 @@ protected static StringSearchInterpolator createInterpolator(CliRequest cliReque @Override public Object getValue(String expression) { if ("session.topDirectory".equals(expression)) { - Path topDirectory = cliRequest.topDirectory; + Path topDirectory = cliRequest.request.getTopDirectory(); if (topDirectory != null) { return topDirectory.toString(); } else { throw new IllegalUseOfUndefinedProperty(expression); } } else if ("session.rootDirectory".equals(expression)) { - Path rootDirectory = cliRequest.rootDirectory; + Path rootDirectory = cliRequest.request.getRootDirectory(); if (rootDirectory != null) { return rootDirectory.toString(); } else { diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index e5fd93acb078..391560b3acf1 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -380,8 +380,8 @@ public void testPropertiesInterpolation() throws Exception { "validate" }, null); - request.rootDirectory = Paths.get("myRootDirectory"); - request.topDirectory = Paths.get("myTopDirectory"); + request.request.setRootDirectory(Paths.get("myRootDirectory")); + request.request.setTopDirectory(Paths.get("myTopDirectory")); // Act cli.cli(request);