Fix possible NPE during project building (#1759)

This commit is contained in:
Guillaume Nodet 2024-10-01 13:02:03 +02:00 committed by GitHub
parent 5207475361
commit 04f3609eb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 15 deletions

View File

@ -499,23 +499,30 @@ public class DefaultProjectBuilder implements ProjectBuilder {
List<ProjectBuildingResult> results = new ArrayList<>();
List<ModelBuilderResult> allModels = results(result).toList();
for (ModelBuilderResult r : allModels) {
File pom = r.getSource().getPath().toFile();
MavenProject project = projectIndex.get(r.getEffectiveModel().getId());
Path rootDirectory = rootLocator.findRoot(pom.getParentFile().toPath());
project.setRootDirectory(rootDirectory);
project.setFile(pom);
project.setExecutionRoot(pom.equals(pomFile));
initProject(project, r);
project.setCollectedProjects(results(r)
.filter(cr -> cr != r)
.map(cr -> projectIndex.get(cr.getEffectiveModel().getId()))
.collect(Collectors.toList()));
if (r.getEffectiveModel() != null) {
File pom = r.getSource().getPath().toFile();
MavenProject project =
projectIndex.get(r.getEffectiveModel().getId());
Path rootDirectory =
rootLocator.findRoot(pom.getParentFile().toPath());
project.setRootDirectory(rootDirectory);
project.setFile(pom);
project.setExecutionRoot(pom.equals(pomFile));
initProject(project, r);
project.setCollectedProjects(results(r)
.filter(cr -> cr != r)
.map(cr -> projectIndex.get(cr.getEffectiveModel().getId()))
.collect(Collectors.toList()));
DependencyResolutionResult resolutionResult = null;
if (request.isResolveDependencies()) {
resolutionResult = resolveDependencies(project);
DependencyResolutionResult resolutionResult = null;
if (request.isResolveDependencies()) {
resolutionResult = resolveDependencies(project);
}
results.add(
new DefaultProjectBuildingResult(project, convert(result.getProblems()), resolutionResult));
} else {
results.add(new DefaultProjectBuildingResult(null, convert(result.getProblems()), null));
}
results.add(new DefaultProjectBuildingResult(project, convert(result.getProblems()), resolutionResult));
}
return results;
}