Search in sources :

Example 1 with ComponentResource

use of org.eclipse.wst.common.componentcore.internal.ComponentResource in project liferay-ide by liferay.

the class ModuleTraverser method traverseWebComponentLocalEntries.

private static void traverseWebComponentLocalEntries(WorkbenchComponent comp, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException {
    IProject warProject = StructureEdit.getContainingProject(comp);
    if (warProject == null || !warProject.hasNature(JavaCore.NATURE_ID)) {
        return;
    }
    IJavaProject project = JavaCore.create(warProject);
    List res = comp.getResources();
    for (Iterator itorRes = res.iterator(); itorRes.hasNext(); ) {
        ComponentResource childComp = (ComponentResource) itorRes.next();
        IClasspathEntry cpe = getClasspathEntry(project, childComp.getSourcePath());
        if (cpe == null)
            continue;
        visitor.visitWebResource(childComp.getRuntimePath(), getOSPath(warProject, project, cpe.getOutputLocation()));
    }
    // Include tagged classpath entries
    Map classpathDeps = getComponentClasspathDependencies(project, true);
    for (Iterator iterator = classpathDeps.keySet().iterator(); iterator.hasNext(); ) {
        IClasspathEntry entry = (IClasspathEntry) iterator.next();
        IClasspathAttribute attrib = (IClasspathAttribute) classpathDeps.get(entry);
        boolean isClassFolder = isClassFolderEntry(entry);
        String rtFolder = attrib.getValue();
        if (rtFolder == null) {
            if (isClassFolder) {
                // $NON-NLS-1$
                rtFolder = "/WEB-INF/classes";
            } else {
                // $NON-NLS-1$
                rtFolder = "/WEB-INF/lib";
            }
        }
        IPath entryPath = entry.getPath();
        IResource entryRes = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
        if (entryRes != null) {
            entryPath = entryRes.getLocation();
        }
        // TODO Determine if different handling is needed for some use cases
        if (isClassFolder) {
            visitor.visitWebResource(new Path(rtFolder), getOSPath(warProject, project, entry.getPath()));
        } else {
            visitor.visitArchiveComponent(new Path(rtFolder), entryPath);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) ComponentResource(org.eclipse.wst.common.componentcore.internal.ComponentResource) Iterator(java.util.Iterator) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Example 2 with ComponentResource

use of org.eclipse.wst.common.componentcore.internal.ComponentResource in project webtools.servertools by eclipse.

the class ModuleTraverser method traverseWebComponentLocalEntries.

private static void traverseWebComponentLocalEntries(WorkbenchComponent comp, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException {
    IProject warProject = StructureEdit.getContainingProject(comp);
    if (warProject == null || !warProject.hasNature(JavaCore.NATURE_ID)) {
        return;
    }
    IJavaProject project = JavaCore.create(warProject);
    List res = comp.getResources();
    for (Iterator itorRes = res.iterator(); itorRes.hasNext(); ) {
        ComponentResource childComp = (ComponentResource) itorRes.next();
        IClasspathEntry cpe = getClasspathEntry(project, childComp.getSourcePath());
        if (cpe == null)
            continue;
        visitor.visitWebResource(childComp.getRuntimePath(), getOSPath(warProject, project, cpe.getOutputLocation()));
    }
    // Include tagged classpath entries
    Map classpathDeps = getComponentClasspathDependencies(project, true);
    for (Iterator iterator = classpathDeps.keySet().iterator(); iterator.hasNext(); ) {
        IClasspathEntry entry = (IClasspathEntry) iterator.next();
        IClasspathAttribute attrib = (IClasspathAttribute) classpathDeps.get(entry);
        boolean isClassFolder = isClassFolderEntry(entry);
        String rtFolder = attrib.getValue();
        if (rtFolder == null) {
            if (isClassFolder) {
                rtFolder = "/WEB-INF/classes";
            } else {
                rtFolder = "/WEB-INF/lib";
            }
        }
        IPath entryPath = entry.getPath();
        IResource entryRes = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
        if (entryRes != null) {
            entryPath = entryRes.getLocation();
        }
        // TODO Determine if different handling is needed for some use cases
        if (isClassFolder) {
            visitor.visitWebResource(new Path(rtFolder), getOSPath(warProject, project, entry.getPath()));
        } else {
            visitor.visitArchiveComponent(new Path(rtFolder), entryPath);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) ComponentResource(org.eclipse.wst.common.componentcore.internal.ComponentResource) Iterator(java.util.Iterator) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Example 3 with ComponentResource

use of org.eclipse.wst.common.componentcore.internal.ComponentResource in project mdw-designer by CenturyLinkCloud.

the class ProjectConfigurator method removeDeploymentAssemblyResourceMappings.

public boolean removeDeploymentAssemblyResourceMappings(IFolder folder) {
    StructureEdit moduleCore = null;
    try {
        moduleCore = StructureEdit.getStructureEditForWrite(project.getSourceProject());
        if (moduleCore != null && moduleCore.getComponent() != null && moduleCore.getComponent().getResources() != null) {
            ComponentResource toRemove = null;
            for (Object o : moduleCore.getComponent().getResources()) {
                ComponentResource resource = (ComponentResource) o;
                if (("/" + folder.getProjectRelativePath()).equals(resource.getSourcePath().toString()))
                    toRemove = resource;
            }
            if (toRemove != null)
                moduleCore.getComponent().getResources().remove(toRemove);
        }
    } finally {
        if (moduleCore != null) {
            moduleCore.saveIfNecessary(new NullProgressMonitor());
            moduleCore.dispose();
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ComponentResource(org.eclipse.wst.common.componentcore.internal.ComponentResource) StructureEdit(org.eclipse.wst.common.componentcore.internal.StructureEdit)

Example 4 with ComponentResource

use of org.eclipse.wst.common.componentcore.internal.ComponentResource in project webtools.servertools by eclipse.

the class ModuleTraverser method traverseDependentEntries.

private static void traverseDependentEntries(IModuleVisitor visitor, IPath runtimeFolder, WorkbenchComponent component, IProgressMonitor monitor) throws CoreException {
    IProject dependentProject = StructureEdit.getContainingProject(component);
    if (!dependentProject.hasNature(JavaCore.NATURE_ID))
        return;
    IJavaProject project = JavaCore.create(dependentProject);
    visitor.visitDependentJavaProject(project);
    // assume it is the same as URI
    String name = component.getName();
    // go thru all entries
    List res = component.getResources();
    for (Iterator itorRes = res.iterator(); itorRes.hasNext(); ) {
        ComponentResource childComp = (ComponentResource) itorRes.next();
        IPath rtPath = childComp.getRuntimePath();
        IPath srcPath = childComp.getSourcePath();
        IClasspathEntry cpe = getClasspathEntry(project, srcPath);
        if (cpe != null) {
            visitor.visitDependentComponent(runtimeFolder.append(rtPath).append(name + ".jar"), getOSPath(dependentProject, project, cpe.getOutputLocation()));
        }
        // Handle META-INF/resources
        String path = rtPath.toString();
        IFolder resFolder = null;
        String targetPath = "";
        if ("/".equals(path)) {
            resFolder = dependentProject.getFolder(srcPath.append("META-INF/resources"));
        } else if ("/META-INF".equals(path)) {
            resFolder = dependentProject.getFolder(srcPath.append("resources"));
        } else if ("/META-INF/resources".equals(path)) {
            resFolder = dependentProject.getFolder(srcPath);
        } else if (path.startsWith("/META-INF/resources/")) {
            resFolder = dependentProject.getFolder(srcPath);
            targetPath = path.substring("/META-INF/resources".length());
        }
        if (resFolder != null && resFolder.exists()) {
            visitor.visitDependentContentResource(new Path(targetPath), resFolder.getLocation());
        }
    }
    // Include tagged classpath entries
    Map classpathDeps = getComponentClasspathDependencies(project, false);
    for (Iterator iterator = classpathDeps.keySet().iterator(); iterator.hasNext(); ) {
        IClasspathEntry entry = (IClasspathEntry) iterator.next();
        boolean isClassFolder = isClassFolderEntry(entry);
        String rtFolder = null;
        if (isClassFolder) {
            rtFolder = "/";
        } else {
            rtFolder = "/WEB-INF/lib";
        }
        IPath entryPath = entry.getPath();
        IResource entryRes = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
        if (entryRes != null) {
            entryPath = entryRes.getLocation();
        }
        // TODO Determine if different handling is needed for some use cases
        if (isClassFolder) {
            visitor.visitDependentComponent(runtimeFolder.append(rtFolder).append(name + ".jar"), getOSPath(dependentProject, project, entry.getPath()));
        } else {
            visitor.visitArchiveComponent(new Path(rtFolder), entryPath);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ComponentResource(org.eclipse.wst.common.componentcore.internal.ComponentResource) Iterator(java.util.Iterator) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with ComponentResource

use of org.eclipse.wst.common.componentcore.internal.ComponentResource in project liferay-ide by liferay.

the class ModuleTraverser method traverseDependentEntries.

private static void traverseDependentEntries(IModuleVisitor visitor, IPath runtimeFolder, WorkbenchComponent component, IProgressMonitor monitor) throws CoreException {
    IProject dependentProject = StructureEdit.getContainingProject(component);
    if (!dependentProject.hasNature(JavaCore.NATURE_ID))
        return;
    IJavaProject project = JavaCore.create(dependentProject);
    visitor.visitDependentJavaProject(project);
    // assume it is the same as URI
    String name = component.getName();
    // go thru all entries
    List res = component.getResources();
    for (Iterator itorRes = res.iterator(); itorRes.hasNext(); ) {
        ComponentResource childComp = (ComponentResource) itorRes.next();
        IPath rtPath = childComp.getRuntimePath();
        IPath srcPath = childComp.getSourcePath();
        IClasspathEntry cpe = getClasspathEntry(project, srcPath);
        if (cpe != null) {
            visitor.visitDependentComponent(runtimeFolder.append(rtPath).append(name + ".jar"), getOSPath(// $NON-NLS-1$
            dependentProject, project, cpe.getOutputLocation()));
        }
        // Handle META-INF/resources
        String path = rtPath.toString();
        IFolder resFolder = null;
        String targetPath = StringPool.EMPTY;
        if ("/".equals(path)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            resFolder = dependentProject.getFolder(srcPath.append("META-INF/resources"));
        } else if ("/META-INF".equals(path)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            resFolder = dependentProject.getFolder(srcPath.append("resources"));
        } else if ("/META-INF/resources".equals(path)) {
            // $NON-NLS-1$
            resFolder = dependentProject.getFolder(srcPath);
        } else if (path.startsWith("/META-INF/resources/")) {
            // $NON-NLS-1$
            resFolder = dependentProject.getFolder(srcPath);
            // $NON-NLS-1$
            targetPath = path.substring("/META-INF/resources".length());
        }
        if (resFolder != null && resFolder.exists()) {
            visitor.visitDependentContentResource(new Path(targetPath), resFolder.getLocation());
        }
    }
    // Include tagged classpath entries
    Map classpathDeps = getComponentClasspathDependencies(project, false);
    for (Iterator iterator = classpathDeps.keySet().iterator(); iterator.hasNext(); ) {
        IClasspathEntry entry = (IClasspathEntry) iterator.next();
        boolean isClassFolder = isClassFolderEntry(entry);
        String rtFolder = null;
        if (isClassFolder) {
            // $NON-NLS-1$
            rtFolder = "/";
        } else {
            // $NON-NLS-1$
            rtFolder = "/WEB-INF/lib";
        }
        IPath entryPath = entry.getPath();
        IResource entryRes = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
        if (entryRes != null) {
            entryPath = entryRes.getLocation();
        }
        // TODO Determine if different handling is needed for some use cases
        if (isClassFolder) {
            visitor.visitDependentComponent(runtimeFolder.append(rtFolder).append(name + ".jar"), getOSPath(// $NON-NLS-1$
            dependentProject, project, entry.getPath()));
        } else {
            visitor.visitArchiveComponent(new Path(rtFolder), entryPath);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ComponentResource(org.eclipse.wst.common.componentcore.internal.ComponentResource) Iterator(java.util.Iterator) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ComponentResource (org.eclipse.wst.common.componentcore.internal.ComponentResource)6 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)4 Map (java.util.Map)4 IProject (org.eclipse.core.resources.IProject)4 IResource (org.eclipse.core.resources.IResource)4 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 IFolder (org.eclipse.core.resources.IFolder)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)2 StructureEdit (org.eclipse.wst.common.componentcore.internal.StructureEdit)2