Example usage for org.eclipse.jdt.core IJavaProject getResolvedClasspath

List of usage examples for org.eclipse.jdt.core IJavaProject getResolvedClasspath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getResolvedClasspath.

Prototype

IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry) throws JavaModelException;

Source Link

Document

This is a helper method returning the resolved classpath for the project as a list of simple (non-variable, non-container) classpath entries.

Usage

From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java

License:Open Source License

private void validateSourceFoldersInSrcIncludes(IBuildEntry includes) {
    if (includes == null)
        return;/*from   w w w .j  ava2  s.  c  o m*/

    List sourceFolderList = new ArrayList(0);
    try {
        IJavaProject javaProject = JavaCore.create(fProject);
        if (javaProject.exists()) {
            IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true);

            for (int index = 0; index < classPathEntries.length; index++) {
                if (classPathEntries[index].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    sourceFolderList.add(classPathEntries[index].getPath());
                }
            }
        }
    } catch (JavaModelException e) { //do nothing
    }

    List reservedTokens = Arrays.asList(RESERVED_NAMES);

    String[] tokens = includes.getTokens();
    for (int i = 0; i < tokens.length; i++) {
        IResource res = fProject.findMember(tokens[i]);
        if (res == null)
            continue;
        String errorMessage = null;
        if (sourceFolderList.contains(res.getFullPath())) {
            errorMessage = MDECoreMessages.BuildErrorReporter_srcIncludesSourceFolder;
        } else if (tokens[i].startsWith(".") //$NON-NLS-1$
                || reservedTokens.contains(res.getName().toString().toLowerCase())) {
            errorMessage = NLS.bind(MDECoreMessages.BuildErrorReporter_srcIncludesSourceFolder1, res.getName());
        }

        if (errorMessage != null) {
            prepareError(includes.getName(), tokens[i], errorMessage, MDEMarkerFactory.B_REMOVAL,
                    fSrcInclSeverity, MDEMarkerFactory.CAT_OTHER);
        }
    }

}

From source file:com.siteview.mde.internal.launching.launcher.LauncherUtils.java

License:Open Source License

private static String getTimeStamp(IProject project) {
    IJavaProject jp = JavaCore.create(project);
    try {//  w w w .ja  v a  2 s.  c  o m
        long timeStamp = 0;
        IClasspathEntry[] entries = jp.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                File file;
                IPath location = entries[i].getOutputLocation();
                if (location == null)
                    location = jp.getOutputLocation();
                IResource res = project.getWorkspace().getRoot().findMember(location);
                IPath path = res == null ? null : res.getLocation();
                if (path == null)
                    continue;
                file = path.toFile();
                Stack files = new Stack();
                files.push(file);
                while (!files.isEmpty()) {
                    file = (File) files.pop();
                    if (file.isDirectory()) {
                        File[] children = file.listFiles();
                        if (children != null) {
                            for (int j = 0; j < children.length; j++)
                                files.push(children[j]);
                        }
                    } else if (file.getName().endsWith(".class") && timeStamp < file.lastModified()) //$NON-NLS-1$
                        timeStamp = file.lastModified();
                }
            }
        }
        IFile[] otherFiles = new IFile[] { PDEProject.getManifest(project),
                PDEProject.getBuildProperties(project) };
        for (int i = 0; i < otherFiles.length; i++) {
            IFile file = otherFiles[i];
            if (file != null) {
                long fileTimeStamp = file.getRawLocation().toFile().lastModified();
                if (timeStamp < fileTimeStamp)
                    timeStamp = fileTimeStamp;
            }
        }
        return Long.toString(timeStamp);
    } catch (JavaModelException e) {
    }
    return "0"; //$NON-NLS-1$
}

From source file:com.sympedia.genfw.util.ClasspathHelper.java

License:Open Source License

public static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls) {
    try {/*from   w w w  .  java  2 s. c o  m*/
        collectClasspathUrlOutput(javaProject.getOutputLocation(), urls);

        IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : resolvedClasspath) {
            try {
                switch (entry.getEntryKind()) {
                case IClasspathEntry.CPE_SOURCE:
                    collectClasspathUrlOutput(entry.getOutputLocation(), urls);
                    break;

                case IClasspathEntry.CPE_LIBRARY:
                    File libFile = new File(entry.getPath().toString());
                    URL url = libFile.toURL();
                    if (!urls.contains(url)) {
                        //              System.out.println("LIB: " + url);
                        urls.add(url);
                    }
                    break;

                case IClasspathEntry.CPE_PROJECT:
                    String projectName = entry.getPath().segment(0);
                    IJavaProject requiredProject = getJavaProject(projectName);
                    collectClasspathURLs(requiredProject, urls);
                    break;

                default:
                    throw new RuntimeException();
                }
            } catch (MalformedURLException ex) {
                ex.printStackTrace();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.temenos.ds.op.xtext.ui.internal.se.JdtBasedProcessorProvider.java

License:Open Source License

protected URLClassLoader createClassLoaderForJavaProject(final IJavaProject projectToUse) {
    try {/*  w w w . j  a v a 2  s  .  c  o  m*/
        final IClasspathEntry[] resolvedClasspath = projectToUse.getResolvedClasspath(true);
        final List<URL> urls = CollectionLiterals.<URL>newArrayList();
        List<URL> _outputFolders = this.getOutputFolders(projectToUse);
        urls.addAll(_outputFolders);
        for (final IClasspathEntry entry : resolvedClasspath) {
            {
                URL url = null;
                int _entryKind = entry.getEntryKind();
                switch (_entryKind) {
                case IClasspathEntry.CPE_SOURCE:
                    break;
                case IClasspathEntry.CPE_PROJECT:
                    IPath path = entry.getPath();
                    IWorkspaceRoot _workspaceRoot = this.getWorkspaceRoot(projectToUse);
                    final IResource project = _workspaceRoot.findMember(path);
                    IProject _project = project.getProject();
                    IJavaProject _create = JavaCore.create(_project);
                    List<URL> _outputFolders_1 = this.getOutputFolders(_create);
                    urls.addAll(_outputFolders_1);
                    break;
                case IClasspathEntry.CPE_LIBRARY:
                    IPath path_1 = entry.getPath();
                    IWorkspaceRoot _workspaceRoot_1 = this.getWorkspaceRoot(projectToUse);
                    final IResource library = _workspaceRoot_1.findMember(path_1);
                    URL _xifexpression = null;
                    boolean _notEquals = (!Objects.equal(library, null));
                    if (_notEquals) {
                        URI _rawLocationURI = library.getRawLocationURI();
                        _xifexpression = _rawLocationURI.toURL();
                    } else {
                        File _file = path_1.toFile();
                        URI _uRI = _file.toURI();
                        _xifexpression = _uRI.toURL();
                    }
                    url = _xifexpression;
                    break;
                default: {
                    IPath path_2 = entry.getPath();
                    File _file_1 = path_2.toFile();
                    URI _uRI_1 = _file_1.toURI();
                    URL _uRL = _uRI_1.toURL();
                    url = _uRL;
                }
                    break;
                }
                boolean _notEquals_1 = (!Objects.equal(url, null));
                if (_notEquals_1) {
                    urls.add(url);
                }
            }
        }
        ClassLoader _parentClassLoader = this.getParentClassLoader();
        return new URLClassLoader(((URL[]) Conversions.unwrapArray(urls, URL.class)), _parentClassLoader);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

private static void getClassURLs(IJavaProject javaProject, List<URL> urls) {
    IProject project = javaProject.getProject();
    IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();

    IClasspathEntry[] paths = null;/*from  w ww .  ja v a2  s  .  c o m*/
    IPath defaultOutputLocation = null;
    try {
        paths = javaProject.getResolvedClasspath(true);
        defaultOutputLocation = javaProject.getOutputLocation();
    } catch (JavaModelException e) {
        // don't show message to user neither log it
        // BytecodeOutlinePlugin.log(e, IStatus.ERROR);
    }
    if (paths != null) {
        IPath projectPath = javaProject.getProject().getLocation();
        for (int i = 0; i < paths.length; ++i) {
            IClasspathEntry cpEntry = paths[i];
            IPath p = null;
            if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                // filter out source container - there are unused for class
                // search - add bytecode output location instead
                p = cpEntry.getOutputLocation();
                if (p == null) {
                    // default output used:
                    p = defaultOutputLocation;
                }
            } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                String projName = cpEntry.getPath().toPortableString().substring(1);
                IProject proj = workspaceRoot.getProject(projName);
                IJavaProject projj = JavaCore.create(proj);
                getClassURLs(projj, urls);
                continue;
            } else {
                p = cpEntry.getPath();
            }

            if (p == null) {
                continue;
            }
            if (!p.toFile().exists()) {
                // removeFirstSegments: remove project from relative path
                p = projectPath.append(p.removeFirstSegments(1));
                if (!p.toFile().exists()) {
                    continue;
                }
            }
            try {
                urls.add(p.toFile().toURI().toURL());
            } catch (MalformedURLException e) {
                // don't show message to user
                BytecodeOutlinePlugin.log(e, IStatus.ERROR);
            }
        }
    }
}

From source file:de.lynorics.eclipse.jangaroo.ui.wizard.NewAS3FileWizardPage.java

License:Open Source License

public static List<IPath> getProjectSourceDirectories(IProject project) {
    List<IPath> paths = new ArrayList<IPath>();
    try {//from  w  w w  . j  a v  a  2 s  .  c  o  m
        if (project.isOpen() && project.getNature(JangarooProjectHelper.NATURE_ID) != null) {
            IJavaProject javaProject = JavaCore.create(project);
            IClasspathEntry[] classpathEntries = null;
            classpathEntries = javaProject.getResolvedClasspath(true);
            for (int i = 0; i < classpathEntries.length; i++) {
                IClasspathEntry entry = classpathEntries[i];
                if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    paths.add(entry.getPath());
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return paths;
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

ICompilationUnit getCompilationUnit(String proj, String file) throws BedrockException {
    //TODO: This should find the current working copy, not the underlying unit

    IProject ip = findProjectForFile(proj, file);
    if (ip == null)
        return null;

    IJavaProject ijp = JavaCore.create(ip);
    ICompilationUnit icu = checkFilePrefix(ijp, null, file);
    if (icu != null)
        return icu;
    if (ijp == null)
        return null;

    try {//from  www  .  ja va2  s .co m
        IClasspathEntry[] ents = ijp.getResolvedClasspath(true);
        for (int i = 0; i < ents.length; ++i) {
            if (ents[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath p = ents[i].getPath();
                File f = BedrockUtil.getFileForPath(p, ip);
                if (!f.exists())
                    continue;
                icu = checkFilePrefix(ijp, f.getAbsolutePath(), file);
                if (icu != null)
                    return icu;
            }
        }
    } catch (JavaModelException e) {
        BedrockPlugin.logE("Problem getting compilation unit: " + e);
    }

    return null;
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void addClassPaths(IJavaProject jp, IvyXmlWriter xw, Set<IProject> done, boolean nest) {
    if (done == null)
        done = new HashSet<IProject>();
    done.add(jp.getProject());//from  www  .j a v  a2  s  .co m
    BedrockPlugin.logD("Getting class path for " + jp.getProject().getName());

    try {
        IClasspathEntry[] ents = jp.getResolvedClasspath(true);
        for (IClasspathEntry ent : ents) {
            addPath(xw, jp, ent, nest);
        }
        IPath op = jp.getOutputLocation();
        if (op != null) {
            xw.begin("PATH");
            xw.field("TYPE", "BINARY");
            File f = BedrockUtil.getFileForPath(op, jp.getProject());
            if (f.exists())
                xw.textElement("BINARY", f.getAbsolutePath());
            xw.end("PATH");
        }
        for (IProject rp : jp.getProject().getReferencedProjects()) {
            if (done.contains(rp))
                continue;
            IJavaProject jrp = JavaCore.create(rp);
            addClassPaths(jrp, xw, done, true);
        }
    } catch (CoreException e) {
        BedrockPlugin.logE("Problem resolving classpath: " + e);
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void addClasses(IJavaProject jp, IvyXmlWriter xw) {
    try {//from  w w w.j a v a  2s .c o m
        IClasspathEntry[] ents = jp.getResolvedClasspath(true);
        for (int k = 0; k < ents.length; ++k) {
            if (ents[k].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPackageFragmentRoot[] rts = jp.findPackageFragmentRoots(ents[k]);
                for (int l = 0; l < rts.length; ++l) {
                    IJavaElement[] elts = rts[l].getChildren();
                    for (int m = 0; m < elts.length; ++m) {
                        if (elts[m] instanceof IPackageFragment) {
                            IPackageFragment frag = (IPackageFragment) elts[m];
                            xw.textElement("PACKAGE", frag.getElementName());
                            for (ICompilationUnit icu : frag.getCompilationUnits()) {
                                for (IType typ : icu.getTypes()) {
                                    outputType(typ, jp, xw);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        BedrockPlugin.logE("Problem getting class list: " + e);
    }
}

From source file:edu.clarkson.serl.critic.loader.SootClasspath.java

License:Open Source License

public static URL[] projectClassPath(IJavaProject javaProject) {
    IWorkspace workspace = CriticPlugin.getWorkspaceRoot().getWorkspace();
    IClasspathEntry[] cp;/*  w  w w  .  ja va 2s  . c o  m*/
    try {
        cp = javaProject.getResolvedClasspath(true);
        Set<URL> urls = new HashSet<URL>();
        String uriString = workspace.getRoot().getFile(javaProject.getOutputLocation()).getLocationURI()
                .toString() + "/";
        urls.add(new URI(uriString).toURL());
        for (IClasspathEntry entry : cp) {
            File file = entry.getPath().toFile();
            URL url = file.toURI().toURL();
            urls.add(url);
        }
        URL[] array = new URL[urls.size()];
        urls.toArray(array);
        return array;
    } catch (JavaModelException e) {
        e.printStackTrace();
        return new URL[0];
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return new URL[0];
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return new URL[0];
    }
}