From accbbcf5a05e85b8cbe94b1cc2f7e8e35ff7e368 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 16 May 2024 10:45:24 +0200 Subject: [PATCH] Fix packaging not found (#1507) * Fix packaging not found * Always keep Projects in cache --- .../org/apache/maven/internal/impl/DefaultProject.java | 8 +++++++- .../org/apache/maven/internal/impl/DefaultSession.java | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java index 103d5a8b86..b3281c8033 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java @@ -42,7 +42,13 @@ public class DefaultProject implements Project { public DefaultProject(InternalMavenSession session, MavenProject project) { this.session = session; this.project = project; - this.packaging = session.requirePackaging(project.getPackaging()); + ClassLoader ttcl = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(project.getClassRealm()); + this.packaging = session.requirePackaging(project.getPackaging()); + } finally { + Thread.currentThread().setContextClassLoader(ttcl); + } } public InternalMavenSession getSession() { diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSession.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSession.java index b848002ef3..1a923a9fe6 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSession.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSession.java @@ -21,6 +21,7 @@ package org.apache.maven.internal.impl; import java.nio.file.Path; import java.time.Instant; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import org.apache.maven.RepositoryUtils; import org.apache.maven.api.*; @@ -49,7 +50,7 @@ public class DefaultSession extends AbstractSession implements InternalMavenSess private final MavenSession mavenSession; private final MavenRepositorySystem mavenRepositorySystem; private final RuntimeInformation runtimeInformation; - private final Map allProjects = Collections.synchronizedMap(new WeakHashMap<>()); + private final Map allProjects = new ConcurrentHashMap<>(); @SuppressWarnings("checkstyle:ParameterNumber") public DefaultSession(