Skip to content
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
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@
*/
package org.apache.maven.buildcache;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.Map;
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;
import org.apache.maven.project.MavenProject;
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
*/
Expand All @@ -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());
Expand All @@ -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
Expand Down