From 9442164ab2946aa76860d5b39c5246d82a99bace Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 13 May 2024 13:15:23 +0200 Subject: [PATCH] [MNG-8108] Fix problem when building the consumer pom (#1506) --- .../transformation/impl/DefaultConsumerPomBuilder.java | 6 +++++- .../org/apache/maven/project/DefaultProjectBuilder.java | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java b/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java index e5d60bcc67..c86f395f33 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.apache.maven.api.SessionData; import org.apache.maven.api.model.Dependency; import org.apache.maven.api.model.DependencyManagement; import org.apache.maven.api.model.DistributionManagement; @@ -65,6 +66,7 @@ import org.apache.maven.internal.impl.model.DefaultModelBuilder; import org.apache.maven.internal.impl.model.DefaultProfileSelector; import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator; import org.apache.maven.internal.impl.resolver.DefaultModelCache; +import org.apache.maven.internal.impl.resolver.DefaultModelRepositoryHolder; import org.apache.maven.model.v4.MavenModelVersion; import org.apache.maven.project.MavenProject; import org.eclipse.aether.RepositorySystem; @@ -196,13 +198,15 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder { profileActivationFilePathInterpolator, modelTransformer, versionParser); + InternalSession iSession = InternalSession.from(session); ModelBuilderRequest.ModelBuilderRequestBuilder request = ModelBuilderRequest.builder(); request.projectBuild(true); - request.session(InternalSession.from(session)); + request.session(iSession); request.source(ModelSource.fromPath(src)); request.validationLevel(ModelBuilderRequest.VALIDATION_LEVEL_MINIMAL); request.locationTracking(false); request.modelResolver(modelResolver); + request.modelRepositoryHolder(iSession.getData().get(SessionData.key(DefaultModelRepositoryHolder.class))); request.transformerContextBuilder(modelBuilder.newTransformerContextBuilder()); request.systemProperties(session.getSystemProperties()); request.userProperties(session.getUserProperties()); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 75bf08c9a5..eb4ccd71e8 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -40,6 +40,7 @@ import java.util.stream.Stream; import org.apache.maven.ProjectCycleException; import org.apache.maven.RepositoryUtils; import org.apache.maven.api.Session; +import org.apache.maven.api.SessionData; import org.apache.maven.api.feature.Features; import org.apache.maven.api.model.*; import org.apache.maven.api.services.ModelBuilder; @@ -1041,13 +1042,15 @@ public class DefaultProjectBuilder implements ProjectBuilder { modelBuildingRequest.userProperties(toMap(request.getUserProperties())); // bv4: modelBuildingRequest.setBuildStartTime(request.getBuildStartTime()); modelBuildingRequest.modelResolver(resolver); - modelBuildingRequest.modelRepositoryHolder(new DefaultModelRepositoryHolder( + DefaultModelRepositoryHolder holder = new DefaultModelRepositoryHolder( internalSession, DefaultModelRepositoryHolder.RepositoryMerging.valueOf( request.getRepositoryMerging().name()), repositories.stream() .map(internalSession::getRemoteRepository) - .toList())); + .toList()); + internalSession.getData().set(SessionData.key(DefaultModelRepositoryHolder.class), holder); + modelBuildingRequest.modelRepositoryHolder(holder); modelBuildingRequest.modelCache(modelCache); modelBuildingRequest.transformerContextBuilder(transformerContextBuilder); /* TODO: bv4