Search in sources :

Example 31 with IVirtualComponent

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

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

the class PluginPackageResourceListener method processPortalDependencyTlds.

protected void processPortalDependencyTlds(Properties props, IProject project) {
    String portalDependencyTlds = props.getProperty("portal-dependency-tlds");
    if (portalDependencyTlds == null) {
        return;
    }
    String[] portalTlds = portalDependencyTlds.split(StringPool.COMMA);
    IVirtualComponent component = ComponentCore.createComponent(project);
    if (component == null) {
        return;
    }
    IFolder webroot = (IFolder) component.getRootFolder().getUnderlyingFolder();
    IFolder tldFolder = webroot.getFolder("WEB-INF/tld");
    IPath portalDir = ServerUtil.getPortalDir(project);
    List<IPath> tldFilesToCopy = new ArrayList<>();
    if (portalDir != null) {
        for (String portalTld : portalTlds) {
            IFile tldFile = tldFolder.getFile(portalTld);
            if (!tldFile.exists()) {
                IPath realPortalTld = portalDir.append("WEB-INF/tld/" + portalTld);
                if (realPortalTld.toFile().exists()) {
                    tldFilesToCopy.add(realPortalTld);
                }
            }
        }
    }
    if (ListUtil.isEmpty(tldFilesToCopy)) {
        return;
    }
    new WorkspaceJob("copy portal tlds") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            CoreUtil.prepareFolder(tldFolder);
            for (IPath tldFileToCopy : tldFilesToCopy) {
                IFile newTldFile = tldFolder.getFile(tldFileToCopy.lastSegment());
                try {
                    newTldFile.create(Files.newInputStream(tldFileToCopy.toFile().toPath()), true, null);
                } catch (Exception e) {
                    throw new CoreException(ProjectCore.createErrorStatus(e));
                }
            }
            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) ArrayList(java.util.ArrayList) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IFolder(org.eclipse.core.resources.IFolder)

Example 33 with IVirtualComponent

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

Example 34 with IVirtualComponent

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

the class PluginFacetInstall method getWebRootFolder.

protected IFolder getWebRootFolder() {
    IDataModel webFacetDataModel = null;
    if (masterModel != null) {
        FacetDataModelMap map = (FacetDataModelMap) masterModel.getProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP);
        webFacetDataModel = map.getFacetDataModel(IJ2EEFacetConstants.DYNAMIC_WEB_FACET.getId());
    } else {
        webFacetDataModel = getFacetDataModel(IModuleConstants.JST_WEB_MODULE);
    }
    IPath webrootFullPath = null;
    if (webFacetDataModel != null) {
        String configFolder = webFacetDataModel.getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER);
        webrootFullPath = project.getFullPath().append(configFolder);
    } else {
        IVirtualComponent component = ComponentCore.createComponent(project);
        if (component != null) {
            IContainer container = component.getRootFolder().getUnderlyingFolder();
            webrootFullPath = container.getFullPath();
        }
    }
    return CoreUtil.getWorkspaceRoot().getFolder(webrootFullPath);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IContainer(org.eclipse.core.resources.IContainer)

Example 35 with IVirtualComponent

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

the class ModuleTraverser method traverse.

/**
 * Scans the module using the specified visitor.
 *
 * @param module module to traverse
 * @param visitor visitor to handle resources
 * @param monitor a progress monitor
 * @throws CoreException
 */
public static void traverse(IModule module, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException {
    if (module == null || module.getModuleType() == null)
        return;
    String typeId = module.getModuleType().getId();
    IVirtualComponent component = ComponentCore.createComponent(module.getProject());
    if (component == null) {
        // + module.getName());
        return;
    }
    if (EAR_MODULE.equals(typeId)) {
        traverseEarComponent(component, visitor, monitor);
    } else if (WEB_MODULE.equals(typeId)) {
        traverseWebComponent(component, visitor, monitor);
    }
}
Also used : IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Aggregations

IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)39 IPath (org.eclipse.core.runtime.IPath)24 IVirtualFolder (org.eclipse.wst.common.componentcore.resources.IVirtualFolder)12 IVirtualReference (org.eclipse.wst.common.componentcore.resources.IVirtualReference)11 IProject (org.eclipse.core.resources.IProject)9 ArrayList (java.util.ArrayList)8 IContainer (org.eclipse.core.resources.IContainer)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6 Path (org.eclipse.core.runtime.Path)6 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)5 CoreException (org.eclipse.core.runtime.CoreException)5 IVirtualResource (org.eclipse.wst.common.componentcore.resources.IVirtualResource)5 Test (org.junit.Test)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 List (java.util.List)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IOException (java.io.IOException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2