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

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

Introduction

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

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:org.apache.felix.sigil.ui.eclipse.handlers.project.ConvertProjectCommandHandler.java

License:Apache License

public Object execute(IResource[] resources, ExecutionEvent event) throws ExecutionException {
    for (IResource r : resources) {
        final IProject project = (IProject) r;
        if (project != null) {
            WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
                @Override// w  ww  .  jav  a2 s . c  o  m
                protected void execute(IProgressMonitor monitor) throws CoreException {
                    SigilCore.makeSigilProject(project, monitor);
                    IJavaProject java = JavaCore.create(project);
                    ISigilProjectModel sigil = SigilCore.create(project);
                    IClasspathEntry[] entries = java.getRawClasspath();
                    for (int i = 0; i < entries.length; i++) {
                        IClasspathEntry entry = entries[i];
                        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                            String encodedClasspath = sigil.getJavaModel().encodeClasspathEntry(entry);
                            sigil.getBundle().addClasspathEntry(encodedClasspath);
                        }
                    }
                    sigil.save(monitor);
                }
            };
            SigilUI.runWorkspaceOperation(op, null);
        }
    }

    return null;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

/**
 * Search the Ivy classpath containers within the specified Java project
 * //from  w ww.  j ava 2  s .co m
 * @param javaProject
 *            the project to search into
 * @return the Ivy classpath container if found
 */
public static List<IvyClasspathContainer> getContainers(IJavaProject javaProject) {
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainer) {
                        containers.add((IvyClasspathContainer) cp);
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

public static List<IvyClasspathContainer> getContainersFromIvyFile(IFile ivyfile) {
    IJavaProject javaProject = JavaCore.create(ivyfile.getProject());
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }//w ww  .  jav  a  2 s  .c o m
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainerImpl) {
                        IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) cp;
                        if (ivycp.getConf().getIvyXmlPath()
                                .equals(ivyfile.getProjectRelativePath().toString())) {
                            containers.add(ivycp);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

public static List<IvyClasspathContainer> getContainersFromIvySettings(IFile ivySettings) {
    IJavaProject javaProject = JavaCore.create(ivySettings.getProject());
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }/*  ww w. j  a  v  a 2  s. c o m*/
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainerImpl) {
                        IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) cp;
                        ResolvedPath settingsPath;
                        try {
                            settingsPath = ivycp.getConf().getInheritedSettingsSetup()
                                    .getResolvedIvySettingsPath(ivycp.getConf().getProject());
                        } catch (IvyDEException e) {
                            // cannot resolve the ivy settings so just ignore
                            continue;
                        }
                        if (settingsPath.getResolvedPath()
                                .equals(ivySettings.getProjectRelativePath().toString())) {
                            containers.add(ivycp);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

/**
 * Search the Ivy classpath entry within the specified Java project with the specific path
 * /*from  w  w w.  ja  v  a2 s .c o  m*/
 * @param containerPath
 *            the path of the container
 * @param javaProject
 *            the project to search into
 * @return the Ivy classpath container if found, otherwise return <code>null</code>
 */
public static IClasspathEntry getEntry(IPath containerPath, IJavaProject javaProject) {
    if (javaProject == null || !javaProject.exists()) {
        return null;
    }
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (containerPath.equals(entry.getPath())) {
                    return entry;
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return null;
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyAttachementManager.java

License:Apache License

public void updateAttchements(IJavaProject project, IPath containerPath,
        IClasspathContainer containerSuggestion) {
    IvyDEMessage.verbose("Updating attachements on the container " + containerPath);

    Properties newProps = new Properties();

    IClasspathEntry[] newEntries = containerSuggestion.getClasspathEntries();
    for (int i = 0; i < newEntries.length; i++) {
        IClasspathEntry entry = newEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            if (entry.getSourceAttachmentPath() != null) {
                newProps.put(path + SRC_SUFFIX, entry.getSourceAttachmentPath().toPortableString());
            }/* w ww .  j  av  a2 s.  com*/
            if (entry.getSourceAttachmentRootPath() != null) {
                newProps.put(path + SRCROOT_SUFFIX, entry.getSourceAttachmentRootPath().toPortableString());
            }
            String javadocUrl = getJavadocLocation(entry);
            if (javadocUrl != null) {
                newProps.put(path + DOC_SUFFIX, javadocUrl);
            }
        }
    }

    IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) IvyClasspathContainerHelper
            .getContainer(containerPath, project);
    if (ivycp == null) {
        IvyDEMessage.error("The IvyDE container could not be found. Aborting updating attachements.");
        // something wrong happened, give up
        return;
    }
    IClasspathEntry[] existingEntries = ivycp.getClasspathEntries();
    for (int i = 0; i < existingEntries.length; i++) {
        IClasspathEntry entry = existingEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            String value = (String) prop.get(path + SRC_SUFFIX);
            if (value != null && entry.getSourceAttachmentPath() != null
                    && value.equals(entry.getSourceAttachmentPath().toPortableString())) {
                newProps.remove(path + SRC_SUFFIX);
            }
            value = (String) prop.get(path + SRCROOT_SUFFIX);
            if (value != null && entry.getSourceAttachmentRootPath() != null
                    && value.equals(entry.getSourceAttachmentRootPath().toPortableString())) {
                newProps.remove(path + SRCROOT_SUFFIX);
            }
        }
    }

    // copy the actually new overrided properties
    prop.putAll(newProps);

    // now update the ivyde container for real
    ivycp.updateClasspathEntries(newEntries);

    // store the global result
    IvyDEMessage.verbose("Saving attachement properties");
    try {
        FileOutputStream out = new FileOutputStream(containersAttachementFile);
        try {
            prop.store(out, "");
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                // don't care
            }
        }
    } catch (IOException ioe) {
        IvyPlugin.logWarn("IvyDE attachement properties could not be saved", ioe);
    }
}

From source file:org.apache.ivyde.internal.eclipse.IvyDERuntimeClasspathEntryResolver.java

License:Apache License

private static IRuntimeClasspathEntry[] computeDefaultContainerEntries(IvyClasspathContainerImpl ivycp,
        IRuntimeClasspathEntry entry) throws CoreException {
    IClasspathEntry[] cpes;/*from w  ww  .j a  va 2s .  c o m*/
    if (ivycp.getClasspathEntries() == null
            || ivycp.getConf().getInheritedAdvancedSetup().isResolveBeforeLaunch()) {
        ClasspathEntriesResolver resolver = new ClasspathEntriesResolver(ivycp, false);
        ResolveRequest request = new ResolveRequest(resolver, ivycp.getState());
        request.setForceFailOnError(true);
        request.setInWorkspace(ivycp.getConf().getInheritedClasspathSetup().isResolveInWorkspace());
        request.setTransitive(ivycp.getConf().getInheritedClasspathSetup().isTransitiveResolve());
        IvyResolveJob resolveJob = IvyPlugin.getDefault().getIvyResolveJob();
        IStatus status = resolveJob.launchRequest(request, new NullProgressMonitor());
        if (status.getCode() != IStatus.OK) {
            throw new CoreException(status);
        }
        cpes = resolver.getClasspathEntries();
    } else {
        cpes = ivycp.getClasspathEntries();
    }
    List resolved = new ArrayList(cpes.length);
    List projects = new ArrayList();
    for (int i = 0; i < cpes.length; i++) {
        IClasspathEntry cpe = cpes[i];
        if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(cpe.getPath().segment(0));
            IJavaProject jp = JavaCore.create(p);
            if (!projects.contains(jp)) {
                projects.add(jp);
                IRuntimeClasspathEntry classpath = JavaRuntime.newProjectRuntimeClasspathEntry(jp);
                resolved.add(classpath);
                IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(classpath, jp);
                for (int j = 0; j < entries.length; j++) {
                    IRuntimeClasspathEntry e = entries[j];
                    if (!resolved.contains(e)) {
                        resolved.add(entries[j]);
                    }
                }
            }
        } else if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IRuntimeClasspathEntry e = JavaRuntime.newArchiveRuntimeClasspathEntry(cpe.getPath());
            if (!resolved.contains(e)) {
                resolved.add(e);
            }
        }
    }
    // set classpath property
    IRuntimeClasspathEntry[] result = new IRuntimeClasspathEntry[resolved.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = (IRuntimeClasspathEntry) resolved.get(i);
        result[i].setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
    }
    return result;
}

From source file:org.apache.ivyde.internal.eclipse.workspaceresolver.WorkspaceResourceChangeListener.java

License:Apache License

/**
 * Return the IvyDE container which include the specified project path as ivy dependency
 *///from w ww .  j  a va2  s . co m
private List getAffectedContainers(IPath projectPath) {
    List/* <IvyClasspathContainer> */ allContainers = new ArrayList();

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IJavaProject[] projects;
    try {
        projects = JavaCore.create(root).getJavaProjects();
    } catch (JavaModelException e) {
        // something bad happend in the JDT...
        IvyPlugin.log(e);
        return allContainers;
    }

    for (int i = 0; i < projects.length; i++) {
        IJavaProject javaProject = projects[i];
        List/* <IvyClasspathContainer> */ containers = IvyClasspathContainerHelper.getContainers(javaProject);
        Iterator/* <IvyClasspathContainer> */ itContainer = containers.iterator();
        while (itContainer.hasNext()) {
            IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) itContainer.next();
            IClasspathEntry[] containerEntries = ivycp.getClasspathEntries();
            for (int j = 0; j < containerEntries.length; j++) {
                IClasspathEntry containerEntry = containerEntries[j];
                if (containerEntry == null || containerEntry.getEntryKind() != IClasspathEntry.CPE_PROJECT
                        || !containerEntry.getPath().equals(projectPath)) {
                    continue;
                }
                allContainers.add(ivycp);
                break;
            }
        }
    }

    return allContainers;
}

From source file:org.azzyzt.jee.tools.project.JavaProject.java

License:EUPL

protected void moveJreToEndOfClassPath() throws JavaModelException {
    IClasspathEntry[] rawClasspath = jp.getRawClasspath();
    IClasspathEntry[] newRawClassPath = new IClasspathEntry[rawClasspath.length];
    for (int i = 0, offset = 0; i < rawClasspath.length; i++) {
        IClasspathEntry cpe = rawClasspath[i];
        if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && cpe.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) {
            if (newRawClassPath[rawClasspath.length - 1] == null) {
                newRawClassPath[rawClasspath.length - 1] = cpe;
                offset = 1;/*from w  w  w. java2s  . c  o m*/
            } else {
                Common.getDefault().log(
                        "FacetedProject " + getP().getName() + " has more than one JRE class path entry!!");
                newRawClassPath[i - offset] = cpe;
            }
        } else {
            newRawClassPath[i - offset] = cpe;
        }
    }
    jp.setRawClasspath(newRawClassPath, null);
}

From source file:org.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
                && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath()))
            return; // already installed
    }//from  w  w  w  .  java2  s .  c  o  m

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

    javaProject.setRawClasspath(newEntries, null);
}