[122107] Migration fixes and tests
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleMigratorManager.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleMigratorManager.java
index d3b341b..4f3dd35 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleMigratorManager.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleMigratorManager.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.wst.common.componentcore.internal;
+import java.util.HashMap;
import java.util.HashSet;
import org.eclipse.core.commands.ExecutionException;
@@ -34,16 +35,19 @@
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
public class ModuleMigratorManager {
- private static ModuleMigratorManager manager;
- private HashSet migrated = new HashSet();
+
+ private static HashMap managerCache = new HashMap();
+ private static HashSet migrated = new HashSet();
private boolean migrating;
private HashSet moved = new HashSet();
public ModuleMigratorManager() {
super();
}
- public static ModuleMigratorManager getManager() {
+ public static ModuleMigratorManager getManager(IProject proj) {
+ ModuleMigratorManager manager = (ModuleMigratorManager)managerCache.get(proj);
if (manager == null) {
manager = new ModuleMigratorManager();
+ managerCache.put(proj,manager);
}
return manager;
}
@@ -73,11 +77,10 @@
}
}
public synchronized void migrateOldMetaData(IProject aProject, final boolean multiComps) throws CoreException {
-
+ migrating = true;
IWorkspaceRunnableWithStatus workspaceRunnable = new IWorkspaceRunnableWithStatus(aProject) {
public void run(IProgressMonitor pm) throws CoreException {
IProject aProj = (IProject)this.getInfo();
- migrating = true;
try {
if (aProj.isAccessible() && ModuleCoreNature.isFlexibleProject(aProj)) {
if (aProj.findMember(".wtpmodules") != null) {
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java
index 03e86dc..9427d22 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java
@@ -96,7 +96,9 @@
*/
public EObject getPrimaryRootObject() {
try {
- prepareProjectModulesIfNecessary();
+ Resource res = prepareProjectModulesIfNecessary();
+ if (res == null)
+ return null;
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -171,17 +173,23 @@
}
public Resource prepareProjectModulesIfNecessary() throws CoreException {
- ModuleMigratorManager manager = ModuleMigratorManager.getManager();
+ ModuleMigratorManager manager = ModuleMigratorManager.getManager(getProject());
XMIResource res = (XMIResource) getPrimaryResource();
if (resNeedsMigrating(res)) {
try {
- if (!manager.isMigrating())
+ if (!manager.isMigrating() && !ResourcesPlugin.getWorkspace().isTreeLocked())
manager.migrateOldMetaData(getProject(),multiComps);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ } finally {
+ res = (XMIResource) getPrimaryResource();
+ if ((res == null) || (res != null && res.getContents().isEmpty())) {
+ if (res != null)
+ removeResource(res);
+ return null;
+ }
}
- res = (XMIResource) getPrimaryResource();
}
if(res == null)
res = makeWTPModulesResource();
@@ -196,7 +204,7 @@
multiComps = false;
if (project==null)
return false;
- boolean needsMigrating = (!project.hasNature(FacetedProjectNature.NATURE_ID)) || (res!=null && !res.isLoaded());
+ boolean needsMigrating = (!project.hasNature(FacetedProjectNature.NATURE_ID)); //|| (res!=null && !res.isLoaded() && ((WTPModulesResource)res).getRootObject() != null);
if (!needsMigrating) {
if (res != null && ((WTPModulesResource)res).getRootObject() != null) {
ProjectComponents components = (ProjectComponents) ((WTPModulesResource)res).getRootObject();
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java
index ebdf8fd..e6b15d4 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java
@@ -663,6 +663,7 @@
*/
public WorkbenchComponent findComponent(IPath aProjectRelativeResourcePath, int resourceFlag) throws UnresolveableURIException {
ProjectComponents projectModules = getComponentModelRoot();
+ if (projectModules == null) return null;
EList modules = projectModules.getComponents();
WorkbenchComponent module = null;
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
index 95e22ae..aad550e 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
@@ -146,6 +146,7 @@
if (core == null)
return props;
WorkbenchComponent component = core.getComponent();
+ if (component == null) return props;
List propList = component.getProperties();
if(propList != null) {
for (int i = 0; i < propList.size(); i++) {