Skip to content

Commit

Permalink
[MNG-8279] The project local repository and project collectors are us…
Browse files Browse the repository at this point in the history
…ing maven.multiModuleProjectDirectory instead of rootDirectory
  • Loading branch information
gnodet committed Oct 2, 2024
1 parent f6417e4 commit 75e3c05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
7 changes: 3 additions & 4 deletions maven-core/src/main/java/org/apache/maven/ReactorReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ private boolean hasBeenPackagedDuringThisSession(MavenProject project) {
}

private Path relativizeOutputFile(final Path outputFile) {
Path projectBaseDirectory =
Paths.get(session.getRequest().getMultiModuleProjectDirectory().toURI());
return projectBaseDirectory.relativize(outputFile);
Path rootDirectory = session.getRequest().getRootDirectory();
return rootDirectory.relativize(outputFile);
}

/**
Expand Down Expand Up @@ -445,7 +444,7 @@ private Path getArtifactPath(Artifact artifact) {

private Path getProjectLocalRepo() {
if (projectLocalRepository == null) {
Path root = session.getRequest().getMultiModuleProjectDirectory().toPath();
Path root = session.getRequest().getRootDirectory();
List<MavenProject> projects = session.getProjects();
if (projects != null) {
projectLocalRepository = projects.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.inject.Singleton;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -61,7 +62,7 @@ public MultiModuleCollectionStrategy(ModelLocator modelLocator, ProjectsSelector

@Override
public List<MavenProject> collectProjects(MavenExecutionRequest request) throws ProjectBuildingException {
File moduleProjectPomFile = getMultiModuleProjectPomFile(request);
File moduleProjectPomFile = getRootProject(request);
List<File> files = Collections.singletonList(moduleProjectPomFile.getAbsoluteFile());
try {
List<MavenProject> projects = projectsSelector.selectProjects(files, request);
Expand Down Expand Up @@ -96,24 +97,24 @@ public List<MavenProject> collectProjects(MavenExecutionRequest request) throws
}
}

private File getMultiModuleProjectPomFile(MavenExecutionRequest request) {
File multiModuleProjectDirectory = request.getMultiModuleProjectDirectory();
if (request.getPom().getParentFile().equals(multiModuleProjectDirectory)) {
private File getRootProject(MavenExecutionRequest request) {
Path rootDirectory = request.getRootDirectory();
if (request.getPom().getParentFile().toPath().equals(rootDirectory)) {
return request.getPom();
} else {
File multiModuleProjectPom = modelLocator.locateExistingPom(multiModuleProjectDirectory);
if (multiModuleProjectPom == null) {
Path rootProjectPom = modelLocator.locateExistingPom(rootDirectory);
if (rootProjectPom == null) {
LOGGER.info(
"Maven detected that the requested POM file is part of a multi-module project, "
+ "but could not find a pom.xml file in the multi-module root directory '{}'.",
multiModuleProjectDirectory);
+ "but could not find a pom.xml file in the root directory '{}'.",
rootDirectory);
LOGGER.info(
"The reactor is limited to all projects under: {}",
request.getPom().getParent());
return request.getPom();
}

return multiModuleProjectPom;
return rootProjectPom.toFile();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ void before() throws Exception {
createProjectBuildingResultMocks(artifactIdProjectMap.values());
when(projectBuilder.build(anyList(), anyBoolean(), any(ProjectBuildingRequest.class)))
.thenReturn(projectBuildingResults);
when(mavenExecutionRequest.getRootDirectory()).thenReturn(null);
}

private MavenProject getMavenProject(String artifactId, MavenProject parentProject) {
Expand Down

0 comments on commit 75e3c05

Please sign in to comment.