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.easyant4e.natures.EasyAntNature.java

License:Apache License

private void removeIvyClasspathContainer() {
    IJavaProject javaProject = JavaCore.create(project);
    ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
    //FIXME call IvyDE command
    try {/*w ww  . j a v  a  2 s  .c  o  m*/
        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 (IvyClasspathContainerHelper.isIvyClasspathContainer(path)) {
                    continue;
                }
            }
            newEntries.add(entry);
        }
        // TODO add progress monitor
        IClasspathEntry[] newClasspathEntries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(newClasspathEntries, null);
    } catch (JavaModelException e) {
        Activator.getEasyAntPlugin().log(IStatus.ERROR, "Cannot remove Ivy ClassPath container", e);
    }
}

From source file:org.apache.easyant4e.tests.ImportProjectTest.java

License:Apache License

private void assertSourceFolders(IProject project) throws Exception {
    assertTrue(project.hasNature(JavaCore.NATURE_ID));
    IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
    assertNotNull(javaProject);/*from   www .j  av  a  2  s. c  om*/
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    entries.addAll(Arrays.asList(javaProject.getRawClasspath()));
    assertTrue(entries.size() > 0);
    HashSet<String> sourceFolders = new HashSet<String>();
    for (IClasspathEntry entry : entries) {
        if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) {
            String path = entry.getPath().toOSString();
            assertNotNull(path);
            sourceFolders.add(path);
        }
    }
    assertTrue(sourceFolders.contains("/simplejavaproject/src/main/java"));
    assertTrue(sourceFolders.contains("/simplejavaproject/src/test/java"));
    assertTrue(sourceFolders.contains("/simplejavaproject/src/main/resources"));
    assertTrue(sourceFolders.contains("/simplejavaproject/src/test/resources"));
}

From source file:org.apache.felix.sigil.eclipse.internal.builders.SigilIncrementalProjectBuilder.java

License:Apache License

private void convert(IClasspathEntry cp, ISigilProjectModel sigil, List<File> files) throws CoreException {
    switch (cp.getEntryKind()) {
    case IClasspathEntry.CPE_PROJECT: {
        convertProject(cp, files);//  w ww  . ja  v  a 2 s  .c  om
        break;
    }
    case IClasspathEntry.CPE_SOURCE: {
        convertSource(sigil, cp, files);
        break;
    }
    case IClasspathEntry.CPE_LIBRARY: {
        convertLibrary(sigil, cp, files);
        break;
    }
    case IClasspathEntry.CPE_VARIABLE:
        convertVariable(cp, files);
        break;
    }
}

From source file:org.apache.felix.sigil.eclipse.internal.model.project.SigilProject.java

License:Apache License

public boolean isInClasspath(ISigilBundle bundle) {
    for (String path : getBundle().getClasspathEntrys()) {
        IClasspathEntry cp = getJavaModel().decodeClasspathEntry(path);
        switch (cp.getEntryKind()) {
        case IClasspathEntry.CPE_PROJECT:
            ISigilProjectModel p = bundle.getAncestor(ISigilProjectModel.class);
            return p != null && cp.getPath().equals(p.getProject().getFullPath());
        case IClasspathEntry.CPE_LIBRARY:
            return cp.getPath().equals(bundle.getLocation());
        }//from  ww w.  jav  a  2  s  .c o  m
    }

    return false;
}

From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java

License:Apache License

private static Collection<IClasspathEntry> newProjectEntry(ISigilProjectModel n, IAccessRule[] rules,
        IClasspathAttribute[] attributes, boolean export) throws CoreException {
    ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    entries.add(JavaCore.newProjectEntry(n.getProject().getFullPath(), rules, false, attributes, export));
    for (IClasspathEntry e : n.getJavaModel().getRawClasspath()) {
        String encoded = n.getJavaModel().encodeClasspathEntry(e);
        if (n.getBundle().getClasspathEntrys().contains(encoded)) {
            switch (e.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), rules, attributes, export));
                break;
            case IClasspathEntry.CPE_VARIABLE:
                IPath path = JavaCore.getResolvedVariablePath(e.getPath());
                if (path != null) {
                    IPath spath = e.getSourceAttachmentPath();
                    if (spath != null) {
                        spath = JavaCore.getResolvedVariablePath(spath);
                    }//from   w  ww. j  av  a2s .c o m

                    entries.add(JavaCore.newLibraryEntry(path, spath, e.getSourceAttachmentRootPath(), rules,
                            attributes, export));
                }
                break;
            }
        }
    }

    return entries;
}

From source file:org.apache.felix.sigil.eclipse.SigilCore.java

License:Apache License

/**
 * @param cp//from  w  w w.j  a  va 2s . c o m
 * @return
 */
private static boolean isSigilOnClasspath(IClasspathEntry[] cp) {
    for (IClasspathEntry e : cp) {
        if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && e.getPath().segment(0).equals(SigilCore.CLASSPATH_CONTAINER_PATH)) {
            return true;
        }
    }
    return false;
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ClasspathSection.java

License:Apache License

private void handleAdd() {
    try {/*from  www  . j  a va  2 s.  com*/
        BackgroundLoadingSelectionDialog<IClasspathEntry> dialog = new BackgroundLoadingSelectionDialog<IClasspathEntry>(
                getSection().getShell(), "Classpath Entry:", true);

        dialog.setDescriptor(new IElementDescriptor<IClasspathEntry>() {
            public String getName(IClasspathEntry element) {
                return element.getPath().toString();
            }

            public String getLabel(IClasspathEntry element) {
                return getName(element);
            }
        });

        dialog.setLabelProvider(new ModelLabelProvider());

        dialog.setFilter(new IFilter<IClasspathEntry>() {
            public boolean select(IClasspathEntry cp) {
                switch (cp.getEntryKind()) {
                case IClasspathEntry.CPE_LIBRARY:
                case IClasspathEntry.CPE_VARIABLE:
                case IClasspathEntry.CPE_SOURCE:
                    return !getBundle().getClasspathEntrys().contains(encode(cp));
                default:
                    return false;
                }
            }
        });

        dialog.setComparator(CLASSPATH_COMPARATOR);

        IClasspathEntry[] classpath = getProjectModel().getJavaModel().getRawClasspath();
        dialog.addElements(Arrays.asList(classpath));
        if (dialog.open() == Window.OK) {
            List<IClasspathEntry> selectedElements = dialog.getSelectedElements();

            Object[] added = selectedElements.toArray();
            for (IClasspathEntry entry : selectedElements) {
                getBundle().addClasspathEntry(encode(entry));
            }
            viewer.add(added);
            viewer.refresh();
            markDirty();
        }
    } catch (JavaModelException e) {
        ErrorDialog.openError(getSection().getShell(), "Error", null, e.getStatus());
    }
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ClasspathSection.java

License:Apache License

private int compareClasspaths(IClasspathEntry o1, IClasspathEntry o2) {
    if (o1.getEntryKind() == o2.getEntryKind()) {
        ModelLabelProvider mlp = viewer.getLabelProvider();
        return mlp.getText(o1).compareTo(mlp.getText(o2));
    } else {//from  w  w  w  .j  av a 2  s  .  co  m
        int i1 = index(o1);
        int i2 = index(o2);

        if (i1 < i2) {
            return -1;
        } else {
            return 1;
        }
    }
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ClasspathSection.java

License:Apache License

private static int index(IClasspathEntry o1) {
    switch (o1.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        return 0;
    case IClasspathEntry.CPE_PROJECT:
        return 1;
    case IClasspathEntry.CPE_LIBRARY:
        return 2;
    case IClasspathEntry.CPE_VARIABLE:
        return 3;
    case IClasspathEntry.CPE_CONTAINER:
        return 4;
    default://from  w w w  .  ja  v  a  2s  .co  m
        throw new IllegalStateException("Unknown classpath entry type " + o1);
    }
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.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 w w . ja  va 2 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);
                    String bsn = project.getName();
                    sigil.getBundle().getBundleInfo().setSymbolicName(bsn);

                    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;
}