From 65a68ce3247bf927124aecc87a3d203cdfca94db Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 13 May 2024 11:36:04 +0200 Subject: [PATCH] [MNG-8108] Fix problem when building the consumer pom --- .../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 e5d60bcc6756..c86f395f3390 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.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.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 @@ public List getActiveProfiles( 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 75bf08c9a5e1..eb4ccd71e8b6 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 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 @@ protected org.apache.maven.model.resolution.ModelResolver getResolver( 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