Search in sources :

Example 1 with IVirtualFolder

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

the class FlexibleProject method _getDefaultDocroot.

private static IFolder _getDefaultDocroot(IProject project) {
    IVirtualFolder webappRoot = _getVirtualDocroot(project);
    if (webappRoot == null) {
        return null;
    }
    try {
        IPath defaultFolder = J2EEModuleVirtualComponent.getDefaultDeploymentDescriptorFolder(webappRoot);
        if (defaultFolder == null) {
            return null;
        }
        IFolder folder = project.getFolder(defaultFolder);
        if (folder.exists()) {
            return folder;
        }
    } catch (Exception e) {
        ProjectCore.logError("Could not determine default docroot", e);
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IVirtualFolder

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

the class PluginFacetInstall method configureDeploymentAssembly.

protected void configureDeploymentAssembly(String srcPath, String deployPath) {
    IVirtualComponent vProject = ComponentCore.createComponent(project);
    IVirtualFolder vProjectFolder = vProject.getRootFolder();
    IVirtualFolder deployFolder = vProjectFolder.getFolder(new Path(deployPath));
    try {
        deployFolder.createLink(new Path(srcPath), IResource.FORCE, null);
    } catch (CoreException ce) {
        ProjectCore.logError("Unable to create link", ce);
    }
    try {
        IPath outputLocation = JavaCore.create(project).getOutputLocation();
        vProject.setMetaProperty(IModuleConstants.PROJ_REL_JAVA_OUTPUT_PATH, outputLocation.toPortableString());
    } catch (JavaModelException jme) {
        ProjectCore.logError("Unable to set java-ouput-path", jme);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Example 3 with IVirtualFolder

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

the class ProjectUtil method fixExtProjectSrcFolderLinks.

public static void fixExtProjectSrcFolderLinks(IProject extProject) throws JavaModelException {
    if (extProject == null) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(extProject);
    if (javaProject == null) {
        return;
    }
    IVirtualComponent c = ComponentCore.createComponent(extProject, false);
    if (c == null) {
        return;
    }
    IVirtualFolder jsrc = c.getRootFolder().getFolder("/WEB-INF/classes");
    if (jsrc == null) {
        return;
    }
    IClasspathEntry[] cp = javaProject.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        IClasspathEntry cpe = cp[i];
        if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = cpe.getPath().removeFirstSegments(1);
            if (path.segmentCount() > 0) {
                try {
                    IFolder srcFolder = CoreUtil.getWorkspaceRoot().getFolder(cpe.getPath());
                    IVirtualResource[] virtualResource = ComponentCore.createResources(srcFolder);
                    if (virtualResource.length == 0) {
                        jsrc.createLink(cpe.getPath().removeFirstSegments(1), 0, null);
                    }
                } catch (Exception e) {
                    ProjectCore.logError(e);
                }
            }
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with IVirtualFolder

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

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