Search in sources :

Example 16 with IVirtualFolder

use of org.eclipse.wst.common.componentcore.resources.IVirtualFolder 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 17 with IVirtualFolder

use of org.eclipse.wst.common.componentcore.resources.IVirtualFolder in project liferay-ide by liferay.

the class FlexibleProject method getDescriptorFile.

@Override
public IFile getDescriptorFile(String name) {
    IFile retval = null;
    IFolder defaultDocrootFolder = getDefaultDocrootFolder();
    if (FileUtil.exists(defaultDocrootFolder)) {
        retval = defaultDocrootFolder.getFile(new Path("WEB-INF").append(name));
    }
    if (retval != null) {
        return retval;
    }
    // fallback to looping through all virtual folders
    IVirtualFolder webappRoot = _getVirtualDocroot(getProject());
    if (webappRoot == null) {
        return retval;
    }
    for (IContainer container : webappRoot.getUnderlyingFolders()) {
        if (FileUtil.exists(container)) {
            IFile descriptorFile = container.getFile(new Path("WEB-INF").append(name));
            if (descriptorFile.exists()) {
                retval = descriptorFile;
                break;
            }
        }
    }
    return retval;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 18 with IVirtualFolder

use of org.eclipse.wst.common.componentcore.resources.IVirtualFolder in project liferay-ide by liferay.

the class FlexibleProject method findDocrootResource.

@Override
public IResource findDocrootResource(IPath path) {
    IVirtualFolder docroot = _getVirtualDocroot(getProject());
    if (docroot == null) {
        return null;
    }
    IVirtualResource virtualResource = docroot.findMember(path);
    if ((virtualResource == null) || !virtualResource.exists()) {
        return null;
    }
    for (IResource resource : virtualResource.getUnderlyingResources()) {
        if (FileUtil.exists(resource) && resource instanceof IFile) {
            return resource;
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) IResource(org.eclipse.core.resources.IResource)

Example 19 with IVirtualFolder

use of org.eclipse.wst.common.componentcore.resources.IVirtualFolder in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method getWebContentFolder.

public IFolder getWebContentFolder() {
    IVirtualComponent webComponent = ComponentCore.createComponent(getWebProject());
    IVirtualFolder webRootFolder = webComponent.getRootFolder();
    return (IFolder) webRootFolder.getUnderlyingFolder();
}
Also used : IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IVirtualFolder (org.eclipse.wst.common.componentcore.resources.IVirtualFolder)19 IPath (org.eclipse.core.runtime.IPath)14 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)12 IVirtualReference (org.eclipse.wst.common.componentcore.resources.IVirtualReference)8 IVirtualResource (org.eclipse.wst.common.componentcore.resources.IVirtualResource)8 IContainer (org.eclipse.core.resources.IContainer)7 Path (org.eclipse.core.runtime.Path)7 IFile (org.eclipse.core.resources.IFile)5 IFolder (org.eclipse.core.resources.IFolder)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IProject (org.eclipse.core.resources.IProject)3 IResource (org.eclipse.core.resources.IResource)3 IVirtualFile (org.eclipse.wst.common.componentcore.resources.IVirtualFile)3 Reference (java.lang.ref.Reference)2 SoftReference (java.lang.ref.SoftReference)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2