Skip to content

XPlugin Issue with Maven Build Cache Extension in IntelliJ #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -126,7 +127,7 @@ public class CacheControllerImpl implements CacheController {
private final LocalCacheRepository localCache;
private final RemoteCacheRepository remoteCache;
private final ConcurrentMap<String, CacheResult> cacheResults = new ConcurrentHashMap<>();
private final LifecyclePhasesHelper lifecyclePhasesHelper;
private final Provider<LifecyclePhasesHelper> providerLifecyclePhasesHelper;
private volatile Map<String, MavenProject> projectIndex;
private final ProjectInputCalculator projectInputCalculator;
private final RestoredArtifactHandler restoreArtifactHandler;
Expand All @@ -152,16 +153,15 @@ public CacheControllerImpl(
CacheConfig cacheConfig,
ProjectInputCalculator projectInputCalculator,
RestoredArtifactHandler restoreArtifactHandler,
LifecyclePhasesHelper lifecyclePhasesHelper,
MavenSession session) {
Provider<LifecyclePhasesHelper> providerLifecyclePhasesHelper) {
// CHECKSTYLE_OFF: ParameterNumber
this.projectHelper = projectHelper;
this.localCache = localCache;
this.remoteCache = remoteCache;
this.cacheConfig = cacheConfig;
this.artifactHandlerManager = artifactHandlerManager;
this.xmlService = xmlService;
this.lifecyclePhasesHelper = lifecyclePhasesHelper;
this.providerLifecyclePhasesHelper = providerLifecyclePhasesHelper;
this.projectInputCalculator = projectInputCalculator;
this.restoreArtifactHandler = restoreArtifactHandler;
}
Expand All @@ -170,6 +170,7 @@ public CacheControllerImpl(
@Nonnull
public CacheResult findCachedBuild(
MavenSession session, MavenProject project, List<MojoExecution> mojoExecutions, boolean skipCache) {
final LifecyclePhasesHelper lifecyclePhasesHelper = providerLifecyclePhasesHelper.get();
final String highestPhase = lifecyclePhasesHelper.resolveHighestLifecyclePhase(project, mojoExecutions);

if (!lifecyclePhasesHelper.isLaterPhaseThanClean(highestPhase)) {
Expand Down Expand Up @@ -256,6 +257,7 @@ private CacheResult analyzeResult(CacheContext context, List<MojoExecution> mojo
build.getCacheImplementationVersion());
}

final LifecyclePhasesHelper lifecyclePhasesHelper = providerLifecyclePhasesHelper.get();
List<MojoExecution> cachedSegment =
lifecyclePhasesHelper.getCachedSegment(context.getProject(), mojoExecutions, build);
List<MojoExecution> missingMojos = build.getMissingExecutions(cachedSegment);
Expand Down Expand Up @@ -295,6 +297,7 @@ private CacheResult analyzeResult(CacheContext context, List<MojoExecution> mojo
}

private boolean canIgnoreMissingSegment(MavenProject project, Build info, List<MojoExecution> mojoExecutions) {
final LifecyclePhasesHelper lifecyclePhasesHelper = providerLifecyclePhasesHelper.get();
final List<MojoExecution> postCachedSegment =
lifecyclePhasesHelper.getPostCachedSegment(project, mojoExecutions, info);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -58,21 +59,23 @@ public class DefaultMultiModuleSupport implements MultiModuleSupport {

private final ProjectBuilder projectBuilder;
private final CacheConfig cacheConfig;
private final MavenSession session;
private final Provider<MavenSession> providerSession;

private volatile boolean built;
private volatile Map<String, MavenProject> projectMap;
private volatile Map<String, MavenProject> sessionProjectMap;

@Inject
public DefaultMultiModuleSupport(ProjectBuilder projectBuilder, CacheConfig cacheConfig, MavenSession session) {
public DefaultMultiModuleSupport(
ProjectBuilder projectBuilder, CacheConfig cacheConfig, Provider<MavenSession> providerSession) {
this.projectBuilder = projectBuilder;
this.cacheConfig = cacheConfig;
this.session = session;
this.providerSession = providerSession;
}

@Override
public boolean isPartOfSession(String groupId, String artifactId, String version) {
MavenSession session = providerSession.get();
return getProjectMap(session).containsKey(KeyUtils.getProjectKey(groupId, artifactId, version));
}

Expand All @@ -85,6 +88,7 @@ public Optional<MavenProject> tryToResolveProject(String groupId, String artifac
@Override
public boolean isPartOfMultiModule(String groupId, String artifactId, String version) {
String projectKey = KeyUtils.getProjectKey(groupId, artifactId, version);
MavenSession session = providerSession.get();
return getProjectMap(session).containsKey(projectKey)
|| getMultiModuleProjectsMap().containsKey(projectKey);
}
Expand All @@ -102,6 +106,7 @@ private Map<String, MavenProject> getMultiModuleProjectsMap() {
if (projectMap != null) {
return projectMap;
}
MavenSession session = providerSession.get();
return getMultiModuleProjectsMapInner(session);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import java.util.LinkedHashSet;
import java.util.Set;
Expand All @@ -44,7 +45,7 @@ public class DefaultProjectInputCalculator implements ProjectInputCalculator {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultProjectInputCalculator.class);

private final MavenSession mavenSession;
private final Provider<MavenSession> providerSession;
private final RemoteCacheRepository remoteCache;
private final CacheConfig cacheConfig;
private final RepositorySystem repoSystem;
Expand All @@ -58,14 +59,14 @@ public class DefaultProjectInputCalculator implements ProjectInputCalculator {

@Inject
public DefaultProjectInputCalculator(
MavenSession mavenSession,
Provider<MavenSession> providerSession,
RemoteCacheRepository remoteCache,
CacheConfig cacheConfig,
RepositorySystem repoSystem,
NormalizedModelProvider rawModelProvider,
MultiModuleSupport multiModuleSupport,
ArtifactHandlerManager artifactHandlerManager) {
this.mavenSession = mavenSession;
this.providerSession = providerSession;
this.remoteCache = remoteCache;
this.cacheConfig = cacheConfig;
this.repoSystem = repoSystem;
Expand Down Expand Up @@ -104,6 +105,7 @@ private ProjectsInputInfo calculateInputInternal(String key, MavenProject projec
+ ", setOfCalculatingProjects=" + projectsSet + "]");
}
try {
final MavenSession mavenSession = providerSession.get();
final MavenProjectInput input = new MavenProjectInput(
project,
normalizedModelProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -114,7 +115,7 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon
private static final Logger LOGGER = LoggerFactory.getLogger(CacheConfigImpl.class);

private final XmlService xmlService;
private final MavenSession session;
private final Provider<MavenSession> providerSession;
private final RuntimeInformation rtInfo;

private volatile CacheState state;
Expand All @@ -123,9 +124,9 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon
private List<Pattern> excludePatterns;

@Inject
public CacheConfigImpl(XmlService xmlService, MavenSession session, RuntimeInformation rtInfo) {
public CacheConfigImpl(XmlService xmlService, Provider<MavenSession> providerSession, RuntimeInformation rtInfo) {
this.xmlService = xmlService;
this.session = session;
this.providerSession = providerSession;
this.rtInfo = rtInfo;
}

Expand All @@ -152,6 +153,7 @@ public CacheState initialize() {
if (StringUtils.isNotBlank(configPathText)) {
configPath = Paths.get(configPathText);
} else {
final MavenSession session = providerSession.get();
configPath =
getMultimoduleRoot(session).resolve(".mvn").resolve("maven-build-cache-config.xml");
}
Expand Down Expand Up @@ -634,6 +636,7 @@ private void checkInitializedState() {
}

private String getProperty(String key, String defaultValue) {
MavenSession session = providerSession.get();
String value = session.getUserProperties().getProperty(key);
if (value == null) {
value = session.getSystemProperties().getProperty(key);
Expand All @@ -645,6 +648,7 @@ private String getProperty(String key, String defaultValue) {
}

private boolean getProperty(String key, boolean defaultValue) {
MavenSession session = providerSession.get();
String value = session.getUserProperties().getProperty(key);
if (value == null) {
value = session.getSystemProperties().getProperty(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.buildcache.xml;

import javax.inject.Provider;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -110,8 +112,9 @@ void setUp() throws IOException {
testCacheConfig = new XmlService().loadCacheConfig("<cache></cache>".getBytes());
when(xmlService.loadCacheConfig(rootConfigFile)).thenReturn(testCacheConfig);

Provider<MavenSession> provider = (() -> mavenSession);
// test object
testObject = new CacheConfigImpl(xmlService, mavenSession, rtInfo);
testObject = new CacheConfigImpl(xmlService, provider, rtInfo);
}

private static void deepMockConfigFile(File mockFile, boolean exists) throws IOException {
Expand Down