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.talend.designer.maven.tools.creator.CreateMavenCodeProject.java

License:Open Source License

public static void changeClasspath(IProgressMonitor monitor, IProject p) {
    try {/* w  w  w  . j  a v  a  2s  .c  o  m*/
        IJavaProject javaProject = JavaCore.create(p);
        IClasspathEntry[] rawClasspathEntries = javaProject.getRawClasspath();
        boolean changed = false;

        for (int index = 0; index < rawClasspathEntries.length; index++) {
            IClasspathEntry entry = rawClasspathEntries[index];

            IClasspathEntry newEntry = null;
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = entry.getPath();
                if (p.getFullPath().isPrefixOf(path)) {
                    path = path.removeFirstSegments(1);
                }

                // src/main/resources, in order to removing the 'excluding="**"'.
                if (MavenSystemFolders.RESOURCES.getPath().equals(path.toString())) {
                    newEntry = JavaCore.newSourceEntry(entry.getPath(), new IPath[0], new IPath[0], //
                            entry.getOutputLocation(), entry.getExtraAttributes());
                }

                // src/test/resources, in order to removing the 'excluding="**"'.
                if (MavenSystemFolders.RESOURCES_TEST.getPath().equals(path.toString())) {
                    newEntry = JavaCore.newSourceEntry(entry.getPath(), new IPath[0], new IPath[0], //
                            entry.getOutputLocation(), entry.getExtraAttributes());
                }

            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                // remove the special version of jre in container.
                IPath defaultJREContainerPath = JavaRuntime.newDefaultJREContainerPath();
                if (defaultJREContainerPath.isPrefixOf(entry.getPath())) {
                    // JavaRuntime.getDefaultJREContainerEntry(); //missing properties
                    newEntry = JavaCore.newContainerEntry(defaultJREContainerPath, entry.getAccessRules(),
                            entry.getExtraAttributes(), entry.isExported());
                }
            }
            if (newEntry != null) {
                rawClasspathEntries[index] = newEntry;
                changed = true;
            }

        }
        if (changed) {
            javaProject.setRawClasspath(rawClasspathEntries, monitor);
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}

From source file:org.teavm.eclipse.debugger.TeaVMSourcePathComputerDelegate.java

License:Apache License

@Override
public ISourceContainer[] computeSourceContainers(ILaunchConfiguration config, IProgressMonitor monitor)
        throws CoreException {
    List<ISourceContainer> sourceContainers = new ArrayList<>();
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject project : projects) {
        if (!project.isOpen()) {
            continue;
        }/*from www .  ja  v a 2  s .c o  m*/
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject javaProject = JavaCore.create(project);
            for (IPackageFragmentRoot fragmentRoot : javaProject.getAllPackageFragmentRoots()) {
                if (fragmentRoot.getResource() instanceof IFolder) {
                    sourceContainers.add(new FolderSourceContainer((IFolder) fragmentRoot.getResource(), true));
                }
            }
            for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) {
                switch (entry.getEntryKind()) {
                case IClasspathEntry.CPE_CONTAINER:
                    sourceContainers.add(new ClasspathContainerSourceContainer(entry.getPath()));
                    break;
                case IClasspathEntry.CPE_LIBRARY:
                    sourceContainers.add(new ExternalArchiveSourceContainer(entry.getPath().toString(), true));
                    if (entry.getSourceAttachmentPath() != null) {
                        System.out.println(entry.getSourceAttachmentPath());
                        sourceContainers.add(new ExternalArchiveSourceContainer(
                                entry.getSourceAttachmentPath().toString(), true));
                        sourceContainers
                                .add(new DirectorySourceContainer(entry.getSourceAttachmentPath(), true));
                    }
                    break;
                case IClasspathEntry.CPE_SOURCE:
                    sourceContainers.add(new DirectorySourceContainer(entry.getPath(), true));
                    break;
                }
            }
        }
    }
    IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedSourceLookupPath(config);
    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries, config);
    sourceContainers.addAll(Arrays.asList(JavaRuntime.getSourceContainers(resolved)));
    return sourceContainers.toArray(new ISourceContainer[sourceContainers.size()]);
}

From source file:repast.simphony.agents.designer.core.AgentBuilderPlugin.java

License:Open Source License

/**
 * Adds classpath entries to the supported list.
 * /*from  ww w .j a v a2 s  . c o m*/
 * @param projectName
 * @param pathEntries
 */
public static void getResolvedClasspath(String projectName, List pathEntries) {

    IJavaProject javaProject = AgentBuilderPlugin.getJavaProject(projectName);
    IPath path = null;
    try {
        IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            path = null;
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                path = getWorkspaceRoot().getLocation()
                        .append(JavaCore.getResolvedClasspathEntry(entry).getPath());
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                path = JavaCore.getResolvedClasspathEntry(entry).getPath();
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                path = entry.getPath().makeAbsolute();
                if (!path.toFile().getAbsoluteFile().exists()) {
                    IPath location = getWorkspaceRoot().getProject(entry.getPath().segment(0))
                            .getFile(entry.getPath().removeFirstSegments(1)).getLocation();
                    if (location != null) {
                        File tmpFile = location.toFile();
                        if (tmpFile.exists())
                            path = location;
                    }
                }
            }
            if (path != null && !pathEntries.contains(path))
                pathEntries.add(path);

            if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject requiredProject = getWorkspaceProject(entry.getPath());
                // recurse into projects
                if (requiredProject != null)
                    getResolvedClasspath(requiredProject, pathEntries);
            }
        }
        IPath outputPath = javaProject.getOutputLocation();
        if (outputPath.segmentCount() == 1)
            outputPath = javaProject.getResource().getLocation();
        else
            outputPath = javaProject.getProject().getFile(outputPath.removeFirstSegments(1)).getLocation();
        if (outputPath != null && !pathEntries.contains(outputPath))
            pathEntries.add(outputPath);
    } catch (JavaModelException e) {
        AgentBuilderPlugin.log(e);
    }
}

From source file:runjettyrun.tabs.action.AddClassFolderAction.java

License:Open Source License

/**
 * Adds all exported entries defined by <code>proj</code> to the list
 * <code>runtimeEntries</code>.
 *
 * @param proj/*from w  w w  .ja  va  2  s .co  m*/
 * @param runtimeEntries
 * @throws JavaModelException
 */
protected void collectExportedEntries(IJavaProject proj, List<IRuntimeClasspathEntry> runtimeEntries)
        throws CoreException {
    IClasspathEntry[] entries = proj.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.isExported()) {
            IRuntimeClasspathEntry rte = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_CONTAINER:
                IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), proj);
                int kind = 0;
                switch (container.getKind()) {
                case IClasspathContainer.K_APPLICATION:
                    kind = IRuntimeClasspathEntry.USER_CLASSES;
                    break;
                case IClasspathContainer.K_SYSTEM:
                    kind = IRuntimeClasspathEntry.BOOTSTRAP_CLASSES;
                    break;
                case IClasspathContainer.K_DEFAULT_SYSTEM:
                    kind = IRuntimeClasspathEntry.STANDARD_CLASSES;
                    break;
                }
                rte = JavaRuntime.newRuntimeContainerClasspathEntry(entry.getPath(), kind, proj);
                break;
            case IClasspathEntry.CPE_LIBRARY:
                rte = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath());
                rte.setSourceAttachmentPath(entry.getSourceAttachmentPath());
                rte.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath());
                break;
            case IClasspathEntry.CPE_PROJECT:
                String name = entry.getPath().segment(0);
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
                if (p.exists()) {
                    IJavaProject jp = JavaCore.create(p);
                    if (jp.exists()) {
                        rte = JavaRuntime.newProjectRuntimeClasspathEntry(jp);
                    }
                }
                break;
            case IClasspathEntry.CPE_VARIABLE:
                rte = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath());
                break;
            default:
                break;
            }
            if (rte != null) {
                if (!runtimeEntries.contains(rte)) {
                    runtimeEntries.add(rte);
                }
            }
        }
    }
}

From source file:x10dt.search.core.pdb.X10FactGenerator.java

License:Open Source License

private void processEntries(final CompilerOptionsBuilder cmpOptBuilder, final IWorkspaceRoot wsRoot,
        final IClasspathEntry[] entries, final IJavaProject javaProject, final IResource contextResource,
        final boolean isInRuntime) throws JavaModelException, AnalysisException {
    for (final IClasspathEntry pathEntry : entries) {
        switch (pathEntry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (pathEntry.getPath().isRoot()) {
                cmpOptBuilder.addToSourcePath(pathEntry.getPath().toFile());
            } else {
                cmpOptBuilder.addToSourcePath(wsRoot.getLocation().append(pathEntry.getPath()).toFile());
            }//from ww w  . ja v  a  2 s  . com
            if (pathEntry.getPath().segmentCount() > 1) {
                processSourceFolder(cmpOptBuilder, wsRoot.getFolder(pathEntry.getPath()), contextResource);
            }
            break;

        case IClasspathEntry.CPE_LIBRARY:
            try {
                final IPackageFragmentRoot pkgRoot = javaProject.findPackageFragmentRoot(pathEntry.getPath());
                if ((pkgRoot != null) && pkgRoot.exists()) {
                    final File localFile;
                    if (pkgRoot.isExternal()) {
                        localFile = pathEntry.getPath().toFile();
                    } else {
                        localFile = pkgRoot.getResource().getLocation().toFile();
                    }
                    cmpOptBuilder.addToClassPath(localFile.getAbsolutePath());
                    if (isInRuntime) {
                        cmpOptBuilder.addToSourcePath(localFile);
                    }
                    final ZipFile zipFile;
                    if (JAR_EXT.equals(pathEntry.getPath().getFileExtension())) {
                        zipFile = new JarFile(localFile);
                    } else {
                        zipFile = new ZipFile(localFile);
                    }
                    processLibrary(cmpOptBuilder, zipFile, localFile, contextResource, isInRuntime);
                }
            } catch (IOException except) {
                throw new AnalysisException(NLS.bind(Messages.XFG_JarReadingError, pathEntry.getPath()),
                        except);
            }
            break;

        case IClasspathEntry.CPE_CONTAINER:
            final IClasspathContainer cpContainer = JavaCore.getClasspathContainer(pathEntry.getPath(),
                    javaProject);
            processEntries(cmpOptBuilder, wsRoot, cpContainer.getClasspathEntries(), javaProject,
                    contextResource, true);
            break;

        case IClasspathEntry.CPE_PROJECT:
            final IResource projectResource = ResourcesPlugin.getWorkspace().getRoot()
                    .findMember(pathEntry.getPath());
            if ((projectResource != null) && projectResource.isAccessible()) {
                final IJavaProject newJavaProject = JavaCore.create((IProject) projectResource);
                processEntries(cmpOptBuilder, wsRoot, newJavaProject.getRawClasspath(), newJavaProject,
                        contextResource, false);
            }
            break;

        case IClasspathEntry.CPE_VARIABLE:
            processEntries(cmpOptBuilder, wsRoot,
                    new IClasspathEntry[] { JavaCore.getResolvedClasspathEntry(pathEntry) }, javaProject,
                    contextResource, false);
            break;
        }
    }
}