[MNG-8108] Fix problem when building the consumer pom

This commit is contained in:
Guillaume Nodet 2024-05-13 18:34:29 +02:00
parent d296927de2
commit bde81a4d85
2 changed files with 19 additions and 26 deletions

View File

@ -66,7 +66,6 @@ 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;
@ -139,9 +138,6 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
@Inject
private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
@Inject
private ModelResolver modelResolver;
Logger logger = LoggerFactory.getLogger(getClass());
@Override
@ -205,8 +201,7 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
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.modelResolver(iSession.getData().get(SessionData.key(ModelResolver.class)));
request.transformerContextBuilder(modelBuilder.newTransformerContextBuilder());
request.systemProperties(session.getSystemProperties());
request.userProperties(session.getUserProperties());

View File

@ -282,6 +282,7 @@ public class DefaultProjectBuilder implements ProjectBuilder {
private final ModelTransformerContextBuilder transformerContextBuilder;
private final ExecutorService executor;
private final ModelCache modelCache;
private final ModelResolver modelResolver;
BuildSession(ProjectBuildingRequest request, boolean localProjects) {
this.request = request;
@ -299,6 +300,21 @@ public class DefaultProjectBuilder implements ProjectBuilder {
}
this.parentCache = new ConcurrentHashMap<>();
this.modelCache = DefaultModelCache.newInstance(session, true);
this.modelResolver = new ModelResolverWrapper() {
@Override
protected org.apache.maven.model.resolution.ModelResolver getResolver(
List<RemoteRepository> repositories) {
return new ProjectModelResolver(
session,
RequestTrace.newChild(null, request),
repoSystem,
repositoryManager,
repositories,
request.getRepositoryMerging(),
modelPool,
parentCache);
}
};
}
ExecutorService createExecutor(int parallelism) {
@ -1006,24 +1022,6 @@ public class DefaultProjectBuilder implements ProjectBuilder {
private ModelBuilderRequest.ModelBuilderRequestBuilder getModelBuildingRequest() {
ModelBuilderRequest.ModelBuilderRequestBuilder modelBuildingRequest = ModelBuilderRequest.builder();
RequestTrace trace = RequestTrace.newChild(null, request).newChild(modelBuildingRequest);
ModelResolver resolver = new ModelResolverWrapper() {
@Override
protected org.apache.maven.model.resolution.ModelResolver getResolver(
List<RemoteRepository> repositories) {
return new ProjectModelResolver(
session,
trace,
repoSystem,
repositoryManager,
repositories,
request.getRepositoryMerging(),
modelPool,
parentCache);
}
};
InternalSession internalSession = InternalSession.from(session);
modelBuildingRequest.session(internalSession.withRemoteRepositories(request.getRemoteRepositories().stream()
.map(r -> internalSession.getRemoteRepository(RepositoryUtils.toRepo(r)))
@ -1041,7 +1039,7 @@ public class DefaultProjectBuilder implements ProjectBuilder {
modelBuildingRequest.systemProperties(toMap(request.getSystemProperties()));
modelBuildingRequest.userProperties(toMap(request.getUserProperties()));
// bv4: modelBuildingRequest.setBuildStartTime(request.getBuildStartTime());
modelBuildingRequest.modelResolver(resolver);
modelBuildingRequest.modelResolver(modelResolver);
DefaultModelRepositoryHolder holder = new DefaultModelRepositoryHolder(
internalSession,
DefaultModelRepositoryHolder.RepositoryMerging.valueOf(
@ -1049,7 +1047,6 @@ public class DefaultProjectBuilder implements ProjectBuilder {
repositories.stream()
.map(internalSession::getRemoteRepository)
.toList());
internalSession.getData().set(SessionData.key(DefaultModelRepositoryHolder.class), holder);
modelBuildingRequest.modelRepositoryHolder(holder);
modelBuildingRequest.modelCache(modelCache);
modelBuildingRequest.transformerContextBuilder(transformerContextBuilder);
@ -1064,6 +1061,7 @@ public class DefaultProjectBuilder implements ProjectBuilder {
}
}
*/
internalSession.getData().set(SessionData.key(ModelResolver.class), modelResolver);
return modelBuildingRequest;
}