This is an automated email from the ASF dual-hosted git repository. olamy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git
The following commit(s) were added to refs/heads/master by this push: new a9c9f67 [MBUILDCACHE-123] do not set projectExecutions if cacheState is disabled (#207) a9c9f67 is described below commit a9c9f67c009d213458b893c8d62d311d5a1bc821 Author: zrlw <z...@sina.com> AuthorDate: Fri Apr 25 09:50:50 2025 +0800 [MBUILDCACHE-123] do not set projectExecutions if cacheState is disabled (#207) * do not set projectExecutions if cacheState is disabled * add sisu-maven-plugin to generate javax.inject.Named --- pom.xml | 13 +++++++++ .../maven/buildcache/MojoParametersListener.java | 34 ++++++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index b42a1d7..9e38e12 100644 --- a/pom.xml +++ b/pom.xml @@ -414,6 +414,19 @@ under the License. </execution> </executions> </plugin> + <!-- mvn sisu:main-index to generate META-INF/sisu/javax.inject.Named --> + <plugin> + <groupId>org.eclipse.sisu</groupId> + <artifactId>sisu-maven-plugin</artifactId> + <executions> + <execution> + <id>generate-index</id> + <goals> + <goal>main-index</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> diff --git a/src/main/java/org/apache/maven/buildcache/MojoParametersListener.java b/src/main/java/org/apache/maven/buildcache/MojoParametersListener.java index 97036ba..edc0e22 100644 --- a/src/main/java/org/apache/maven/buildcache/MojoParametersListener.java +++ b/src/main/java/org/apache/maven/buildcache/MojoParametersListener.java @@ -18,6 +18,7 @@ */ package org.apache.maven.buildcache; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -25,6 +26,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.apache.maven.buildcache.checksum.MavenProjectInput; +import org.apache.maven.buildcache.xml.CacheConfig; +import org.apache.maven.buildcache.xml.CacheState; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.execution.MojoExecutionListener; import org.apache.maven.plugin.MojoExecutionException; @@ -32,6 +36,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.maven.buildcache.xml.CacheState.DISABLED; +import static org.apache.maven.buildcache.xml.CacheState.INITIALIZED; + /** * MojoParametersListener */ @@ -45,6 +52,13 @@ public class MojoParametersListener implements MojoExecutionListener { private final ConcurrentMap<MavenProject, Map<String, MojoExecutionEvent>> projectExecutions = new ConcurrentHashMap<>(); + private final CacheConfig cacheConfig; + + @Inject + public MojoParametersListener(CacheConfig cacheConfig) { + this.cacheConfig = cacheConfig; + } + @Override public void beforeMojoExecution(MojoExecutionEvent event) { final String executionKey = CacheUtils.mojoExecutionKey(event.getExecution()); @@ -53,15 +67,23 @@ public void beforeMojoExecution(MojoExecutionEvent event) { executionKey, event.getMojo().getClass()); final MavenProject project = event.getProject(); - Map<String, MojoExecutionEvent> projectEvents = projectExecutions.get(project); - if (projectEvents == null) { - Map<String, MojoExecutionEvent> candidate = new ConcurrentHashMap<>(); - projectEvents = projectExecutions.putIfAbsent(project, candidate); + CacheState cacheState = DISABLED; + boolean cacheIsDisabled = MavenProjectInput.isCacheDisabled(project); + if (!cacheIsDisabled) { + cacheState = cacheConfig.initialize(); + } + LOGGER.debug("cacheState: {}", cacheState); + if (cacheState == INITIALIZED) { + Map<String, MojoExecutionEvent> projectEvents = projectExecutions.get(project); if (projectEvents == null) { - projectEvents = candidate; + Map<String, MojoExecutionEvent> candidate = new ConcurrentHashMap<>(); + projectEvents = projectExecutions.putIfAbsent(project, candidate); + if (projectEvents == null) { + projectEvents = candidate; + } } + projectEvents.put(executionKey, event); } - projectEvents.put(executionKey, event); } @Override