From f191c652f531073951ebc39d6f400ebc4ff381a8 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 7 Nov 2024 19:10:14 +0100 Subject: [PATCH] Restore ModelCacheFactory --- daemon/pom.xml | 5 ++++ .../maven/project/SnapshotModelCache.java | 9 ++++++-- .../project/SnapshotModelCacheFactory.java | 23 ++++++++----------- pom.xml | 5 ++++ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/daemon/pom.xml b/daemon/pom.xml index 7c07b30dc..959e14705 100644 --- a/daemon/pom.xml +++ b/daemon/pom.xml @@ -33,6 +33,7 @@ + full @@ -60,6 +61,10 @@ org.apache.maven maven-cli + + org.apache.maven + maven-api-di + org.codehaus.plexus plexus-interactivity-api diff --git a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java index e27bf76e8..0ab483af4 100644 --- a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java +++ b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java @@ -21,8 +21,8 @@ import java.util.Objects; import java.util.function.Supplier; -import org.apache.maven.building.Source; -import org.apache.maven.model.building.ModelCache; +import org.apache.maven.api.services.Source; +import org.apache.maven.api.services.model.ModelCache; public class SnapshotModelCache implements ModelCache { @@ -44,6 +44,11 @@ public T computeIfAbsent(Source path, String tag, Supplier data) { return reactorCache.computeIfAbsent(path, tag, data); } + @Override + public void clear() { + reactorCache.clear(); + } + private ModelCache getDelegate(String version) { return version.contains("SNAPSHOT") || version.contains("${") ? reactorCache : globalCache; } diff --git a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java index fe285af69..d276439f7 100644 --- a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java +++ b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java @@ -18,16 +18,13 @@ */ package org.apache.maven.project; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.model.building.ModelCache; -import org.apache.maven.repository.internal.DefaultModelCacheFactory; -import org.apache.maven.repository.internal.ModelCacheFactory; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.sisu.Priority; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.di.Named; +import org.apache.maven.api.di.Priority; +import org.apache.maven.api.di.Singleton; +import org.apache.maven.api.services.model.ModelCache; +import org.apache.maven.api.services.model.ModelCacheFactory; +import org.apache.maven.internal.impl.model.DefaultModelCacheFactory; import static org.mvndaemon.mvnd.common.Environment.MVND_NO_MODEL_CACHE; @@ -42,14 +39,14 @@ public class SnapshotModelCacheFactory implements ModelCacheFactory { @Inject public SnapshotModelCacheFactory(DefaultModelCacheFactory factory) { this.factory = factory; - this.globalCache = factory.createCache(new DefaultRepositorySystemSession()); + this.globalCache = factory.newInstance(); } @Override - public ModelCache createCache(RepositorySystemSession session) { + public ModelCache newInstance() { boolean noModelCache = Boolean.parseBoolean(MVND_NO_MODEL_CACHE.asOptional().orElse(MVND_NO_MODEL_CACHE.getDefault())); - ModelCache reactorCache = factory.createCache(session); + ModelCache reactorCache = factory.newInstance(); ModelCache globalCache = noModelCache ? reactorCache : this.globalCache; return new SnapshotModelCache(globalCache, reactorCache); } diff --git a/pom.xml b/pom.xml index da542bff8..f95870a13 100644 --- a/pom.xml +++ b/pom.xml @@ -178,6 +178,11 @@ maven-cli ${maven.version} + + org.apache.maven + maven-api-di + ${maven.version} + org.apache.maven maven-jline