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

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

Introduction

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

Prototype

boolean isExported();

Source Link

Document

Returns whether this entry is exported to dependent projects.

Usage

From source file:org.seasar.kijimuna.core.util.JavaProjectClassLoader.java

License:Apache License

protected void addClasspathEntries(IJavaProject project, Set already, boolean atFirst) {
    already.add(project);//www  .  jav  a2s . com

    try {
        IContainer workspaceroot = project.getProject().getParent();
        IPath path = project.getOutputLocation();
        addURL(toURL(workspaceroot.getFolder(path).getLocation()));

        IClasspathEntry[] entries = project.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                IPath dist = entry.getOutputLocation();
                if (dist != null) {
                    addURL(toURL(workspaceroot.getFolder(dist).getLocation()));
                }
                break;
            case IClasspathEntry.CPE_LIBRARY:
            case IClasspathEntry.CPE_CONTAINER:
            case IClasspathEntry.CPE_VARIABLE:
                IPath p = entry.getPath();
                if (p.toFile().exists()) {
                    addURL(toURL(p));
                } else {
                    addURL(toURL(workspaceroot.getFile(p).getLocation()));
                }
                break;
            case IClasspathEntry.CPE_PROJECT:
                IJavaProject proj = JavaCore.create(ProjectUtils.getProject(entry.getPath().segment(0)));
                if (proj != null && proj.exists() && already.contains(proj) == false
                        && (atFirst || entry.isExported())) {
                    addClasspathEntries(proj, already, false);
                }
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        KijimunaCore.reportException(e);
    }
}

From source file:org.sonar.ide.eclipse.jdt.internal.JavaProjectConfigurator.java

License:Open Source License

/**
 * Adds the classpath of an eclipse project to the sonarProject recursively, i.e
 * it iterates all dependent projects. Libraries and output folders of dependent projects
 * are added, but no source folders./*from  ww w.  ja v a  2s. c o  m*/
 * @param javaProject the eclipse project to get the classpath from
 * @param sonarProjectProperties the sonar project properties to add the classpath to
 * @param context
 * @param topProject indicate we are working on the project to be analysed and not on a dependent project
 * @throws JavaModelException see {@link IJavaProject#getResolvedClasspath(boolean)}
 */
private void addClassPathToSonarProject(IJavaProject javaProject, JavaProjectConfiguration context,
        boolean topProject) throws JavaModelException {
    IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classPath) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!isSourceExcluded(entry)) {
                processSourceEntry(entry, javaProject, context, topProject);
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            if (topProject || entry.isExported()) {
                final String libDir = resolveLibrary(javaProject, entry);
                if (libDir != null) {
                    LOG.debug("Library: {}", libDir);
                    context.libraries().add(libDir);
                }
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            IJavaModel javaModel = javaProject.getJavaModel();
            IJavaProject referredProject = javaModel.getJavaProject(entry.getPath().segment(0));
            if (!context.dependentProjects().contains(referredProject)) {
                LOG.debug("Adding project: {}", referredProject.getProject().getName());
                addClassPathToSonarProject(referredProject, context, false);
                context.dependentProjects().add(referredProject);
            }
            break;
        default:
            LOG.warn("Unhandled ClassPathEntry : {}", entry);
            break;
        }
    }

    processOutputDir(javaProject.getOutputLocation(), context, topProject);
}

From source file:org.sonarlint.eclipse.jdt.internal.JavaProjectConfigurator.java

License:Open Source License

/**
 * Adds the classpath of an eclipse project to the sonarProject recursively, i.e
 * it iterates all dependent projects. Libraries and output folders of dependent projects
 * are added, but no source folders./*from w ww.j a  va2 s .  c  o m*/
 * @param javaProject the eclipse project to get the classpath from
 * @param sonarProjectProperties the sonar project properties to add the classpath to
 * @param context
 * @param topProject indicate we are working on the project to be analysed and not on a dependent project
 * @throws JavaModelException see {@link IJavaProject#getResolvedClasspath(boolean)}
 */
private void addClassPathToSonarProject(IJavaProject javaProject, JavaProjectConfiguration context,
        boolean topProject) throws JavaModelException {
    IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classPath) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!isSourceExcluded(entry)) {
                processSourceEntry(entry, javaProject, context, topProject);
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            if (topProject || entry.isExported()) {
                final String libPath = resolveLibrary(javaProject, entry);
                if (libPath != null) {
                    context.libraries().add(libPath);
                }
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            IJavaModel javaModel = javaProject.getJavaModel();
            IJavaProject referredProject = javaModel.getJavaProject(entry.getPath().segment(0));
            if (!context.dependentProjects().contains(referredProject)) {
                context.dependentProjects().add(referredProject);
                addClassPathToSonarProject(referredProject, context, false);
            }
            break;
        default:
            SonarLintCorePlugin.getDefault().info("Unhandled ClassPathEntry : " + entry);
            break;
        }
    }

    processOutputDir(javaProject.getOutputLocation(), context, topProject);
}

From source file:org.sonarlint.eclipse.jdt.internal.JdtUtils.java

License:Open Source License

private static void processLibraryEntry(IClasspathEntry entry, IJavaProject javaProject,
        JavaProjectConfiguration context, boolean topProject) throws JavaModelException {
    if (topProject || entry.isExported()) {
        final String libPath = resolveLibrary(javaProject, entry);
        if (libPath != null) {
            context.libraries().add(libPath);
        }//  w w w .  j av a 2s . c  o m
    }
}

From source file:org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyProjectConverter.java

License:Open Source License

private static void convertGradleProject(IProject project, SubMonitor sub) throws Exception {
    // nature//from   ww  w .j  a  v a  2s .  c om
    IProjectDescription description = project.getDescription();
    String[] ids = description.getNatureIds();
    List<String> newIds = new ArrayList<String>(ids.length);
    for (int i = 0; i < ids.length; i++) {
        if (!ids[i].equals(GRADLE_OLD_NATURE) && !ids[i].equals(GRADLE_NEW_NATURE)) {
            newIds.add(ids[i]);
        } else {
            newIds.add(GRADLE_NEW_NATURE);
        }
    }
    description.setNatureIds(newIds.toArray(new String[0]));
    project.setDescription(description, sub);

    // project preferences
    // DO NOTHING: gradle tooling handles these itself by reading in both old and new locations.

    // classpath container
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String path = entry.getPath().toString();
            if (path.contains(GRADLE_OLD_PREFIX)) {
                entry = JavaCore.newContainerEntry(new Path(path.replace(GRADLE_OLD_PREFIX, GRADLE_NEW_PREFIX)),
                        entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
            }
        }
        newClasspath.add(entry);
    }
    javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), sub);
}

From source file:org.talend.designer.maven.tools.creator.CreateMavenCodeProject.java

License:Open Source License

public static void changeClasspath(IProgressMonitor monitor, IProject p) {
    try {// ww  w.  j a  v a2  s.  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.talend.designer.maven.utils.MavenProjectUtils.java

License:Open Source License

public static void changeClasspath(IProgressMonitor monitor, IProject p, ProjectSystemFolder[] folders) {
    try {/*from   w  w w  . j  a  v  a 2  s.  c o  m*/
        if (!p.hasNature(JavaCore.NATURE_ID)) {
            JavaUtils.addJavaNature(p, monitor);
        }
        IJavaProject javaProject = JavaCore.create(p);
        IClasspathEntry[] rawClasspathEntries = javaProject.getRawClasspath();

        List<IClasspathEntry> list = new LinkedList<>();
        ClasspathAttribute attribute = new ClasspathAttribute("maven.pomderived", Boolean.TRUE.toString());
        for (ProjectSystemFolder psf : folders) {
            IFolder resources = p.getFolder(psf.getPath());
            if (resources.exists()) { // add the condition mostly for routines, since the resources folder might not exist
                IFolder output = p.getFolder(psf.getOutputPath());
                IClasspathEntry newEntry = JavaCore.newSourceEntry(resources.getFullPath(), new IPath[0],
                        new IPath[0], output.getFullPath(), new IClasspathAttribute[] { attribute });
                list.add(newEntry);
            }
        }
        IPath defaultJREContainerPath = JavaRuntime.newDefaultJREContainerPath();

        IClasspathEntry newEntry = JavaCore.newContainerEntry(defaultJREContainerPath, new IAccessRule[] {},
                new IClasspathAttribute[] { attribute }, false);
        list.add(newEntry);

        newEntry = JavaCore.newContainerEntry(new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"),
                newEntry.getAccessRules(), new IClasspathAttribute[] { attribute }, newEntry.isExported());
        list.add(newEntry);

        if (!Arrays.equals(rawClasspathEntries, list.toArray(new IClasspathEntry[] {}))
                || !p.getFile(".classpath").exists()) {
            rawClasspathEntries = list.toArray(new IClasspathEntry[] {});
            javaProject.setRawClasspath(rawClasspathEntries, monitor);
            javaProject.setOutputLocation(p.getFolder(MavenSystemFolders.JAVA.getOutputPath()).getFullPath(),
                    monitor);
        }
    } catch (

    CoreException e) {
        ExceptionHandler.process(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.j a v  a 2s.c  om*/
 * @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);
                }
            }
        }
    }
}