[nobug] Fixing tests
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ArtifactEdit.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ArtifactEdit.java
index 20fb710..64e174a 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ArtifactEdit.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ArtifactEdit.java
@@ -422,6 +422,7 @@
*
* @param listener
* A non-null EditModelListener
+ *
*/
public void removeListener(EditModelListener listener) {
artifactEditModel.removeListener(listener);
@@ -466,16 +467,21 @@
/**
* @return The EMF command stack managed by the underlying editmodel
+ * @deprecated Use ((ArtifactEditModel)getAdapter(ArtifactEditModel.ADAPTER_TYPE)).getCommandStack()
*/
public CommandStack getCommandStack() {
return artifactEditModel.getCommandStack();
}
-
+ /**
+ *
+ * @deprecated Use ((ArtifactEditModel)getAdapter(ArtifactEditModel.ADAPTER_TYPE)).deleteResource(aResource);
+ */
public void deleteResource(Resource aResource) {
artifactEditModel.deleteResource(aResource);
}
/**
* @return The isDirty flag based the underlying editmodel's list of resources.
+ * @deprecated Use ((ArtifactEditModel)getAdapter(ArtifactEditModel.ADAPTER_TYPE)).isDirty()
*/
public boolean isDirty() {
return artifactEditModel.isDirty();
@@ -492,6 +498,7 @@
/**
* Force all of the known resource URIs to be loaded
* if they are not already.
+ * @deprecated Use ((ArtifactEditModel)getAdapter(ArtifactEditModel.ADAPTER_TYPE)).forceLoadKnownResources();
*/
public void forceLoadKnownResources() {
List uris = getArtifactEditModel().getKnownResourceUris();
@@ -504,6 +511,7 @@
/**
* Return a Resource for @aUri.
+ * @deprecated Use ((ArtifactEditModel)getAdapter(ArtifactEditModel.ADAPTER_TYPE)).getResource(aResource);
*/
public Resource getResource(URI aUri) {
return getArtifactEditModel().getResource(aUri);
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 73d6de5..ea6aae1 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
@@ -9,9 +9,11 @@
package org.eclipse.wst.common.componentcore.internal;
import java.io.IOException;
+import java.util.Collections;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMIResource;
@@ -66,6 +68,15 @@
aResource.releaseFromWrite();
}
+ protected boolean removeResource(Resource aResource) {
+ if (aResource != null) {
+ synchronized (aResource) {
+ aResource.eAdapters().remove(resourceAdapter);
+ return getResources().remove(aResource);
+ }
+ }
+ return false;
+ }
/* (non-Javadoc)
* @see org.eclipse.wst.common.internal.emfworkbench.integration.EditModel#getPrimaryRootObject()
@@ -112,4 +123,20 @@
}
}
}
+ protected Resource getAndLoadLocalResource(URI aUri) {
+
+ Resource resource = getLocalResource(aUri);
+ if (null != resource) {
+ synchronized (resource) {
+ if (!resource.isLoaded()) {
+ try {
+ resource.load(Collections.EMPTY_MAP); // reload it
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ return resource;
+ }
}
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 cb2f1b3..76a5f51 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
@@ -522,7 +522,7 @@
public WorkbenchComponent[] getWorkbenchModules() {
ProjectComponents pc = getComponentModelRoot();
if(pc != null) {
- List wbModules = getComponentModelRoot().getComponents();
+ List wbModules = pc.getComponents();
return (WorkbenchComponent[]) wbModules.toArray(new WorkbenchComponent[wbModules.size()]);
}
return NO_COMPONENTS;
@@ -695,6 +695,48 @@
}
/**
* <p>
+ * Locates the {@see WorkbenchComponent}s that contains the resource with the given source
+ * path. There are no representations about the containment of the {@see ComponentResource}s
+ * which are returned. The only guarantee is that the returned elements are contained within the
+ * same project.
+ * </p>
+ * <p>
+ * The sourcePath of each {@see ComponentResource} will be mapped to either an IFile or an
+ * IFolder. As a result, if the {@see ComponentResource} is a container mapping, the path
+ * of the supplied resource may not be identical the sourcePath of the {@see ComponentResource}.
+ * </p>
+ *
+ * @param aProjectRelativePath
+ * A valid project-relative path of a given resource
+ * resourceFlag
+ * A bit flag that determines if Resources should be created during the search
+ * CREATE_NONE
+ * CREATE_RESOURCE_ALWAYS
+ * CREATE_TREENODE_IFNEC
+ * @return An array of WorkbenchModuleResources which have sourcePaths that contain the given
+ * resource
+ * @throws UnresolveableURIException
+ * If the supplied module URI is invalid or unresolveable.
+ */
+ public WorkbenchComponent findComponent(IPath aProjectRelativeResourcePath, int resourceFlag) throws UnresolveableURIException {
+ ProjectComponents projectModules = getComponentModelRoot();
+ EList modules = projectModules.getComponents();
+
+ WorkbenchComponent module = null;
+ boolean resourceExists = false;
+ for (int i = 0; i < modules.size(); i++) {
+ module = (WorkbenchComponent) modules.get(i);
+ resourceExists = module.exists(aProjectRelativeResourcePath,resourceFlag);
+ if (!resourceExists && aProjectRelativeResourcePath.segments().length > 1) {
+ resourceExists = module.exists(aProjectRelativeResourcePath.removeFirstSegments(1),resourceFlag);
+ }
+ if (resourceExists)
+ return module;
+ }
+ return null;
+ }
+ /**
+ * <p>
* Locates the {@see ComponentResource}s that contain the supplied resource in their source
* path. There are no representations about the containment of the {@see ComponentResource}s
* which are returned. The only guarantee is that the returned elements are contained within the
@@ -708,6 +750,11 @@
*
* @param aProjectRelativePath
* A valid project-relative path of a given resource
+ * resourceFlag
+ * A bit flag that determines if Resources should be created during the search
+ * CREATE_NONE
+ * CREATE_RESOURCE_ALWAYS
+ * CREATE_TREENODE_IFNEC
* @return An array of WorkbenchModuleResources which have sourcePaths that contain the given
* resource
* @throws UnresolveableURIException
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/WorkbenchComponent.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/WorkbenchComponent.java
index 3690268..ff2e0d1 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/WorkbenchComponent.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/WorkbenchComponent.java
@@ -128,5 +128,7 @@
ComponentResource[] findResourcesByRuntimePath(IPath aDeployPath);
ComponentResource[] findResourcesBySourcePath(IPath aSourcePath, int resourceFlag);
+
+ boolean exists(IPath aSourcePath, int resourceFlag);
} // WorkbenchComponent
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/ResourceTreeNode.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/ResourceTreeNode.java
index 2bbdd3a..aee3e3e 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/ResourceTreeNode.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/ResourceTreeNode.java
@@ -142,6 +142,19 @@
return NO_MODULE_RESOURCES;
return (ComponentResource[]) foundModuleResources.toArray(new ComponentResource[foundModuleResources.size()]);
}
+ public boolean exists(IPath aPath, int creationFlags) {
+
+ Set foundModuleResources = findModuleResourcesSet(aPath, aPath, creationFlags);
+ if (foundModuleResources.size() == 0) {
+ if (true) {
+ ResourceTreeNode child = findChild(aPath.segment(0), creationFlags);
+ if (child != null)
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
public boolean hasModuleResources() {
return moduleResources.size() > 0;
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/WorkbenchComponentImpl.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/WorkbenchComponentImpl.java
index f5a54fc..a26578b 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/WorkbenchComponentImpl.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/WorkbenchComponentImpl.java
@@ -2,7 +2,7 @@
* <copyright>
* </copyright>
*
- * $Id: WorkbenchComponentImpl.java,v 1.3 2005/05/18 03:02:06 cbridgha Exp $
+ * $Id: WorkbenchComponentImpl.java,v 1.4 2005/08/29 21:10:14 cbridgha Exp $
*/
package org.eclipse.wst.common.componentcore.internal.impl;
@@ -376,6 +376,10 @@
ResourceTreeRoot resourceTreeRoot = ResourceTreeRoot.getSourceResourceTreeRoot(this);
return resourceTreeRoot.findModuleResources(aSourcePath, resourceFlag);
}
+ public boolean exists(IPath aSourcePath, int resourceFlag) {
+ ResourceTreeRoot resourceTreeRoot = ResourceTreeRoot.getSourceResourceTreeRoot(this);
+ return resourceTreeRoot.exists(aSourcePath, resourceFlag);
+ }
} // WorkbenchComponentImpl
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ModuleCoreEclipseAdapterFactory.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ModuleCoreEclipseAdapterFactory.java
index d668a9f..05ff7ae 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ModuleCoreEclipseAdapterFactory.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ModuleCoreEclipseAdapterFactory.java
@@ -14,10 +14,10 @@
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.UnresolveableURIException;
-import org.eclipse.wst.common.componentcore.internal.ComponentResource;
import org.eclipse.wst.common.componentcore.internal.ModuleStructuralModel;
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent;
+import org.eclipse.wst.common.componentcore.internal.impl.ResourceTreeNode;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
/**
@@ -49,23 +49,14 @@
if (!resource.exists()) return null;
try {
moduleCore = StructureEdit.getStructureEditForRead(resource.getProject());
- if (moduleCore.getWorkbenchModules().length == 1)
- module = moduleCore.getWorkbenchModules()[0];
- else {
- ComponentResource[] resources = moduleCore.findResourcesBySourcePath(resource.getFullPath());
- for (int i = 0; i < resources.length; i++) {
- module = resources[i].getComponent();
- if (module != null)
- break;
- }
- }
+ module = moduleCore.findComponent(resource.getFullPath(),ResourceTreeNode.CREATE_NONE);
} catch (UnresolveableURIException e) {
// Ignore
} finally {
if (moduleCore != null)
moduleCore.dispose();
}
- return ComponentCore.createComponent(resource.getProject(), module.getName());
+ return module == null ? null : ComponentCore.createComponent(resource.getProject(), module.getName());
}
/* (non-Javadoc)