Fix packaging not found (#1507)

* Fix packaging not found
* Always keep Projects in cache
This commit is contained in:
Guillaume Nodet 2024-05-16 10:45:24 +02:00 committed by GitHub
parent 71bb3bdf95
commit accbbcf5a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

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

View File

@ -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<String, Project> allProjects = Collections.synchronizedMap(new WeakHashMap<>());
private final Map<String, Project> allProjects = new ConcurrentHashMap<>();
@SuppressWarnings("checkstyle:ParameterNumber")
public DefaultSession(