Skip to content

Commit

Permalink
Restore ModelCacheFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 8, 2024
1 parent 31c765e commit f191c65
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
5 changes: 5 additions & 0 deletions daemon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<properties>
<!-- If using release, sun.misc is not reachable (see SignalHelper) -->
<!-- <maven.compiler.release />-->
<maven.compiler.proc>full</maven.compiler.proc>
</properties>

<dependencies>
Expand Down Expand Up @@ -60,6 +61,10 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-cli</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-di</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interactivity-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -44,6 +44,11 @@ public <T> T computeIfAbsent(Source path, String tag, Supplier<T> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
<artifactId>maven-cli</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-di</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-jline</artifactId>
Expand Down

0 comments on commit f191c65

Please sign in to comment.