Example usage for org.eclipse.jdt.core IClasspathContainer getClasspathEntries

List of usage examples for org.eclipse.jdt.core IClasspathContainer getClasspathEntries

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathContainer getClasspathEntries.

Prototype

IClasspathEntry[] getClasspathEntries();

Source Link

Document

Answers the set of classpath entries this container is mapping to.

Usage

From source file:at.bestsolution.efxclipse.robovm.RobovmSetupHandler.java

License:Open Source License

private void resolveDataProject(IJavaProject project, Set<IPath> listProjectSourceDirs,
        Set<IPath> listRefProjectSourceDirs, Set<IPath> listRefLibraries) {
    try {/*from  www.j a v  a 2  s.  co  m*/
        IClasspathEntry[] entries = project.getRawClasspath();
        for (IClasspathEntry e : entries) {
            if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(e.getPath().lastSegment());
                if (p.exists()) {
                    resolveDataProject(JavaCore.create(p), listRefProjectSourceDirs, listRefProjectSourceDirs,
                            listRefLibraries);
                }
            } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                listRefLibraries.add(e.getPath());
            } else if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                listProjectSourceDirs.add(e.getPath());
            } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                String start = e.getPath().segment(0);
                // TODO remove hard coded strings
                if (!"org.eclipse.jdt.launching.JRE_CONTAINER".equals(start)
                        && !"org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER".equals(start)) {
                    IClasspathContainer cpe = JavaCore.getClasspathContainer(e.getPath(), project);
                    IClasspathEntry[] cpEntries = cpe.getClasspathEntries();
                    for (IClasspathEntry tmp : cpEntries) {
                        if (tmp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                            listRefLibraries.add(tmp.getPath());
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.handler.AbstractAntHandler.java

License:Open Source License

private void resolveDataProject(IJavaProject project, Set<IPath> listProjectSourceDirs,
        Set<IPath> listRefProjectSourceDirs, Set<IPath> listRefLibraries) {
    try {// w w w  . j av  a 2 s.c om
        IClasspathEntry[] entries = project.getRawClasspath();
        for (IClasspathEntry e : entries) {
            if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(e.getPath().lastSegment());
                if (p.exists()) {
                    resolveDataProject(JavaCore.create(p), listRefProjectSourceDirs, listRefProjectSourceDirs,
                            listRefLibraries);
                }
            } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                listRefLibraries.add(e.getPath());
            } else if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                listProjectSourceDirs.add(e.getPath());
            } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                String start = e.getPath().segment(0);
                // TODO remove hard coded strings
                if (!"org.eclipse.jdt.launching.JRE_CONTAINER".equals(start)
                        && !"at.bestsolution.efxclipse.tooling.jdt.core.JAVAFX_CONTAINER".equals(start)) {
                    IClasspathContainer cpe = JavaCore.getClasspathContainer(e.getPath(), project);
                    IClasspathEntry[] cpEntries = cpe.getClasspathEntries();
                    for (IClasspathEntry tmp : cpEntries) {
                        if (tmp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                            listRefLibraries.add(tmp.getPath());
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:at.bestsolution.efxclipse.tooling.ui.preview.LivePreviewSynchronizer.java

License:Open Source License

private void resolveDataProject(IJavaProject project, Set<IPath> outputPath, Set<IPath> listRefLibraries) {
    try {//from  w ww.  ja  v  a  2  s  .  com
        IClasspathEntry[] entries = project.getRawClasspath();
        outputPath.add(project.getOutputLocation());
        for (IClasspathEntry e : entries) {
            if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(e.getPath().lastSegment());
                if (p.exists()) {
                    resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries);
                }
            } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                listRefLibraries.add(e.getPath());
            } else if ("org.eclipse.pde.core.requiredPlugins".equals(e.getPath().toString())) {
                IClasspathContainer cpContainer = JavaCore.getClasspathContainer(e.getPath(), project);
                for (IClasspathEntry cpEntry : cpContainer.getClasspathEntries()) {
                    if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                        IProject p = ResourcesPlugin.getWorkspace().getRoot()
                                .getProject(cpEntry.getPath().lastSegment());
                        if (p.exists()) {
                            resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries);
                        }
                    } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        listRefLibraries.add(cpEntry.getPath());
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:at.bestsolution.fxide.jdt.corext.util.JavaModelUtil.java

License:Open Source License

/**
 * Finds an entry in a container. <code>null</code> is returned if the entry can not be found
 * @param container The container//from  ww  w  . j a v a2 s. c o  m
 * @param libPath The path of the library to be found
 * @return IClasspathEntry A classpath entry from the container of
 * <code>null</code> if the container can not be modified.
 */
public static IClasspathEntry findEntryInContainer(IClasspathContainer container, IPath libPath) {
    IClasspathEntry[] entries = container.getClasspathEntries();
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry curr = entries[i];
        IClasspathEntry resolved = JavaCore.getResolvedClasspathEntry(curr);
        if (resolved != null && libPath.equals(resolved.getPath())) {
            return curr; // return the real entry
        }
    }
    return null; // attachment not possible
}

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

public CPListElement(Object parent, IJavaProject project, int entryKind, IPath path, boolean newElement,
        IResource res, IPath linkTarget) {
    fProject = project;// w  w  w  .  j  a  va 2  s.co m

    fEntryKind = entryKind;
    fPath = path;
    fOrginalPath = newElement ? null : path;
    fLinkTarget = linkTarget;
    fOrginalLinkTarget = linkTarget;
    fChildren = new ArrayList<Object>();
    fResource = res;
    fIsExported = false;

    fIsMissing = false;
    fCachedEntry = null;
    fParentContainer = parent;

    switch (entryKind) {
    case IClasspathEntry.CPE_SOURCE:
        createAttributeElement(OUTPUT, null, true);
        createAttributeElement(INCLUSION, new Path[0], true);
        createAttributeElement(EXCLUSION, new Path[0], true);
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        createAttributeElement(IGNORE_OPTIONAL_PROBLEMS, null, false);
        break;
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
        createAttributeElement(SOURCEATTACHMENT, null, true);
        createAttributeElement(JAVADOC, null, false);
        createAttributeElement(SOURCE_ATTACHMENT_ENCODING, null, false);
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
        break;
    case IClasspathEntry.CPE_PROJECT:
        createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
        createAttributeElement(COMBINE_ACCESSRULES, Boolean.FALSE, true); // not rendered
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        break;
    case IClasspathEntry.CPE_CONTAINER:
        createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(fPath, fProject);
            if (container != null) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                if (entries != null) { // catch invalid container implementation
                    for (int i = 0; i < entries.length; i++) {
                        IClasspathEntry entry = entries[i];
                        if (entry != null) {
                            CPListElement curr = createFromExisting(this, entry, fProject);
                            fChildren.add(curr);
                        } else {
                            JavaPlugin.logErrorMessage("Null entry in container '" + fPath + "'"); //$NON-NLS-1$//$NON-NLS-2$
                        }
                    }
                } else {
                    JavaPlugin.logErrorMessage("container returns null as entries: '" + fPath + "'"); //$NON-NLS-1$//$NON-NLS-2$
                }
            }
        } catch (JavaModelException e) {
        }
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        break;
    default:
    }
}

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPUserLibraryElement.java

License:Open Source License

public CPUserLibraryElement(String name, IClasspathContainer container, IJavaProject project) {
    fName = name;/*  w w w  .ja va2 s .co  m*/
    fChildren = new ArrayList<CPListElement>();
    if (container != null) {
        IClasspathEntry[] entries = container.getClasspathEntries();
        CPListElement[] res = new CPListElement[entries.length];
        for (int i = 0; i < res.length; i++) {
            IClasspathEntry curr = entries[i];
            CPListElement elem = CPListElement.createFromExisting(this, curr, project);
            //elem.setAttribute(CPListElement.SOURCEATTACHMENT, curr.getSourceAttachmentPath());
            //elem.setAttribute(CPListElement.JAVADOC, JavaUI.getLibraryJavadocLocation(curr.getPath()));
            fChildren.add(elem);
        }
        fIsSystemLibrary = container.getKind() == IClasspathContainer.K_SYSTEM;
    } else {
        fIsSystemLibrary = false;
    }
}

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPUserLibraryElement.java

License:Open Source License

public boolean hasChanges(IClasspathContainer oldContainer) {
    if (oldContainer == null || (oldContainer.getKind() == IClasspathContainer.K_SYSTEM) != fIsSystemLibrary) {
        return true;
    }/*ww w .j a  v a  2s  . c o  m*/
    IClasspathEntry[] oldEntries = oldContainer.getClasspathEntries();
    if (fChildren.size() != oldEntries.length) {
        return true;
    }
    for (int i = 0; i < oldEntries.length; i++) {
        CPListElement child = fChildren.get(i);
        if (!child.getClasspathEntry().equals(oldEntries[i])) {
            return true;
        }
    }
    return false;
}

From source file:bz.davide.dmeclipsesavehookplugin.builder.DMEclipseSaveHookPluginBuilder.java

License:Open Source License

static void findTransitiveDepProjects(IJavaProject current, ArrayList<IProject> projects,
        ArrayList<String> fullClasspath) throws CoreException {
    if (!projects.contains(current.getProject())) {
        projects.add(current.getProject());
    }/*from   w w  w. jav  a2 s  .c o m*/

    fullClasspath.add(ResourcesPlugin.getWorkspace().getRoot().findMember(current.getOutputLocation())
            .getLocation().toOSString() + "/");
    ArrayList<IClasspathEntry> classPaths = new ArrayList<IClasspathEntry>();
    classPaths.addAll(Arrays.asList(current.getRawClasspath()));

    for (int x = 0; x < classPaths.size(); x++) {
        IClasspathEntry cp = classPaths.get(x);
        if (cp.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            String prjName = cp.getPath().lastSegment();
            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
            if (prj.hasNature(JavaCore.NATURE_ID)) {
                IJavaProject javaProject = JavaCore.create(prj);
                findTransitiveDepProjects(javaProject, projects, fullClasspath);
            }
            continue;
        }
        if (cp.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String fullContainerName = cp.getPath().toString();
            if (!fullContainerName.startsWith("org.eclipse.jdt.launching.JRE_CONTAINER/")) {
                System.out.println("CP C: " + fullContainerName);
                IClasspathContainer container = JavaCore.getClasspathContainer(cp.getPath(), current);
                classPaths.addAll(Arrays.asList(container.getClasspathEntries()));

            }
        }
        if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath path = cp.getPath();
            // Check first if this path is relative to workspace
            IResource workspaceMember = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
            if (workspaceMember != null) {
                String fullPath = workspaceMember.getLocation().toOSString();
                fullClasspath.add(fullPath);
            } else {
                fullClasspath.add(path.toOSString());
            }
        }
    }
}

From source file:ch.mlutz.plugins.t4e.container.T4eClasspathContainerInitializer.java

License:Open Source License

public void initialize(IPath containerPath, final IJavaProject project) {
    if (isT4eClasspathContainer(containerPath)) {
        IClasspathContainer container;
        final Activator plugin = Activator.getDefault();
        try {/*ww  w  .  j av a  2  s . c  om*/
            container = JavaCore.getClasspathContainer(containerPath, project);
        } catch (JavaModelException e) {
            log.error("Unable to get container for " + containerPath.toString(), e);
            return;
        }

        // plugin.getMavenModelManager().initModels(new NullProgressMonitor());

        T4eClasspathContainer t4eContainer;
        if (container == null) {

            // parse the pom.xml
            IProject resourceProject = project.getProject();

            PomParser pomParser = new PomParser();

            IFile pomFile = resourceProject.getFile("pom.xml");
            List<Dependency> dependencies;
            if (pomFile.exists()) {

                try {
                    pomParser.parse(pomFile.getContents());
                } catch (UnsupportedEncodingException e) {
                    log.warn("Unsupported encoding in pom.xml: " + e);
                } catch (CoreException e) {
                    log.warn("CoreException when getting contents of pom.xml: " + e);
                }

                dependencies = pomParser.getDependencyManagement();
                log.info("DependencyManagement dependencies count: " + String.valueOf(dependencies.size()));
                dependencies = pomParser.getDependencies();
                log.info("Dependencies count: " + String.valueOf(dependencies.size()));
            } else {
                log.warn("pom.xml doesn't seem to exist.");
            }

            // add dependency management entries to T4eClasspathContainer7
            List<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>();

            String mavenRepositoryBasePath = MavenTools.getMavenLocalRepoPath().replaceAll("\\\\", "/");
            dependencies = pomParser.getDependencyManagement();
            for (Dependency dependency : dependencies) {
                Path path = new Path(
                        mavenRepositoryBasePath + "/" + dependency.getGroupId().replaceAll("\\.", "/") + "/"
                                + dependency.getArtifactId() + "/" + dependency.getVersion() + "/"
                                + dependency.getArtifactId() + "-" + dependency.getVersion() + ".jar");
                entryList.add(JavaCore.newLibraryEntry(path, null, null, true));
            }

            t4eContainer = new T4eClasspathContainer(new Path(Constants.CONTAINER_ID),
                    (IClasspathEntry[]) entryList.toArray(new IClasspathEntry[0]));
        } else {
            t4eContainer = new T4eClasspathContainer(containerPath, container.getClasspathEntries());
        }

        try {
            JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project },
                    new IClasspathContainer[] { t4eContainer }, new NullProgressMonitor());
        } catch (JavaModelException e) {
            log.warn("Unable to set container for " + containerPath.toString(), e);
            return;
        }

        if (container != null) {
            return;
        }

        /*
        plugin.getBuildpathManager().scheduleUpdateClasspathContainer(project.getProject());
        */
    }
}

From source file:cn.dockerfoundry.ide.eclipse.server.core.internal.application.JavaWebApplicationDelegate.java

License:Open Source License

/**
 * Attempts to determine the framework based on the contents and nature of
 * the project. Returns null if no framework was determined.
 * @param project//from  www  .jav a 2s.c o m
 * @return Framework type or null if framework was not determined.
 * @deprecated kept for reference as to how application type was being
 * determined from a Java project for legacy v1 CF servers. v2 Servers no
 * longer require a framework for an application, as frameworks have been
 * replaced with buildpacks.
 */
protected String getFramework(IProject project) {
    if (project != null) {
        IJavaProject javaProject = DockerFoundryProjectUtil.getJavaProject(project);
        if (javaProject != null) {
            if (DockerFoundryProjectUtil.hasNature(project, DockerFoundryConstants.GRAILS_NATURE)) {
                return DockerFoundryConstants.GRAILS;
            }

            // in case user has Grails projects without the nature
            // attached
            if (project.isAccessible() && project.getFolder("grails-app").exists() //$NON-NLS-1$
                    && project.getFile("application.properties").exists()) { //$NON-NLS-1$
                return DockerFoundryConstants.GRAILS;
            }

            IClasspathEntry[] entries;
            boolean foundSpringLibrary = false;
            try {
                entries = javaProject.getRawClasspath();
                for (IClasspathEntry entry : entries) {
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        if (isLiftLibrary(entry)) {
                            return DockerFoundryConstants.LIFT;
                        }
                        if (isSpringLibrary(entry)) {
                            foundSpringLibrary = true;
                        }
                    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                        IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
                                javaProject);
                        if (container != null) {
                            for (IClasspathEntry childEntry : container.getClasspathEntries()) {
                                if (isLiftLibrary(childEntry)) {
                                    return DockerFoundryConstants.LIFT;
                                }
                                if (isSpringLibrary(childEntry)) {
                                    foundSpringLibrary = true;
                                }
                            }
                        }
                    }
                }
            } catch (JavaModelException e) {
                // Log the error but don't throw it again as there may be
                // other ways to detect the framework
                DockerFoundryPlugin.log(new Status(IStatus.WARNING, DockerFoundryPlugin.PLUGIN_ID,
                        "Unexpected error during auto detection of application type", e)); //$NON-NLS-1$
            }

            if (DockerFoundryProjectUtil.isSpringProject(project)) {
                return DockerFoundryConstants.SPRING;
            }

            if (foundSpringLibrary) {
                return DockerFoundryConstants.SPRING;
            }
        }
    }
    return null;
}