Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-04-21 13:53:37 +0000
committerIgor Fedorenko2011-04-21 14:16:02 +0000
commit02d54276dd0bf9f477801cccfd452e15dc840106 (patch)
tree1cb9a40a4469e49b2985f1a26846f266390aceec /org.eclipse.m2e.tests.common
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>
Diffstat (limited to 'org.eclipse.m2e.tests.common')
-rw-r--r--org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java30
1 files changed, 26 insertions, 4 deletions
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