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:org.lunifera.dsl.eclipse.ui.buildpath.EntityLibClasspathAdder.java

License:Open Source License

protected boolean addToClasspath(IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException {
    IClasspathEntry xtendContainerEntry = JavaCore
            .newContainerEntry(EntityContainerInitializer.ENTITY_LIBRARY_PATH);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    IClasspathEntry[] newRawClasspath = new IClasspathEntry[rawClasspath.length + 1];
    for (int i = 0; i < rawClasspath.length; ++i) {
        IClasspathEntry entry = rawClasspath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && entry.getPath().equals(xtendContainerEntry.getPath())) {
            return false;
        }/*from www. jav  a  2  s .c  om*/
        newRawClasspath[i + 1] = entry;
    }
    newRawClasspath[0] = xtendContainerEntry;
    javaProject.setRawClasspath(newRawClasspath, monitor);
    return true;
}

From source file:org.lwjgl.tools.LWJGLClasspathContainerInitializer.java

License:Open Source License

private static void rebindClasspathEntries(IJavaModel model, IPath containerPath) throws JavaModelException {
    List<IJavaProject> affectedProjects = new ArrayList<IJavaProject>();

    IJavaProject[] projects = model.getJavaProjects();
    for (int i = 0; i < projects.length; i++) {
        IJavaProject project = projects[i];
        IClasspathEntry[] entries = project.getRawClasspath();
        for (int k = 0; k < entries.length; k++) {
            IClasspathEntry curr = entries[k];
            if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER && containerPath.equals(curr.getPath())) {
                affectedProjects.add(project);
            }/*from   w w  w  .ja  v a2s . c  o  m*/
        }
    }
    if (!affectedProjects.isEmpty()) {
        IJavaProject[] affected = (IJavaProject[]) affectedProjects
                .toArray(new IJavaProject[affectedProjects.size()]);
        IClasspathContainer[] containers = new IClasspathContainer[affected.length];
        for (int i = 0; i < containers.length; i++) {
            containers[i] = getNewContainer(containerPath);
        }
        JavaCore.setClasspathContainer(containerPath, affected, containers, null);
    }
}

From source file:org.maven.ide.eclipse.embedder.BuildPathManager.java

License:Apache License

public void updateSourceFolders(IProject project, ResolverConfiguration configuration,
        IProgressMonitor monitor) {/*from   w  ww. j ava 2s.  c o m*/
    IFile pom = project.getFile(Maven2Plugin.POM_FILE_NAME);
    if (!pom.exists()) {
        return;
    }

    monitor.beginTask("Updating sources " + project.getName(), IProgressMonitor.UNKNOWN);
    long t1 = System.currentTimeMillis();
    try {
        Set sources = new LinkedHashSet();
        List entries = new ArrayList();

        MavenProject mavenProject = collectSourceEntries(project, entries, sources, configuration, monitor);

        monitor.subTask("Configuring Build Path");
        IJavaProject javaProject = JavaCore.create(project);

        if (mavenProject != null) {
            Map options = collectOptions(mavenProject);
            setOption(javaProject, options, JavaCore.COMPILER_COMPLIANCE);
            setOption(javaProject, options, JavaCore.COMPILER_SOURCE);
            setOption(javaProject, options, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);

            String source = (String) options.get(JavaCore.COMPILER_SOURCE);
            if (source == null) {
                entries.add(JavaRuntime.getDefaultJREContainerEntry());
            } else {
                entries.add(getJREContainer(source));
            }
        }

        IClasspathEntry[] currentClasspath = javaProject.getRawClasspath();
        for (int i = 0; i < currentClasspath.length; i++) {
            // Delete all non container (e.g. JRE library) entries. See MNGECLIPSE-9 
            IClasspathEntry entry = currentClasspath[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (!JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) {
                    entries.add(entry);
                }
            }
        }

        if (mavenProject != null) {
            String outputDirectory = toRelativeAndFixSeparator(project.getLocation().toFile(), //
                    mavenProject.getBuild().getOutputDirectory());
            IFolder outputFolder = project.getFolder(outputDirectory);
            Util.createFolder(outputFolder);
            javaProject.setRawClasspath(
                    (IClasspathEntry[]) entries.toArray(new IClasspathEntry[entries.size()]),
                    outputFolder.getFullPath(), monitor);
        } else {
            javaProject.setRawClasspath(
                    (IClasspathEntry[]) entries.toArray(new IClasspathEntry[entries.size()]), monitor);
        }

        long t2 = System.currentTimeMillis();
        console.logMessage(
                "Updated source folders for project " + project.getName() + " " + (t2 - t1) / 1000 + "sec");

    } catch (Exception ex) {
        String msg = "Unable to update source folders " + project.getName() + "; " + ex.toString();
        console.logMessage(msg);
        Maven2Plugin.log(msg, ex);

    } finally {
        monitor.done();
    }
}

From source file:org.maven.ide.eclipse.embedder.BuildPathManager.java

License:Apache License

public static IClasspathContainer getMaven2ClasspathContainer(IJavaProject project) throws JavaModelException {
    IClasspathEntry[] entries = project.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && isMaven2ClasspathContainer(entry.getPath())) {
            return JavaCore.getClasspathContainer(entry.getPath(), project);
        }//from  ww w  .  ja v  a 2s  .  c  o m
    }
    return null;
}

From source file:org.maven.ide.eclipse.scala.ScalaProjectConfigurator.java

License:Open Source License

private static IClasspathEntry getContainer(IJavaProject javaProject, String containerPath)
        throws JavaModelException {
    IClasspathEntry[] cp = javaProject.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        if (IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind()
                && containerPath.equals(cp[i].getPath().lastSegment())) {
            return cp[i];
        }/*w w w .j ava2  s .  c  om*/
    }
    return null;
}

From source file:org.mule.ide.ui.wizards.AddMuleSupportWizard.java

License:Open Source License

/**
 * Add the Mule libraries to the project classpath.
 * //from   w  w  w  . j a  v a 2  s .com
 * @param muleProject the mule project
 * @throws JavaModelException
 */
protected void addMuleLibraries(IJavaProject muleProject, IProgressMonitor mon)
        throws JavaModelException, MuleModelException {
    Collection selectedModules = wizardPage.getSelectedMuleModules();
    IClasspathEntry[] initial = muleProject.getRawClasspath();

    int existingMulePosition = -1;
    for (int i = 0; i < initial.length; ++i) {
        if (initial[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && initial[i].getPath().segment(0).equals(MuleCorePlugin.ID_MULE_CLASSPATH_CONTAINER)) {
            existingMulePosition = i;
            break;
        }
    }

    IClasspathEntry muleEntry = MuleClasspathUtils
            .createMuleClasspathContainer(wizardPage.getDistributionHint(), selectedModules);
    IClasspathEntry[] result;
    if (existingMulePosition != -1) {
        result = initial;
        result[existingMulePosition] = muleEntry;
    } else {
        IClasspathEntry[] entries = new IClasspathEntry[] { muleEntry };
        result = new IClasspathEntry[initial.length + entries.length];
        System.arraycopy(initial, 0, result, 0, initial.length);
        System.arraycopy(entries, 0, result, initial.length, entries.length);
    }
    muleProject.setRawClasspath(result,
            new SubProgressMonitor(mon, 50, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
}

From source file:org.neuro4j.studio.core.util.ClassloaderHelper.java

License:Apache License

private static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls, Set<IJavaProject> visited,
        boolean isFirstProject) {
    if (visited.contains(javaProject))
        return;//  www. jav  a  2 s  .  co m
    visited.add(javaProject);
    IPath outPath = getJavaProjectOutputAbsoluteLocation(javaProject.getProject());
    if (outPath != null) {
        outPath = outPath.addTrailingSeparator();
        URL out = createFileURL(outPath);
        urls.add(out);

    }

    IClasspathEntry[] entries = null;
    try {
        entries = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        return;
    }
    IClasspathEntry entry;
    for (int i = 0; i < entries.length; i++) {
        entry = entries[i];
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            collectClasspathEntryURL(entry, urls);
            break;
        case IClasspathEntry.CPE_CONTAINER:
        case IClasspathEntry.CPE_VARIABLE:
            collectClasspathEntryURL(entry, urls);
            break;
        case IClasspathEntry.CPE_PROJECT: {
            if (isFirstProject || entry.isExported())
                collectClasspathURLs(getJavaProject(entry), urls, visited, false);
            break;
        }
        }
    }
}

From source file:org.neuro4j.studio.core.util.ClassloaderHelper.java

License:Apache License

private static void collectClasspathIPath(IJavaProject javaProject, List<IPath> urls, Set<IJavaProject> visited,
        boolean isFirstProject) {
    if (visited.contains(javaProject))
        return;/*from w ww .j av a2 s .c om*/
    visited.add(javaProject);

    IClasspathEntry[] entries = null;
    try {
        entries = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        return;
    }
    IClasspathEntry entry;
    for (int i = 0; i < entries.length; i++) {
        entry = entries[i];
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            addJarToList(entry.getPath(), urls);
            break;
        case IClasspathEntry.CPE_CONTAINER:
        case IClasspathEntry.CPE_SOURCE:
            break;
        case IClasspathEntry.CPE_VARIABLE:

            addJarToList(entry.getPath(), urls);
            break;
        case IClasspathEntry.CPE_PROJECT: {
            if (isFirstProject || entry.isExported())
                collectClasspathIPath(getJavaProject(entry), urls, visited, false);
            break;
        }
        }
    }
}

From source file:org.objectstyle.wolips.jdt.javaelementfilters.WOFrameworkFilter.java

License:Open Source License

public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof ClassPathContainer) {
        ClassPathContainer container = (ClassPathContainer) element;
        IClasspathEntry entry = container.getClasspathEntry();
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            IPath entryPath = entry.getPath();
            if (WOFrameworkClasspathContainer.ID.equals(entryPath.segment(0))) {
                return false;
            }/*w  w w  .j  a va 2s .co  m*/
        }
    }
    return true;
}

From source file:org.objectstyle.wolips.jrebel.utils.WOProjectClassLoader.java

License:BSD License

private void addURLs(IJavaProject javaProject, boolean exportsOnly) {
    if (!javaProjects.contains(javaProject)) {
        javaProjects.add(javaProject);/*  www  .  jav a2s  .co m*/

        try {
            // Add default output location
            addURL(javaProject.getOutputLocation());

            // Add each classpath entry
            IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);
            for (IClasspathEntry classpathEntry : classpathEntries) {
                if (classpathEntry.isExported() || !exportsOnly) {
                    switch (classpathEntry.getEntryKind()) {

                    // Recurse on projects
                    case IClasspathEntry.CPE_PROJECT:
                        IProject project = javaProject.getProject().getWorkspace().getRoot()
                                .getProject(classpathEntry.getPath().toString());
                        IJavaProject javaProj = JavaCore.create(project);
                        if (javaProj != null) {
                            addURLs(javaProj, true);
                        }
                        break;

                    // Library
                    case IClasspathEntry.CPE_LIBRARY:
                        addURL(classpathEntry);
                        break;

                    // Only Source entries with custom output location need to be added
                    case IClasspathEntry.CPE_SOURCE:
                        IPath outputLocation = classpathEntry.getOutputLocation();
                        if (outputLocation != null) {
                            addURL(outputLocation);
                        }
                        break;

                    // Variable and Container entries should not be happening, because
                    // we've asked for resolved entries.
                    case IClasspathEntry.CPE_VARIABLE:
                    case IClasspathEntry.CPE_CONTAINER:
                        break;
                    }
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
            // log.debug("MalformedURLException occurred: " + e.getLocalizedMessage(),e);
        }
    }
}