Example usage for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER

List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.

Prototype

int CPE_CONTAINER

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.

Click Source Link

Document

Entry kind constant describing a classpath entry representing a name classpath container.

Usage

From source file:com.liferay.ide.project.core.util.ClasspathUtil.java

License:Open Source License

public static boolean hasNewLiferaySDKContainer(final IClasspathEntry[] entries) {
    boolean retVal = false;
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) {
            retVal = true;/*from w  w  w.  j ava2s  .  c  o  m*/
            break;
        }
    }

    return retVal;
}

From source file:com.liferay.ide.project.core.util.ClasspathUtil.java

License:Open Source License

public static void updateRequestContainer(IProject project) throws CoreException {
    final IJavaProject javaProject = JavaCore.create(project);
    IPath containerPath = null;//from   w  w w.  j  a  va 2s .  c  o m

    final IClasspathEntry[] entries = javaProject.getRawClasspath();

    for (final IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) {
                containerPath = entry.getPath();
                break;
            }
        }
    }

    if (containerPath != null) {
        final IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(containerPath,
                javaProject);

        final String id = containerPath.segment(0);

        if (id.equals(SDKClasspathContainer.ID)) {
            ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(id);
            initializer.requestClasspathContainerUpdate(containerPath, javaProject, classpathContainer);
        }
    }
}

From source file:com.liferay.ide.project.core.util.ProjectUtil.java

License:Open Source License

public static IProject createExistingProject(final ProjectRecord record, IRuntime runtime, String sdkLocation,
        IProgressMonitor monitor) throws CoreException {
    String projectName = record.getProjectName();

    final IWorkspace workspace = ResourcesPlugin.getWorkspace();

    IProject project = workspace.getRoot().getProject(projectName);

    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);

        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());

        // If it is under the root use the default location
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {//from   w w  w  . jav  a2s.co  m
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }

    monitor.beginTask(Msgs.importingProject, 100);

    project.create(record.description, new SubProgressMonitor(monitor, 30));

    project.open(IResource.FORCE, new SubProgressMonitor(monitor, 70));

    // need to check to see if we an ext project with source folders with incorrect parent attributes
    if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        fixExtProjectClasspathEntries(project);
    }

    IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);

    FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);

    String pluginType = guessPluginType(fpwc);

    SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record);

    fpwc.commitChanges(monitor);

    final IJavaProject javaProject = JavaCore.create(fProject.getProject());

    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                        && entry.getPath().segment(0).equals(PluginClasspathContainerInitializer.ID)) {
                    JavaCore.getClasspathContainerInitializer(PluginClasspathContainerInitializer.ID)
                            .initialize(entry.getPath(), javaProject);
                    break;
                }
            }

            monitor.done();
        }
    }, monitor);

    return project;
}

From source file:com.liferay.ide.project.core.util.ProjectUtil.java

License:Open Source License

public static IProject createExistingProject(final ProjectRecord record, final IPath sdkLocation,
        IProgressMonitor monitor) throws CoreException {
    String projectName = record.getProjectName();

    final IWorkspace workspace = ResourcesPlugin.getWorkspace();

    IProject project = workspace.getRoot().getProject(projectName);

    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);
        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());

        // If it is under the root use the default location
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {/*  w  w w  .j av a 2  s.  c om*/
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }

    project.create(record.description, new SubProgressMonitor(monitor, 30));

    project.open(IResource.FORCE, new SubProgressMonitor(monitor, 70));

    // need to check to see if we an ext project with source folders with incorrect parent attributes
    if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        fixExtProjectClasspathEntries(project);
    }

    IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);

    FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);

    final String pluginType = guessPluginType(fpwc);

    SDKPluginFacetUtil.configureProjectAsSDKProject(fpwc, pluginType, sdkLocation.toPortableString(), record);

    fpwc.commitChanges(monitor);

    final IJavaProject javaProject = JavaCore.create(fProject.getProject());

    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            List<IClasspathEntry> rawClasspaths = new ArrayList<IClasspathEntry>();

            IPath containerPath = null;

            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                        && entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) {
                    containerPath = entry.getPath();
                    break;
                }

                if (!isLiferayRuntimePluginClassPath(entry)) {
                    rawClasspaths.add(entry);
                }
            }

            if (containerPath != null) {
                JavaCore.getClasspathContainerInitializer(SDKClasspathContainer.ID).initialize(containerPath,
                        javaProject);
            } else {
                javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]),
                        new NullProgressMonitor());

                javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]),
                        new NullProgressMonitor());

                IAccessRule[] accessRules = new IAccessRule[] {};

                IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute(
                        IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) };

                IPath cpePath = new Path(SDKClasspathContainer.ID);
                ;

                IClasspathEntry newEntry = JavaCore.newContainerEntry(cpePath, accessRules, attributes, false);

                IClasspathEntry[] entries = javaProject.getRawClasspath();

                for (IClasspathEntry entry : entries) {
                    if (entry.getPath().equals(cpePath)) {
                        return;
                    }
                }

                IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];

                System.arraycopy(entries, 0, newEntries, 0, entries.length);

                newEntries[entries.length] = newEntry;

                javaProject.setRawClasspath(newEntries, monitor);
            }
            monitor.done();

            final SDK sdk = SDKUtil.createSDKFromLocation(sdkLocation);

            SDKUtil.openAsProject(sdk);
        }
    }, monitor);
    return project;
}

From source file:com.liferay.ide.project.core.util.ProjectUtil.java

License:Open Source License

private static boolean isLiferayRuntimePluginClassPath(IClasspathEntry entry) {
    boolean retval = false;

    if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        for (String path : entry.getPath().segments()) {
            if (path.equals(PluginClasspathContainerInitializer.ID)
                    || path.equals("com.liferay.studio.server.tomcat.runtimeClasspathProvider")
                    || path.equals("com.liferay.ide.eclipse.server.tomcat.runtimeClasspathProvider")) {
                retval = true;/* w  w  w  .jav a  2  s  . c  o  m*/
                break;
            }
        }
    }
    return retval;
}

From source file:com.liferay.ide.server.core.portal.PortalServerBehavior.java

License:Open Source License

@Override
public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy launch, IProgressMonitor monitor)
        throws CoreException {
    final String existingProgArgs = launch.getAttribute(ATTR_PROGRAM_ARGUMENTS, (String) null);
    launch.setAttribute(ATTR_PROGRAM_ARGUMENTS,
            mergeArguments(existingProgArgs, getRuntimeStartProgArgs(), null, true));

    final String existingVMArgs = launch.getAttribute(ATTR_VM_ARGUMENTS, (String) null);

    final String[] configVMArgs = getRuntimeStartVMArguments();
    launch.setAttribute(ATTR_VM_ARGUMENTS, mergeArguments(existingVMArgs, configVMArgs, null, false));

    final PortalRuntime portalRuntime = getPortalRuntime();
    final IVMInstall vmInstall = portalRuntime.getVMInstall();

    if (vmInstall != null) {
        launch.setAttribute(ATTR_JRE_CONTAINER_PATH,
                JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
    }/*  w  w w. ja v  a  2  s  . c  o m*/

    final IRuntimeClasspathEntry[] orgClasspath = JavaRuntime.computeUnresolvedRuntimeClasspath(launch);
    final int orgClasspathSize = orgClasspath.length;

    final List<IRuntimeClasspathEntry> oldCp = new ArrayList<>(orgClasspathSize);
    Collections.addAll(oldCp, orgClasspath);

    final List<IRuntimeClasspathEntry> runCpEntries = portalRuntime.getRuntimeClasspathEntries();

    for (IRuntimeClasspathEntry cpEntry : runCpEntries) {
        mergeClasspath(oldCp, cpEntry);
    }

    if (vmInstall != null) {
        try {
            final String typeId = vmInstall.getVMInstallType().getId();
            final IRuntimeClasspathEntry newJRECp = JavaRuntime.newRuntimeContainerClasspathEntry(
                    new Path(JavaRuntime.JRE_CONTAINER).append(typeId).append(vmInstall.getName()),
                    IRuntimeClasspathEntry.BOOTSTRAP_CLASSES);
            replaceJREConatiner(oldCp, newJRECp);
        } catch (Exception e) {
            // ignore
        }

        final IPath jrePath = new Path(vmInstall.getInstallLocation().getAbsolutePath());

        if (jrePath != null) {
            final IPath toolsPath = jrePath.append("lib/tools.jar");

            if (toolsPath.toFile().exists()) {
                final IRuntimeClasspathEntry toolsJar = JavaRuntime.newArchiveRuntimeClasspathEntry(toolsPath);
                // Search for index to any existing tools.jar entry
                int toolsIndex;

                for (toolsIndex = 0; toolsIndex < oldCp.size(); toolsIndex++) {
                    final IRuntimeClasspathEntry entry = oldCp.get(toolsIndex);

                    if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE
                            && entry.getPath().lastSegment().equals("tools.jar")) {
                        break;
                    }
                }

                // If existing tools.jar found, replace in case it's different. Otherwise add.
                if (toolsIndex < oldCp.size()) {
                    oldCp.set(toolsIndex, toolsJar);
                } else {
                    mergeClasspath(oldCp, toolsJar);
                }
            }
        }
    }

    final List<String> cp = new ArrayList<>();

    for (IRuntimeClasspathEntry entry : oldCp) {
        try {
            if (entry.getClasspathEntry().getEntryKind() != IClasspathEntry.CPE_CONTAINER) {
                entry = new LiferayRuntimeClasspathEntry(entry.getClasspathEntry());
            }
            cp.add(entry.getMemento());
        } catch (Exception e) {
            LiferayServerCore.logError("Could not resolve cp entry " + entry, e);
        }
    }

    launch.setAttribute(ATTR_CLASSPATH, cp);
    launch.setAttribute(ATTR_DEFAULT_CLASSPATH, false);

    setupAgent();

    setupAriesJmxBundles();
}

From source file:com.liferay.ide.theme.core.facet.ThemePluginFacetInstall.java

License:Open Source License

protected void removeUnneededClasspathEntries() {
    IFacetedProjectWorkingCopy facetedProject = getFacetedProject();
    IJavaProject javaProject = JavaCore.create(facetedProject.getProject());

    try {//ww  w  .  j a  v  a  2 s.  c o m
        IClasspathEntry[] existingClasspath = javaProject.getRawClasspath();
        List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();

        for (IClasspathEntry entry : existingClasspath) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                continue;
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                String path = entry.getPath().toPortableString();
                if (path.contains("org.eclipse.jdt.launching.JRE_CONTAINER") || //$NON-NLS-1$
                        path.contains("org.eclipse.jst.j2ee.internal.web.container") || //$NON-NLS-1$
                        path.contains("org.eclipse.jst.j2ee.internal.module.container")) //$NON-NLS-1$
                {
                    continue;
                }
            }

            newClasspath.add(entry);
        }

        javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), null);

        IResource sourceFolder = javaProject.getProject()
                .findMember(IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER);

        if (sourceFolder.exists()) {
            sourceFolder.delete(true, null);
        }
    } catch (Exception e) {

    }
}

From source file:com.microsoft.javapkgbuild.Tasks.java

License:MIT License

private static String getClassPathType(IClasspathEntry cp) {
    switch (cp.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        return "con";
    case IClasspathEntry.CPE_LIBRARY:
        return "lib";
    case IClasspathEntry.CPE_PROJECT:
        return "proj";
    case IClasspathEntry.CPE_SOURCE:
        return "src";
    case IClasspathEntry.CPE_VARIABLE:
        return "var";
    default://  ww  w .j a  v a2 s  .co m
        return "unexpected";
    }
}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException {
    IClasspathEntry rawEntry = root.getRawClasspathEntry();
    int rawEntryKind = rawEntry.getEntryKind();
    switch (rawEntryKind) {
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
    case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037
        if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) {
            IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry();
            if (resolvedEntry.getReferencingEntry() != null)
                return resolvedEntry;
            else//ww w.  j a v a  2 s.c om
                return rawEntry;
        }
    }
    return rawEntry;
}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IPath path;/* w  w  w . java 2s .c o m*/
    IClasspathEntry classpathEntry = null;
    try {
        classpathEntry = getClasspathEntry(root);
        IPath rawPath = classpathEntry.getPath();
        if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute())
            path = rawPath;
        else
            path = root.getPath();
    } catch (JavaModelException e) {
        path = root.getPath();
    }
    if (getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)) {
        int segements = path.segmentCount();
        if (segements > 0) {
            fBuffer.append(path.segment(segements - 1));
            int offset = fBuffer.length();
            if (segements > 1 || path.getDevice() != null) {
                fBuffer.append(CONCAT_STRING);
                fBuffer.append(path.removeLastSegments(1).toOSString());
            }
            if (classpathEntry != null) {
                IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(" (from ");
                    fBuffer.append(Name.CLASS_PATH.toString());
                    fBuffer.append(" of ");
                    fBuffer.append(referencingEntry.getPath().lastSegment());
                    fBuffer.append(")");
                }
            }
        } else {
            fBuffer.append(path.toOSString());
        }
    } else {
        fBuffer.append(path.toOSString());
    }
}