Search in sources :

Example 26 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer 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 27 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project liferay-ide by liferay.

the class PluginPackageResourceListener method processPropertiesFile.

protected void processPropertiesFile(IFile pluginPackagePropertiesFile) throws CoreException {
    IProject project = pluginPackagePropertiesFile.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    IPath containerPath = null;
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String segment = entry.getPath().segment(0);
            if (segment.equals(PluginClasspathContainerInitializer.ID) || segment.equals(SDKClasspathContainer.ID)) {
                containerPath = entry.getPath();
                break;
            }
        }
    }
    if (containerPath != null) {
        IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(containerPath, javaProject);
        String id = containerPath.segment(0);
        if (id.equals(PluginClasspathContainerInitializer.ID) || id.equals(SDKClasspathContainer.ID)) {
            ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(id);
            initializer.requestClasspathContainerUpdate(containerPath, javaProject, classpathContainer);
        }
    }
    Properties props = new Properties();
    InputStream contents = null;
    try {
        contents = pluginPackagePropertiesFile.getContents();
        props.load(contents);
        // processPortalDependencyTlds(props, pluginPackagePropertiesFile.getProject());
        processRequiredDeploymentContexts(props, pluginPackagePropertiesFile.getProject());
    } catch (Exception e) {
        ProjectCore.logError(e);
    } finally {
        if (contents != null) {
            try {
                contents.close();
            } catch (IOException ioe) {
            // ignore, this is best effort
            }
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) InputStream(java.io.InputStream) IOException(java.io.IOException) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) IAddReferenceDataModelProperties(org.eclipse.wst.common.componentcore.datamodel.properties.IAddReferenceDataModelProperties) Properties(java.util.Properties) IProject(org.eclipse.core.resources.IProject) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 28 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project liferay-ide by liferay.

the class SDKClasspathContainerInitializer method requestClasspathContainerUpdate.

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
    String key = SDKClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());
    IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
    cpDecorations.clearAllDecorations(key);
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        IPath srcpath = entry.getSourceAttachmentPath();
        IPath srcrootpath = entry.getSourceAttachmentRootPath();
        IClasspathAttribute[] attrs = entry.getExtraAttributes();
        if ((srcpath != null) || ListUtil.isNotEmpty(attrs)) {
            String eid = entry.getPath().toString();
            ClasspathDecorations dec = new ClasspathDecorations();
            dec.setSourceAttachmentPath(srcpath);
            dec.setSourceAttachmentRootPath(srcrootpath);
            dec.setExtraAttributes(attrs);
            cpDecorations.setDecorations(key, eid, dec);
        }
    }
    cpDecorations.save();
    IPath portalDir = null;
    IPath portalGlobalDir = null;
    String javadocURL = null;
    IPath sourceLocation = null;
    IPath bundleDir = null;
    IPath[] bundleDependencyJarPaths = null;
    PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());
    boolean containerChanged = true;
    if (containerSuggestion instanceof SDKClasspathContainer) {
        portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir();
        bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir();
        portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir();
        javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL();
        sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation();
        bundleDependencyJarPaths = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath();
        if ((bundle != null) && bundle.getAppServerPortalDir().equals(portalDir)) {
            containerChanged = false;
        }
    }
    if (containerChanged == true) {
        if (bundle == null) {
            return;
        }
        portalDir = bundle.getAppServerPortalDir();
        portalGlobalDir = bundle.getAppServerLibGlobalDir();
        bundleDependencyJarPaths = bundle.getBundleDependencyJars();
    }
    IPath[] sdkDependencyPaths = _getSDKDependencies(project);
    if ((portalDir != null) && (portalGlobalDir != null)) {
        IClasspathContainer newContainer = new SDKClasspathContainer(containerPath, project, portalDir, javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleDependencyJarPaths, sdkDependencyPaths);
        IJavaProject[] projects = { project };
        IClasspathContainer[] containers = { newContainer };
        JavaCore.setClasspathContainer(containerPath, projects, containers, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) ClasspathDecorations(org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 29 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project liferay-ide by liferay.

the class ClasspathUtil method updateRequestContainer.

public static void updateRequestContainer(IProject project) throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    IPath containerPath = null;
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String segment = entry.getPath().segment(0);
            if (segment.equals(SDKClasspathContainer.ID)) {
                containerPath = entry.getPath();
                break;
            }
        }
    }
    if (containerPath != null) {
        IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(containerPath, javaProject);
        String id = containerPath.segment(0);
        if (id.equals(SDKClasspathContainer.ID)) {
            ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(id);
            initializer.requestClasspathContainerUpdate(containerPath, javaProject, classpathContainer);
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer)

Example 30 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project eclipse.jdt.ls by eclipse.

the class JavaElementLabels method getContainerEntryLabel.

/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
    if (container != null) {
        return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(container.getDescription());
    }
    ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (initializer != null) {
        return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(initializer.getDescription(containerPath, project));
    }
    return BasicElementLabels.getPathLabel(containerPath, false);
}
Also used : IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer)

Aggregations

IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)34 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)16 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 IPath (org.eclipse.core.runtime.IPath)13 CoreException (org.eclipse.core.runtime.CoreException)10 ClasspathContainerInitializer (org.eclipse.jdt.core.ClasspathContainerInitializer)8 ArrayList (java.util.ArrayList)6 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 Map (java.util.Map)5 IProject (org.eclipse.core.resources.IProject)5 HashMap (java.util.HashMap)4 WeakHashMap (java.util.WeakHashMap)3 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)3 ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)2 PortalBundle (com.liferay.ide.server.core.portal.PortalBundle)2 IResource (org.eclipse.core.resources.IResource)2 IStatus (org.eclipse.core.runtime.IStatus)2 Path (org.eclipse.core.runtime.Path)2 IJavaModelStatus (org.eclipse.jdt.core.IJavaModelStatus)2 ClasspathDecorations (org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations)2