use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.
the class FacetModuleCoreSupportDelegate method resolveInReferenced.
private static IPath resolveInReferenced(IProject project, IPath runtimeReference) {
IVirtualReference[] references = ComponentCore.createComponent(project).getReferences();
if (references != null) {
for (int i = 0; i < references.length; i++) {
IVirtualComponent referencedComponent = references[i].getReferencedComponent();
if (referencedComponent == null)
continue;
IVirtualComponent component = referencedComponent.getComponent();
if (component == null)
continue;
IVirtualFolder rootFolder = component.getRootFolder();
if (rootFolder == null)
continue;
IPath referencedPathRoot = rootFolder.getWorkspaceRelativePath();
/* http://bugs.eclipse.org/410161 */
if (referencedPathRoot != null) {
/*
* See Servlet 3.0, section 4.6, web fragments as required
* projects
*/
IPath resolved = referencedPathRoot.append(FacetModuleCoreSupport.META_INF_RESOURCES).append(runtimeReference);
if (resolved != null && component.getProject().findMember(resolved.removeFirstSegments(1)) != null) {
return resolved;
}
}
// overlay?
IVirtualResource member = rootFolder.findMember(runtimeReference);
if (member != null) {
return member.getWorkspaceRelativePath();
}
}
}
return null;
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.
the class ModuleCoreSupportDelegate method getRuntimePath.
/**
* @param path
* - the full path to a resource within the workspace
* @return - the runtime path of the resource if one exists, null
* otherwise
*/
static IPath getRuntimePath(IPath path) {
if (path == null)
return null;
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
if (!ModuleCoreNature.isFlexibleProject(project))
return null;
IVirtualResource[] virtualResources = ComponentCore.createResources(ResourcesPlugin.getWorkspace().getRoot().getFile(path));
if (virtualResources != null && virtualResources.length > 0) {
return virtualResources[0].getRuntimePath();
}
return null;
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.
the class FacetModuleCoreSupportDelegate method resolve.
/**
* @param basePath -
* the full path to a resource within the workspace
* @param reference -
* the reference string to resolve
* @return - the full path within the workspace that corresponds to the
* given reference according to the virtual pathing support
*/
static IPath resolve(IPath basePath, String reference) {
if (reference == null || basePath == null || basePath.segmentCount() == 0)
return null;
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(basePath.segment(0));
if (!ModuleCoreNature.isFlexibleProject(project))
return null;
if (basePath.segmentCount() > 1) {
IResource baseResource = ResourcesPlugin.getWorkspace().getRoot().findMember(basePath);
if (baseResource != null) {
IVirtualResource[] virtualResources = ComponentCore.createResources(baseResource);
for (int i = 0; i < virtualResources.length; i++) {
IPath referenceRuntimePath = null;
if (reference.startsWith(SLASH)) {
referenceRuntimePath = new Path(reference);
} else {
IPath baseRuntimePath = virtualResources[i].getRuntimePath();
referenceRuntimePath = baseRuntimePath.removeLastSegments(1).append(reference);
}
IVirtualFile virtualFile = ComponentCore.createFile(project, referenceRuntimePath);
if (virtualFile != null && virtualFile.exists()) {
IFile[] underlyingFiles = virtualFile.getUnderlyingFiles();
for (int j = 0; j < underlyingFiles.length; j++) {
if (underlyingFiles[j].isAccessible()) {
return underlyingFiles[j].getFullPath();
}
}
if (underlyingFiles.length > 0) {
return underlyingFiles[0].getFullPath();
}
} else {
// http://bugs.eclipse.org/338751
IVirtualFolder virtualFolder = ComponentCore.createFolder(project, referenceRuntimePath);
if (virtualFolder != null && virtualFolder.exists()) {
IContainer[] underlyingFolders = virtualFolder.getUnderlyingFolders();
for (int j = 0; j < underlyingFolders.length; j++) {
if (underlyingFolders[j].isAccessible()) {
return underlyingFolders[j].getFullPath();
}
}
if (underlyingFolders.length > 0) {
return underlyingFolders[0].getFullPath();
}
} else {
// check assembled projects
return resolveInReferenced(project, referenceRuntimePath);
}
}
}
}
} else {
IVirtualFile virtualFile = ComponentCore.createFile(project, new Path(reference));
if (virtualFile != null && virtualFile.exists()) {
return virtualFile.getUnderlyingFile().getFullPath();
}
}
return null;
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.
the class ComponentDeployable method getMembers.
protected IModuleResource[] getMembers(IVirtualContainer cont, IPath path) throws CoreException {
IVirtualResource[] res = cont.members();
int size2 = res.length;
List<IModuleFile> list = new ArrayList<IModuleFile>(size2);
for (int j = 0; j < size2; j++) {
if (res[j] instanceof IVirtualContainer) {
IVirtualContainer cc = (IVirtualContainer) res[j];
// Retrieve already existing module folder if applicable
ModuleFolder mf = (ModuleFolder) getExistingModuleResource(members, path.append(new Path(cc.getName()).makeRelative()));
if (mf == null) {
mf = new ModuleFolder((IContainer) cc.getUnderlyingResource(), cc.getName(), path);
ModuleFolder parent = (ModuleFolder) getExistingModuleResource(members, path);
if (path.isEmpty())
members.add(mf);
else {
if (parent == null)
parent = ensureParentExists(path, (IContainer) cc.getUnderlyingResource());
addMembersToModuleFolder(parent, new IModuleResource[] { mf });
}
}
IModuleResource[] mr = getMembers(cc, path.append(cc.getName()));
addMembersToModuleFolder(mf, mr);
} else {
IFile f = (IFile) res[j].getUnderlyingResource();
IModuleFile mf = null;
if (shouldAddComponentFile(f)) {
mf = createModuleFile(f, path);
list.add(mf);
}
}
}
IModuleResource[] mr = new IModuleResource[list.size()];
list.toArray(mr);
return mr;
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.
the class ModuleCoreSupportDelegate method resolve.
/**
* @param basePath
* - the full path to a resource within the workspace
* @param reference
* - the reference string to resolve
* @return - the full path within the workspace that corresponds to the
* given reference according to the virtual pathing support
*/
static IPath resolve(IPath basePath, String reference) {
if (reference == null || basePath == null || basePath.segmentCount() == 0)
return null;
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(basePath.segment(0));
if (!ModuleCoreNature.isFlexibleProject(project))
return null;
if (basePath.segmentCount() > 1) {
/*
* It can take the better part of a full second to do this, so
* cache the result.
*/
IPath resolved = null;
Map mapForBaseResource = null;
mapForBaseResource = (Map) fResolvedMap.get(basePath);
if (mapForBaseResource != null) {
Reference resolvedReference = (Reference) mapForBaseResource.get(reference);
if (resolvedReference != null)
resolved = (IPath) resolvedReference.get();
} else {
mapForBaseResource = new HashMap();
fResolvedMap.put(basePath, mapForBaseResource);
}
if (resolved == null) {
IFile baseFile = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath);
IVirtualResource[] virtualResources = ComponentCore.createResources(baseFile);
for (int i = 0; i < virtualResources.length; i++) {
IPath baseRuntimePath = virtualResources[i].getRuntimePath();
IPath referenceRuntimePath = null;
if (reference.startsWith(SLASH)) {
referenceRuntimePath = new Path(reference);
} else {
referenceRuntimePath = baseRuntimePath.removeLastSegments(1).append(reference);
}
IVirtualFile virtualFile = ComponentCore.createFile(project, referenceRuntimePath);
if (virtualFile != null && virtualFile.exists()) {
IFile[] underlyingFiles = virtualFile.getUnderlyingFiles();
for (int j = 0; j < underlyingFiles.length; j++) {
if (underlyingFiles[j].getProject().equals(project) && underlyingFiles[j].exists()) {
mapForBaseResource.put(reference, new SoftReference(underlyingFiles[j].getFullPath()));
resolved = underlyingFiles[j].getFullPath();
}
}
} else {
// http://bugs.eclipse.org/338751
IVirtualFolder virtualFolder = ComponentCore.createFolder(project, referenceRuntimePath);
if (virtualFolder != null && virtualFolder.exists()) {
IContainer[] underlyingFolders = virtualFolder.getUnderlyingFolders();
for (int j = 0; j < underlyingFolders.length; j++) {
if (underlyingFolders[j].getProject().equals(project) && underlyingFolders[j].isAccessible()) {
return underlyingFolders[j].getFullPath();
}
}
} else {
// check assembled projects
return resolveInReferenced(project, referenceRuntimePath);
}
}
}
}
return resolved;
} else {
IVirtualFile virtualFile = ComponentCore.createFile(project, new Path(reference));
if (virtualFile != null && virtualFile.exists()) {
return virtualFile.getUnderlyingFile().getFullPath();
}
}
return null;
}
Aggregations