1818 */
1919package org .apache .maven .buildcache ;
2020
21+ import javax .inject .Inject ;
2122import javax .inject .Named ;
2223import javax .inject .Singleton ;
2324
2425import java .util .Map ;
2526import java .util .concurrent .ConcurrentHashMap ;
2627import java .util .concurrent .ConcurrentMap ;
2728
29+ import org .apache .maven .buildcache .checksum .MavenProjectInput ;
30+ import org .apache .maven .buildcache .xml .CacheConfig ;
31+ import org .apache .maven .buildcache .xml .CacheState ;
2832import org .apache .maven .execution .MojoExecutionEvent ;
2933import org .apache .maven .execution .MojoExecutionListener ;
3034import org .apache .maven .plugin .MojoExecutionException ;
3135import org .apache .maven .project .MavenProject ;
3236import org .slf4j .Logger ;
3337import org .slf4j .LoggerFactory ;
3438
39+ import static org .apache .maven .buildcache .xml .CacheState .DISABLED ;
40+ import static org .apache .maven .buildcache .xml .CacheState .INITIALIZED ;
41+
3542/**
3643 * MojoParametersListener
3744 */
@@ -45,6 +52,13 @@ public class MojoParametersListener implements MojoExecutionListener {
4552 private final ConcurrentMap <MavenProject , Map <String , MojoExecutionEvent >> projectExecutions =
4653 new ConcurrentHashMap <>();
4754
55+ private final CacheConfig cacheConfig ;
56+
57+ @ Inject
58+ public MojoParametersListener (CacheConfig cacheConfig ) {
59+ this .cacheConfig = cacheConfig ;
60+ }
61+
4862 @ Override
4963 public void beforeMojoExecution (MojoExecutionEvent event ) {
5064 final String executionKey = CacheUtils .mojoExecutionKey (event .getExecution ());
@@ -53,15 +67,23 @@ public void beforeMojoExecution(MojoExecutionEvent event) {
5367 executionKey ,
5468 event .getMojo ().getClass ());
5569 final MavenProject project = event .getProject ();
56- Map <String , MojoExecutionEvent > projectEvents = projectExecutions .get (project );
57- if (projectEvents == null ) {
58- Map <String , MojoExecutionEvent > candidate = new ConcurrentHashMap <>();
59- projectEvents = projectExecutions .putIfAbsent (project , candidate );
70+ CacheState cacheState = DISABLED ;
71+ boolean cacheIsDisabled = MavenProjectInput .isCacheDisabled (project );
72+ if (!cacheIsDisabled ) {
73+ cacheState = cacheConfig .initialize ();
74+ }
75+ LOGGER .debug ("cacheState: {}" , cacheState );
76+ if (cacheState == INITIALIZED ) {
77+ Map <String , MojoExecutionEvent > projectEvents = projectExecutions .get (project );
6078 if (projectEvents == null ) {
61- projectEvents = candidate ;
79+ Map <String , MojoExecutionEvent > candidate = new ConcurrentHashMap <>();
80+ projectEvents = projectExecutions .putIfAbsent (project , candidate );
81+ if (projectEvents == null ) {
82+ projectEvents = candidate ;
83+ }
6284 }
85+ projectEvents .put (executionKey , event );
6386 }
64- projectEvents .put (executionKey , event );
6587 }
6688
6789 @ Override
0 commit comments