[
https://issues.apache.org/jira/browse/MNG-7038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17704183#comment-17704183
]
ASF GitHub Bot commented on MNG-7038:
-------------------------------------
michael-o commented on code in PR #1061:
URL: https://github.com/apache/maven/pull/1061#discussion_r1146267900
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -86,8 +86,34 @@ default String getId() {
return getModel().getId();
}
+ /**
+ * @deprecated use {@link #isTopdirProject()} instead
+ */
+ @Deprecated
boolean isExecutionRoot();
+ /**
+ * Returns a boolean indicating if the project is the top leve project for
+ * this reactor build. The top level project may be different from the
+ * {@code rootDirProject}, especially if a subtree of the project is being
+ * built, either because maven has been launched in a subdirectory or using
+ * a {@code -f} option.
+ *
+ * @return {@code true} if the project is the top level project for this
build
+ */
+ boolean isTopdirProject();
+
+ /**
+ * Returns a boolean indicating if the project is the project from the root
+ * directory of this reactor. The root project is the top-most project
containing
+ * the {@code .mvn} directory. If only a subtree of the reactor is build
(because
+ * the current directory is in a subtree or because the {@code -f} option
has been
+ * specified, then there may be no rootDirProject in this reactor.
+ *
+ * @return {@code true} if the project is the root dir project
+ */
+ boolean isRootdirProject();
Review Comment:
Same here
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -86,8 +86,34 @@ default String getId() {
return getModel().getId();
}
+ /**
+ * @deprecated use {@link #isTopdirProject()} instead
+ */
+ @Deprecated
boolean isExecutionRoot();
+ /**
+ * Returns a boolean indicating if the project is the top leve project for
+ * this reactor build. The top level project may be different from the
+ * {@code rootDirProject}, especially if a subtree of the project is being
+ * built, either because maven has been launched in a subdirectory or using
+ * a {@code -f} option.
+ *
+ * @return {@code true} if the project is the top level project for this
build
+ */
+ boolean isTopdirProject();
Review Comment:
Why not `isTopProject()` or `isTopLevelProject()`?
##########
maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java:
##########
@@ -494,14 +504,49 @@ public interface MavenExecutionRequest {
/**
* @since 3.3.0
+ * @deprecated use {@link #setRootdir(Path)} instead
*/
+ @Deprecated
void setMultiModuleProjectDirectory(File file);
/**
* @since 3.3.0
+ * @deprecated use {@link #getRootdir()} instead
*/
+ @Deprecated
File getMultiModuleProjectDirectory();
+ /**
+ * Sets the root dir of the project.
+ *
+ * @since 4.0.0
+ */
+ MavenExecutionRequest setRootdir(Path rootdir);
+
+ /**
+ * Gets the root dir of the project, which is the up-most directory of the
reactor, usually containing
Review Comment:
Here you use the term "up-most" which is likely better
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -86,8 +86,34 @@ default String getId() {
return getModel().getId();
}
+ /**
+ * @deprecated use {@link #isTopdirProject()} instead
+ */
+ @Deprecated
boolean isExecutionRoot();
+ /**
+ * Returns a boolean indicating if the project is the top leve project for
Review Comment:
level
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -86,8 +86,34 @@ default String getId() {
return getModel().getId();
}
+ /**
+ * @deprecated use {@link #isTopdirProject()} instead
+ */
+ @Deprecated
boolean isExecutionRoot();
+ /**
+ * Returns a boolean indicating if the project is the top leve project for
+ * this reactor build. The top level project may be different from the
+ * {@code rootDirProject}, especially if a subtree of the project is being
+ * built, either because maven has been launched in a subdirectory or using
Review Comment:
Maven
##########
maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java:
##########
@@ -494,14 +504,49 @@ public interface MavenExecutionRequest {
/**
* @since 3.3.0
+ * @deprecated use {@link #setRootdir(Path)} instead
*/
+ @Deprecated
void setMultiModuleProjectDirectory(File file);
/**
* @since 3.3.0
+ * @deprecated use {@link #getRootdir()} instead
*/
+ @Deprecated
File getMultiModuleProjectDirectory();
+ /**
+ * Sets the root dir of the project.
+ *
+ * @since 4.0.0
+ */
+ MavenExecutionRequest setRootdir(Path rootdir);
+
+ /**
+ * Gets the root dir of the project, which is the up-most directory of the
reactor, usually containing
+ * the {@code .mvn} directory.
+ *
+ * @since 4.0.0
+ */
+ Path getRootdir();
+
+ /**
+ * Sets the top dir of the project.
+ *
+ * @since 4.0.0
+ */
+ MavenExecutionRequest setTopdir(Path topdir);
+
+ /**
+ * Gets the top dir of the project, which is the up-most directory of the
reactor projects.
Review Comment:
This gets confusing
##########
maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java:
##########
@@ -136,6 +136,13 @@ static Properties getBuildProperties() {
}
public static void showError(Logger logger, String message, Throwable e,
boolean showStackTrace) {
+ if (logger == null) {
Review Comment:
But this is unrelated to this change, right?
##########
maven-model-builder/src/site/apt/index.apt:
##########
@@ -190,6 +190,10 @@ Maven Model Builder
*----+------+------+
| <<<*>>> | model properties, such as project properties set in the pom |
<<<$\{any.key\}>>> |
*----+------+------+
+| <<<session.rootdir>>> | the directory containing the root <<<pom.xml>>> file
of a multi module project, in a single module project this is the same as
<<<project.basedir>>> | <<<$\{session.rootdir\}>>> |
+*----+------+------+
+| <<<session.topdir>>> | the directory containing the top-level <<<pom.xml>>>
in this reactor build | <<<$\{session.topdir\}>>> |
+*----+------+------+
Review Comment:
Same concern as above.
##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -321,6 +323,46 @@ void initialize(CliRequest cliRequest) throws
ExitException {
}
}
+ Path topdir = Paths.get(cliRequest.workingDirectory);
+ boolean isAltFile = false;
+ for (String arg : cliRequest.args) {
+ if (isAltFile) {
+ Path path = Paths.get(arg);
+ if (Files.isDirectory(path)) {
Review Comment:
I don't understand this loop, why not use `cliRequest.commandLine for this?
Like
```
String alternatePomFile = null;
if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) {
alternatePomFile =
commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
}
```
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -86,8 +86,34 @@ default String getId() {
return getModel().getId();
}
+ /**
+ * @deprecated use {@link #isTopdirProject()} instead
+ */
+ @Deprecated
boolean isExecutionRoot();
+ /**
+ * Returns a boolean indicating if the project is the top leve project for
+ * this reactor build. The top level project may be different from the
+ * {@code rootDirProject}, especially if a subtree of the project is being
+ * built, either because maven has been launched in a subdirectory or using
+ * a {@code -f} option.
+ *
+ * @return {@code true} if the project is the top level project for this
build
+ */
+ boolean isTopdirProject();
+
+ /**
+ * Returns a boolean indicating if the project is the project from the root
+ * directory of this reactor. The root project is the top-most project
containing
Review Comment:
I have a problem what explaining the rootdir with a term "topmost". That
leads to confusion with the other property.
##########
maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java:
##########
@@ -166,7 +166,11 @@ public Object evaluate(String expr, Class<?> type) throws
ExpressionEvaluationEx
return expression.replace("$$", "$");
}
- if ("localRepository".equals(expression)) {
+ if ("rootdir".equals(expression) ||
"session.rootdir".equals(expression)) {
+ value = session.getRootdir();
+ } else if ("topdir".equals(expression) ||
"session.topdir".equals(expression)) {
+ value = session.getTopdir();
+ } else if ("localRepository".equals(expression)) {
Review Comment:
Same here
##########
maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java:
##########
@@ -165,7 +165,11 @@ public Object evaluate(String expr, Class<?> type) throws
ExpressionEvaluationEx
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
- if ("localRepository".equals(expression)) {
+ if ("rootdir".equals(expression) ||
"session.rootdir".equals(expression)) {
+ value = session.getRootdir();
+ } else if ("topdir".equals(expression) ||
"session.topdir".equals(expression)) {
+ value = session.getTopdir();
Review Comment:
I wonder now, we don't have an expression for ther items in `session` which
starts with `session.`. Why should they be prefixed, by not make then
unqualified like the rest? `session.foo` will work via bean introspection, no?
> Introduce public property to point to a root directory of (multi-module)
> project
> --------------------------------------------------------------------------------
>
> Key: MNG-7038
> URL: https://issues.apache.org/jira/browse/MNG-7038
> Project: Maven
> Issue Type: Improvement
> Reporter: Envious Guest
> Priority: Major
> Fix For: Issues to be reviewed for 4.x
>
>
> This is a request to expose a property *maven.multiModuleProjectDirectory*
> which is currently internal (or introduce a brand new one with analogous
> functionality).
> * For a single-module project, its value should be same as *project.basedir*
> * For multi-module project, its value should point to a project.basedir of a
> root module
> Example:
> multi-module // located at /home/me/sources
> +- module-a
> +- module B
> Sample multi-module/pom.xml:
> {{<project>}}
> {{ <parent>}}
> {{ <groupId>com.acme</groupId>}}
> {{ <artifactId>corp-parent</artifactId>}}
> {{ <version>1.0.0-RELEASE</version>}}
> {{ </parent>}}
> {{ <groupId>com.acme</groupId>}}
> {{ <artifactId>multi-module</artifactId>}}
> {{ <version>0.5.2-SNAPSHOT</version>}}
> {{ <modules>}}
> {{ <module>module-a</module>}}
> {{ <module>module-b</module>}}
> {{ </modules>}}
> {{</project>}}
> The property requested should return /home/me/sources/multi-module,
> regardless of whether it's referenced in any of the child modules (module-a,
> module-b) or in multi-module.
> Note that multi-module itself has parent (e.g. installed in a local
> repository), so the new property should be smart enough to detect it and
> still point to /home/me/sources/multi-module instead of the local repository
> where the corp-parent is installed.
> The use-case for such a property could be to have a directory for combined
> report of static analysis tools. Typical example - jacoco combined coverage
> reports.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)