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.jboss.tools.common.model.project.ClassPathUpdate.java

License:Open Source License

public IClasspathEntry createNewClasspathEntry(IPath path, int entryKind) {
    switch (entryKind) {
    case IClasspathEntry.CPE_SOURCE:
        return JavaCore.newSourceEntry(path);
    case IClasspathEntry.CPE_LIBRARY:
        return JavaCore.newLibraryEntry(path, null, null);
    case IClasspathEntry.CPE_VARIABLE:
        return JavaCore.newVariableEntry(path, null, null);
    case IClasspathEntry.CPE_CONTAINER:
        return JavaCore.newContainerEntry(path);
    default:/*from   w w  w .j a v  a  2  s  .  c  o m*/
        return null;
    }
}

From source file:org.jboss.tools.common.model.util.EclipseResourceUtil.java

License:Open Source License

/**
 * Returns list of canonical paths to resources of libraries (jars and class folders) included in class path.
 * @throws IOException //from w w w  .  j  av  a 2s.c o  m
 */
public static List<String> getClassPath(IProject project) throws CoreException, IOException {
    IJavaProject javaProject = getJavaProject(project);
    if (javaProject == null) {
        return null;
    }

    ArrayList<String> l = new ArrayList<String>();
    IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
    for (int i = 0; i < es.length; i++) {
        if (es[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            String s = expandPath(es[i].getPath(), project);
            if (s != null) {
                l.add(s);
            }
        }
    }
    return l;
}

From source file:org.jboss.tools.common.model.util.EclipseResourceUtil.java

License:Open Source License

public static IResource[] getClasspathResources(IProject project) {
    IJavaProject javaProject = getJavaProject(project);
    if (javaProject == null)
        return new IProject[0];

    ArrayList<IResource> l = new ArrayList<IResource>();

    IClasspathEntry[] es = null;/*w  w  w.  java 2 s . c  om*/

    try {
        es = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        //ignore - if project cannot respond, it may not have resources of interest.
        return new IProject[0];
    }

    if (es != null)
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IPath path = es[i].getPath();
                IProject p = (IProject) project.getWorkspace().getRoot().findMember(path);
                l.add(p);
            } else if (es[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath path = es[i].getPath();
                IResource r = project.getWorkspace().getRoot().findMember(path);
                if (r instanceof IContainer) {
                    l.add(r);
                } else if (r != null && !project.getFullPath().isPrefixOf(r.getFullPath())) {
                    l.add(r); //probably it is jar 
                }
            }
        }

    return l.toArray(new IResource[0]);
}

From source file:org.jboss.tools.fuse.transformation.editor.internal.util.JavaUtil.java

License:Open Source License

/**
 * Creates a ClassLoader using the project's build path.
 *
 * @param javaProject the Java project./*from  w w w .java  2 s .c o m*/
 * @param parentClassLoader the parent class loader, may be null.
 *
 * @return a new ClassLoader based on the project's build path.
 *
 * @throws Exception if something goes wrong.
 */
public static ClassLoader getProjectClassLoader(IJavaProject javaProject, ClassLoader parentClassLoader)
        throws Exception {
    IProject project = javaProject.getProject();
    IWorkspaceRoot root = project.getWorkspace().getRoot();
    List<URL> urls = new ArrayList<>();
    urls.add(new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) //$NON-NLS-1$
            + "/") //$NON-NLS-1$
                    .toURI().toURL());
    for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) {
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            IPath projectPath = classpathEntry.getPath();
            IProject otherProject = root.getProject(projectPath.segment(0));
            IJavaProject otherJavaProject = JavaCore.create(otherProject);
            urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$
                    + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$
        } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL());
        }
    }
    if (parentClassLoader == null) {
        return new URLClassLoader(urls.toArray(new URL[urls.size()]));
    }
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader);
}

From source file:org.jboss.tools.jst.web.project.AddServletSupportWizard.java

License:Open Source License

private void addServletSupport() throws XModelException {
    XModelObject web = model.getByPath("Web"); //$NON-NLS-1$
    if (web == null)
        return;// w w  w  . j  a v  a 2 s  . co  m
    String servletVersion = web.getAttributeValue("servlet version"); //$NON-NLS-1$
    if (servletVersion == null || "".equals(servletVersion)) { //$NON-NLS-1$
        servletVersion = WebPreference.DEFAULT_SERVLET_VERSION.getValue();
        model.changeObjectAttribute(web, "servlet version", servletVersion); //$NON-NLS-1$
    }
    String[] jars = WebUtils.getServletLibraries(getTemplatesBase(), servletVersion);
    if (web.getChildren(WebModuleConstants.ENTITY_WEB_MODULE).length == 0
            && web.getChildren("WebJSFModule").length == 0) { //$NON-NLS-1$
        return;
    }
    for (int i = 0; i < jars.length; i++) {
        IPath jarPath = new Path(jars[i]);
        IPath variablePath = JavaCore.getClasspathVariable(jarPath.segment(0));
        IClasspathEntry entry = null;
        if (variablePath == null)
            entry = update.createNewClasspathEntry(jarPath, IClasspathEntry.CPE_LIBRARY);
        else
            entry = update.createNewClasspathEntry(jarPath, IClasspathEntry.CPE_VARIABLE);
        update.registerEntry(entry);
    }
}

From source file:org.jboss.tools.m2e.extras.AptBuildParticipant.java

License:Open Source License

private void processClasspathElement(IClasspathEntry ice, IProject containingProject,
        Xpp3Dom newClasspathElementsDom) throws JavaModelException {
    IPath path;// w  w w  . ja  va 2 s . c o  m
    switch (ice.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE: {
        path = ice.getOutputLocation();
        if (path == null) {
            path = JavaCore.create(containingProject).getOutputLocation();
        }
        break;
    }
    case IClasspathEntry.CPE_PROJECT: {
        IProject referenceProject = containingProject.getWorkspace().getRoot()
                .getProject(ice.getPath().toPortableString());
        for (IClasspathEntry resolvedIce : JavaCore.create(referenceProject).getRawClasspath()) {
            // we're only concerned with exported libraries and the project
            // output
            if (resolvedIce.isExported() || resolvedIce.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                try {
                    processClasspathElement(resolvedIce, referenceProject, newClasspathElementsDom);
                } catch (JavaModelException e) {
                }
            }
        }
        return;
    }
    case IClasspathEntry.CPE_CONTAINER: {
        // we're only concerned with the PDE container
        if (!PDE_CLASSPATH_CONTAINER.equals(ice.getPath())) {
            return;
        }
        IClasspathContainer icc = JavaCore.getClasspathContainer(ice.getPath(),
                JavaCore.create(containingProject));
        if (icc == null) {
            return;
        }
        for (IClasspathEntry resolvedIce : icc.getClasspathEntries()) {
            try {
                processClasspathElement(resolvedIce, containingProject, newClasspathElementsDom);
            } catch (JavaModelException e) {
            }
        }
        return;
    }
    case IClasspathEntry.CPE_LIBRARY:
        path = ice.getPath();
        break;
    case IClasspathEntry.CPE_VARIABLE:
        ice = JavaCore.getResolvedClasspathEntry(ice);
        if (ice == null) {
            return;
        }
        path = ice.getPath();
        break;
    default:
        return;
    }
    // make sure we have an absolute file system path
    Xpp3Dom child = new Xpp3Dom("#");
    IResource resource = containingProject.getWorkspace().getRoot().findMember(path);
    if (resource == null) {
        child.setValue(ice.getPath().toPortableString());
    } else {
        child.setValue(resource.getLocation().toPortableString());
    }
    newClasspathElementsDom.addChild(child);
}

From source file:org.jboss.tools.maven.conversion.core.internal.JavaDependency.java

License:Open Source License

public JavaDependency(IClasspathEntry cpe) {
    super();/*from   ww  w. j av  a  2 s.c o  m*/
    Assert.isNotNull(cpe, "classpentry parameter can not be null");
    classpathEntry = cpe;
    if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        setDependencyKind(DependencyKind.Project);
    } else if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        setDependencyKind(DependencyKind.Archive);
    } else {
        setDependencyKind(DependencyKind.Unsupported);
    }
}

From source file:org.jboss.tools.maven.conversion.ui.handlers.ConvertToMavenDependencyHandler.java

License:Open Source License

private void addClasspathEntry(IPackageFragmentRoot pfr, Collection<IClasspathEntry> entries) {
    if (pfr.isArchive()) {
        pfr.getResource();/*w w w .j av  a  2 s  . c  o m*/
        try {
            IClasspathEntry cpe = pfr.getResolvedClasspathEntry();
            if (cpe != null && cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                entries.add(cpe);
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.jboss.tools.maven.seam.configurators.FixClasspathConfigurator.java

License:Open Source License

private void configureInternal(MavenProject mavenProject, IProject project, IProgressMonitor monitor)
        throws CoreException {
    if (!project.hasNature(JavaCore.NATURE_ID)) {
        return;//from   ww  w.  j  av a2  s . c  o m
    }
    List<Resource> resources = mavenProject.getResources();
    for (Resource resource : resources) {

        File directory = new File(resource.getDirectory());
        String absolutePath = directory.getAbsolutePath();
        try {
            absolutePath = directory.getCanonicalPath();
        } catch (IOException e) {
            MavenSeamActivator.log(e);
        }
        if (!new File(absolutePath).exists()) {
            continue;
        }
        IPath relativePath = getProjectRelativePath(project, absolutePath);
        IResource r = project.findMember(relativePath);
        if (r != null) {
            continue;
        }
        String path = getWorkspaceRelativePath(absolutePath);
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        boolean exists = false;
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath entryPath = entry.getPath();
                if (entryPath != null && path.equals(entryPath.toString())) {
                    exists = true;
                    break;
                }
            }
        }
        if (!exists) {
            IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
            for (int i = 0; i < entries.length; i++) {
                newEntries[i] = entries[i];
            }
            IClasspathEntry pathEntry = JavaCore.newLibraryEntry(new Path(path), null, null);
            newEntries[entries.length] = pathEntry;
            javaProject.setRawClasspath(newEntries, monitor);
        }
    }
}

From source file:org.jboss.tools.seam.internal.core.project.facet.WtpUtils.java

License:Open Source License

static private void insertClasspathEntry(IClasspathEntry entry, List<IClasspathEntry> entries) {
    int length = entries.size();
    IClasspathEntry[] elements = entries.toArray(new IClasspathEntry[length]);
    int i = 0;//  w  w  w .ja v a 2s. c o m
    while (i < length && elements[i].getEntryKind() != entry.getEntryKind()) {
        i++;
    }
    if (i < length) {
        i++;
        while (i < length && elements[i].getEntryKind() == entry.getEntryKind()) {
            i++;
        }
        entries.add(i, entry);
        return;
    }

    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        entries.add(0, entry);
        break;
    case IClasspathEntry.CPE_CONTAINER:
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_PROJECT:
    case IClasspathEntry.CPE_VARIABLE:
    default:
        entries.add(entry);
        break;
    }
}