Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-04-21 22:46:25 -0400
committerIgor Fedorenko2011-04-21 22:46:25 -0400
commit428e5a954fbb47adf47d862b8dfead7901c73288 (patch)
tree87233a8dcb451db032833b3d3bd9fb28328c3d84
parent4ab6896523ca6c2a6a8bc8563101fd1a023a991b (diff)
downloadm2e-core-428e5a954fbb47adf47d862b8dfead7901c73288.tar.gz
m2e-core-428e5a954fbb47adf47d862b8dfead7901c73288.tar.xz
m2e-core-428e5a954fbb47adf47d862b8dfead7901c73288.zip
Cleanup MavenUpdateRequest API class
Added some javadoc and renamed parameters to better describe what they do. events are fired by maven project import. Maven project import synchronously create project facades, so background refresh is redundant. Removed #force attribute and made related changes to DependencyResolutionContext and ProjectRegistryRefreshJob. Check for facade.isStale in resource change listener instead. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/DependencyResolutionContext.java9
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java7
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java15
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java59
4 files changed, 39 insertions, 51 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/DependencyResolutionContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/DependencyResolutionContext.java
index 54860fd5..e73ebfa2 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/DependencyResolutionContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/DependencyResolutionContext.java
@@ -11,7 +11,6 @@
package org.eclipse.m2e.core.internal.project;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -33,9 +32,6 @@ public class DependencyResolutionContext {
/** Set of all pom files to resolve */
private final Set<IFile> pomFiles = new LinkedHashSet<IFile>();
- /** Set of pom files to resolve regardless of their isStale() state */
- private final Set<IFile> forcedPomFiles = new HashSet<IFile>();
-
/** The template request for invocations of Maven */
private MavenExecutionRequest executionRequest;
@@ -51,7 +47,6 @@ public class DependencyResolutionContext {
public synchronized void forcePomFiles(Set<IFile> pomFiles) {
this.pomFiles.addAll(pomFiles);
- this.forcedPomFiles.addAll(pomFiles);
}
public MavenUpdateRequest getRequest() {
@@ -62,10 +57,6 @@ public class DependencyResolutionContext {
return executionRequest;
}
- public boolean isForce(IFile pom) {
- return request.isForce() || forcedPomFiles.contains(pom);
- }
-
public synchronized IFile pop() {
Iterator<IFile> i = pomFiles.iterator();
IFile pom = i.next();
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 ca7c9a95..f7ad01a2 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
@@ -353,11 +353,6 @@ public class ProjectRegistryManager {
if(pom.isAccessible() && pom.getProject().hasNature(IMavenConstants.NATURE_ID)) {
MavenProjectFacade oldFacade = newState.getProjectFacade(pom);
- if(!context.isForce(pom) && oldFacade != null && !oldFacade.isStale()) {
- // skip refresh if not forced and up-to-date facade
- continue;
- }
-
flushCaches(pom, oldFacade);
if(oldFacade != null) {
@@ -605,7 +600,7 @@ public class ProjectRegistryManager {
configureExecutionRequest(mavenRequest, state, pom, resolverConfiguration);
getMaven().populateDefaults(mavenRequest);
mavenRequest.setOffline(context.getRequest().isOffline());
- mavenRequest.setUpdateSnapshots(context.isForce(pom) && context.getRequest().isUpdateSnapshots());
+ mavenRequest.setUpdateSnapshots(context.getRequest().isForceDependencyUpdate());
return mavenRequest;
}
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 f043a1c2..b8e83f8e 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
@@ -39,6 +39,7 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChange
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.internal.Messages;
import org.eclipse.m2e.core.jobs.IBackgroundProcessingQueue;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenUpdateRequest;
public class ProjectRegistryRefreshJob extends Job implements IResourceChangeListener, IPreferenceChangeListener, IBackgroundProcessingQueue {
@@ -124,12 +125,12 @@ public class ProjectRegistryRefreshJob extends Job implements IResourceChangeLis
return;
}
boolean offline = mavenConfiguration.isOffline();
- boolean updateSnapshots = false;
+ boolean forceDependencyUpdate = false;
int type = event.getType();
if(IResourceChangeEvent.PRE_CLOSE == type || IResourceChangeEvent.PRE_DELETE == type) {
- queue(new MavenUpdateRequest((IProject) event.getResource(), offline, updateSnapshots));
+ queue(new MavenUpdateRequest((IProject) event.getResource(), offline, forceDependencyUpdate));
} else {
// if (IResourceChangeEvent.POST_CHANGE == type)
IResourceDelta delta = event.getDelta(); // workspace delta
@@ -137,14 +138,18 @@ public class ProjectRegistryRefreshJob extends Job implements IResourceChangeLis
Set<IProject> refreshProjects = new LinkedHashSet<IProject>();
for(int i = 0; i < projectDeltas.length; i++ ) {
if(projectChanged(projectDeltas[i])) {
- refreshProjects.add((IProject) projectDeltas[i].getResource());
+ IProject project = (IProject) projectDeltas[i].getResource();
+ IMavenProjectFacade facade = manager.getProject(project);
+ if(facade == null || facade.isStale()) {
+ // facade is up-to-date for resource change events fired right after project import
+ refreshProjects.add(project);
+ }
}
}
if(!refreshProjects.isEmpty()) {
IProject[] projects = refreshProjects.toArray(new IProject[refreshProjects.size()]);
- MavenUpdateRequest updateRequest = new MavenUpdateRequest(projects, offline, updateSnapshots);
- updateRequest.setForce(false);
+ MavenUpdateRequest updateRequest = new MavenUpdateRequest(projects, offline, forceDependencyUpdate);
queue(updateRequest);
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java
index 8f936f24..cef502eb 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java
@@ -19,34 +19,43 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.m2e.core.core.IMavenConstants;
+
/**
* Maven project update request
- *
+ *
* @author Eugene Kuleshov
*/
public class MavenUpdateRequest {
+
+ /**
+ * Put Maven repository system in offline mode. Same effect as -o mvn command line parameter.
+ */
private boolean offline = false;
- private boolean updateSnapshots = false;
- private boolean force = true;
-
+
+ /**
+ * Forces a check for updated releases and snapshots on remote repositories. Same effect as -U mvn command line
+ * parameter.
+ */
+ private boolean forceDependencyUpdate = false;
+
/**
* Set of {@link IFile}
*/
private final Set<IFile> pomFiles = new LinkedHashSet<IFile>();
- public MavenUpdateRequest(boolean offline, boolean updateSnapshots) {
+ public MavenUpdateRequest(boolean offline, boolean forceDependencyUpdate) {
this.offline = offline;
- this.updateSnapshots = updateSnapshots;
+ this.forceDependencyUpdate = forceDependencyUpdate;
}
-
+
public MavenUpdateRequest(IProject project, boolean offline, boolean updateSnapshots) {
this(offline, updateSnapshots);
addPomFile(project);
}
-
+
public MavenUpdateRequest(IProject[] projects, boolean offline, boolean updateSnapshots) {
this(offline, updateSnapshots);
-
+
for(int i = 0; i < projects.length; i++ ) {
addPomFile(projects[i]);
}
@@ -55,13 +64,13 @@ public class MavenUpdateRequest {
public boolean isOffline() {
return this.offline;
}
-
- public boolean isUpdateSnapshots() {
- return this.updateSnapshots;
+
+ public boolean isForceDependencyUpdate() {
+ return this.forceDependencyUpdate;
}
public void addPomFiles(Set<IFile> pomFiles) {
- for (IFile pomFile : pomFiles) {
+ for(IFile pomFile : pomFiles) {
addPomFile(pomFile);
}
}
@@ -69,16 +78,15 @@ public class MavenUpdateRequest {
public void addPomFile(IFile pomFile) {
pomFiles.add(pomFile);
}
-
+
public void addPomFile(IProject project) {
pomFiles.add(project.getFile(IMavenConstants.POM_FILE_NAME));
-
}
public void removePomFile(IFile pomFile) {
pomFiles.remove(pomFile);
}
-
+
/**
* Returns Set of {@link IFile}
*/
@@ -90,14 +98,6 @@ public class MavenUpdateRequest {
return this.pomFiles.isEmpty();
}
- public boolean isForce() {
- return force;
- }
-
- public void setForce(boolean force) {
- this.force = force;
- }
-
public String toString() {
StringBuilder sb = new StringBuilder("["); //$NON-NLS-1$
String sep = ""; //$NON-NLS-1$
@@ -107,17 +107,14 @@ public class MavenUpdateRequest {
sep = ", "; //$NON-NLS-1$
}
sb.append("]"); //$NON-NLS-1$
-
+
if(offline) {
sb.append(" offline"); //$NON-NLS-1$
}
- if(updateSnapshots) {
- sb.append(" updateSnapshots"); //$NON-NLS-1$
+ if(forceDependencyUpdate) {
+ sb.append(" forceDependencyUpdate"); //$NON-NLS-1$
}
- if(force) {
- sb.append(" force"); //$NON-NLS-1$
- }
-
+
return sb.toString();
}

Back to the top