Search in sources :

Example 6 with IVirtualResource

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;
}
Also used : IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) IProject(org.eclipse.core.resources.IProject)

Example 7 with IVirtualResource

use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.

the class ModuleCoreSupportDelegate 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;
            // overlay?
            IVirtualResource member = rootFolder.findMember(runtimeReference);
            if (member != null) {
                return member.getWorkspaceRelativePath();
            }
        }
    }
    return null;
}
Also used : IVirtualReference(org.eclipse.wst.common.componentcore.resources.IVirtualReference) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource)

Example 8 with IVirtualResource

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IVirtualReference(org.eclipse.wst.common.componentcore.resources.IVirtualReference) Reference(java.lang.ref.Reference) SoftReference(java.lang.ref.SoftReference) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) IProject(org.eclipse.core.resources.IProject) IVirtualFile(org.eclipse.wst.common.componentcore.resources.IVirtualFile) SoftReference(java.lang.ref.SoftReference) IContainer(org.eclipse.core.resources.IContainer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with IVirtualResource

use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.

the class ModuleCoreSupportDelegate 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;
            // overlay?
            IVirtualResource member = rootFolder.findMember(runtimeReference);
            if (member != null) {
                return member.getWorkspaceRelativePath();
            }
        }
    }
    return null;
}
Also used : IVirtualReference(org.eclipse.wst.common.componentcore.resources.IVirtualReference) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource)

Example 10 with IVirtualResource

use of org.eclipse.wst.common.componentcore.resources.IVirtualResource in project webtools.sourceediting by eclipse.

the class FacetModuleCoreSupportDelegate 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;
}
Also used : IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) IProject(org.eclipse.core.resources.IProject)

Aggregations

IVirtualResource (org.eclipse.wst.common.componentcore.resources.IVirtualResource)17 IPath (org.eclipse.core.runtime.IPath)10 IVirtualFolder (org.eclipse.wst.common.componentcore.resources.IVirtualFolder)8 IResource (org.eclipse.core.resources.IResource)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 IProject (org.eclipse.core.resources.IProject)6 IFile (org.eclipse.core.resources.IFile)5 CoreException (org.eclipse.core.runtime.CoreException)5 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)5 IVirtualReference (org.eclipse.wst.common.componentcore.resources.IVirtualReference)5 File (java.io.File)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 List (java.util.List)4 IContainer (org.eclipse.core.resources.IContainer)4 IStatus (org.eclipse.core.runtime.IStatus)4 Path (org.eclipse.core.runtime.Path)4 Status (org.eclipse.core.runtime.Status)4 Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)4