Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-04-21 09:53:37 -0400
committerIgor Fedorenko2011-04-21 10:16:02 -0400
commit02d54276dd0bf9f477801cccfd452e15dc840106 (patch)
tree1cb9a40a4469e49b2985f1a26846f266390aceec
parent9790d5d92a1722d284263b90221f5a06b246a4a6 (diff)
downloadm2e-core-02d54276dd0bf9f477801cccfd452e15dc840106.tar.gz
m2e-core-02d54276dd0bf9f477801cccfd452e15dc840106.tar.xz
m2e-core-02d54276dd0bf9f477801cccfd452e15dc840106.zip
343526 - NPE in ProjectRegistryManager after workspace restart
Facade's mavenProject instance can be null when updating dependent projects not directly listed in original update request. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java9
-rw-r--r--org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java30
2 files changed, 33 insertions, 6 deletions
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 c1176704..e096f795 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
@@ -432,8 +432,13 @@ public class ProjectRegistryManager {
newFacade = newState.getProjectFacade(pom);
}
if(newFacade != null) {
- // loose any session state
- newFacade = new MavenProjectFacade(newFacade);
+ if(newFacade.getMavenProject() == null) {
+ // facade from workspace state that has not been refreshed yet
+ newFacade = readMavenProject(pom, context, newState, monitor);
+ } else {
+ // loose any session state
+ newFacade = new MavenProjectFacade(newFacade);
+ }
}
Set<Capability> capabilities = null;
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 1f238ff1..33842439 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
@@ -17,6 +17,8 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
@@ -396,17 +398,21 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
}
protected void copyContent(IProject project, String from, String to) throws Exception {
- copyContent(project, project.getFile(from).getContents(), to);
+ copyContent(project, project.getFile(from).getContents(), to, true);
+ }
+
+ protected void copyContent(IProject project, String from, String to, boolean waitForJobsToComplete) throws Exception {
+ copyContent(project, project.getFile(from).getContents(), to, waitForJobsToComplete);
}
protected void copyContent(IProject project, File from, String to) throws Exception {
- copyContent(project, new FileInputStream(from), to);
+ copyContent(project, new FileInputStream(from), to, true);
}
/**
* closes contents stream
*/
- private void copyContent(IProject project, InputStream contents, String to) throws CoreException, IOException,
+ private void copyContent(IProject project, InputStream contents, String to, boolean waitForJobsToComplete) throws CoreException, IOException,
InterruptedException {
try {
IFile file = project.getFile(to);
@@ -418,7 +424,9 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
} finally {
contents.close();
}
- waitForJobsToComplete();
+ if (waitForJobsToComplete) {
+ waitForJobsToComplete();
+ }
}
public static void copyDir(File src, File dst) throws IOException {
@@ -454,4 +462,18 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
container.addComponentDescriptor(descriptor);
}
}
+
+ /**
+ * Nullifies all transient IMavenProjectFacade fields, which should have roughly the same effect as writing it to
+ * workspace state and reading it back after workspace restart.
+ */
+ protected void deserializeFromWorkspaceState(final IMavenProjectFacade projectFacade) throws IllegalAccessException {
+ // pretend it was deserialized from workspace state
+ for(Field field : projectFacade.getClass().getDeclaredFields()) {
+ if(Modifier.isTransient(field.getModifiers())) {
+ field.setAccessible(true);
+ field.set(projectFacade, null);
+ }
+ }
+ }
}

Back to the top