Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2013-04-10 18:12:18 -0400
committerIgor Fedorenko2013-06-16 12:54:18 -0400
commit561d6fbfd7c132dcdc29f4bd610aa2a590c498c7 (patch)
tree65b4c443c4f3a4d05737dc03c2c49f3b566216f8
parent83f6d238b62f35d5be5f4f58c01bd6af33ecef39 (diff)
downloadm2e-core-561d6fbfd7c132dcdc29f4bd610aa2a590c498c7.tar.gz
m2e-core-561d6fbfd7c132dcdc29f4bd610aa2a590c498c7.tar.xz
m2e-core-561d6fbfd7c132dcdc29f4bd610aa2a590c498c7.zip
Do not retain MavenProject instances forever
Before this change, MavenProject instances were eagerly loaded for each workspace Maven project are were retained for as long as the projects were opened. With this change, MavenProject instances are loaded on as needed basis and discarded when they are not needed any more. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java104
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java206
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java172
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java41
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java3
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java2
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java21
-rw-r--r--org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java15
-rw-r--r--org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java3
9 files changed, 355 insertions, 212 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
index 032153a2..95dc5637 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
@@ -14,7 +14,9 @@ package org.eclipse.m2e.core.internal.embedder;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.eclipse.core.runtime.CoreException;
@@ -32,7 +34,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.properties.internal.EnvironmentUtils;
-import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.transfer.TransferListener;
import org.eclipse.m2e.core.embedder.ICallable;
@@ -43,24 +44,30 @@ import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
* @since 1.4
*/
public class MavenExecutionContext implements IMavenExecutionContext {
- private static final ThreadLocal<Deque<MavenExecutionContext>> context = new ThreadLocal<Deque<MavenExecutionContext>>();
- private final MavenImpl maven;
+ private static final String CTX_PREFIX = MavenExecutionContext.class.getName();
- private MavenExecutionRequest request;
+ private static final String CTX_LOCALREPOSITORY = CTX_PREFIX + "/localRepository";
+
+ private static final String CTX_MAVENSESSION = CTX_PREFIX + "/mavenSession";
- private ArtifactRepository localRepository;
+ private static final String CTX_REPOSITORYSESSION = CTX_PREFIX + "/repositorySession";
- private FilterRepositorySystemSession repositorySession;
+ private static final ThreadLocal<Deque<MavenExecutionContext>> threadLocal = new ThreadLocal<Deque<MavenExecutionContext>>();
- private MavenSession mavenSession;
+ private final MavenImpl maven;
+
+ private MavenExecutionRequest request;
+
+ // TODO maybe delegate to parent context
+ private Map<String, Object> context;
public MavenExecutionContext(MavenImpl maven) {
this.maven = maven;
}
public MavenExecutionRequest getExecutionRequest() throws CoreException {
- if(request != null && mavenSession != null) {
+ if(request != null && context != null) {
return new ReadonlyMavenExecutionRequest(request);
}
if(request == null) {
@@ -71,7 +78,7 @@ public class MavenExecutionContext implements IMavenExecutionContext {
protected MavenExecutionRequest newExecutionRequest() throws CoreException {
MavenExecutionRequest request = null;
- Deque<MavenExecutionContext> stack = context.get();
+ Deque<MavenExecutionContext> stack = threadLocal.get();
if(stack != null && !stack.isEmpty()) {
MavenExecutionRequest parent = stack.peek().request;
if(parent == null) {
@@ -90,10 +97,10 @@ public class MavenExecutionContext implements IMavenExecutionContext {
}
public <V> V execute(MavenProject project, ICallable<V> callable, IProgressMonitor monitor) throws CoreException {
- Deque<MavenExecutionContext> stack = context.get();
+ Deque<MavenExecutionContext> stack = threadLocal.get();
if(stack == null) {
stack = new ArrayDeque<MavenExecutionContext>();
- context.set(stack);
+ threadLocal.set(stack);
}
final MavenExecutionContext parent = stack.peek();
@@ -103,52 +110,50 @@ public class MavenExecutionContext implements IMavenExecutionContext {
}
// remember original configuration to "pop" the session stack properly
- final ArtifactRepository origlocalRepository = localRepository;
- final FilterRepositorySystemSession origRepositorySession = repositorySession;
- final MavenSession origMavenSession = mavenSession;
final MavenExecutionRequest origRequest = request;
+ final Map<String, Object> origContext = context;
if(request == null && parent != null) {
this.request = parent.request;
- this.localRepository = parent.localRepository;
- this.repositorySession = parent.repositorySession;
- this.mavenSession = parent.mavenSession;
+ this.context = new HashMap<String, Object>(parent.context);
} else {
+ this.context = new HashMap<String, Object>();
if(request == null) {
request = newExecutionRequest();
}
maven.populateDefaults(request);
populateSystemProperties(request);
- this.localRepository = request.getLocalRepository();
- this.repositorySession = maven.createRepositorySession(request);
+ setValue(CTX_LOCALREPOSITORY, request.getLocalRepository());
+ final FilterRepositorySystemSession repositorySession = maven.createRepositorySession(request);
+ setValue(CTX_REPOSITORYSESSION, repositorySession);
if(parent != null) {
- this.repositorySession.setData(parent.repositorySession.getData());
+ repositorySession.setData(parent.getRepositorySession().getData());
}
final MavenExecutionResult result = new DefaultMavenExecutionResult();
- this.mavenSession = new MavenSession(maven.getPlexusContainer(), repositorySession, request, result);
+ setValue(CTX_MAVENSESSION, new MavenSession(maven.getPlexusContainer(), repositorySession, request, result));
}
final LegacySupport legacySupport = maven.lookup(LegacySupport.class);
final MavenSession origLegacySession = legacySupport.getSession(); // TODO validate == origSession
stack.push(this);
- legacySupport.setSession(mavenSession);
+ legacySupport.setSession(getSession());
try {
return executeBare(project, callable, monitor);
} finally {
stack.pop();
if(stack.isEmpty()) {
- context.set(null); // TODO decide if this is useful
+ threadLocal.set(null); // TODO decide if this is useful
}
legacySupport.setSession(origLegacySession);
- mavenSession = origMavenSession;
- repositorySession = origRepositorySession;
- localRepository = origlocalRepository;
request = origRequest;
+ context = origContext;
}
}
private <V> V executeBare(MavenProject project, ICallable<V> callable, IProgressMonitor monitor) throws CoreException {
+ final MavenSession mavenSession = getSession();
+ final FilterRepositorySystemSession repositorySession = getRepositorySession();
final TransferListener origTransferListener = repositorySession.setTransferListener(maven
.createArtifactTransferListener(monitor));
final MavenProject origProject = mavenSession.getCurrentProject();
@@ -169,29 +174,36 @@ public class MavenExecutionContext implements IMavenExecutionContext {
}
public MavenSession getSession() {
- if(mavenSession == null) {
+ if(context == null) {
throw new IllegalStateException();
}
- return mavenSession;
+ return getValue(CTX_MAVENSESSION);
}
public ArtifactRepository getLocalRepository() {
- if(mavenSession == null) {
+ if(context == null) {
throw new IllegalStateException();
}
- return localRepository;
+ return getValue(CTX_LOCALREPOSITORY);
}
- public RepositorySystemSession getRepositorySession() {
- if(mavenSession == null) {
+ public FilterRepositorySystemSession getRepositorySession() {
+ if(context == null) {
throw new IllegalStateException();
}
- return repositorySession;
+ return getValue(CTX_REPOSITORYSESSION);
}
public static MavenExecutionContext getThreadContext() {
- final Deque<MavenExecutionContext> stack = context.get();
- return stack != null ? stack.peek() : null;
+ return getThreadContext(true);
+ }
+
+ /**
+ * @since 1.5
+ */
+ public static MavenExecutionContext getThreadContext(boolean innermost) {
+ final Deque<MavenExecutionContext> stack = threadLocal.get();
+ return stack != null ? (innermost ? stack.peekFirst() : stack.peekLast()) : null;
}
public static void populateSystemProperties(MavenExecutionRequest request) {
@@ -233,8 +245,8 @@ public class MavenExecutionContext implements IMavenExecutionContext {
* @since 1.5
*/
public static Deque<MavenExecutionContext> suspend() {
- Deque<MavenExecutionContext> queue = context.get();
- context.set(null);
+ Deque<MavenExecutionContext> queue = threadLocal.get();
+ threadLocal.set(null);
return queue;
}
@@ -245,10 +257,24 @@ public class MavenExecutionContext implements IMavenExecutionContext {
* @since 1.5
*/
public static void resume(Deque<MavenExecutionContext> queue) {
- if(context.get() != null) {
+ if(threadLocal.get() != null) {
throw new IllegalStateException();
}
- context.set(queue);
+ threadLocal.set(queue);
+ }
+
+ /**
+ * @since 1.5
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getValue(String key) {
+ return (T) context.get(key);
}
+ /**
+ * @since 1.5
+ */
+ public <T> void setValue(String key, T value) {
+ context.put(key, value);
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java
index dfbce967..93d0879d 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java
@@ -14,7 +14,10 @@ package org.eclipse.m2e.core.internal.project.registry;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -25,12 +28,8 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
@@ -39,8 +38,6 @@ import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.ArtifactRef;
import org.eclipse.m2e.core.embedder.ArtifactRepositoryRef;
import org.eclipse.m2e.core.embedder.IMaven;
-import org.eclipse.m2e.core.internal.IMavenConstants;
-import org.eclipse.m2e.core.internal.Messages;
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenProjectUtils;
@@ -52,6 +49,10 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
private static final long serialVersionUID = -3648172776786224087L;
+ private static final String CTX_EXECUTION_PLANS = MavenProjectFacade.class.getName() + "/executionPlans";
+
+ private static final String CTX_SETUP_EXECUTIONS = MavenProjectFacade.class.getName() + "/setupExecutions";
+
public static final String PROP_LIFECYCLE_MAPPING = MavenProjectFacade.class.getName() + "/lifecycleMapping";
public static final String PROP_CONFIGURATORS = MavenProjectFacade.class.getName() + "/configurators";
@@ -62,20 +63,9 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
private final File pomFile;
- private transient MavenProject mavenProject;
-
- /**
- * Maps LIFECYCLE_* to corresponding mojo executions
- */
- private transient Map<String, List<MojoExecution>> executionPlans;
-
- private transient Map<MojoExecutionKey, MojoExecution> setupMojoExecutions;
-
- private transient Map<String, Object> sessionProperties;
-
private final ResolverConfiguration resolverConfiguration;
- private final long[] timestamp = new long[ProjectRegistryManager.METADATA_PATH.size() + 1];
+ private final long[] timestamp;
// cached values from mavenProject
private final ArtifactKey artifactKey;
@@ -100,24 +90,27 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
private final Set<ArtifactRepositoryRef> pluginArtifactRepositories;
+ // TODO make final
private Set<ArtifactRef> artifacts; // dependencies are resolved after facade instance is created
// lifecycle mapping
+
+ // TODO make final
private String lifecycleMappingId;
+ // TODO make final
private Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping;
+ private transient Map<String, Object> sessionProperties;
+
public MavenProjectFacade(ProjectRegistryManager manager, IFile pom, MavenProject mavenProject,
- Map<String, List<MojoExecution>> executionPlans, ResolverConfiguration resolverConfiguration) {
+ ResolverConfiguration resolverConfiguration) {
this.manager = manager;
this.pom = pom;
IPath location = pom.getLocation();
this.pomFile = location == null ? null : location.toFile(); // save pom file
this.resolverConfiguration = resolverConfiguration;
- this.mavenProject = mavenProject;
- this.executionPlans = executionPlans;
-
this.artifactKey = new ArtifactKey(mavenProject.getArtifact());
this.packaging = mavenProject.getPackaging();
this.modules = mavenProject.getModules();
@@ -147,16 +140,47 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
this.pluginArtifactRepositories.add(new ArtifactRepositoryRef(repository));
}
- setMavenProjectArtifacts();
-
- updateTimestamp();
+ timestamp = new long[ProjectRegistryManager.METADATA_PATH.size() + 1];
+ IProject project = getProject();
+ int i = 0;
+ for(IPath metadataPath : ProjectRegistryManager.METADATA_PATH) {
+ timestamp[i] = getModificationStamp(project.getFile(metadataPath));
+ i++ ;
+ }
+ timestamp[timestamp.length - 1] = getModificationStamp(pom);
}
/**
* Copy constructor. Does NOT preserve session state.
*/
public MavenProjectFacade(MavenProjectFacade other) {
- this(other.manager, other.pom, other.mavenProject, other.executionPlans, other.resolverConfiguration);
+ this.manager = other.manager;
+ this.pom = other.pom;
+ this.pomFile = other.pomFile;
+ this.resolverConfiguration = other.resolverConfiguration;
+
+ this.artifactKey = other.artifactKey;
+ this.packaging = other.packaging;
+ this.modules = new ArrayList<String>(other.modules);
+
+ this.resourceLocations = arrayCopy(other.resourceLocations);
+ this.testResourceLocations = arrayCopy(other.testResourceLocations);
+ this.compileSourceLocations = arrayCopy(other.compileSourceLocations);
+ this.testCompileSourceLocations = arrayCopy(other.testCompileSourceLocations);
+
+ this.outputLocation = other.outputLocation;
+
+ this.testOutputLocation = other.testOutputLocation;
+
+ this.artifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>(other.artifactRepositories);
+
+ this.pluginArtifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>(other.pluginArtifactRepositories);
+
+ this.timestamp = Arrays.copyOf(other.timestamp, other.timestamp.length);
+ }
+
+ private static <T> T[] arrayCopy(T[] a) {
+ return Arrays.copyOf(a, a.length);
}
/**
@@ -214,20 +238,12 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
/**
* Lazy load and cache MavenProject instance
*/
- public synchronized MavenProject getMavenProject(IProgressMonitor monitor) throws CoreException {
- if(mavenProject == null) {
- MavenExecutionResult result = manager.readProjectWithDependencies(pom, resolverConfiguration, monitor);
- mavenProject = result.getProject();
- if(mavenProject == null) {
- MultiStatus status = new MultiStatus(IMavenConstants.PLUGIN_ID, 0, Messages.MavenProjectFacade_error, null);
- List<Throwable> exceptions = result.getExceptions();
- for(Throwable e : exceptions) {
- status.add(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, e.getMessage(), e));
- }
- throw new CoreException(status);
- }
- }
- return mavenProject;
+ public MavenProject getMavenProject(IProgressMonitor monitor) throws CoreException {
+ return manager.getMavenProject(this, monitor);
+ }
+
+ public MavenProject getMavenProject() {
+ return manager.getMavenProject(this);
}
public String getPackaging() {
@@ -262,8 +278,8 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
return artifacts;
}
- void setMavenProjectArtifacts() {
- this.artifacts = ArtifactRef.fromArtifact(mavenProject.getArtifacts());
+ void setMavenProjectArtifacts(MavenProject mavenProject) {
+ this.artifacts = Collections.unmodifiableSet(ArtifactRef.fromArtifact(mavenProject.getArtifacts()));
}
public ResolverConfiguration getResolverConfiguration() {
@@ -285,16 +301,6 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
return false;
}
- private void updateTimestamp() {
- IProject project = getProject();
- int i = 0;
- for(IPath path : ProjectRegistryManager.METADATA_PATH) {
- timestamp[i] = getModificationStamp(project.getFile(path));
- i++ ;
- }
- timestamp[timestamp.length - 1] = getModificationStamp(pom);
- }
-
private static long getModificationStamp(IFile file) {
/*
* this implementation misses update in the following scenario
@@ -311,10 +317,6 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
return artifactKey;
}
- public MavenProject getMavenProject() {
- return mavenProject;
- }
-
public synchronized void setSessionProperty(String key, Object value) {
if(sessionProperties == null) {
sessionProperties = new HashMap<String, Object>();
@@ -339,23 +341,67 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
}
public String toString() {
- if(mavenProject == null) {
- return "Maven Project: null";
- }
- return mavenProject.toString();
+ StringBuilder sb = new StringBuilder();
+ sb.append(getProject().toString()).append(": ").append(getArtifactKey().toString());
+ return sb.toString();
}
public String getLifecycleMappingId() {
return lifecycleMappingId;
}
+ public void setLifecycleMappingId(String lifecycleMappingId) {
+ this.lifecycleMappingId = lifecycleMappingId;
+ }
+
public Map<MojoExecutionKey, List<IPluginExecutionMetadata>> getMojoExecutionMapping() {
return mojoExecutionMapping;
}
- public synchronized MojoExecution getMojoExecution(MojoExecutionKey mojoExecutionKey, IProgressMonitor monitor)
+ public void setMojoExecutionMapping(Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping) {
+ this.mojoExecutionMapping = mojoExecutionMapping;
+ }
+
+ // mojo executions
+
+ /**
+ * Maps LIFECYCLE_* to corresponding mojo executions. The mojo executions are not fully setup and cannot be executed
+ * directly.
+ */
+ private Map<String, List<MojoExecution>> getExecutionPlans(IProgressMonitor monitor) throws CoreException {
+ MavenProject mavenProject = getMavenProject(monitor);
+ Map<String, List<MojoExecution>> executionPlans = getContextValue(mavenProject, CTX_EXECUTION_PLANS);
+ if(executionPlans == null) {
+ executionPlans = manager.calculateExecutionPlans(pom, mavenProject, monitor);
+ mavenProject.setContextValue(CTX_EXECUTION_PLANS, executionPlans);
+ }
+ return executionPlans;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> T getContextValue(MavenProject mavenProject, String key) {
+ // XXX this is not thread safe, but needs to be fixed in maven, I can't fix this properly from m2e end
+ return (T) mavenProject.getContextValue(key);
+ }
+
+ /**
+ * Returns cache of fully setup MojoExecution instances. Lifespan of the cache is linked to the lifespan of
+ * MavenProject instance. The cache is initially empty and it is up to the callers to populate and maintain it.
+ */
+ private Map<MojoExecutionKey, MojoExecution> getSetupMojoExecutions(IProgressMonitor monitor) throws CoreException {
+ MavenProject mavenProject = getMavenProject(monitor);
+ Map<MojoExecutionKey, MojoExecution> executionPlans = getContextValue(mavenProject, CTX_SETUP_EXECUTIONS);
+ if(executionPlans == null) {
+ executionPlans = new LinkedHashMap<MojoExecutionKey, MojoExecution>();
+ mavenProject.setContextValue(CTX_SETUP_EXECUTIONS, executionPlans);
+ }
+ return executionPlans;
+ }
+
+ public MojoExecution getMojoExecution(MojoExecutionKey mojoExecutionKey, IProgressMonitor monitor)
throws CoreException {
- MojoExecution execution = setupMojoExecutions != null ? setupMojoExecutions.get(mojoExecutionKey) : null;
+ Map<MojoExecutionKey, MojoExecution> setupMojoExecutions = getSetupMojoExecutions(monitor);
+ MojoExecution execution = setupMojoExecutions.get(mojoExecutionKey);
if(execution == null) {
for(MojoExecution _execution : getMojoExecutions(monitor)) {
if(mojoExecutionKey.match(_execution)) {
@@ -363,22 +409,20 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
break;
}
}
- putSetupMojoExecution(mojoExecutionKey, execution);
+ putSetupMojoExecution(setupMojoExecutions, mojoExecutionKey, execution);
}
return execution;
}
- private void putSetupMojoExecution(MojoExecutionKey mojoExecutionKey, MojoExecution execution) {
+ private void putSetupMojoExecution(Map<MojoExecutionKey, MojoExecution> setupMojoExecutions,
+ MojoExecutionKey mojoExecutionKey, MojoExecution execution) {
if(execution != null) {
- if(setupMojoExecutions == null) {
- setupMojoExecutions = new HashMap<MojoExecutionKey, MojoExecution>();
- }
setupMojoExecutions.put(mojoExecutionKey, execution);
}
}
- public synchronized List<MojoExecution> getMojoExecutions(String groupId, String artifactId,
- IProgressMonitor monitor, String... goals) throws CoreException {
+ public List<MojoExecution> getMojoExecutions(String groupId, String artifactId, IProgressMonitor monitor,
+ String... goals) throws CoreException {
List<MojoExecution> result = new ArrayList<MojoExecution>();
List<MojoExecution> _executions = getMojoExecutions(monitor);
if(_executions != null) {
@@ -386,10 +430,11 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
if(groupId.equals(_execution.getGroupId()) && artifactId.equals(_execution.getArtifactId())
&& contains(goals, _execution.getGoal())) {
MojoExecutionKey _key = new MojoExecutionKey(_execution);
- MojoExecution execution = setupMojoExecutions != null ? setupMojoExecutions.get(_key) : null;
+ Map<MojoExecutionKey, MojoExecution> setupMojoExecutions = getSetupMojoExecutions(monitor);
+ MojoExecution execution = setupMojoExecutions.get(_key);
if(execution == null) {
execution = manager.setupMojoExecution(this, _execution, monitor);
- putSetupMojoExecution(_key, execution);
+ putSetupMojoExecution(setupMojoExecutions, _key, execution);
}
result.add(execution);
}
@@ -407,14 +452,6 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
return false;
}
- public void setLifecycleMappingId(String lifecycleMappingId) {
- this.lifecycleMappingId = lifecycleMappingId;
- }
-
- public void setMojoExecutionMapping(Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping) {
- this.mojoExecutionMapping = mojoExecutionMapping;
- }
-
/**
* Returns cached list of MojoExecutions bound to project's clean, default and site lifecycles. Returned
* MojoExecutions are not fully setup and {@link IMaven#setupMojoExecution(MavenSession, MavenProject, MojoExecution)}
@@ -452,15 +489,4 @@ public class MavenProjectFacade implements IMavenProjectFacade, Serializable {
Map<String, List<MojoExecution>> executionPlans = getExecutionPlans(monitor);
return executionPlans != null ? executionPlans.get(lifecycle) : null;
}
-
- private synchronized Map<String, List<MojoExecution>> getExecutionPlans(IProgressMonitor monitor)
- throws CoreException {
- if(executionPlans == null) {
- if(monitor == null) {
- return null;
- }
- executionPlans = manager.calculateExecutionPlans(this, monitor);
- }
- return executionPlans;
- }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
index 15152e99..320f1c33 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
@@ -18,6 +18,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -35,8 +36,11 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
@@ -48,7 +52,6 @@ import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
-import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@@ -66,6 +69,7 @@ import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
import org.eclipse.m2e.core.internal.ExtensionReader;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.Messages;
+import org.eclipse.m2e.core.internal.builder.MavenBuilder;
import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext;
import org.eclipse.m2e.core.internal.embedder.MavenImpl;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
@@ -117,6 +121,8 @@ public class ProjectRegistryManager {
new Path(".classpath"), // //$NON-NLS-1$
new Path(".settings/" + IMavenConstants.PLUGIN_ID + ".prefs")); // dirty trick! //$NON-NLS-1$ //$NON-NLS-2$
+ private static final String CTX_MAVENPROJECTS = ProjectRegistryManager.class.getName() + "/mavenProjects";
+
private final ProjectRegistry projectRegistry;
/*package*/final MavenImpl maven;
@@ -129,6 +135,11 @@ public class ProjectRegistryManager {
private volatile Thread syncRefreshThread;
+ /**
+ * Backwards compatibility with clients that request setup MojoExecution outside of {@link MavenBuilder} execution.
+ */
+ private final Map<MavenProjectFacade, MavenProject> legacyMavenProjects = new IdentityHashMap<MavenProjectFacade, MavenProject>();
+
public ProjectRegistryManager(MavenImpl maven, File stateLocationDir, boolean readState,
IMavenMarkerManager mavenMarkerManager) {
this.markerManager = mavenMarkerManager;
@@ -165,7 +176,7 @@ public class ProjectRegistryManager {
MavenExecutionResult executionResult = readProjectWithDependencies(projectRegistry, pom, configuration, monitor);
MavenProject mavenProject = executionResult.getProject();
if(mavenProject != null) {
- projectFacade = new MavenProjectFacade(this, pom, mavenProject, null, configuration);
+ projectFacade = new MavenProjectFacade(this, pom, mavenProject, configuration);
} else {
List<Throwable> exceptions = executionResult.getExceptions();
if(exceptions != null) {
@@ -241,7 +252,7 @@ public class ProjectRegistryManager {
if(facade != null) {
key = facade.getArtifactKey();
- project = facade.getMavenProject();
+ project = getMavenProject(facade); // cached only
}
try {
IManagedCache cache = (IManagedCache) maven.getPlexusContainer().lookup(MavenMetadataCache.class);
@@ -359,12 +370,13 @@ public class ProjectRegistryManager {
IFile pom = context.pop();
monitor.subTask(NLS.bind(Messages.ProjectRegistryManager_task_project, pom.getProject().getName()));
+ MavenProjectFacade oldFacade = newState.getProjectFacade(pom);
+ flushCaches(pom, oldFacade);
+ if(oldFacade != null) {
+ putMavenProject(oldFacade, null); // maintain maven project cache
+ }
MavenProjectFacade newFacade = null;
if(pom.isAccessible() && pom.getProject().hasNature(IMavenConstants.NATURE_ID)) {
- MavenProjectFacade oldFacade = newState.getProjectFacade(pom);
-
- flushCaches(pom, oldFacade);
-
if(oldFacade != null) {
// refresh old child modules
MavenCapability mavenParentCapability = MavenCapability.createMavenParent(oldFacade.getArtifactKey());
@@ -374,7 +386,6 @@ public class ProjectRegistryManager {
newFacade = readMavenProjectFacade(pom, context, newState, monitor);
} else {
// refresh children of deleted/closed parent
- MavenProjectFacade oldFacade = newState.getProjectFacade(pom);
if(oldFacade != null) {
MavenCapability mavenParentCapability = MavenCapability.createMavenParent(oldFacade.getArtifactKey());
context.forcePomFiles(newState.getDependents(mavenParentCapability, true));
@@ -397,7 +408,7 @@ public class ProjectRegistryManager {
}
Set<RequiredCapability> requirements = new LinkedHashSet<RequiredCapability>();
- DefaultMavenDependencyResolver.addParentRequirements(requirements, newFacade.getMavenProject());
+ DefaultMavenDependencyResolver.addParentRequirements(requirements, getMavenProject(newFacade));
Set<RequiredCapability> oldRequirements = newState.setRequirements(pom, requirements);
if(!originalRequirements.containsKey(pom)) {
originalRequirements.put(pom, oldRequirements);
@@ -435,18 +446,23 @@ public class ProjectRegistryManager {
newFacade = newState.getProjectFacade(pom);
}
if(newFacade != null) {
- if(newFacade.getMavenProject() == null) {
+ MavenProject mavenProject = getMavenProject(newFacade);
+ if(mavenProject == null) {
// facade from workspace state that has not been refreshed yet
newFacade = readMavenProjectFacade(pom, context, newState, monitor);
} else {
- // loose any session state
+ // recreate facade instance to trigger project changed event
+ // this is only necessary for facades that are refreshed because their dependencies changed
+ // but this is relatively cheap, so all facades are recreated here
+ putMavenProject(newFacade, null);
newFacade = new MavenProjectFacade(newFacade);
+ putMavenProject(newFacade, mavenProject);
}
}
if(newFacade != null) {
final MavenProjectFacade _newFacade = newFacade;
- final MavenProject mavenProject = newFacade.getMavenProject();
+ final MavenProject mavenProject = getMavenProject(newFacade);
final ResolverConfiguration resolverConfiguration = _newFacade.getResolverConfiguration();
final ICallable<Void> callable = new ICallable<Void>() {
public Void call(IMavenExecutionContext executionContext, IProgressMonitor monitor) throws CoreException {
@@ -483,7 +499,7 @@ public class ProjectRegistryManager {
capabilities.add(mavenParentCapability); // TODO consider packaging
// maven projects always have these requirements
- DefaultMavenDependencyResolver.addParentRequirements(requirements, newFacade.getMavenProject());
+ DefaultMavenDependencyResolver.addParentRequirements(requirements, getMavenProject(newFacade));
AbstractMavenDependencyResolver resolver = getMavenDependencyResolver(newFacade, monitor);
resolver.setContextProjectRegistry(newState);
@@ -496,7 +512,7 @@ public class ProjectRegistryManager {
newState.setProject(pom, newFacade);
- newFacade.setMavenProjectArtifacts();
+ newFacade.setMavenProjectArtifacts(getMavenProject(newFacade));
} else {
if(pom.isAccessible() && pom.getProject().hasNature(IMavenConstants.NATURE_ID)) {
try {
@@ -544,9 +560,9 @@ public class ProjectRegistryManager {
private void setupLifecycleMapping(MutableProjectRegistry newState, IProgressMonitor monitor,
MavenProjectFacade newFacade) throws CoreException {
- LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(newFacade
- .getMavenProject(), newFacade.getMojoExecutions(),
- newFacade.getResolverConfiguration().getLifecycleMappingId(), monitor);
+ LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(
+ getMavenProject(newFacade), newFacade.getMojoExecutions(), newFacade.getResolverConfiguration()
+ .getLifecycleMappingId(), monitor);
newFacade.setLifecycleMappingId(mappingResult.getLifecycleMappingId());
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping = mappingResult
@@ -631,7 +647,7 @@ public class ProjectRegistryManager {
}
private AbstractMavenDependencyResolver getMavenDependencyResolver(MavenProjectFacade newFacade,
- IProgressMonitor monitor) throws CoreException {
+ IProgressMonitor monitor) {
ILifecycleMapping lifecycleMapping = LifecycleMappingFactory.getLifecycleMapping(newFacade);
if(lifecycleMapping instanceof ILifecycleMapping2) {
@@ -668,19 +684,13 @@ public class ProjectRegistryManager {
// don't cache maven session
getMaven().detachFromSession(mavenProject);
- final MavenSession mavenSession = context.getSession();
- final MavenProject origCurrentProject = mavenSession.getCurrentProject();
- try {
- mavenSession.setCurrentProject(mavenProject);
- Map<String, List<MojoExecution>> executionPlans = calculateExecutionPlans(pom, mavenProject, monitor);
-
- // create and return new project facade
- MavenProjectFacade mavenProjectFacade = new MavenProjectFacade(ProjectRegistryManager.this, pom,
- mavenProject, executionPlans, resolverConfiguration);
- return mavenProjectFacade;
- } finally {
- mavenSession.setCurrentProject(origCurrentProject);
- }
+ // create and return new project facade
+ MavenProjectFacade mavenProjectFacade = new MavenProjectFacade(ProjectRegistryManager.this, pom, mavenProject,
+ resolverConfiguration);
+
+ putMavenProject(mavenProjectFacade, mavenProject); // maintain maven project cache
+
+ return mavenProjectFacade;
}
}, monitor);
}
@@ -875,20 +885,25 @@ public class ProjectRegistryManager {
return maven;
}
- public MojoExecution setupMojoExecution(MavenProjectFacade projectFacade, MojoExecution mojoExecution,
+ /*package*/MojoExecution setupMojoExecution(MavenProjectFacade projectFacade, MojoExecution mojoExecution,
IProgressMonitor monitor) throws CoreException {
- return maven.setupMojoExecution(projectFacade.getMavenProject(), mojoExecution, monitor);
- }
-
- public Map<String, List<MojoExecution>> calculateExecutionPlans(final MavenProjectFacade projectFacade,
- final IProgressMonitor monitor) throws CoreException {
- return execute(projectRegistry, projectFacade.getPom(), projectFacade.getResolverConfiguration(),
- new ICallable<Map<String, List<MojoExecution>>>() {
- public Map<String, List<MojoExecution>> call(IMavenExecutionContext context, IProgressMonitor monitor)
- throws CoreException {
- return calculateExecutionPlans(projectFacade.getPom(), projectFacade.getMavenProject(monitor), monitor);
- }
- }, monitor);
+ MavenProject mavenProject = null;
+ if(MavenExecutionContext.getThreadContext() == null) {
+ // the intent of this code is to provide backwards compatibility for clients that request setup MojoExecution
+ // outside of MavenBuilder context. Setup MojoExecutions are specific to MavenProject instances, so keep
+ // MavenProject until the facade is discarded
+ synchronized(legacyMavenProjects) {
+ mavenProject = legacyMavenProjects.get(projectFacade);
+ if(mavenProject == null) {
+ mavenProject = getMavenProject(projectFacade, monitor);
+ legacyMavenProjects.put(projectFacade, mavenProject);
+ }
+ }
+ }
+ if(mavenProject == null) {
+ mavenProject = getMavenProject(projectFacade, monitor);
+ }
+ return maven.setupMojoExecution(mavenProject, mojoExecution, monitor);
}
private <V> V execute(final IProjectRegistry state, final IFile pom,
@@ -908,4 +923,73 @@ public class ProjectRegistryManager {
throws CoreException {
return createExecutionContext(projectRegistry, pom, resolverConfiguration);
}
+
+ MavenProject getMavenProject(MavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
+ MavenProject mavenProject;
+ synchronized(legacyMavenProjects) {
+ mavenProject = legacyMavenProjects.get(facade);
+ }
+ if(mavenProject != null) {
+ return mavenProject;
+ }
+ Map<MavenProjectFacade, MavenProject> mavenProjects = getContextProjects();
+ mavenProject = mavenProjects.get(facade);
+ if(mavenProject == null) {
+ MavenExecutionResult result = readProjectWithDependencies(facade.getPom(), facade.getResolverConfiguration(),
+ monitor);
+ mavenProject = result.getProject();
+ if(mavenProject == null) {
+ MultiStatus status = new MultiStatus(IMavenConstants.PLUGIN_ID, 0, Messages.MavenProjectFacade_error, null);
+ List<Throwable> exceptions = result.getExceptions();
+ for(Throwable e : exceptions) {
+ status.add(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, e.getMessage(), e));
+ }
+ throw new CoreException(status);
+ }
+ mavenProjects.put(facade, mavenProject);
+ }
+ return mavenProject;
+ }
+
+ MavenProject getMavenProject(MavenProjectFacade facade) {
+ MavenProject mavenProject;
+ synchronized(legacyMavenProjects) {
+ mavenProject = legacyMavenProjects.get(facade);
+ }
+ if(mavenProject == null) {
+ mavenProject = getContextProjects().get(facade);
+ }
+ return mavenProject;
+ }
+
+ /**
+ * @noreference public for test purposes only
+ */
+ public void putMavenProject(MavenProjectFacade facade, MavenProject mavenProject) {
+ Map<MavenProjectFacade, MavenProject> mavenProjects = getContextProjects();
+ if(mavenProject != null) {
+ mavenProjects.put(facade, mavenProject);
+ } else {
+ mavenProjects.remove(facade);
+ synchronized(legacyMavenProjects) {
+ legacyMavenProjects.remove(facade);
+ }
+ }
+ }
+
+ Map<MavenProjectFacade, MavenProject> getContextProjects() {
+ Map<MavenProjectFacade, MavenProject> projects = null;
+ MavenExecutionContext context = MavenExecutionContext.getThreadContext(false);
+ if(context != null) {
+ projects = context.getValue(CTX_MAVENPROJECTS);
+ if(projects == null) {
+ projects = new IdentityHashMap<MavenProjectFacade, MavenProject>();
+ context.setValue(CTX_MAVENPROJECTS, projects);
+ }
+ }
+ if(projects == null) {
+ projects = new IdentityHashMap<MavenProjectFacade, MavenProject>();
+ }
+ return projects;
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java
index d52fc289..8a26f084 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java
@@ -74,7 +74,7 @@ public class ProjectRegistryRefreshJob extends Job implements IResourceChangeLis
public IStatus run(final IProgressMonitor monitor) {
monitor.beginTask(Messages.ProjectRegistryRefreshJob_task_refreshing, IProgressMonitor.UNKNOWN);
- ArrayList<MavenUpdateRequest> requests;
+ final ArrayList<MavenUpdateRequest> requests;
synchronized(this.queue) {
requests = new ArrayList<MavenUpdateRequest>(this.queue);
this.queue.clear();
@@ -83,25 +83,30 @@ public class ProjectRegistryRefreshJob extends Job implements IResourceChangeLis
try {
final MutableProjectRegistry newState = manager.newMutableProjectRegistry();
try {
- for(final MavenUpdateRequest request : requests) {
- if(monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- manager.getMaven().execute(request.isOffline(), request.isForceDependencyUpdate(), new ICallable<Void>() {
- public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
- manager.refresh(newState, request.getPomFiles(), monitor);
- return null;
+ manager.getMaven().execute(new ICallable<Void>() {
+ public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
+ for(final MavenUpdateRequest request : requests) {
+ if(monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ manager.getMaven().execute(request.isOffline(), request.isForceDependencyUpdate(), new ICallable<Void>() {
+ public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
+ manager.refresh(newState, request.getPomFiles(), monitor);
+ return null;
+ }
+ }, monitor);
}
- }, monitor);
- }
- ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
- getJobManager().beginRule(rule, monitor);
- try {
- manager.applyMutableProjectRegistry(newState, monitor);
- } finally {
- getJobManager().endRule(rule);
- }
+ ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
+ getJobManager().beginRule(rule, monitor);
+ try {
+ manager.applyMutableProjectRegistry(newState, monitor);
+ } finally {
+ getJobManager().endRule(rule);
+ }
+ return null;
+ }
+ }, monitor);
} finally {
newState.close();
}
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
index f3481c6f..c7935aad 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
@@ -1064,9 +1064,6 @@ public class MavenPomEditor extends FormEditor implements IResourceChangeListene
return pomFile;
}
- /**
- *
- */
private void reloadMavenProjectCache() {
//reload the cached MavenProject instance here.
Job jb = new Job("reload maven project") {
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
index 4ea415a2..012ad9db 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
@@ -316,7 +316,7 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
boolean downloadJavaDoc = desc.getJavadocUrl() == null && javaDocUrl == null
&& mavenConfiguration.isDownloadJavaDoc();
- scheduleDownload(facade.getProject(), facade.getMavenProject(), aKey, downloadSources, downloadJavaDoc);
+ scheduleDownload(facade.getProject(), facade.getMavenProject(monitor), aKey, downloadSources, downloadJavaDoc);
}
}
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java
index dac28f71..08f24256 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java
@@ -40,7 +40,9 @@ import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.embedder.ICallable;
import org.eclipse.m2e.core.embedder.IMaven;
+import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
import org.eclipse.m2e.core.internal.jobs.IBackgroundProcessingQueue;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
@@ -121,17 +123,28 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
}
public IStatus run(IProgressMonitor monitor) {
- ArrayList<DownloadRequest> downloadRequests;
+ final ArrayList<DownloadRequest> downloadRequests;
synchronized(this.queue) {
downloadRequests = new ArrayList<DownloadRequest>(this.queue);
this.queue.clear();
}
- ArrayList<IStatus> exceptions = new ArrayList<IStatus>();
+ try {
+ return maven.execute(new ICallable<IStatus>() {
+ public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) {
+ return run(downloadRequests, monitor);
+ }
+ }, monitor);
+ } catch(CoreException ex) {
+ return ex.getStatus();
+ }
+ }
- Set<IProject> mavenProjects = new LinkedHashSet<IProject>();
- Map<IPackageFragmentRoot, File[]> nonMavenProjects = new LinkedHashMap<IPackageFragmentRoot, File[]>();
+ IStatus run(ArrayList<DownloadRequest> downloadRequests, IProgressMonitor monitor) {
+ final ArrayList<IStatus> exceptions = new ArrayList<IStatus>();
+ final Set<IProject> mavenProjects = new LinkedHashSet<IProject>();
+ final Map<IPackageFragmentRoot, File[]> nonMavenProjects = new LinkedHashMap<IPackageFragmentRoot, File[]>();
for(DownloadRequest request : downloadRequests) {
try {
diff --git a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java
index b1a55dce..b6e5a123 100644
--- a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java
+++ b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java
@@ -16,8 +16,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -37,7 +35,6 @@ import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingResult;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource;
import org.eclipse.m2e.core.internal.project.registry.MavenProjectFacade;
-import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager;
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
@@ -47,6 +44,7 @@ import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
@SuppressWarnings("restriction")
+@RequireMavenExecutionContext
public abstract class AbstractLifecycleMappingTest extends AbstractMavenProjectTestCase {
protected IMavenProjectRegistry mavenProjectManager;
@@ -99,17 +97,8 @@ public abstract class AbstractLifecycleMappingTest extends AbstractMavenProjectT
*/
protected MavenProjectFacade newMavenProjectFacade(IFile pom) throws CoreException {
MavenProject mavenProject = MavenPlugin.getMaven().readProject(pom.getLocation().toFile(), monitor);
- Map<String, List<MojoExecution>> executionPlans = new LinkedHashMap<String, List<MojoExecution>>();
- executionPlans.put(ProjectRegistryManager.LIFECYCLE_CLEAN, new ArrayList<MojoExecution>());
- executionPlans.put(
- ProjectRegistryManager.LIFECYCLE_DEFAULT,
- MavenPlugin
- .getMaven()
- .calculateExecutionPlan(mavenProject, Arrays.asList(ProjectRegistryManager.LIFECYCLE_DEFAULT), false,
- monitor).getMojoExecutions());
- executionPlans.put(ProjectRegistryManager.LIFECYCLE_SITE, new ArrayList<MojoExecution>());
MavenProjectFacade facade = new MavenProjectFacade(MavenPluginActivator.getDefault().getMavenProjectManagerImpl(),
- pom, mavenProject, executionPlans, new ResolverConfiguration());
+ pom, mavenProject, new ResolverConfiguration());
return facade;
}
diff --git a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java
index 54bb2d00..6e56fec0 100644
--- a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java
+++ b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java
@@ -67,6 +67,7 @@ import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.embedder.AbstractRunnable;
import org.eclipse.m2e.core.internal.embedder.MavenImpl;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
+import org.eclipse.m2e.core.internal.project.registry.MavenProjectFacade;
import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectImportResult;
@@ -492,6 +493,8 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
field.set(projectFacade, null);
}
}
+ MavenPluginActivator.getDefault().getMavenProjectManagerImpl()
+ .putMavenProject((MavenProjectFacade) projectFacade, null);
}
@Override

Back to the top