Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-04-16 00:01:54 -0400
committerIgor Fedorenko2011-04-16 00:01:54 -0400
commite7dc0e311794cc95cf4fe0c49cecb45e2b7ced86 (patch)
treea85f0cbd541f038b34ca8e27a7e45670700b908b
parentf3738a023734dc6375a03ec10933ea6c08cbdb7b (diff)
downloadm2e-core-e7dc0e311794cc95cf4fe0c49cecb45e2b7ced86.tar.gz
m2e-core-e7dc0e311794cc95cf4fe0c49cecb45e2b7ced86.tar.xz
m2e-core-e7dc0e311794cc95cf4fe0c49cecb45e2b7ced86.zip
342910 automatically refresh projects that depend on resolved artifacts
Changed ProjectRegistryManager to automatically refresh all workspace projects that depend on new/changed artifacts changed in the local repository. This should guarantee that the same external dependency is consistently resolved by all workspace projects that depend on it. Implementation uses ILocalRepositoryListener to recieve local repository event callbacks and should properly handle new SNAPSHOT versions, missing artifacts that become available and replaced RELEASE artifacts. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ILocalRepositoryListener.java7
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/EclipseRepositoryListener.java12
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java1
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/IndexingTransferListener.java2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java51
5 files changed, 59 insertions, 14 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ILocalRepositoryListener.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ILocalRepositoryListener.java
index 5a7d7211..e09e3c0b 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ILocalRepositoryListener.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ILocalRepositoryListener.java
@@ -13,11 +13,11 @@ package org.eclipse.m2e.core.embedder;
import java.io.File;
+
/**
* ILocalRepositoryListener
- *
- * @author igor
*
+ * @author igor
* @provisional This interface is provisional and can be changed or removed without notice
*/
public interface ILocalRepositoryListener {
@@ -25,5 +25,6 @@ public interface ILocalRepositoryListener {
/**
* New artifact has been downloaded or installed to maven local repository
*/
- public void artifactInstalled(File repositoryBasedir, ArtifactKey artifact, File artifactFile);
+ public void artifactInstalled(File repositoryBasedir, ArtifactKey baseArtifact, ArtifactKey artifact,
+ File artifactFile);
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/EclipseRepositoryListener.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/EclipseRepositoryListener.java
index adf309f2..1b44268a 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/EclipseRepositoryListener.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/EclipseRepositoryListener.java
@@ -47,12 +47,20 @@ public class EclipseRepositoryListener extends AbstractRepositoryListener implem
MavenImpl maven = (MavenImpl) MavenPlugin.getMaven();
Artifact artifact = event.getArtifact();
ArtifactKey key = new ArtifactKey(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
- artifact.getClassifier());
+ nes(artifact.getClassifier()));
+ ArtifactKey baseKey = new ArtifactKey(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(),
+ nes(artifact.getClassifier()));
File basedir = event.getSession().getLocalRepository().getBasedir();
for(ILocalRepositoryListener listener : maven.getLocalRepositoryListeners()) {
- listener.artifactInstalled(basedir, key, file);
+ listener.artifactInstalled(basedir, baseKey, key, file);
}
}
}
+ private static String nes(String str) {
+ if (str == null || str.trim().length() == 0) {
+ return null;
+ }
+ return str.trim();
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
index 4bc1e5e0..0001cd73 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
@@ -116,7 +116,6 @@ import org.apache.maven.project.ProjectSorter;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
-import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/IndexingTransferListener.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/IndexingTransferListener.java
index 538eeeed..31f6590e 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/IndexingTransferListener.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/IndexingTransferListener.java
@@ -24,7 +24,7 @@ public class IndexingTransferListener implements ILocalRepositoryListener {
this.indexManager = indexManager;
}
- public void artifactInstalled(File repositoryBasedir, ArtifactKey artifact, File artifactFile) {
+ public void artifactInstalled(File repositoryBasedir, ArtifactKey baseArtifact, ArtifactKey artifact, File artifactFile) {
NexusIndex localIndex = indexManager.getLocalIndex();
if(artifactFile.getName().endsWith(".jar")) { //$NON-NLS-1$
localIndex.addArtifact(artifactFile, artifact);
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 b51e26bd..c70e9595 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
@@ -43,7 +43,6 @@ import org.eclipse.osgi.util.NLS;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
@@ -62,6 +61,7 @@ import org.apache.maven.repository.DelegatingLocalArtifactRepository;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.embedder.ILocalRepositoryListener;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.internal.ExtensionReader;
@@ -86,7 +86,7 @@ import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
* provides mapping between Maven and the workspace.
*/
public class ProjectRegistryManager {
- private static final Logger log = LoggerFactory.getLogger(ProjectRegistryManager.class);
+ static final Logger log = LoggerFactory.getLogger(ProjectRegistryManager.class);
static final String ARTIFACT_TYPE_POM = "pom"; //$NON-NLS-1$
static final String ARTIFACT_TYPE_JAR = "jar"; //$NON-NLS-1$
@@ -286,14 +286,48 @@ public class ProjectRegistryManager {
}
}
- void refresh(MutableProjectRegistry newState, MavenUpdateRequest updateRequest, IProgressMonitor monitor) throws CoreException {
+ void refresh(final MutableProjectRegistry newState, MavenUpdateRequest updateRequest, IProgressMonitor monitor)
+ throws CoreException {
log.debug("Refreshing: {}", updateRequest.toString()); //$NON-NLS-1$
MavenExecutionRequest executionRequest = getMaven().createExecutionRequest(monitor);
- DependencyResolutionContext context = new DependencyResolutionContext(updateRequest, executionRequest);
-
- refresh(newState, context, monitor);
+ final DependencyResolutionContext context = new DependencyResolutionContext(updateRequest, executionRequest);
+
+ // safety net -- do not force refresh of the same installed/resolved artifact more than once
+ final Set<ArtifactKey> installedArtifacts = new HashSet<ArtifactKey>();
+
+ ILocalRepositoryListener listener = new ILocalRepositoryListener() {
+ public void artifactInstalled(File repositoryBasedir, ArtifactKey baseArtifact, ArtifactKey artifact,
+ File artifactFile) {
+ if(artifactFile == null) {
+ // resolution error
+ return;
+ }
+ // TODO remove=false?
+ Set<IFile> refresh = new LinkedHashSet<IFile>();
+ if(installedArtifacts.add(artifact)) {
+ refresh.addAll(newState.getDependents(MavenCapability.createMavenParent(artifact), true));
+ refresh.addAll(newState.getDependents(MavenCapability.createMavenArtifact(artifact), true));
+ }
+ if(installedArtifacts.add(baseArtifact)) {
+ refresh.addAll(newState.getDependents(MavenCapability.createMavenParent(baseArtifact), true));
+ refresh.addAll(newState.getDependents(MavenCapability.createMavenArtifact(baseArtifact), true));
+ }
+ if (!refresh.isEmpty()) {
+ log.debug("Automatic refresh. artifact={}/{}. projects={}", new Object[] {baseArtifact, artifact, refresh});
+ context.forcePomFiles(refresh);
+ }
+ }
+ };
+
+ maven.addLocalRepositoryListener(listener);
+ try {
+ refresh(newState, context, monitor);
+ } finally {
+ maven.removeLocalRepositoryListener(listener);
+ }
+
log.debug("Refreshed: {}", updateRequest.toString()); //$NON-NLS-1$
}
@@ -393,7 +427,10 @@ public class ProjectRegistryManager {
continue;
}
- MavenProjectFacade newFacade = newState.getProjectFacade(pom);
+ MavenProjectFacade newFacade = null;
+ if(pom.isAccessible() && pom.getProject().hasNature(IMavenConstants.NATURE_ID)) {
+ newFacade = newState.getProjectFacade(pom);
+ }
if(newFacade != null) {
// loose any session state
newFacade = new MavenProjectFacade(newFacade);

Back to the top