Search in sources :

Example 1 with IVirtualFile

use of org.eclipse.wst.common.componentcore.resources.IVirtualFile in project webtools.servertools by eclipse.

the class TomcatPublishModuleVisitor method getProjectContextXml.

/**
 * Load a META-INF/context.xml file from project, if available
 *
 * @param component web component containing the context.xml
 * @return context element containing the context.xml
 * @throws CoreException
 */
protected Context getProjectContextXml(IVirtualComponent component) throws CoreException {
    // load or create module's context.xml document
    IVirtualFile contextFile = (IVirtualFile) component.getRootFolder().findMember("META-INF/context.xml");
    Context contextElement = null;
    if (contextFile != null && contextFile.exists()) {
        Factory factory = new Factory();
        factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        InputStream fis = null;
        try {
            fis = contextFile.getUnderlyingFile().getContents();
            contextElement = (Context) factory.loadDocument(fis);
        } catch (Exception e) {
            Trace.trace(Trace.SEVERE, "Exception reading " + contextFile, e);
        } finally {
            try {
                fis.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
    return contextElement;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) IVirtualFile(org.eclipse.wst.common.componentcore.resources.IVirtualFile) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 2 with IVirtualFile

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

the class JSWebResourceEventManager method getRoots.

/**
 * <p>Uses module core to get the roots of the given project.</p>
 *
 * @param project find the module core roots for this {@link IProject}
 * @return the module core roots for the given {@link IProject
 */
private static IResource[] getRoots(IProject project) {
    IVirtualFile root = ComponentCore.createFile(project, Path.ROOT);
    IResource[] underlyingResources = root.getUnderlyingResources();
    if (underlyingResources == null || underlyingResources.length == 0) {
        underlyingResources = new IResource[] { root.getUnderlyingResource() };
    }
    return underlyingResources;
}
Also used : IVirtualFile(org.eclipse.wst.common.componentcore.resources.IVirtualFile) IResource(org.eclipse.core.resources.IResource)

Example 3 with IVirtualFile

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

use of org.eclipse.wst.common.componentcore.resources.IVirtualFile 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;
}
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) 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) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 5 with IVirtualFile

use of org.eclipse.wst.common.componentcore.resources.IVirtualFile 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)

Aggregations

IVirtualFile (org.eclipse.wst.common.componentcore.resources.IVirtualFile)5 IContainer (org.eclipse.core.resources.IContainer)3 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 IVirtualFolder (org.eclipse.wst.common.componentcore.resources.IVirtualFolder)3 IVirtualResource (org.eclipse.wst.common.componentcore.resources.IVirtualResource)3 Reference (java.lang.ref.Reference)2 SoftReference (java.lang.ref.SoftReference)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IResource (org.eclipse.core.resources.IResource)2 IVirtualReference (org.eclipse.wst.common.componentcore.resources.IVirtualReference)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CoreException (org.eclipse.core.runtime.CoreException)1 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)1 Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)1