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.iw.plugins.spindle.ui.wizards.project.BaseNewTapestryProjectJavaPage.java

License:Mozilla Public License

/**
 * @param entries/*  www. j a v a2  s. com*/
 * @return
 */
private IClasspathEntry[] checkEntries(IClasspathEntry[] entries) throws CoreException {

    if (entries == null) {
        createSrcFolder();
        return new IClasspathEntry[] { createSrcClasspathEntry(), TapestryProjectInstallData.TAPESTRY_FRAMEWORK,
                JavaRuntime.getDefaultJREContainerEntry() };

    }

    boolean hasSrcEntry = false;
    boolean hasTapestryEntry = false;
    boolean hasDefaultJREEntry = false;
    List allEntries = Arrays.asList(entries);
    for (Iterator iter = allEntries.iterator(); iter.hasNext();) {
        IClasspathEntry element = (IClasspathEntry) iter.next();
        if (!hasSrcEntry && element.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            hasSrcEntry = true;
        } else if (element.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (!hasTapestryEntry)
                hasTapestryEntry = element.getPath().segment(0).equals(TapestryCore.CORE_CONTAINER);
            if (!hasDefaultJREEntry)
                hasDefaultJREEntry = element.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER);
        }
    }

    if (!hasSrcEntry) {
        createSrcFolder();
        allEntries.add(createSrcClasspathEntry());

    }

    if (!hasTapestryEntry)
        allEntries.add(TapestryProjectInstallData.TAPESTRY_FRAMEWORK);

    if (!hasDefaultJREEntry)
        allEntries.add(JavaRuntime.getDefaultJREContainerEntry());

    return (IClasspathEntry[]) allEntries.toArray(new IClasspathEntry[allEntries.size()]);
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Get all the resolved classpath entries for a specific project. The entries 
 * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved
 * or included in the result. At also add the source and output folder provided with the 
 * project//from   w  w w  . j  ava2s . c om
 * 
 * @param project the project where the file to compile is contained, must be not null
 * @return a not null list of string that contains the classpath to include in the compilation project
 */
private List<String> getClasspaths(IProject project) {
    IJavaProject jprj = JavaCore.create(project);
    List<String> classpath = new ArrayList<String>();
    IWorkspaceRoot wsRoot = project.getWorkspace().getRoot();
    if (jprj != null) {
        try {
            IClasspathEntry[] entries = jprj.getRawClasspath();

            //Add the default output folder if any
            IPath defaultLocationPath = jprj.getOutputLocation();
            if (defaultLocationPath != null) {
                IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath);
                classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
            }

            for (IClasspathEntry en : entries) {
                if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    String containerPath = en.getPath().toString();
                    //Don't add the eclipse runtime and the classpath extension defined in the exclusion list
                    if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER)
                            && !classpathExclusionSet.contains(containerPath)) {
                        addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(),
                                classpath, jprj);
                    }
                } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator);
                } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    //check if is a source folder and if it has a custom output folder to add them also to the classpath
                    IPath entryOutputLocation = en.getOutputLocation();
                    if (entryOutputLocation != null) {
                        IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation);
                        classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
                    }
                } else {
                    //It is a jar check if it is internal to the workspace of external
                    IPath location = wsRoot.getFile(en.getPath()).getLocation();
                    if (location == null) {
                        //The location could not be resolved from the root of the workspace, it is external
                        classpath.add(en.getPath().toOSString());
                    } else {
                        //The location has been resolved from the root of the workspace, it is internal
                        classpath.add(location.toOSString());
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return classpath;
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Add an array of classpath entry to the result set. If an entry is a classpath container 
 * then it is resolved and the resulting entries are added recursively
 * //from  w  ww  . j a v a  2  s  .  com
 * @param entries the entries to add
 * @param classpath the current result
 * @param jprj the current java project
 */
private void addEntries(IClasspathEntry[] entries, List<String> classpath, IJavaProject jprj) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    for (IClasspathEntry en : entries) {
        if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            try {
                addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath,
                        jprj);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT
                || en.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            classpath.add(workspace.getRoot().findMember(en.getPath()).getLocation().toOSString()
                    + File.separator + "*"); //$NON-NLS-1$
        } else {
            classpath.add(en.getPath().toOSString());
        }
    }
}

From source file:com.legstar.eclipse.plugin.common.wizards.AbstractWizardPage.java

License:Open Source License

/**
 * What we do here is that we search a project classpath for any occurrence
 * of a container library.//from   w  w  w  .  j ava 2  s .co  m
 * 
 * @param jproject the target java project
 * @param libraryName the name of the container library
 * @return true if the container library is already on the classpath
 */
public boolean lookupContainerLibrary(final IJavaProject jproject, final String libraryName) {
    try {
        IClasspathEntry[] cpe = jproject.getRawClasspath();
        for (int i = 0; i < cpe.length; i++) {
            if (cpe[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (cpe[i].getPath().equals(new Path(libraryName))) {
                    return true;
                }
            }
        }
        return false;
    } catch (JavaModelException e) {
        return false;
    }
}

From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java

License:Open Source License

/**
 * Given classpath entries from a java project, populate a list of
 * collections./*ww w  .j a  v a 2 s . c  o  m*/
 * 
 * @param selectedPathElementsLocations the output path locations
 * @param classPathEntries the java project class path entries
 * @param javaProject the java project
 * @throws JavaModelException if invalid classpath
 */
private void addPathElements(final List<String> selectedPathElementsLocations,
        final IClasspathEntry[] classPathEntries, final IJavaProject javaProject) throws JavaModelException {

    IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
    IPath projectPath = javaProject.getProject().getLocation();

    for (int i = 0; i < classPathEntries.length; i++) {
        IClasspathEntry classpathEntry = classPathEntries[i];
        String pathElementLocation = null;
        switch (classpathEntry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            pathElementLocation = classpathEntry.getPath().toOSString();
            break;
        case IClasspathEntry.CPE_CONTAINER:
            /* No need for the default jre */
            if (classpathEntry.equals(jreEntry)) {
                break;
            }
            /* Resolve container into class path entries */
            IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(classpathEntry.getPath(),
                    javaProject);
            addPathElements(selectedPathElementsLocations, classpathContainer.getClasspathEntries(),
                    javaProject);
            break;
        case IClasspathEntry.CPE_VARIABLE:
            pathElementLocation = JavaCore.getResolvedVariablePath(classpathEntry.getPath()).toOSString();
            break;
        case IClasspathEntry.CPE_SOURCE:
            /*
             * If source has no specific output, use the project default
             * one
             */
            IPath outputLocation = classpathEntry.getOutputLocation();
            if (outputLocation == null) {
                outputLocation = javaProject.getOutputLocation();
            }
            pathElementLocation = projectPath.append(outputLocation.removeFirstSegments(1)).toOSString();
            break;
        default:
            break;
        }

        if (pathElementLocation != null && !selectedPathElementsLocations.contains(pathElementLocation)) {
            selectedPathElementsLocations.add(pathElementLocation);
        }
    }
}

From source file:com.liferay.ide.layouttpl.core.facet.LayoutTplPluginFacetInstall.java

License:Open Source License

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

    try {// w  ww . j  a  va  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) {
        // no need to report errors
    }
}

From source file:com.liferay.ide.project.core.PluginPackageResourceListener.java

License:Open Source License

protected void processPropertiesFile(IFile pluginPackagePropertiesFile) throws CoreException {
    IProject project = pluginPackagePropertiesFile.getProject();

    IJavaProject javaProject = JavaCore.create(project);

    IPath containerPath = null;/*from   w  w  w .j  a  v  a 2s  .  c  o  m*/

    IClasspathEntry[] entries = javaProject.getRawClasspath();

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

                break;
            }
        }
    }

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

        final 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 e) {
                // ignore, this is best effort
            }
        }
    }

}

From source file:com.liferay.ide.project.core.PluginsSDKProjectRuntimeValidator.java

License:Open Source License

public void validate(IFacetedProject fproj) throws CoreException {

    final IProject proj = fproj.getProject();

    if (ProjectUtil.isLiferayFacetedProject(proj)) {
        clearMarkers(proj);/*from ww  w .j ava  2 s.  c  o m*/

        if (SDKUtil.isSDKProject(fproj.getProject())) {
            IJavaProject javaProject = JavaCore.create(proj);

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

            if (fproj.getPrimaryRuntime() == null) {
                setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR,
                        MSG_PRIMARY_RUNTIME_NOT_SET, LOCATION_TARGETED_RUNTIMES, ID_PRIMARY_RUNTIME_NOT_SET);
            } else {
                if (!ServerUtil.isLiferayRuntime((BridgedRuntime) fproj.getPrimaryRuntime())) {
                    setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR,
                            MSG_PRIMARY_RUNTIME_NOT_LIFERAY_RUNTIME, LOCATION_TARGETED_RUNTIMES,
                            ID_PRIMARY_RUNTIME_NOT_LIFERAY_RUNTIME);
                }
            }
        } else if (!ProjectUtil.isMavenProject(proj)) {

            setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR,
                    Msgs.pluginSDKNotSet, LOCATION_TARGETED_SDK, ID_PLUGINS_SDK_NOT_SET);
        }
    }
}

From source file:com.liferay.ide.project.core.tests.ImportPluginsSDKProjectTests.java

License:Open Source License

private boolean isLiferayRuntimePluginClassPath(List<IClasspathEntry> entries, final String entryPath) {
    boolean retval = false;
    for (Iterator<IClasspathEntry> iterator = entries.iterator(); iterator.hasNext();) {
        IClasspathEntry entry = iterator.next();

        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            for (String path : entry.getPath().segments()) {
                if (path.equals(entryPath)) {
                    retval = true;//  www .  j  a va2s .  co m
                    break;
                }
            }
        }
    }
    return retval;
}

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

License:Open Source License

public static boolean isPluginContainerEntry(final IClasspathEntry e) {
    return e != null && e.getEntryKind() == IClasspathEntry.CPE_CONTAINER
            && e.getPath().segment(0).equals(SDKClasspathContainer.ID);
}