Example usage for org.eclipse.jdt.core JavaCore getClasspathContainer

List of usage examples for org.eclipse.jdt.core JavaCore getClasspathContainer

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore getClasspathContainer.

Prototype

public static IClasspathContainer getClasspathContainer(IPath containerPath, IJavaProject project)
        throws JavaModelException 

Source Link

Document

Answers the project specific value for a given classpath container.

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 {// ww  w .  j a v a2  s .  c o  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 ww  .  ja  va  2s.  c  o 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)
                        && !"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 {/*ww w  .j  a  v  a 2s  .  c om*/
        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

/**
 * Helper method that tests if an classpath entry can be found in a
 * container. <code>null</code> is returned if the entry can not be found
 * or if the container does not allows the configuration of source
 * attachments/* w  w  w  . j  a va  2s .  c  o  m*/
 * @param jproject The container's parent project
 * @param containerPath The path of the container
 * @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.
 * @throws JavaModelException thrown if accessing the container failed
 */
public static IClasspathEntry getClasspathEntryToEdit(IJavaProject jproject, IPath containerPath, IPath libPath)
        throws JavaModelException {
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject);
    ClasspathContainerInitializer initializer = JavaCore
            .getClasspathContainerInitializer(containerPath.segment(0));
    if (container != null && initializer != null
            && initializer.canUpdateClasspathContainer(containerPath, jproject)) {
        return findEntryInContainer(container, libPath);
    }
    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  .  ja v a2 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.CPListElement.java

License:Open Source License

public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement,
        IJavaProject project) {//from  w ww .  j ava2 s .  c  om
    IPath path = curr.getPath();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    // get the resource
    IResource res = null;
    boolean isMissing = false;
    IPath linkTarget = null;

    switch (curr.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        try {
            isMissing = project != null && (JavaCore.getClasspathContainer(path, project) == null);
        } catch (JavaModelException e) {
            isMissing = true;
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        IPath resolvedPath = JavaCore.getResolvedVariablePath(path);
        isMissing = root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists();
        break;
    case IClasspathEntry.CPE_LIBRARY:
        res = root.findMember(path);
        if (res == null) {
            if (!ArchiveFileFilter.isArchivePath(path, true)) {
                if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
                        && root.getProject(path.segment(0)).exists()) {
                    res = root.getFolder(path);
                }
            }

            IPath rawPath = path;
            if (project != null) {
                IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(curr);
                if (roots.length == 1)
                    rawPath = roots[0].getPath();
            }
            isMissing = !rawPath.toFile().exists(); // look for external JARs and folders
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_SOURCE:
        path = path.removeTrailingSeparator();
        res = root.findMember(path);
        if (res == null) {
            if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
                res = root.getFolder(path);
            }
            isMissing = true;
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_PROJECT:
        res = root.findMember(path);
        isMissing = (res == null);
        break;
    }
    CPListElement elem = new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res,
            linkTarget);
    elem.setExported(curr.isExported());
    elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath());
    elem.setAttribute(OUTPUT, curr.getOutputLocation());
    elem.setAttribute(EXCLUSION, curr.getExclusionPatterns());
    elem.setAttribute(INCLUSION, curr.getInclusionPatterns());
    elem.setAttribute(ACCESSRULES, curr.getAccessRules());
    elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules()));

    IClasspathAttribute[] extraAttributes = curr.getExtraAttributes();
    for (int i = 0; i < extraAttributes.length; i++) {
        IClasspathAttribute attrib = extraAttributes[i];
        CPListElementAttribute attribElem = elem.findAttributeElement(attrib.getName());
        if (attribElem == null) {
            elem.createAttributeElement(attrib.getName(), attrib.getValue(), false);
        } else {
            attribElem.setValue(attrib.getValue());
        }
    }

    elem.setIsMissing(isMissing);
    return elem;
}

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());
    }/* w  w  w.j  ava  2  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;//  w w w.  ja v  a2s .c  o  m
        final Activator plugin = Activator.getDefault();
        try {
            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/*w  w  w .  ja v a 2 s .  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;
}

From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java

License:Apache License

/**
 * Get all classpathentries for the given project.
 * /*from   w w w.j av  a 2s . c  o  m*/
 * @param javaProject
 *            project to get the classpath for.
 * @return classpathentries
 */
private static String[] getJavaClasspath(IJavaProject javaProject) throws CoreException {
    List<String> classPath = new ArrayList<String>();
    String[] defaultClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
    classPath.addAll(Arrays.asList(defaultClassPath));

    // add CPE_CONTAINER classpathes
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    for (IClasspathEntry entry : rawClasspath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(entry.getPath(),
                    javaProject);
            if (classpathContainer != null) {
                IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries();
                for (IClasspathEntry cEntry : classpathEntries) {
                    classPath.add(cEntry.getPath().toOSString());
                }
            }
        }
    }
    return classPath.toArray(new String[] {});
}