You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2024/10/08 19:45:33 UTC
(maven) branch master updated: Make rootDirectory mandatory (#1787)
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 445236398d Make rootDirectory mandatory (#1787)
445236398d is described below
commit 445236398d208b81c410e76389adf8d7a993659a
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Tue Oct 8 21:45:28 2024 +0200
Make rootDirectory mandatory (#1787)
Co-authored-by: Guillaume Nodet <gn...@gmail.com>
---
.../main/java/org/apache/maven/api/Session.java | 1 -
.../maven/api/services/model/RootDetector.java | 30 ++++++++
.../maven/api/services/model/RootLocator.java | 22 +-----
.../internal/impl/model/DefaultModelBuilder.java | 25 +------
.../impl/model/rootlocator/DefaultRootLocator.java | 85 ++++++++++++++++++++++
.../impl/model/rootlocator/DotMvnRootDetector.java | 33 +++++++++
.../PomXmlRootDetector.java} | 21 +-----
...rg.apache.maven.api.services.model.RootDetector | 2 +
...org.apache.maven.api.services.model.RootLocator | 1 +
.../maven/internal/impl/standalone/ApiRunner.java | 5 +-
.../impl/standalone/RepositorySystemSupplier.java | 2 +-
.../org/apache/maven/cling/invoker/BaseParser.java | 31 ++------
.../maven/AbstractCoreMavenComponentTestCase.java | 3 +-
.../project/AbstractMavenProjectTestCase.java | 2 +-
.../repository/LegacyRepositorySystemTest.java | 2 +-
.../execution/DefaultMavenExecutionRequest.java | 7 ++
.../maven/AbstractCoreMavenComponentTestCase.java | 4 +-
.../java/org/apache/maven/MavenTestHelper.java | 2 +-
.../org/apache/maven/internal/impl/TestApi.java | 2 +-
.../project/AbstractMavenProjectTestCase.java | 2 +-
.../maven/model/root/DefaultRootLocator.java | 2 +-
.../org/apache/maven/model/root/RootLocator.java | 2 +-
.../internal/MavenRepositorySystemSupplier.java | 2 +-
23 files changed, 188 insertions(+), 100 deletions(-)
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
index 26eeaf118d..60757fa756 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
@@ -158,7 +158,6 @@ public interface Session {
* Gets the root directory of the session, which is the root directory for the top directory project.
*
* @return the root directory, never {@code null}
- * @throws IllegalStateException if the root directory could not be found
* @see #getTopDirectory()
* @see Project#getRootDirectory()
* @see Project#isRootProject()
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootDetector.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootDetector.java
new file mode 100644
index 0000000000..7c1f1b3015
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootDetector.java
@@ -0,0 +1,30 @@
+/*
+ * 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.api.services.model;
+
+import java.nio.file.Path;
+
+import org.apache.maven.api.Service;
+
+/**
+ * Interface used to detect is a given directory "root directory".
+ */
+public interface RootDetector extends Service {
+ boolean isRootDirectory(Path dir);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java
index d010590243..5b41bec688 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java
@@ -22,12 +22,11 @@ import java.nio.file.Path;
import org.apache.maven.api.Service;
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.
+ * The root locator is usually looked up from the DI 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.
@@ -42,27 +41,10 @@ public interface RootLocator extends Service {
+ " attribute on the root project's model to identify it.";
@Nonnull
- default Path findMandatoryRoot(@Nullable Path basedir) {
- Path rootDirectory = findRoot(basedir);
- if (rootDirectory == null) {
- throw new IllegalStateException(getNoRootMessage());
- }
- return rootDirectory;
- }
-
- @Nullable
- default Path findRoot(@Nullable Path basedir) {
- Path rootDirectory = basedir;
- while (rootDirectory != null && !isRootDirectory(rootDirectory)) {
- rootDirectory = rootDirectory.getParent();
- }
- return rootDirectory;
- }
+ Path findMandatoryRoot(@Nonnull Path basedir);
@Nonnull
default String getNoRootMessage() {
return UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE;
}
-
- boolean isRootDirectory(Path dir);
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
index 7af8f910a9..4de108f1ff 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
@@ -106,7 +106,6 @@ import org.apache.maven.api.services.model.PluginManagementInjector;
import org.apache.maven.api.services.model.ProfileActivationContext;
import org.apache.maven.api.services.model.ProfileInjector;
import org.apache.maven.api.services.model.ProfileSelector;
-import org.apache.maven.api.services.model.RootLocator;
import org.apache.maven.api.services.xml.XmlReaderException;
import org.apache.maven.api.services.xml.XmlReaderRequest;
import org.apache.maven.api.spi.ModelParserException;
@@ -633,12 +632,7 @@ public class DefaultModelBuilder implements ModelBuilder {
top = top.toAbsolutePath().normalize();
// Obtain the root directory, resolving it if necessary
- Path rootDirectory;
- try {
- rootDirectory = session.getRootDirectory();
- } catch (IllegalStateException e) {
- rootDirectory = session.getService(RootLocator.class).findRoot(top);
- }
+ Path rootDirectory = session.getRootDirectory();
// Locate and normalize the root POM if it exists, fallback to top otherwise
Path root = modelProcessor.locateExistingPom(rootDirectory);
@@ -1177,19 +1171,11 @@ public class DefaultModelBuilder implements ModelBuilder {
Model doReadFileModel() throws ModelBuilderException {
ModelSource modelSource = request.getSource();
Model model;
- Path rootDirectory;
+ Path rootDirectory = request.getSession().getRootDirectory();
setSource(modelSource.getLocation());
logger.debug("Reading file model from " + modelSource.getLocation());
try {
boolean strict = request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM;
- try {
- rootDirectory = request.getSession().getRootDirectory();
- } catch (IllegalStateException ignore) {
- rootDirectory = modelSource.getPath();
- while (rootDirectory != null && !Files.isDirectory(rootDirectory)) {
- rootDirectory = rootDirectory.getParent();
- }
- }
try (InputStream is = modelSource.openStream()) {
model = modelProcessor.read(XmlReaderRequest.builder()
.strict(strict)
@@ -1592,12 +1578,7 @@ public class DefaultModelBuilder implements ModelBuilder {
return null;
}
- Path rootDirectory;
- try {
- rootDirectory = request.getSession().getRootDirectory();
- } catch (IllegalStateException e) {
- rootDirectory = null;
- }
+ Path rootDirectory = request.getSession().getRootDirectory();
if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM && rootDirectory != null) {
Path sourcePath = importSource.getPath();
if (sourcePath != null && sourcePath.startsWith(rootDirectory)) {
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/DefaultRootLocator.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/DefaultRootLocator.java
new file mode 100644
index 0000000000..f43c050a94
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/DefaultRootLocator.java
@@ -0,0 +1,85 @@
+/*
+ * 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.internal.impl.model.rootlocator;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.ServiceLoader;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.services.model.RootDetector;
+import org.apache.maven.api.services.model.RootLocator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Objects.requireNonNull;
+
+@Named
+public class DefaultRootLocator implements RootLocator {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+ private final List<RootDetector> rootDetectors;
+
+ public DefaultRootLocator() {
+ this.rootDetectors = ServiceLoader.load(RootDetector.class).stream()
+ .map(ServiceLoader.Provider::get)
+ .toList();
+ }
+
+ @Nonnull
+ public Path findMandatoryRoot(@Nonnull Path basedir) {
+ requireNonNull(basedir, "basedir is null");
+ Path rootDirectory = basedir;
+ while (rootDirectory != null && !isRootDirectory(rootDirectory)) {
+ rootDirectory = rootDirectory.getParent();
+ }
+ Optional<Path> rdf = getMultiModuleProjectDirectory();
+ if (rootDirectory == null) {
+ logger.warn(getNoRootMessage());
+ rootDirectory = rdf.orElseGet(() -> Paths.get("").toAbsolutePath());
+ } else {
+ if (rdf.isPresent() && !Objects.equals(rootDirectory, rdf.get())) {
+ logger.warn("Project root directory and multiModuleProjectDirectory are not aligned");
+ }
+ }
+ return rootDirectory;
+ }
+
+ protected boolean isRootDirectory(Path dir) {
+ requireNonNull(dir, "dir is null");
+ for (RootDetector rootDetector : rootDetectors) {
+ if (rootDetector.isRootDirectory(dir)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected Optional<Path> getMultiModuleProjectDirectory() {
+ String mmpd = System.getProperty("maven.multiModuleProjectDirectory");
+ if (mmpd != null) {
+ return Optional.of(Paths.get(mmpd));
+ }
+ return Optional.empty();
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/DotMvnRootDetector.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/DotMvnRootDetector.java
new file mode 100644
index 0000000000..f0e5c7c00b
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/DotMvnRootDetector.java
@@ -0,0 +1,33 @@
+/*
+ * 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.internal.impl.model.rootlocator;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.services.model.RootDetector;
+
+@Named
+public class DotMvnRootDetector implements RootDetector {
+ @Override
+ public boolean isRootDirectory(Path dir) {
+ return Files.isDirectory(dir.resolve(".mvn"));
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultRootLocator.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/PomXmlRootDetector.java
similarity index 80%
rename from maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultRootLocator.java
rename to maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/PomXmlRootDetector.java
index a5a3649018..32959f90cb 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultRootLocator.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/rootlocator/PomXmlRootDetector.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.internal.impl.model;
+package org.apache.maven.internal.impl.model.rootlocator;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
@@ -27,28 +27,13 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
-import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.di.Named;
-import org.apache.maven.api.services.model.RootLocator;
+import org.apache.maven.api.services.model.RootDetector;
@Named
-public class DefaultRootLocator implements RootLocator {
-
- @Override
- @Nullable
- public Path findRoot(Path basedir) {
- Path rootDirectory = basedir;
- while (rootDirectory != null && !isRootDirectory(rootDirectory)) {
- rootDirectory = rootDirectory.getParent();
- }
- return rootDirectory;
- }
-
+public class PomXmlRootDetector implements RootDetector {
@Override
public boolean isRootDirectory(Path dir) {
- if (Files.isDirectory(dir.resolve(".mvn"))) {
- return true;
- }
// we're too early to use the modelProcessor ...
Path pom = dir.resolve("pom.xml");
try (InputStream is = Files.newInputStream(pom)) {
diff --git a/maven-api-impl/src/main/resources/META-INF/services/org.apache.maven.api.services.model.RootDetector b/maven-api-impl/src/main/resources/META-INF/services/org.apache.maven.api.services.model.RootDetector
new file mode 100644
index 0000000000..472ffe1612
--- /dev/null
+++ b/maven-api-impl/src/main/resources/META-INF/services/org.apache.maven.api.services.model.RootDetector
@@ -0,0 +1,2 @@
+org.apache.maven.internal.impl.model.rootlocator.DotMvnRootDetector
+org.apache.maven.internal.impl.model.rootlocator.PomXmlRootDetector
diff --git a/maven-api-impl/src/main/resources/META-INF/services/org.apache.maven.api.services.model.RootLocator b/maven-api-impl/src/main/resources/META-INF/services/org.apache.maven.api.services.model.RootLocator
new file mode 100644
index 0000000000..db7fa8e7c7
--- /dev/null
+++ b/maven-api-impl/src/main/resources/META-INF/services/org.apache.maven.api.services.model.RootLocator
@@ -0,0 +1 @@
+org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator
diff --git a/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java b/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java
index 05a3cfaa18..7259384c33 100644
--- a/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java
+++ b/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java
@@ -52,6 +52,7 @@ import org.apache.maven.api.services.PackagingRegistry;
import org.apache.maven.api.services.RepositoryFactory;
import org.apache.maven.api.services.SettingsBuilder;
import org.apache.maven.api.services.TypeRegistry;
+import org.apache.maven.api.services.model.RootLocator;
import org.apache.maven.api.settings.Settings;
import org.apache.maven.api.spi.TypeProvider;
import org.apache.maven.di.Injector;
@@ -153,12 +154,12 @@ public class ApiRunner {
@Override
public Path getTopDirectory() {
- return null;
+ return Paths.get("");
}
@Override
public Path getRootDirectory() {
- throw new IllegalStateException();
+ return getService(RootLocator.class).findMandatoryRoot(getTopDirectory());
}
@Override
diff --git a/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java b/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java
index bb0d4c2df5..597cf9a76d 100644
--- a/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java
+++ b/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java
@@ -47,8 +47,8 @@ import org.apache.maven.internal.impl.model.DefaultPathTranslator;
import org.apache.maven.internal.impl.model.DefaultPluginManagementInjector;
import org.apache.maven.internal.impl.model.DefaultProfileInjector;
import org.apache.maven.internal.impl.model.DefaultProfileSelector;
-import org.apache.maven.internal.impl.model.DefaultRootLocator;
import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator;
+import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator;
import org.apache.maven.internal.impl.resolver.DefaultArtifactDescriptorReader;
import org.apache.maven.internal.impl.resolver.DefaultModelResolver;
import org.apache.maven.internal.impl.resolver.DefaultVersionRangeResolver;
diff --git a/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java b/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java
index 4c4a3f31db..2ae2bd94d6 100644
--- a/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java
+++ b/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java
@@ -31,7 +31,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.function.Function;
@@ -43,10 +42,10 @@ import org.apache.maven.api.cli.Parser;
import org.apache.maven.api.cli.ParserException;
import org.apache.maven.api.cli.ParserRequest;
import org.apache.maven.api.cli.extensions.CoreExtension;
+import org.apache.maven.api.services.model.RootLocator;
import org.apache.maven.cli.CLIReportingUtils;
import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader;
import org.apache.maven.cli.props.MavenPropertiesLoader;
-import org.apache.maven.model.root.RootLocator;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.properties.internal.SystemProperties;
@@ -196,30 +195,10 @@ public abstract class BaseParser<O extends Options, R extends InvokerRequest<O>>
}
protected Path getRootDirectory(LocalContext context) throws ParserException {
- RootLocator rootLocator =
- ServiceLoader.load(RootLocator.class).iterator().next();
- Path rootDirectory = rootLocator.findRoot(requireNonNull(context.topDirectory));
-
- // TODO: multiModuleProjectDirectory vs rootDirectory?
- // fallback if no root? otherwise make sure they are same?
- Path mmpd = System.getProperty("maven.multiModuleProjectDirectory") == null
- ? null
- : getCanonicalPath(context.cwd.resolve(requireNonNull(
- System.getProperty("maven.multiModuleProjectDirectory"),
- "maven.multiModuleProjectDirectory is not set")));
- if (rootDirectory == null) {
- context.parserRequest.logger().warn(rootLocator.getNoRootMessage());
- rootDirectory = requireNonNull(
- mmpd, "maven.multiModuleProjectDirectory is not set and rootDirectory was not discovered");
- } else {
- rootDirectory = getCanonicalPath(rootDirectory);
- if (mmpd != null && !Objects.equals(rootDirectory, mmpd)) {
- context.parserRequest
- .logger()
- .warn("Project root directory and multiModuleProjectDirectory are not aligned");
- }
- }
- return getCanonicalPath(rootDirectory);
+ return getCanonicalPath(ServiceLoader.load(RootLocator.class)
+ .iterator()
+ .next()
+ .findMandatoryRoot(requireNonNull(context.topDirectory)));
}
protected Map<String, String> populateSystemProperties(LocalContext context) throws ParserException {
diff --git a/maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
index 0201b2fd0a..0df571dc0e 100644
--- a/maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
+++ b/maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
@@ -90,7 +90,7 @@ public abstract class AbstractCoreMavenComponentTestCase {
}
protected MavenExecutionRequest createMavenExecutionRequest(File pom) throws Exception {
- MavenExecutionRequest request = new DefaultMavenExecutionRequest()
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest(true)
.setPom(pom)
.setProjectPresent(true)
.setShowErrors(true)
@@ -102,6 +102,7 @@ public abstract class AbstractCoreMavenComponentTestCase {
if (pom != null) {
request.setMultiModuleProjectDirectory(pom.getParentFile());
+ request.setRootDirectory(pom.getParentFile().toPath());
}
return request;
diff --git a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
index fffdbb85c6..0d7c5f21a9 100644
--- a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
+++ b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
@@ -161,7 +161,7 @@ public abstract class AbstractMavenProjectTestCase {
session.setLocalRepositoryManager(new LegacyLocalRepositoryManager(localRepo));
request.setRepositorySession(session);
- DefaultMavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
+ DefaultMavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(true);
MavenSession msession =
new MavenSession(getContainer(), session, mavenExecutionRequest, new DefaultMavenExecutionResult());
DefaultSession iSession = new DefaultSession(
diff --git a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java
index 5feff15253..b1dc38a054 100644
--- a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java
+++ b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java
@@ -123,7 +123,7 @@ class LegacyRepositorySystemTest {
new LocalRepository(request.getLocalRepository().getBasedir());
session.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepo));
LegacySupport legacySupport = container.lookup(LegacySupport.class);
- DefaultMavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
+ DefaultMavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(true);
MavenSession mavenSession =
new MavenSession(container, session, mavenExecutionRequest, new DefaultMavenExecutionResult());
legacySupport.setSession(mavenSession);
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 aa9748ca51..1d715fcfcd 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
@@ -20,6 +20,7 @@ package org.apache.maven.execution;
import java.io.File;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -172,6 +173,12 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest {
public DefaultMavenExecutionRequest() {}
+ public DefaultMavenExecutionRequest(boolean withDefaultRoot) {
+ if (withDefaultRoot) {
+ setRootDirectory(Paths.get("").toAbsolutePath());
+ }
+ }
+
public static MavenExecutionRequest copy(MavenExecutionRequest original) {
DefaultMavenExecutionRequest copy = new DefaultMavenExecutionRequest();
copy.setLocalRepository(original.getLocalRepository());
diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
index 8484b60200..e8f8433b47 100644
--- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
+++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java
@@ -21,6 +21,7 @@ package org.apache.maven;
import javax.inject.Inject;
import java.io.File;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -90,7 +91,8 @@ public abstract class AbstractCoreMavenComponentTestCase {
protected MavenExecutionRequest createMavenExecutionRequest(File pom) throws Exception {
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
- .setRootDirectory(pom != null ? pom.toPath().getParent() : null)
+ .setRootDirectory(
+ pom != null ? pom.toPath().getParent() : Paths.get("").toAbsolutePath())
.setPom(pom)
.setProjectPresent(true)
.setShowErrors(true)
diff --git a/maven-core/src/test/java/org/apache/maven/MavenTestHelper.java b/maven-core/src/test/java/org/apache/maven/MavenTestHelper.java
index 358ab86ebe..8020cf7e12 100644
--- a/maven-core/src/test/java/org/apache/maven/MavenTestHelper.java
+++ b/maven-core/src/test/java/org/apache/maven/MavenTestHelper.java
@@ -32,7 +32,7 @@ public class MavenTestHelper {
public static DefaultRepositorySystemSession createSession(
MavenRepositorySystem repositorySystem, PlexusContainer container) {
DefaultRepositorySystemSession repoSession = new DefaultRepositorySystemSession(h -> false);
- DefaultMavenExecutionRequest request = new DefaultMavenExecutionRequest();
+ DefaultMavenExecutionRequest request = new DefaultMavenExecutionRequest(true);
MavenSession mavenSession = new MavenSession(repoSession, request, new DefaultMavenExecutionResult());
DefaultSession session =
new DefaultSession(mavenSession, null, null, repositorySystem, new DefaultLookup(container), null);
diff --git a/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java b/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java
index d8278b2b3b..68f8df087f 100644
--- a/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java
+++ b/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java
@@ -119,7 +119,7 @@ class TestApi {
.get()
.withLocalRepositoryBaseDirectories(new File("target").toPath())
.build();
- DefaultMavenExecutionRequest mer = new DefaultMavenExecutionRequest();
+ DefaultMavenExecutionRequest mer = new DefaultMavenExecutionRequest(true);
DefaultMavenExecutionResult meres = new DefaultMavenExecutionResult();
MavenSession ms = new MavenSession(rss, mer, meres);
DefaultSession session = new DefaultSession(
diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
index 652479a879..35cec20d4a 100644
--- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
+++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
@@ -164,7 +164,7 @@ public abstract class AbstractMavenProjectTestCase {
new DefaultSessionFactory(repoSystem, repositorySystem, new DefaultLookup(container), null);
MavenSession session = new MavenSession(
- getContainer(), repoSession, new DefaultMavenExecutionRequest(), new DefaultMavenExecutionResult());
+ getContainer(), repoSession, new DefaultMavenExecutionRequest(true), new DefaultMavenExecutionResult());
session.setSession(defaultSessionFactory.newSession(session));
DefaultSession s = new DefaultSession(session, null, null, null, null, null);
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/root/DefaultRootLocator.java b/maven-model-builder/src/main/java/org/apache/maven/model/root/DefaultRootLocator.java
index b7c763a031..871642d1d3 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/root/DefaultRootLocator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/root/DefaultRootLocator.java
@@ -29,7 +29,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
/**
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
+ * @deprecated use {@link org.apache.maven.api.services.model.RootLocator} instead
*/
@Named
@Deprecated(since = "4.0.0")
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/root/RootLocator.java b/maven-model-builder/src/main/java/org/apache/maven/model/root/RootLocator.java
index 50200d7c0b..55c35696f1 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/root/RootLocator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/root/RootLocator.java
@@ -35,7 +35,7 @@ import org.apache.maven.api.annotations.Nullable;
* or a {@code pom.xml} containing the {@code root="true"} attribute.
*
* @see DefaultRootLocator
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
+ * @deprecated use {@link org.apache.maven.api.services.model.RootLocator} instead
*/
@Deprecated(since = "4.0.0")
public interface RootLocator {
diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSupplier.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSupplier.java
index 17893aa6c9..9e5d004d21 100644
--- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSupplier.java
+++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSupplier.java
@@ -47,8 +47,8 @@ import org.apache.maven.internal.impl.model.DefaultPathTranslator;
import org.apache.maven.internal.impl.model.DefaultPluginManagementInjector;
import org.apache.maven.internal.impl.model.DefaultProfileInjector;
import org.apache.maven.internal.impl.model.DefaultProfileSelector;
-import org.apache.maven.internal.impl.model.DefaultRootLocator;
import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator;
+import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator;
import org.apache.maven.internal.impl.resolver.DefaultArtifactDescriptorReader;
import org.apache.maven.internal.impl.resolver.DefaultVersionRangeResolver;
import org.apache.maven.internal.impl.resolver.DefaultVersionResolver;