Skip to content

Commit a9c9f67

Browse files
authored
[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
1 parent 3899336 commit a9c9f67

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,19 @@ under the License.
414414
</execution>
415415
</executions>
416416
</plugin>
417+
<!-- mvn sisu:main-index to generate META-INF/sisu/javax.inject.Named -->
418+
<plugin>
419+
<groupId>org.eclipse.sisu</groupId>
420+
<artifactId>sisu-maven-plugin</artifactId>
421+
<executions>
422+
<execution>
423+
<id>generate-index</id>
424+
<goals>
425+
<goal>main-index</goal>
426+
</goals>
427+
</execution>
428+
</executions>
429+
</plugin>
417430
</plugins>
418431
</build>
419432

src/main/java/org/apache/maven/buildcache/MojoParametersListener.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@
1818
*/
1919
package org.apache.maven.buildcache;
2020

21+
import javax.inject.Inject;
2122
import javax.inject.Named;
2223
import javax.inject.Singleton;
2324

2425
import java.util.Map;
2526
import java.util.concurrent.ConcurrentHashMap;
2627
import 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;
2832
import org.apache.maven.execution.MojoExecutionEvent;
2933
import org.apache.maven.execution.MojoExecutionListener;
3034
import org.apache.maven.plugin.MojoExecutionException;
3135
import org.apache.maven.project.MavenProject;
3236
import org.slf4j.Logger;
3337
import 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

Comments
 (0)