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:at.bestsolution.javafx.ide.jdt.internal.NewJavaProjectService.java

License:Open Source License

public static void flush(List<CPListElement> classPathEntries, IPath outputLocation, IJavaProject javaProject,
        String newProjectCompliance, IProgressMonitor monitor)
        throws CoreException, OperationCanceledException {
    IProject project = javaProject.getProject();
    IPath projPath = project.getFullPath();

    IPath oldOutputLocation;// ww  w  . j a  va 2s. c  o m
    try {
        oldOutputLocation = javaProject.getOutputLocation();
    } catch (CoreException e) {
        oldOutputLocation = projPath.append(
                "bin"/*PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)*/);
    }

    if (oldOutputLocation.equals(projPath) && !outputLocation.equals(projPath)) {
        if (BuildPathsBlock.hasClassfiles(project)) {
            //            if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(false, projPath)) {
            BuildPathsBlock.removeOldClassfiles(project);
            //            }
        }
    } else if (!outputLocation.equals(oldOutputLocation)) {
        IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation);
        if (folder.exists()) {
            if (folder.members().length == 0) {
                BuildPathsBlock.removeOldClassfiles(folder);
            } else {
                //               if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(folder.isDerived(), oldOutputLocation)) {
                BuildPathsBlock.removeOldClassfiles(folder);
                //               }
            }
        }
    }

    monitor.worked(1);

    IWorkspaceRoot fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    //create and set the output path first
    if (!fWorkspaceRoot.exists(outputLocation)) {
        IFolder folder = fWorkspaceRoot.getFolder(outputLocation);
        CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
    } else {
        monitor.worked(1);
    }
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }

    int nEntries = classPathEntries.size();
    IClasspathEntry[] classpath = new IClasspathEntry[nEntries];
    int i = 0;

    for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) {
        CPListElement entry = iter.next();
        classpath[i] = entry.getClasspathEntry();
        i++;

        IResource res = entry.getResource();
        //1 tick
        if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) {
            CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1));
        } else {
            monitor.worked(1);
        }

        //3 ticks
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT);
            if (folderOutput != null && folderOutput.segmentCount() > 1) {
                IFolder folder = fWorkspaceRoot.getFolder(folderOutput);
                CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
            } else {
                monitor.worked(1);
            }

            IPath path = entry.getPath();
            if (projPath.equals(path)) {
                monitor.worked(2);
                continue;
            }

            if (projPath.isPrefixOf(path)) {
                path = path.removeFirstSegments(projPath.segmentCount());
            }
            IFolder folder = project.getFolder(path);
            IPath orginalPath = entry.getOrginalPath();
            if (orginalPath == null) {
                if (!folder.exists()) {
                    //New source folder needs to be created
                    if (entry.getLinkTarget() == null) {
                        CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2));
                    } else {
                        folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                new SubProgressMonitor(monitor, 2));
                    }
                }
            } else {
                if (projPath.isPrefixOf(orginalPath)) {
                    orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount());
                }
                IFolder orginalFolder = project.getFolder(orginalPath);
                if (entry.getLinkTarget() == null) {
                    if (!folder.exists()) {
                        //Source folder was edited, move to new location
                        IPath parentPath = entry.getPath().removeLastSegments(1);
                        if (projPath.isPrefixOf(parentPath)) {
                            parentPath = parentPath.removeFirstSegments(projPath.segmentCount());
                        }
                        if (parentPath.segmentCount() > 0) {
                            IFolder parentFolder = project.getFolder(parentPath);
                            if (!parentFolder.exists()) {
                                CoreUtility.createFolder(parentFolder, true, true,
                                        new SubProgressMonitor(monitor, 1));
                            } else {
                                monitor.worked(1);
                            }
                        } else {
                            monitor.worked(1);
                        }
                        orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1));
                    }
                } else {
                    if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) {
                        orginalFolder.delete(true, new SubProgressMonitor(monitor, 1));
                        folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                new SubProgressMonitor(monitor, 1));
                    }
                }
            }
        } else {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (!path.equals(entry.getOrginalPath())) {
                    String eeID = JavaRuntime.getExecutionEnvironmentId(path);
                    if (eeID != null) {
                        BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance);
                        newProjectCompliance = null; // don't set it again below
                    }
                }
                if (newProjectCompliance != null) {
                    Map<String, String> options = javaProject.getOptions(false);
                    JavaModelUtil.setComplianceOptions(options, newProjectCompliance);
                    JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options
                    javaProject.setOptions(options);
                }
            }
            monitor.worked(3);
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
    }

    javaProject.setRawClasspath(classpath, outputLocation, new SubProgressMonitor(monitor, 2));
}

From source file:bndtools.builder.BndProjectNature.java

License:Open Source License

private void installBndClasspath() throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && BndContainerInitializer.PATH_ID.equals(entry.getPath()))
            return; // already installed
    }/*from  ww  w  . j a  v  a  2s . com*/

    IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + 1];
    System.arraycopy(classpath, 0, newEntries, 0, classpath.length);
    newEntries[classpath.length] = JavaCore.newContainerEntry(BndContainerInitializer.PATH_ID);

    javaProject.setRawClasspath(newEntries, null);
}

From source file:bndtools.builder.BndProjectNature.java

License:Open Source License

private void removeBndClasspath() throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(classpath.length);

    boolean changed = false;
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && BndContainerInitializer.PATH_ID.equals(entry.getPath())) {
            changed = true;//from   ww w .j ava2  s .co  m
        } else {
            newEntries.add(entry);
        }
    }

    if (changed)
        javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null);
}

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  . jav a  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:ca.mcgill.sable.soot.launching.DavaHandler.java

License:Open Source License

public void handleAfter() {
    ArrayList newMembers = new ArrayList();
    IPath jreLibPath = null;//from   ww w .ja  v  a 2s  .c o m
    try {
        IResource[] elems = getSootOutputFolder().getFolder(Messages.getString("DavaHandler.dava"))
                .getFolder(Messages.getString("DavaHandler.src")).members();
        for (int i = 0; i < elems.length; i++) {
            if (getBeforeList() == null) {
                newMembers.add(elems[i]);
                if (elems[i] instanceof IFile) {

                    SootPlugin.getDefault().getManager().setToFalseRemove((IFile) elems[i]);
                }
            } else if (getBeforeList().contains(elems[i])) {
                if (elems[i] instanceof IFile) {

                    if (SootPlugin.getDefault().getManager().isFileMarkersRemove((IFile) elems[i])) {
                        newMembers.add(elems[i]);
                        // this sets changed bit to 0 - so file doesn't stay on list indefinitely

                        SootPlugin.getDefault().getManager().setToFalseRemove((IFile) elems[i]);
                    }
                }

            } else if (!getBeforeList().contains(elems[i])) {
                if (SootPlugin.getDefault().getManager().getChangedResources() == null) {
                } else if (SootPlugin.getDefault().getManager().getChangedResources().containsKey(elems[i])) {
                    newMembers.add(elems[i]);
                    // this sets changed bit to 0 - so file doesn't stay on list indefinitely
                    if (elems[i] instanceof IFile) {

                        SootPlugin.getDefault().getManager().setToFalseRemove((IFile) elems[i]);
                    }
                }
            }
        }

        // testing class lib copying
        IProject proj = getSootOutputFolder().getProject();
        IResource[] elements = proj.members();

        IJavaProject jProj = JavaCore.create(proj);
        IClasspathEntry[] paths = jProj.getRawClasspath();

        for (int i = 0; i < paths.length; i++) {
            switch (paths[i].getEntryKind()) {
            case IClasspathEntry.CPE_CONTAINER: {
                jreLibPath = paths[i].getPath();

                break;
            }

            }
        }
    } catch (CoreException e) {
    }

    if (!newMembers.isEmpty()) {

        // if is special dava project add src files there
        if (davaProjectExists()) {
            setDavaProj(JavaCore.create(SootPlugin.getWorkspace().getRoot().getProject(getDavaProjName())));
            if (getDavaProj().isOpen()) {
                if (shouldCopyFiles()) {
                    copyFiles(newMembers);
                }
            } else {
                openProject();
                if (shouldCopyFiles()) {
                    copyFiles(newMembers);
                }
            }
        }
        // if not special dava project ask user to create and add files there
        else {
            boolean result = createSpecialDavaProject(jreLibPath);
            if (result) {
                copyFiles(newMembers);
            }

        }
    }
}

From source file:ccw.builder.ClojureBuilder.java

License:Open Source License

private static Map<IFolder, IFolder> getSrcFolders(IProject project) throws CoreException {
    Map<IFolder, IFolder> srcFolders = new HashMap<IFolder, IFolder>();

    IJavaProject jProject = JavaCore.create(project);
    IClasspathEntry[] entries = jProject.getResolvedClasspath(true);
    IPath defaultOutputFolder = jProject.getOutputLocation();
    for (IClasspathEntry entry : entries) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            IFolder folder = project.getWorkspace().getRoot().getFolder(entry.getPath());
            IFolder outputFolder = project.getWorkspace().getRoot().getFolder(
                    (entry.getOutputLocation() == null) ? defaultOutputFolder : entry.getOutputLocation());
            if (folder.exists())
                srcFolders.put(folder, outputFolder);
            break;
        case IClasspathEntry.CPE_LIBRARY:
            break;
        case IClasspathEntry.CPE_PROJECT:
            // TODO should compile here ?
            break;
        case IClasspathEntry.CPE_CONTAINER:
        case IClasspathEntry.CPE_VARIABLE:
            // Impossible cases, since entries are resolved
        default:/*from   www  .j a va 2 s .c om*/
            break;
        }
    }
    return srcFolders;
}

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   w w  w .  ja v  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;
}

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

License:Apache License

public static boolean isContainerInClasspath(IJavaProject javaProject, IClasspathContainer container)
        throws JavaModelException {
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    // IClasspathEntry[] temps = container.getClasspathEntries();
    boolean result = false;

    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && entry.getPath().equals(container.getPath())) {
            result = true;/*from   w  w w.  j  av  a  2s  .  com*/
            break;
        }
    }
    return result;
}

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

License:Apache License

/**
 * Get all classpathentries for the given project.
 * /*w w  w .  j  av a2 s .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[] {});
}

From source file:cn.ieclipse.aorm.eclipse.helpers.IntentReflectionHelper.java

License:Apache License

/**
 * Get all classpathentries for the given project.
 * // ww w .  ja v a 2 s .  com
 * @param javaProject
 *            project to get the classpath for.
 * @return classpathentries
 */
private 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[] {});
}