Search in sources :

Example 1 with WorkbenchComponent

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

the class LiferayMavenProjectConfigurator method configureDeployedName.

protected void configureDeployedName(IProject project, String deployedFileName) {
    // We need to remove the file extension from deployedFileName
    int extSeparatorPos = deployedFileName.lastIndexOf('.');
    String deployedName = extSeparatorPos > -1 ? deployedFileName.substring(0, extSeparatorPos) : deployedFileName;
    // From jerr's patch in MNGECLIPSE-965
    IVirtualComponent projectComponent = ComponentCore.createComponent(project);
    if ((projectComponent != null) && !deployedName.equals(projectComponent.getDeployedName())) {
        // MNGECLIPSE-2331 :
        // Seems
        // projectComponent.getDeployedName()
        // can be null
        StructureEdit moduleCore = null;
        try {
            moduleCore = StructureEdit.getStructureEditForWrite(project);
            if (moduleCore != null) {
                WorkbenchComponent component = moduleCore.getComponent();
                if (component != null) {
                    component.setName(deployedName);
                    moduleCore.saveIfNecessary(null);
                }
            }
        } finally {
            if (moduleCore != null) {
                moduleCore.dispose();
            }
        }
    }
}
Also used : WorkbenchComponent(org.eclipse.wst.common.componentcore.internal.WorkbenchComponent) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) StructureEdit(org.eclipse.wst.common.componentcore.internal.StructureEdit)

Example 2 with WorkbenchComponent

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

the class ModuleTraverser method traverseWebComponent.

private static void traverseWebComponent(IVirtualComponent component, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException {
    visitor.visitWebComponent(component);
    IProject proj = component.getProject();
    StructureEdit warStruct = StructureEdit.getStructureEditForRead(proj);
    try {
        WorkbenchComponent comp = warStruct.getComponent();
        if (comp == null) {
            Trace.trace(Trace.SEVERE, "Error getting WorkbenchComponent from war project. IProject=\"" + proj + "\" StructureEdit=\"" + warStruct + "\" WorkbenchComponent=\"" + comp + "\"");
            return;
        }
        traverseWebComponentLocalEntries(comp, visitor, monitor);
        // traverse referenced components
        List children = comp.getReferencedComponents();
        for (Iterator itor = children.iterator(); itor.hasNext(); ) {
            ReferencedComponent childRef = (ReferencedComponent) itor.next();
            IPath rtFolder = childRef.getRuntimePath();
            URI refHandle = childRef.getHandle();
            if (PlatformURLModuleConnection.CLASSPATH.equals(refHandle.segment(ModuleURIUtil.ModuleURI.SUB_PROTOCOL_INDX))) {
                IPath refPath = getResolvedPathForArchiveComponent(refHandle);
                // If an archive component, add to list
                if (refPath != null) {
                    if (!refPath.isAbsolute()) {
                        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(refPath);
                        IPath refPath2 = file.getLocation();
                        if (refPath2 != null) {
                            visitor.visitArchiveComponent(rtFolder, refPath2);
                        } else {
                            Trace.trace(Trace.WARNING, NLS.bind("Could not get the location of a referenced component.  It may not exist.  Project={0}, Parent Component={1}, Referenced Component Path={2}", new Object[] { proj.getName(), comp.getName(), refPath }));
                        }
                    } else {
                        visitor.visitArchiveComponent(rtFolder, refPath);
                    }
                } else {
                // TODO Determine if any use case would arrive here.
                }
            } else {
                try {
                    WorkbenchComponent childCom = warStruct.findComponentByURI(refHandle);
                    if (childCom == null) {
                        continue;
                    }
                    traverseDependentEntries(visitor, rtFolder, childCom, monitor);
                } catch (UnresolveableURIException e) {
                    TomcatPlugin.log(e);
                }
            }
        }
    } finally {
        warStruct.dispose();
    }
    visitor.endVisitWebComponent(component);
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) WorkbenchComponent(org.eclipse.wst.common.componentcore.internal.WorkbenchComponent) Iterator(java.util.Iterator) List(java.util.List) ReferencedComponent(org.eclipse.wst.common.componentcore.internal.ReferencedComponent) UnresolveableURIException(org.eclipse.wst.common.componentcore.UnresolveableURIException) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) StructureEdit(org.eclipse.wst.common.componentcore.internal.StructureEdit)

Example 3 with WorkbenchComponent

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

the class ModuleTraverser method traverseWebComponent.

private static void traverseWebComponent(IVirtualComponent component, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException {
    visitor.visitWebComponent(component);
    IProject proj = component.getProject();
    StructureEdit warStruct = StructureEdit.getStructureEditForRead(proj);
    try {
        WorkbenchComponent comp = warStruct.getComponent();
        if (comp == null) {
            // + "\" WorkbenchComponent=\"" + comp + "\""); //$NON-NLS-1$ //$NON-NLS-2$
            return;
        }
        traverseWebComponentLocalEntries(comp, visitor, monitor);
        // traverse referenced components
        List children = comp.getReferencedComponents();
        for (Iterator itor = children.iterator(); itor.hasNext(); ) {
            ReferencedComponent childRef = (ReferencedComponent) itor.next();
            IPath rtFolder = childRef.getRuntimePath();
            URI refHandle = childRef.getHandle();
            if (PlatformURLModuleConnection.CLASSPATH.equals(refHandle.segment(ModuleURIUtil.ModuleURI.SUB_PROTOCOL_INDX))) {
                IPath refPath = getResolvedPathForArchiveComponent(refHandle);
                // If an archive component, add to list
                if (refPath != null) {
                    if (!refPath.isAbsolute()) {
                        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(refPath);
                        IPath refPath2 = file.getLocation();
                        if (refPath2 != null) {
                            visitor.visitArchiveComponent(rtFolder, refPath2);
                        } else {
                        // Trace.trace(Trace.WARNING, NLS.bind(
                        // "Could not get the location of a referenced component.  It may not exist.  Project={0}, Parent Component={1}, Referenced Component Path={2}", //$NON-NLS-1$
                        // new Object[] { proj.getName(), comp.getName(), refPath}));
                        }
                    } else {
                        visitor.visitArchiveComponent(rtFolder, refPath);
                    }
                } else {
                // TODO Determine if any use case would arrive here.
                }
            } else {
                try {
                    WorkbenchComponent childCom = warStruct.findComponentByURI(refHandle);
                    if (childCom == null) {
                        continue;
                    }
                    traverseDependentEntries(visitor, rtFolder, childCom, monitor);
                } catch (UnresolveableURIException e) {
                    LiferayServerCore.logError(e);
                }
            }
        }
    } finally {
        warStruct.dispose();
    }
    visitor.endVisitWebComponent(component);
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) WorkbenchComponent(org.eclipse.wst.common.componentcore.internal.WorkbenchComponent) Iterator(java.util.Iterator) List(java.util.List) ReferencedComponent(org.eclipse.wst.common.componentcore.internal.ReferencedComponent) UnresolveableURIException(org.eclipse.wst.common.componentcore.UnresolveableURIException) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) StructureEdit(org.eclipse.wst.common.componentcore.internal.StructureEdit)

Aggregations

StructureEdit (org.eclipse.wst.common.componentcore.internal.StructureEdit)3 WorkbenchComponent (org.eclipse.wst.common.componentcore.internal.WorkbenchComponent)3 Iterator (java.util.Iterator)2 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 URI (org.eclipse.emf.common.util.URI)2 UnresolveableURIException (org.eclipse.wst.common.componentcore.UnresolveableURIException)2 ReferencedComponent (org.eclipse.wst.common.componentcore.internal.ReferencedComponent)2 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)1