[
https://issues.apache.org/jira/browse/MNG-7038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17714109#comment-17714109
]
ASF GitHub Bot commented on MNG-7038:
-------------------------------------
michael-o commented on code in PR #1061:
URL: https://github.com/apache/maven/pull/1061#discussion_r1171338733
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -86,8 +86,42 @@ default String getId() {
return getModel().getId();
}
+ /**
+ * @deprecated use {@link #isTopProject()} instead
+ */
+ @Deprecated
boolean isExecutionRoot();
+ /**
+ * Returns a boolean indicating if the project is the top level 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
Review Comment:
missed this one
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -86,8 +86,42 @@ default String getId() {
return getModel().getId();
}
+ /**
+ * @deprecated use {@link #isTopProject()} instead
+ */
+ @Deprecated
boolean isExecutionRoot();
+ /**
+ * Returns a boolean indicating if the project is the top level 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 isTopProject();
+
+ /**
+ * Returns a boolean indicating if the project is a root project,
+ * meaning that .
Review Comment:
incomplete
##########
maven-model-builder/src/main/java/org/apache/maven/model/root/RootLocator.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.model.root;
+
+import java.nio.file.Path;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+
+/**
+ * Interface used to locate the root directory for a given project.
+ *
+ * The root locator is usually looked up from the plexus container.
+ * One notable exception is the computation of the early {@code
session.rootDirectory}
+ * property which happens very early. The implementation used in this case
+ * will be discovered using the JDK service mechanism.
+ *
+ * The default implementation will look for a {@code .mvn} child directory
+ * or a {@code pom.xml} containing the {@code root="true"} attribute.
+ *
+ * @see DefaultRootLocator
+ */
+public interface RootLocator {
+
+ String UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE = "Unable to find the root
directory. "
+ + "Create a .mvn directory in the root directory or add the
root=\"true\""
+ + " attribute on the root project's model to identify it.";
+
+ @Nonnull
+ default Path findMandatoryRoot(Path basedir) {
+ Path rootDirectory = findRoot(basedir);
+ if (rootDirectory == null) {
+ throw new IllegalStateException(getNoRootMessage());
+ }
+ return rootDirectory;
+ }
+
+ @Nullable
+ default Path findRoot(Path basedir) {
+ Path rootDirectory = basedir;
+ while (rootDirectory != null && !isRootDir(rootDirectory)) {
+ rootDirectory = rootDirectory.getParent();
+ }
+ return rootDirectory;
+ }
+
+ @Nonnull
+ default String getNoRootMessage() {
+ return UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE;
+ }
+
+ boolean isRootDir(Path dir);
Review Comment:
missed this one
##########
maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java:
##########
@@ -494,14 +504,51 @@ 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 top dir of the project.
+ *
+ * @since 4.0.0
+ */
+ MavenExecutionRequest setTopdir(Path topdir);
+
+ /**
+ * Gets the directory of the topmost project being built, usually the
current directory or the
+ * directory pointed at by the {@code -f/--file} command line argument.
+ *
+ * @since 4.0.0
+ */
+ Path getTopdir();
+
+ /**
+ * Sets the root dir of the project.
Review Comment:
Yeo
##########
maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java:
##########
@@ -494,14 +504,51 @@ 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 top dir of the project.
Review Comment:
Yep
##########
maven-model-builder/src/site/apt/index.apt:
##########
@@ -41,7 +41,7 @@ Maven Model Builder
** profile activation: see
{{{./apidocs/org/apache/maven/model/profile/activation/package-summary.html}available
activators}}.
Notice that model interpolation hasn't happened yet, then interpolation for
file-based activation is limited to
- <<<$\{basedir}>>> (since Maven 3), system properties and user properties
+ <<<$\{basedir}>>> (since Maven 3), <<<$\{rootDirectory}>>> (since Maven 4)
system properties and user properties
Review Comment:
comma missing after "... Maven 4)"
##########
maven-core/src/main/java/org/apache/maven/execution/MavenSession.java:
##########
@@ -141,10 +142,30 @@ public List<MavenProject> getProjects() {
return projects;
}
+ /**
+ * @deprecated use {@link #getTopdir()}
+ */
+ @Deprecated
public String getExecutionRootDirectory() {
return request.getBaseDirectory();
}
+ /**
+ * @see MavenExecutionRequest#getTopDirectory()
+ * @since 4.0.0
+ */
+ public Path getTopdir() {
Review Comment:
missed this one
##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -320,6 +324,49 @@ void initialize(CliRequest cliRequest) throws
ExitException {
}
}
+ Path topDirectory = Paths.get(cliRequest.workingDirectory);
+ boolean isAltFile = false;
+ for (String arg : cliRequest.args) {
+ if (isAltFile) {
+ Path path = Paths.get(arg);
+ if (Files.isDirectory(path)) {
+ topDirectory = path;
+ } else if (Files.isRegularFile(topDirectory)) {
+ 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 {
+ isAltFile =
arg.equals(String.valueOf(CLIManager.ALTERNATE_POM_FILE)) || arg.equals("file");
Review Comment:
This looks pretty low level, can't we use high level CLI to get this value?
##########
maven-core/src/main/java/org/apache/maven/execution/MavenSession.java:
##########
@@ -141,10 +142,30 @@ public List<MavenProject> getProjects() {
return projects;
}
+ /**
+ * @deprecated use {@link #getTopdir()}
Review Comment:
missed this one
> 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
> Assignee: Guillaume Nodet
> Priority: Major
> Fix For: 4.0.0-alpha-6
>
>
> 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)