[MNG-8108] Fix problem when building the consumer pom (#1506)

This commit is contained in:
Guillaume Nodet 2024-05-13 13:15:23 +02:00 committed by GitHub
parent 583667a869
commit 9442164ab2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -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());

View File

@ -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