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

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

Introduction

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

Prototype

IPath getPath();

Source Link

Document

Returns the path of this classpath entry.

Usage

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 w w  . j a  v a2  s. co  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.ui.NewIvyDEContainerWizard.java

License:Apache License

public boolean performFinish() {
    containerPage.finish();//  ww w.j a v  a  2 s  . c o  m
    IClasspathEntry newEntry = containerPage.getSelection();
    IPath path = newEntry.getPath();
    IJavaProject project = containerPage.getProject();
    try {
        IvyClasspathContainerImpl ivycp = new IvyClasspathContainerImpl(project, path, new IClasspathEntry[0],
                new IClasspathAttribute[0]);
        JavaCore.setClasspathContainer(path, new IJavaProject[] { project },
                new IClasspathContainer[] { ivycp }, null);
        IClasspathEntry[] entries = project.getRawClasspath();
        List newEntries = new ArrayList(Arrays.asList(entries));
        newEntries.add(newEntry);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        project.setRawClasspath(entries, project.getOutputLocation(), null);
        ivycp.launchResolve(false, null);
    } catch (JavaModelException e) {
        IvyPlugin.log(e);
        return false;
    }
    return true;
}

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 v a  2  s.c o  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  ww  w  . jav  a2 s .  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  .  j  a va  2  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);
}

From source file:org.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
                && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath())) {
            changed = true;/* www .ja v  a 2s  . c om*/
        } else {
            newEntries.add(entry);
        }
    }

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

From source file:org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore.java

License:Open Source License

protected Predicate<IClasspathEntry> repositoryDependenciesEntry() {
    return new Predicate<IClasspathEntry>() {

        @Override/*from   w  ww .ja va 2  s .  c o m*/
        public boolean apply(final IClasspathEntry input) {
            return input.getPath().equals(new Path("repositoryDependencies"));
        }
    };
}

From source file:org.bonitasoft.studio.common.repository.Repository.java

License:Open Source License

@Override
public URLClassLoader createProjectClassloader() {
    final List<URL> jars = new ArrayList<URL>();
    try {//from w w w  . j av  a  2s. co m
        if (!classpathExists()) {
            initClasspath(getProject());
        }

        //Synchronize with build jobs
        Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, NULL_PROGRESS_MONITOR);
        Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, NULL_PROGRESS_MONITOR);

        IProject project = getProject();
        String workspacePath = project.getLocation().toFile().getParent();
        String outputPath = workspacePath + getJavaProject().getOutputLocation().toString();
        jars.add(new File(outputPath).toURI().toURL());
        for (IClasspathEntry entry : getJavaProject().getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                File jar = entry.getPath().toFile();
                if (!jar.exists()) { // jar location relative to project
                    jar = new File(workspacePath + File.separator + jar);
                }
                jars.add(jar.toURI().toURL());
            }
        }
    } catch (Exception e) {
        BonitaStudioLog.error(e);
    }

    return new NonLockingJarFileClassLoader(getName() + "_URLClassLoader", jars.toArray(new URL[jars.size()]),
            BusinessArchive.class.getClassLoader());
}

From source file:org.bonitasoft.studio.repository.test.TestExtensionProject.java

License:Open Source License

public void testExtensionProjectClasspathDoesNotContainAbsoluteFile() throws JavaModelException {
    for (IClasspathEntry entry : RepositoryManager.getInstance().getCurrentRepository().getJavaProject()
            .getRawClasspath()) {//  w  w w  . j a v a2 s.c  o  m
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            File file = new File(entry.getPath().toString());
            if (file.exists() && file.isAbsolute() && !Platform.inDevelopmentMode()) {
                fail("Classpath should not contain absolute entry: " + entry.getPath().toString());
            }
        }
    }
}

From source file:org.checkthread.plugin.eclipse.CheckThreadRunner.java

License:Open Source License

private static void loadDirFromProject(HashMap<IProject, Boolean> projectSearchMap, boolean isrecursed,
        IProject project, ArrayList<IPath> srcDirList, ArrayList<URI> targetFileList,
        ArrayList<URI> classPathList) {

    // if we already searched this project
    if (projectSearchMap.get(project) != null) {
        return;/*from   w ww  .  j ava 2s.  c o  m*/

        // we haven't searched this project yet
    } else {
        // add to cache
        projectSearchMap.put(project, true);
    }

    // recursive traverse referenced projects
    // stopping condition: project already searched
    try {
        IProject[] projectList = project.getReferencedProjects();
        for (IProject p : projectList) {
            loadDirFromProject(projectSearchMap, true, p, srcDirList, targetFileList, classPathList);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    IJavaProject javaProject = JavaCore.create(project);
    IPath defaultOutputLocationRelative = null;

    try {
        defaultOutputLocationRelative = javaProject.getOutputLocation();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    sLogger.info("DEFAULT OUTPUT LOCATION RELATIVE: " + defaultOutputLocationRelative);

    IPath projectLocationAbsolute = project.getLocation();
    sLogger.info("PROJECT LOCATION: " + projectLocationAbsolute);

    // Make path absolute
    IPath defaultOutputLocationAbsolute = projectLocationAbsolute
            .append(defaultOutputLocationRelative.removeFirstSegments(1));
    sLogger.info("DEFAULT OUTPUT LOCATION ABSOLUTE: " + defaultOutputLocationAbsolute);

    // Work around, stomp over target java files. Instead, just give the
    // root directory
    sLogger.info("WORKAROUND: IGNORE CHANGED CLASS FILES< RECHECK EVERYTHING");

    if (!isrecursed) {
        URI uri = defaultOutputLocationAbsolute.toFile().toURI();
        if (uri != null) {
            targetFileList.add(uri);
        }
    }

    // Add to input
    URI cURI = defaultOutputLocationAbsolute.toFile().toURI();
    if (cURI != null) {
        classPathList.add(cURI);
    }

    // Loop through classpath entries and get src directory list
    IClasspathEntry[] rawClassPathList = null;
    try {
        rawClassPathList = javaProject.getRawClasspath();
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    if (rawClassPathList != null) {
        for (IClasspathEntry classPathEntry : rawClassPathList) {
            switch (classPathEntry.getEntryKind()) {

            // Source Directory
            case IClasspathEntry.CPE_SOURCE: {
                if (!isrecursed) {
                    IPath p = classPathEntry.getPath().removeFirstSegments(1);
                    if (p != null) {
                        srcDirList.add(p);
                        sLogger.info("CPE_SOURCE: " + p);
                    }
                }
                break;
            }

            // external libraries used
            case IClasspathEntry.CPE_LIBRARY: {

                File file = classPathEntry.getPath().toFile();
                IPath p;
                // The entry may be a relative path to the project root
                // or it could be an absolute path to a library.
                if (file.isFile() || file.isDirectory()) {
                    p = classPathEntry.getPath();
                } else {
                    p = projectLocationAbsolute.append(classPathEntry.getPath().removeFirstSegments(1));
                }

                URI uri = p.toFile().toURI();
                if (uri != null) {
                    classPathList.add(uri);
                }
                sLogger.info("CPE_LIBRARY: " + uri);
                break;
            }

            // ignore
            case IClasspathEntry.CPE_CONTAINER:
                sLogger.info("CPE_CONTAINER: " + classPathEntry);
                break;

            //ignore
            case IClasspathEntry.CPE_PROJECT:
                sLogger.info("CPE_PROJECT: " + classPathEntry);
                break;
            }
        }
    }
}