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.eclipse.e4.tools.ui.designer.utils.ClassLoaderHelper.java

License:Open Source License

private static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls, Set<IJavaProject> visited,
        boolean isFirstProject) {
    if (visited.contains(javaProject))
        return;/*  ww  w.  ja  v  a  2  s.  c o  m*/
    visited.add(javaProject);
    try {
        IPath outPath = javaProject.getProject().getWorkspace().getRoot().getFullPath()
                .append(javaProject.getOutputLocation());
        outPath = outPath.addTrailingSeparator();
        URL out = createFileURL(outPath);
        urls.add(out);
        IClasspathEntry[] entries = null;
        entries = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : entries) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
            case IClasspathEntry.CPE_CONTAINER:
            case IClasspathEntry.CPE_VARIABLE:
                collectClasspathEntryURL(entry, urls);
                break;
            case IClasspathEntry.CPE_PROJECT: {
                if (isFirstProject || entry.isExported())
                    collectClasspathURLs(getJavaProject(entry), urls, visited, false);
                break;
            }
            }
        }
    } catch (JavaModelException e) {
        return;
    }
}

From source file:org.eclipse.e4.xwt.tools.ui.designer.jdt.ProjectHelper.java

License:Open Source License

protected static boolean containsJar(IJavaProject javaProject, IClasspathEntry entry, String jarName) {
    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_VARIABLE:
        IClasspathEntry resolvedEntry = JavaCore.getJavaCore().getResolvedClasspathEntry(entry);
        IPath resolvedPath = resolvedEntry.getPath();
        String string = resolvedPath.toString();
        if (string.indexOf(jarName) != -1) {
            return true;
        }/*from   w w  w.  j av a2  s  . c o  m*/
        break;
    case IClasspathEntry.CPE_CONTAINER:
        try {
            IPath path = entry.getPath();
            IClasspathContainer classpathContainer = JavaCore.getJavaCore().getClasspathContainer(path,
                    javaProject);
            if (classpathContainer != null) {
                classpathContainer.getClasspathEntries();
                IClasspathEntry[] oldclasspath = classpathContainer.getClasspathEntries();
                for (int i = 0; i < oldclasspath.length; i++) {
                    if (containsJar(javaProject, oldclasspath[i], jarName)) {
                        return true;
                    }
                }
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        break;
    case IClasspathEntry.CPE_SOURCE:
    case IClasspathEntry.CPE_LIBRARY:
        IPath path = entry.getPath();
        String value = path.toString();
        if (value.indexOf(jarName) != -1) {
            return true;
        }
    }

    return false;
}

From source file:org.eclipse.edt.debug.core.java.filters.ClasspathEntryFilter.java

License:Open Source License

protected void processEntries(IClasspathEntry[] entries, IJavaProject project, Map<String, Object> classMap)
        throws CoreException {
    for (IClasspathEntry entry : entries) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            processLibraryEntry(entry, classMap);
            break;

        case IClasspathEntry.CPE_CONTAINER:
            processContainerEntry(entry, project, classMap);
            break;

        case IClasspathEntry.CPE_SOURCE:
            processSourceEntry(entry, classMap);
            break;

        case IClasspathEntry.CPE_PROJECT:
            IProject depProject = ResourcesPlugin.getWorkspace().getRoot()
                    .getProject(entry.getPath().lastSegment());
            if (depProject.isAccessible() && depProject.hasNature(JavaCore.NATURE_ID)) {
                IJavaProject jp = JavaCore.create(depProject);
                processEntries(jp.getResolvedClasspath(true), jp, classMap);
            }//w w w  . j  ava 2 s.  c om
            break;

        default:
            EDTDebugCorePlugin.log(new Status(IStatus.WARNING, EDTDebugCorePlugin.PLUGIN_ID,
                    NLS.bind(EDTDebugCoreMessages.TypeFilterClasspathEntryNotSupported,
                            new Object[] { entry.getEntryKind(), getId() })));
            break;
        }
    }
}

From source file:org.eclipse.edt.debug.core.java.filters.WorkspaceProjectClassFilter.java

License:Open Source License

@Override
protected IClasspathEntry[] getCommonClasspathEntries() {
    String[] projects = getProjectNames();
    if (projects != null && projects.length > 0) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        List<IClasspathEntry> list = new ArrayList<IClasspathEntry>();
        for (String project : projects) {
            IProject proj = root.getProject(project);
            try {
                if (proj.isAccessible() && proj.hasNature(JavaCore.NATURE_ID)) {
                    for (IClasspathEntry entry : JavaCore.create(proj).getResolvedClasspath(true)) {
                        switch (entry.getEntryKind()) {
                        case IClasspathEntry.CPE_LIBRARY:
                            if (includeLibraries()) {
                                list.add(entry);
                            }//from w  ww.  j  a  v  a2  s  . c  o m
                            break;

                        case IClasspathEntry.CPE_PROJECT:
                            if (includeReferencedProjects()) {
                                list.add(entry);
                            }
                            break;

                        case IClasspathEntry.CPE_CONTAINER:
                            if (includeContainers()) {
                                list.add(entry);
                            }
                            break;

                        case IClasspathEntry.CPE_SOURCE:
                            if (includeSource()) {
                                list.add(entry);
                            }
                            break;
                        }
                    }
                }
            } catch (CoreException ce) {
                EDTDebugCorePlugin.log(ce);
            }
        }
        return list.toArray(new IClasspathEntry[list.size()]);
    }
    return null;
}

From source file:org.eclipse.edt.debug.internal.core.java.SMAPBuilder.java

License:Open Source License

private void buildAll() throws CoreException {
    // Performance: only visit the bin directories.
    IJavaProject project = JavaCore.create(getProject());
    IClasspathEntry[] cp = project.getResolvedClasspath(true);

    Set<IPath> binDirectories = new HashSet<IPath>(cp.length);
    for (IClasspathEntry entry : cp) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath outputLocation = entry.getOutputLocation();
            if (outputLocation != null) {
                binDirectories.add(outputLocation);
            }/*from  w ww  .jav  a 2  s  .  co  m*/
        }
    }

    IPath outputLocation = project.getOutputLocation();
    if (outputLocation != null) {
        binDirectories.add(outputLocation);
    }

    ResourceVisitor visitor = new ResourceVisitor();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    for (IPath path : binDirectories) {
        IResource resource = root.findMember(path);
        if (resource != null) {
            resource.accept(visitor);
        }
    }
}

From source file:org.eclipse.edt.ide.core.utils.EclipseUtilities.java

License:Open Source License

/**
 * Get the source folder name. For new Java projects, check the source
 * folder name in the Java Build Path preferences. For all types of Java
 * projects, use the first source folder from the classpath.
 * //w  w  w .j  a  v a 2  s.c o m
 * @param myProject
 *            The project where the folder for Java source resides.
 * 
 * @return String The Java source folder name.
 */
public static String getJavaSourceFolderName(IProject project) {
    String folderName = null;

    try {
        if (project.hasNature(JavaCore.NATURE_ID)) {
            // Use the first folder from the project's classpath. 
            IJavaProject javaProject = JavaCore.create(project);
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    // Get the folder from the entry's path.  The project name
                    // needs to be removed from the path before this will work.
                    IPath path = entry.getPath().removeFirstSegments(1);
                    return path.toString();
                }
            }
        }
    } catch (Exception e) {
    }
    return folderName;
}

From source file:org.eclipse.edt.ide.deployment.rui.operation.CopyJavaRuntimeResourcesOperation.java

License:Open Source License

/**
 * Finds all the classpath entries on the Java build path, including referenced projects, that are of type {@link IClasspathEntry#CPE_CONTAINER}.
 * @throws CoreException/*w  w  w  . j ava 2s  . c om*/
 */
private void getClasspathContainers(IJavaProject project, Set<IJavaProject> seen, Set<IClasspathEntry> entries)
        throws CoreException {
    if (seen.contains(project)) {
        return;
    }

    seen.add(project);

    for (IClasspathEntry entry : project.getRawClasspath()) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_CONTAINER:
            entries.add(entry);
            break;

        case IClasspathEntry.CPE_PROJECT:
            IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment());
            if (p.isAccessible() && p.hasNature(JavaCore.NATURE_ID)) {
                getClasspathContainers(JavaCore.create(p), seen, entries);
            }
            break;
        }
    }
}

From source file:org.eclipse.edt.ide.deployment.services.generators.ServiceUriMappingGenerator.java

License:Open Source License

private static String createClasspath(IJavaProject javaProject)
        throws JavaModelException, MalformedURLException, URISyntaxException {
    StringBuffer classpath = new StringBuffer();
    String path;/*from   w w w .j  a  v  a 2s  .co  m*/
    IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
    for (int i = 0; i < resolvedClasspath.length; i++) {
        IClasspathEntry entry = resolvedClasspath[i];
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            path = entry.getPath().toPortableString();
        } else {
            if (entry.getOutputLocation() != null) {
                path = javaProject.getProject().getLocation().removeLastSegments(1)
                        .append(entry.getOutputLocation()).toPortableString();
            } else {
                path = javaProject.getProject().getLocation().removeLastSegments(1)
                        .append(javaProject.getOutputLocation()).toPortableString();
            }
        }
        classpath.append(path);
        classpath.append(";");
    }
    return classpath.toString();
}

From source file:org.eclipse.edt.ide.deployment.services.operation.ConfigureRuntimePropertiesOperation.java

License:Open Source License

private void genProperties(DeploymentContext context, Set<Part> services, boolean setGlobalProperty,
        DeploymentResultMessageRequestor requestor) {
    IFile file = null;/*from   www .j  a v  a 2s  .  co  m*/
    try {
        if (context.getTargetProject().hasNature(JavaCore.NATURE_ID)) {
            IJavaProject javaProject = JavaCore.create(context.getTargetProject());
            IPath srcFolder = null;
            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    srcFolder = entry.getPath();
                    break;
                }
            }

            if (srcFolder != null) {
                StringBuilder contents = new StringBuilder(100);
                Properties props = new Properties();
                file = ResourcesPlugin.getWorkspace().getRoot().getFile(srcFolder.append(RUNUNIT_PROPERTIES));
                if (file.exists()) {
                    // Read in the previous entries.
                    BufferedInputStream bis = null;
                    try {
                        bis = new BufferedInputStream(file.getContents(true));
                        props.load(bis);

                        // Also load the previous file contents so we can append to it.
                        contents.append(Util.getFileContents(file));
                        if (contents.charAt(contents.length() - 1) != '\n') {
                            contents.append('\n');
                        }
                    } finally {
                        if (bis != null) {
                            try {
                                bis.close();
                            } catch (IOException ioe) {
                            }
                        }
                    }

                }

                String ddName = context.getDeploymentDesc().getEGLDDFileName().toLowerCase();
                boolean changed = false;

                if (setGlobalProperty && appendPropertyIfNecessary(Constants.APPLICATION_PROPERTY_FILE_NAME_KEY,
                        ddName, props, contents)) {
                    changed = true;
                }

                for (Part part : services) {
                    String generatedName;
                    String id = part.getCaseSensitiveName();
                    String pkg = part.getCaseSensitivePackageName();

                    if (pkg == null || pkg.length() == 0) {
                        generatedName = JavaAliaser.getAlias(id);
                    } else {
                        generatedName = JavaAliaser.packageNameAlias(pkg) + '.' + JavaAliaser.getAlias(id);
                    }

                    String key = Constants.APPLICATION_PROPERTY_FILE_NAME_KEY + '.' + generatedName;
                    if (appendPropertyIfNecessary(key, ddName, props, contents)) {
                        changed = true;
                    }
                }

                if (changed) {
                    ByteArrayInputStream bais = new ByteArrayInputStream(contents.toString().getBytes());
                    if (file.exists()) {
                        file.setContents(bais, true, false, null);
                    } else {
                        file.create(bais, true, null);
                    }

                    requestor.addMessage(DeploymentUtilities.createEGLDeploymentInformationalMessage(
                            EGLMessage.EGL_DEPLOYMENT_DEPLOYED_RT_PROPERTY_FILE, null,
                            new String[] { file.getProjectRelativePath().toPortableString() }));
                }
            }
        }
    } catch (Exception e) {
        requestor.addMessage(DeploymentUtilities.createEGLDeploymentErrorMessage(
                EGLMessage.EGL_DEPLOYMENT_FAILED_DEPLOY_RT_PROPERTY_FILE, null,
                new String[] { file == null ? RUNUNIT_PROPERTIES
                        : file.getProjectRelativePath().toPortableString() }));
        requestor.addMessage(
                DeploymentUtilities.createEGLDeploymentErrorMessage(EGLMessage.EGL_DEPLOYMENT_EXCEPTION, null,
                        new String[] { DeploymentUtilities.createExceptionMessage(e) }));
    }
}

From source file:org.eclipse.edt.ide.ui.internal.property.pages.VariableBlock.java

License:Open Source License

private boolean doesChangeRequireFullBuild(List removed, List changed) {
    try {/*from w w  w  .j  a v a  2 s  .co m*/
        IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
        IJavaProject[] projects = model.getJavaProjects();
        for (int i = 0; i < projects.length; i++) {
            IClasspathEntry[] entries = projects[i].getRawClasspath();
            for (int k = 0; k < entries.length; k++) {
                IClasspathEntry curr = entries[k];
                if (curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                    String var = curr.getPath().segment(0);
                    if (removed.contains(var) || changed.contains(var)) {
                        return true;
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        return true;
    }
    return false;
}