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:com.technophobia.substeps.syntax.ProjectToSyntaxTransformer.java

License:Open Source License

private Set<String> outputFoldersForProject(final IJavaProject project) {
    final Set<String> outputFolders = new HashSet<String>();
    final IPath projectLocation = projectLocationPath(project);

    try {/*from w w  w .j a  v  a2 s  . co m*/
        final IPath defaultOutputLocation = project.getOutputLocation();
        if (defaultOutputLocation != null) {
            final IPath fullPath = appendPathTo(projectLocation, defaultOutputLocation);
            if (fullPath.toFile().exists()) {
                outputFolders.add(fullPath.toOSString());
            }
        }
        for (final IClasspathEntry entry : project.getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                final IPath outputLocation = entry.getOutputLocation();
                if (outputLocation != null) {
                    final IPath fullPath = appendPathTo(projectLocation, outputLocation);
                    if (fullPath.toFile().exists()) {
                        outputFolders.add(fullPath.toOSString());
                    }
                }
            }
        }
    } catch (final JavaModelException ex) {
        FeatureEditorPlugin.instance()
                .warn("Could not get output folder location for project " + project.getElementName());
    }

    return outputFolders;
}

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

License:Open Source License

protected URLClassLoader createClassLoaderForJavaProject(final IJavaProject projectToUse) {
    try {//from  w  ww .ja v a2s. c  om
        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:com.temenos.ds.op.xtext.ui.internal.se.JdtBasedProcessorProvider.java

License:Open Source License

private List<URL> getOutputFolders(final IJavaProject javaProject) {
    try {//from ww  w  .  ja  v  a  2  s .  co m
        final List<URL> result = CollectionLiterals.<URL>newArrayList();
        IPath _outputLocation = javaProject.getOutputLocation();
        IPath path = _outputLocation.addTrailingSeparator();
        String _string = path.toString();
        org.eclipse.emf.common.util.URI _createPlatformResourceURI = org.eclipse.emf.common.util.URI
                .createPlatformResourceURI(_string, true);
        String _string_1 = _createPlatformResourceURI.toString();
        URL url = new URL(_string_1);
        result.add(url);
        IClasspathEntry[] _rawClasspath = javaProject.getRawClasspath();
        for (final IClasspathEntry entry : _rawClasspath) {
            int _entryKind = entry.getEntryKind();
            switch (_entryKind) {
            case IClasspathEntry.CPE_SOURCE:
                IPath _outputLocation_1 = entry.getOutputLocation();
                path = _outputLocation_1;
                boolean _notEquals = (!Objects.equal(path, null));
                if (_notEquals) {
                    IPath _addTrailingSeparator = path.addTrailingSeparator();
                    String _string_2 = _addTrailingSeparator.toString();
                    org.eclipse.emf.common.util.URI _createPlatformResourceURI_1 = org.eclipse.emf.common.util.URI
                            .createPlatformResourceURI(_string_2, true);
                    String _string_3 = _createPlatformResourceURI_1.toString();
                    URL _uRL = new URL(_string_3);
                    url = _uRL;
                    result.add(url);
                }
                break;
            }
        }
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java

License:LGPL

/**
 * Gets a classpath container from a project. (Assumes that the path is only
 * used once.)/*w  w w .jav  a  2 s. c o  m*/
 * 
 * @param project
 *        The project
 * @param path
 *        The path
 * @return The classpath container or null
 * @throws JavaModelException
 *         In case of an Eclipse JDT error
 */
public static IClasspathContainer getClasspathContainer(IJavaProject project, IPath path)
        throws JavaModelException {
    IClasspathEntry[] entries = project.getRawClasspath();
    for (IClasspathEntry entry : entries)
        if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path)))
            return (IClasspathContainer) entry;
    return null;
}

From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java

License:LGPL

/**
 * Sets a classpath container in a project. If the classpath container is
 * already there, will recreate it. (Assumes that the path is only used
 * once.)/*from www  . java 2  s.c o m*/
 * 
 * @param project
 *        The project
 * @param container
 *        The classpath container
 * @throws JavaModelException
 *         In case of an Eclipse JDT error
 */
public static void setClasspathContainer(IJavaProject project, IClasspathContainer container)
        throws JavaModelException {
    IPath path = container.getPath();
    IClasspathEntry[] entries = project.getRawClasspath();

    int found = -1;
    for (int i = 0, length = entries.length; i < length; i++) {
        IClasspathEntry entry = entries[i];
        if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) {
            found = i;
            break;
        }
    }

    if (found == -1) {
        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
        System.arraycopy(entries, 0, newEntries, 0, entries.length);
        newEntries[entries.length] = JavaCore.newContainerEntry(container.getPath());
        project.setRawClasspath(newEntries, null);
    } else {
        entries[found] = JavaCore.newContainerEntry(path);
        project.setRawClasspath(entries, null);
    }

    JavaCore.setClasspathContainer(Classpath.PATH, new IJavaProject[] { project },
            new IClasspathContainer[] { container }, null);
}

From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java

License:LGPL

/**
 * Removes a classpath container from project if it is there. (Assumes that
 * the path is only used once.)//from  w w w.  j  av a2 s  . co  m
 * 
 * @param project
 *        The project
 * @param path
 *        The path
 * @throws JavaModelException
 *         In case of an Eclipse JDT error
 */
public static void removeClasspathContainer(IJavaProject project, IPath path) throws JavaModelException {
    IClasspathEntry[] entries = project.getRawClasspath();

    int found = -1;
    for (int i = 0, length = entries.length; i < length; i++) {
        IClasspathEntry entry = entries[i];
        if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) {
            found = i;
            break;
        }
    }

    if (found != -1) {
        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1];
        System.arraycopy(entries, 0, newEntries, 0, found);
        if (found != entries.length)
            System.arraycopy(entries, found + 1, newEntries, found, entries.length - found - 1);
        project.setRawClasspath(newEntries, null);
    }
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

/**
 * Appends target project build path with source project build path.
 * /*from  w w  w  .ja v a2  s . c  o  m*/
 * @param targetProject the target project
 * @param sourceProject the source project
 * @throws CoreException
 */
public static void appendProjectBuildPath(IJavaProject targetProject, IJavaProject sourceProject)
        throws CoreException {
    try {
        // copy required entries to target
        IClasspathEntry[] srcEntries = sourceProject.getRawClasspath();
        for (int i = 0; i < srcEntries.length; i++) {
            IClasspathEntry entry = srcEntries[i];
            if (entry.isExported() || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
                continue;
            addToClasspath(targetProject, entry);
        }
        // add the source project as a project entry
        IClasspathEntry srcPrjEntry = JavaCore.newProjectEntry(sourceProject.getPath());
        addToClasspath(targetProject, srcPrjEntry);
    } catch (JavaModelException e) {
        // we interested only in core exceptions
        if (e.getCause() instanceof CoreException) {
            throw (CoreException) e.getCause();
        }
    }
}

From source file:com.windowtester.eclipse.ui.convert.WTAPIUsage.java

License:Open Source License

private void collectPluginsReferencedByClasspathEntry(PrintWriter writer, Collection<String> pluginIds,
        IJavaProject proj, IClasspathEntry entry) throws IOException {
    IPath path = entry.getPath();//from   w  w  w.jav a  2 s  . c  om
    switch (entry.getEntryKind()) {

    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
        for (int i = path.segmentCount() - 1; i >= 0; i--) {
            String segment = path.segment(i);
            if (segment.startsWith("com.windowtester.")) {
                String id = segment;
                i++;
                while (i < path.segmentCount())
                    id += "/" + path.segment(i++);
                pluginIds.add(id);
                break;
            }
        }
        break;

    case IClasspathEntry.CPE_CONTAINER:
        if (path.segmentCount() >= 1 && path.segment(0).equals("org.eclipse.pde.core.requiredPlugins"))
            collectPluginsReferencedInManifest(pluginIds, proj);
        break;

    case IClasspathEntry.CPE_SOURCE:
    case IClasspathEntry.CPE_PROJECT:
        // ignored
        break;

    default:
        pluginIds.add("unknown " + entry.getEntryKind() + " - " + entry);
        break;
    }
}

From source file:com.windowtester.eclipse.ui.wizard.NewExampleProjectWizard.java

License:Open Source License

private void importProject(String projectName, IProgressMonitor monitor) throws CoreException {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject project = workspace.getRoot().getProject(projectName);
    IProjectDescription description = workspace.newProjectDescription(projectName);
    description.setLocation(null);/* w w  w .  j av a2s.c om*/
    project.create(description, new SubProgressMonitor(monitor, 1));
    project.open(new SubProgressMonitor(monitor, 1));

    // Direct ECLIPSE_HOME references are different each Eclipse installation
    // so adjust the classpath accordingly

    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    boolean modified = false;
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
            continue;
        IPath path = entry.getPath();
        if (path.segmentCount() != 3)
            continue;
        if (!path.segment(0).equals("ECLIPSE_HOME"))
            continue;
        if (!path.segment(1).equals("plugins"))
            continue;
        String jarName = path.segment(2);
        path = path.removeLastSegments(1);
        IPath pluginsPath = JavaCore.getResolvedVariablePath(path);
        if (pluginsPath == null) {
            Logger.log("Failed to resolve " + path);
            continue;
        }
        File pluginsDir = pluginsPath.toFile();
        String jarPrefix = jarName.substring(0, jarName.indexOf('_') + 1);
        String[] childNames = pluginsDir.list();
        if (childNames == null) {
            Logger.log("Failed to obtain children for " + pluginsDir.getPath());
            continue;
        }
        for (int j = 0; j < childNames.length; j++) {
            String name = childNames[j];
            if (name.startsWith(jarPrefix)) {
                modified = true;
                classpath[i] = JavaCore.newVariableEntry(path.append(name), null, null);
                break;
            }
        }
    }
    if (modified)
        javaProject.setRawClasspath(classpath, new NullProgressMonitor());
}

From source file:com.windowtester.swt.codegen.wizards.NewTestTypeWizard.java

License:Open Source License

private void updateClasspath(IResource resource) {
    try {//from  ww w  .  jav a  2 s.  co  m
        if (_wizardPage.isRcpApplication()) {
            IPath requiredPluginsPath = new Path("org.eclipse.pde.core.requiredPlugins");
            IJavaProject javaProject = JavaCore.create(resource.getProject());
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    if (entry.getPath().equals(requiredPluginsPath)) {
                        return; // no need to process
                    }
                }
            }
            IClasspathEntry requiredPlugins = JavaCore.newContainerEntry(requiredPluginsPath);
            IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
            System.arraycopy(entries, 0, newEntries, 0, entries.length);
            newEntries[entries.length] = requiredPlugins;
            javaProject.setRawClasspath(newEntries, null);
        }
    } catch (CoreException e) {
        Logger.log(e);
    }
}