Search in sources :

Example 11 with IVirtualReference

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

the class PluginPackageResourceListener method processRequiredDeploymentContexts.

protected void processRequiredDeploymentContexts(Properties props, IProject project) {
    IVirtualComponent rootComponent = ComponentCore.createComponent(project);
    if (rootComponent == null) {
        return;
    }
    List<IVirtualReference> removeRefs = new ArrayList<>();
    IClasspathContainer webAppLibrariesContainer = J2EEComponentClasspathContainerUtils.getInstalledWebAppLibrariesContainer(project);
    if (webAppLibrariesContainer == null) {
        return;
    }
    IClasspathEntry[] existingEntries = webAppLibrariesContainer.getClasspathEntries();
    for (IClasspathEntry entry : existingEntries) {
        IPath path = entry.getPath();
        String archiveName = path.lastSegment();
        if (archiveName.endsWith("-service.jar")) {
            IFile file = _getWorkspaceFile(path);
            if (file.exists() && ProjectUtil.isLiferayFacetedProject(file.getProject())) {
                for (IVirtualReference ref : rootComponent.getReferences()) {
                    if (archiveName.equals(ref.getArchiveName())) {
                        removeRefs.add(ref);
                    }
                }
            }
        }
    }
    List<IVirtualReference> addRefs = new ArrayList<>();
    String requiredDeploymenContexts = props.getProperty("required-deployment-contexts");
    if (requiredDeploymenContexts != null) {
        String[] contexts = requiredDeploymenContexts.split(StringPool.COMMA);
        if (ListUtil.isNotEmpty(contexts)) {
            for (String context : contexts) {
                IVirtualReference ref = processContext(rootComponent, context);
                if (ref != null) {
                    addRefs.add(ref);
                }
            }
        }
    }
    new WorkspaceJob("Update virtual component.") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            updateVirtualComponent(rootComponent, removeRefs, addRefs);
            updateWebClasspathContainer(rootComponent, addRefs);
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IVirtualReference(org.eclipse.wst.common.componentcore.resources.IVirtualReference) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 12 with IVirtualReference

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

the class PluginPackageResourceListener method processContext.

protected IVirtualReference processContext(IVirtualComponent rootComponent, String context) {
    // first check for jar file
    IFile serviceJar = ComponentUtil.findServiceJarForContext(context);
    if (serviceJar == null) {
        return null;
    }
    IPath serviceJarPath = serviceJar.getFullPath();
    if (rootComponent == null) {
        return null;
    }
    String type = VirtualArchiveComponent.LIBARCHIVETYPE + IPath.SEPARATOR;
    IVirtualComponent archive = ComponentCore.createArchiveComponent(rootComponent.getProject(), type + serviceJarPath.makeRelative().toString());
    IVirtualReference ref = ComponentCore.createReference(rootComponent, archive, new Path(J2EEConstants.WEB_INF_LIB).makeAbsolute());
    ref.setArchiveName(serviceJarPath.lastSegment());
    return ref;
}
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) IVirtualReference(org.eclipse.wst.common.componentcore.resources.IVirtualReference) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Aggregations

IVirtualReference (org.eclipse.wst.common.componentcore.resources.IVirtualReference)12 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)11 IPath (org.eclipse.core.runtime.IPath)6 IVirtualFolder (org.eclipse.wst.common.componentcore.resources.IVirtualFolder)6 ArrayList (java.util.ArrayList)5 List (java.util.List)3 IContainer (org.eclipse.core.resources.IContainer)3 IFile (org.eclipse.core.resources.IFile)3 IVirtualResource (org.eclipse.wst.common.componentcore.resources.IVirtualResource)3 IProject (org.eclipse.core.resources.IProject)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IFolder (org.eclipse.core.resources.IFolder)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 ClasspathContainerInitializer (org.eclipse.jdt.core.ClasspathContainerInitializer)1