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

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

Introduction

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

Prototype

int CPE_LIBRARY

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a library.

Usage

From source file:org.apache.cactus.eclipse.webapp.internal.ui.WebAppConfigurationBlock.java

License:Apache License

/**
 * Returns the array of jar entries selected in the libraryPage.
 * @return IClasspathEntry[] the array of jar entries selected
 */// ww  w. j  a va  2 s .c o  m
public final IClasspathEntry[] getWebappClasspath() {
    Vector result = new Vector();
    List cplist = classPathList.getElements();
    for (int i = 0; i < cplist.size(); i++) {
        CPListElement elem = (CPListElement) cplist.get(i);
        if (elem.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            result.add(elem.getClasspathEntry());
        }
    }
    return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]);
}

From source file:org.apache.cactus.eclipse.webapp.internal.ui.WebAppConfigurationBlock.java

License:Apache License

/**
 * Returns a list of jar entries contained in an array of entries.
 * @param theClasspathEntries array of classpath entries 
 * @return ArrayList list containing the jar entries
 *///from  w ww. j  av a2s  .co m
private ArrayList getExistingEntries(final IClasspathEntry[] theClasspathEntries) {
    ArrayList newClassPath = new ArrayList();
    for (int i = 0; i < theClasspathEntries.length; i++) {
        IClasspathEntry curr = theClasspathEntries[i];
        if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            try {
                newClassPath.add(CPListElement.createFromExisting(curr, javaProject));
            } catch (NullPointerException e) {
                // an error occured when parsing the entry
                // (possibly invalid entry)
                // We don't add it
            }
        }
    }
    return newClassPath;

}

From source file:org.apache.cactus.eclipse.webapp.internal.WarBuilder.java

License:Apache License

/**
 * For each IClasspathEntry transform the path in an absolute path.
 * @param theEntries array of IClasspathEntry to render asbolute
 * @return an array of absolute IClasspathEntries
 *///  www.j  a  v  a  2s.  c  o  m
private static IClasspathEntry[] getAbsoluteEntries(final IClasspathEntry[] theEntries) {
    if (theEntries == null) {
        return new IClasspathEntry[0];
    }
    Vector result = new Vector();
    for (int i = 0; i < theEntries.length; i++) {
        IClasspathEntry currentEntry = theEntries[i];
        if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath path = currentEntry.getPath();
            Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true);
            if (target instanceof IFile) {
                IFile file = (IFile) target;
                IPath absolutePath = file.getLocation();
                result.add(JavaCore.newLibraryEntry(absolutePath, null, null));
            } else if (target instanceof File) {
                File file = (File) target;
                result.add(JavaCore.newLibraryEntry(new Path(file.getAbsolutePath()), null, null));
            }
        }
    }
    return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]);
}

From source file:org.apache.cactus.eclipse.webapp.internal.WarBuilder.java

License:Apache License

/**
 * @param theJarEntries the jars to build ZipFileSets from
 * @return an array of ZipFileSet corresponding to the given jars
 *//* w w  w.  j  ava  2s. c om*/
private static ZipFileSet[] getZipFileSets(final IClasspathEntry[] theJarEntries) {
    Vector result = new Vector();
    for (int i = 0; i < theJarEntries.length; i++) {

        IClasspathEntry currentEntry = theJarEntries[i];
        if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            File currentJar = currentEntry.getPath().toFile();
            ZipFileSet zipFS = new ZipFileSet();
            zipFS.setFile(currentJar);
            result.add(zipFS);
        }
    }
    return (ZipFileSet[]) result.toArray(new ZipFileSet[result.size()]);
}

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);/* ww  w  .j  a  v a2 s. co m*/
        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  w  ww  . ja va2 s. co 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 w w  .jav a  2  s .c  om

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

    return entries;
}

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

License:Apache License

private void handleAdd() {
    try {/*  w w  w.  j a va2s .  c  o  m*/
        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 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://ww  w .  j  a  v  a2 s.  c om
        throw new IllegalStateException("Unknown classpath entry type " + o1);
    }
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyAttachementManager.java

License:Apache License

public void updateAttchements(IJavaProject project, IPath containerPath,
        IClasspathContainer containerSuggestion) {
    IvyDEMessage.verbose("Updating attachements on the container " + containerPath);

    Properties newProps = new Properties();

    IClasspathEntry[] newEntries = containerSuggestion.getClasspathEntries();
    for (int i = 0; i < newEntries.length; i++) {
        IClasspathEntry entry = newEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            if (entry.getSourceAttachmentPath() != null) {
                newProps.put(path + SRC_SUFFIX, entry.getSourceAttachmentPath().toPortableString());
            }//w ww.j a va2s  . c o  m
            if (entry.getSourceAttachmentRootPath() != null) {
                newProps.put(path + SRCROOT_SUFFIX, entry.getSourceAttachmentRootPath().toPortableString());
            }
            String javadocUrl = getJavadocLocation(entry);
            if (javadocUrl != null) {
                newProps.put(path + DOC_SUFFIX, javadocUrl);
            }
        }
    }

    IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) IvyClasspathContainerHelper
            .getContainer(containerPath, project);
    if (ivycp == null) {
        IvyDEMessage.error("The IvyDE container could not be found. Aborting updating attachements.");
        // something wrong happened, give up
        return;
    }
    IClasspathEntry[] existingEntries = ivycp.getClasspathEntries();
    for (int i = 0; i < existingEntries.length; i++) {
        IClasspathEntry entry = existingEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            String value = (String) prop.get(path + SRC_SUFFIX);
            if (value != null && entry.getSourceAttachmentPath() != null
                    && value.equals(entry.getSourceAttachmentPath().toPortableString())) {
                newProps.remove(path + SRC_SUFFIX);
            }
            value = (String) prop.get(path + SRCROOT_SUFFIX);
            if (value != null && entry.getSourceAttachmentRootPath() != null
                    && value.equals(entry.getSourceAttachmentRootPath().toPortableString())) {
                newProps.remove(path + SRCROOT_SUFFIX);
            }
        }
    }

    // copy the actually new overrided properties
    prop.putAll(newProps);

    // now update the ivyde container for real
    ivycp.updateClasspathEntries(newEntries);

    // store the global result
    IvyDEMessage.verbose("Saving attachement properties");
    try {
        FileOutputStream out = new FileOutputStream(containersAttachementFile);
        try {
            prop.store(out, "");
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                // don't care
            }
        }
    } catch (IOException ioe) {
        IvyPlugin.logWarn("IvyDE attachement properties could not be saved", ioe);
    }
}