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

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

Introduction

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

Prototype

int CPE_VARIABLE

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

Click Source Link

Document

Entry kind constant describing a classpath entry defined using a path that begins with a classpath variable reference.

Usage

From source file:org.entirej.ide.core.project.EJPluginEntireJClassLoader.java

License:Apache License

private static void processEntry(IJavaProject javaProject, List<URL> urlList, IClasspathEntry entry,
        boolean ignoreSource) throws MalformedURLException {
    // This source output ... always included & exported
    if (!ignoreSource && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
        IPath outputLocation = entry.getOutputLocation();

        if (outputLocation != null) {
            URL url = new URL("file", null, outputLocation.toString() + "/");
            urlList.add(url);/*www . ja v  a  2  s  .  co  m*/
        }
    }

    // Referenced project classpath. If this project is exported,
    // Then all *exported* entries are exported with respect to this
    // project,
    else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        IProject ijproject = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().segment(0));
        IJavaProject ref = JavaCore.create(ijproject);
        Collection<URL> cpEntries = getClasspathEntries(ref, false);
        urlList.addAll(cpEntries);
    }

    // This is the Directories classpath
    else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        IPath entryPath = entry.getPath();
        URL url = new URL("file", null, entryPath.toString());
        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);

        if (res != null && res.exists()) {
            url = new URL("file", null, res.getLocation().toString());
        }
        urlList.add(url);
    }
    // This is Library classpath
    else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        IPath entryPath = entry.getPath();
        URL url = new URL("file", null, entryPath.toString());

        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
        if (res != null && res.exists()) {
            url = new URL("file", null, res.getLocation().toString());
        }
        urlList.add(url);
    }
    // This is Variables classpath
    else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        String variableName = entry.getPath().segment(0);
        IPath variablePath = JavaCore.getClasspathVariable(variableName);
        if (variablePath != null) {
            URL url = new URL("file", null, variablePath.toString());
            urlList.add(url);
        }
    }
}

From source file:org.evosuite.eclipse.popup.actions.TestGenerationJob.java

License:Open Source License

private String buildProjectCP() throws JavaModelException {
    IJavaProject jProject = JavaCore.create(target.getProject());
    IClasspathEntry[] oldEntries = jProject.getRawClasspath();
    String classPath = "";
    boolean first = true;

    for (int i = 0; i < oldEntries.length; i++) {
        IClasspathEntry curr = oldEntries[i];
        System.out.println("Current entry: " + curr.getPath());

        if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath path = curr.getPath();
            if (path.toFile().getName().startsWith("evosuite")) {
                System.out.println("Skipping evosuite.jar");
                continue;
            }/*from   w  w w  . jav a 2 s . com*/
            if (!first)
                classPath += File.pathSeparator;
            else
                first = false;

            if (path.toFile().exists()) {
                classPath += path.toOSString();
                System.out.println("Adding CPE_LIBRARY to classpath: " + path.toOSString());
            } else {
                classPath += target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString();
                System.out.println("Adding CPE_LIBRARY to classpath: "
                        + target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString());
            }
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (curr.isExported()) {
                if (curr.toString().equals("org.eclipse.jdt.launching.JRE_CONTAINER")) {
                    System.out.println("Found JRE container");
                } else if (curr.toString().startsWith("org.eclipse.jdt.junit.JUNIT_CONTAINER")) {
                    System.out.println("Found JUnit container");
                } else {
                    System.out.println("Found unknown container: " + curr);
                }
            } else {
                System.out.println("Container not exported: " + curr);
            }
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            // Add binary dirs of this project to classpath
            System.out.println("Don't handle CPE_PROJECT yet");
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            System.out.println("Path: " + curr.getPath());
            System.out.println("Resolved Path: " + JavaCore.getResolvedVariablePath(curr.getPath()));
            if (!first)
                classPath += File.pathSeparator;
            else
                first = false;

            classPath += JavaCore.getResolvedVariablePath(curr.getPath());
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            System.out.println("Don't handle CPE_SOURCE yet");
        } else {
            System.out.println("CP type: " + curr.getEntryKind());
        }
    }
    ResourceList.resetAllCaches();
    if (!first)
        classPath += File.pathSeparator;

    classPath += target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()).getLocation()
            .toOSString();
    return classPath;
}

From source file:org.gw4e.eclipse.facade.TestResourceGeneration.java

License:Open Source License

public static void getProjectClassPath(IJavaProject project, List<File> dst) throws Exception {
    IRuntimeClasspathEntry[] rentries = JavaRuntime.computeUnresolvedRuntimeClasspath(project);
    for (IRuntimeClasspathEntry entry : rentries) {
        switch (entry.getType()) {
        case IClasspathEntry.CPE_SOURCE:
            break;
        case IClasspathEntry.CPE_PROJECT:
            break;
        case IClasspathEntry.CPE_LIBRARY:
            break;
        case IClasspathEntry.CPE_VARIABLE:
            // JRE like entries
            IRuntimeClasspathEntry[] variableEntries = JavaRuntime.resolveRuntimeClasspathEntry(entry, project);
            break;
        case IClasspathEntry.CPE_CONTAINER:
            IRuntimeClasspathEntry[] containerEntries = JavaRuntime.resolveRuntimeClasspathEntry(entry,
                    project);//from w w w . j a va 2 s. c  o  m
            for (IRuntimeClasspathEntry containerentry : containerEntries) {
                dst.add(new File(containerentry.getLocation()));
            }
            break;
        default:
            throw new Exception("unsupported classpath entry " + entry);
        }
    }
}

From source file:org.jboss.tools.arquillian.core.internal.classpath.ArquillianClassLoader.java

License:Open Source License

private static Set<URL> getURLSet(IJavaProject jProject) {
    Set<URL> urls = new HashSet<URL>();
    Set<IJavaProject> dependentProjects = new HashSet<IJavaProject>();
    if (jProject == null) {
        return urls;
    }// w  w  w  .  j  a va 2 s  .c o  m
    try {
        IClasspathEntry[] entries = jProject.getRawClasspath();

        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                addSource(jProject, urls, entry);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IClasspathEntry resLib = JavaCore.getResolvedClasspathEntry(entry);
                addLibrary(urls, resLib);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                addProject(urls, entry, dependentProjects);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                IClasspathEntry resLib = JavaCore.getResolvedClasspathEntry(entry);
                addLibrary(urls, resLib);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (!entry.getPath().segment(0).toString().endsWith("JRE_CONTAINER")) { //$NON-NLS-1$
                    addContainer(jProject, urls, entry, dependentProjects);
                }
            }
        }

    } catch (Exception e) {
        ArquillianCoreActivator.log(e);
    }

    return urls;
}

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:/*w ww  .  j  a v a2  s.c  o  m*/
        return null;
    }
}

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;//from  w  w w.  ja va  2  s.  c  om
    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;//from w w w .  ja v a  2s . c  om
    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.seam.internal.core.project.facet.WtpUtils.java

License:Open Source License

public static IResource createSourceFolder(IProject project, IPath path, IPath exclude, IPath outputFolder) {
    IJavaProject javaProject;//from w w  w.  ja  v  a 2 s .  c  o m
    IClasspathEntry[] javaProjectEntries;
    IPath outputLocation;

    if (project == null || !project.exists()) {
        return null;
    }
    if (!project.isOpen()) {
        return null;
    }
    try {
        if (!project.hasNature(JavaCore.NATURE_ID))
            return null;

        javaProject = JavaCore.create(project);
        javaProjectEntries = javaProject.getRawClasspath();
        outputLocation = javaProject.getOutputLocation();

        IPath projPath = javaProject.getProject().getFullPath();
        IPath newSourceFolderPath = projPath.append(path);
        IPath excludeSourceFolderPath = projPath.append(exclude);

        ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(javaProjectEntries.length + 1);
        int projectEntryIndex = -1;

        for (int i = 0; i < javaProjectEntries.length; i++) {
            IClasspathEntry curr = javaProjectEntries[i];
            IClasspathEntry resolved = curr;
            if (resolved.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                try {
                    resolved = JavaCore.getResolvedClasspathEntry(resolved);
                } catch (AssertionFailedException e) {
                    continue;
                }
            }
            if (resolved.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                if (newSourceFolderPath.equals(resolved.getPath())) {
                    return null;
                }
                if (projPath.equals(resolved.getPath())) {
                    projectEntryIndex = i;
                }
                if (excludeSourceFolderPath.equals(resolved.getPath())) {
                    continue;
                }
            }
            newEntries.add(curr);
        }
        if (outputFolder != null) {
            CoreUtility.createDerivedFolder(project.getFolder(outputFolder), true, true,
                    new NullProgressMonitor());
        }
        IFolder newSourceFolder = javaProject.getProject().getFolder(path);
        if (!newSourceFolder.exists()) {
            CoreUtility.createFolder(newSourceFolder, true, true, new NullProgressMonitor());
        }

        IClasspathEntry newEntry = JavaCore.newSourceEntry(newSourceFolderPath, new Path[] {}, new Path[] {},
                outputFolder != null ? project.getFullPath().append(outputFolder) : null);

        if (projectEntryIndex != -1) {
            newEntries.set(projectEntryIndex, newEntry);
        } else {
            insertClasspathEntry(newEntry, newEntries);
        }

        IClasspathEntry[] newClasspathEntries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        IPath newOutputLocation = outputLocation;

        IJavaModelStatus result = JavaConventions.validateClasspath(javaProject, newClasspathEntries,
                newOutputLocation);
        if (!result.isOK()) {
            if (outputLocation.equals(projPath)) {
                newOutputLocation = projPath.append(
                        PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
                result = JavaConventions.validateClasspath(javaProject, newClasspathEntries, newOutputLocation);
                if (!result.isOK()) {
                    return null;
                }
            } else {
                return null;
            }
        }

        javaProject.setRawClasspath(newClasspathEntries, newOutputLocation, new NullProgressMonitor());
        return newSourceFolder;
    } catch (CoreException e) {
        SeamCorePlugin.getPluginLog().logError(e);
    }
    return null;
}

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;//  ww  w .  ja v a  2 s  .c om
    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;
    }
}

From source file:org.jboss.tools.ws.creation.core.utils.ClasspathParser.java

License:Open Source License

private String[] classpathEntryToString(IClasspathEntry entry, IProject project) {
    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY: {
        return new String[] { pathToString(entry.getPath()) };
    }/*from ww w . j  a  v  a2s .c o  m*/
    case IClasspathEntry.CPE_PROJECT: {
        return getClasspath(ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()),
                true);
    }
    case IClasspathEntry.CPE_SOURCE: {
        IPath path = entry.getPath();
        if (path.segment(0).equals(project.getName()))
            path = path.removeFirstSegments(1);
        return new String[] { pathToString(project.getLocation().addTrailingSeparator().append(path)) };
    }
    case IClasspathEntry.CPE_VARIABLE: {
        return classpathEntryToString(JavaCore.getResolvedClasspathEntry(entry), project);
    }
    default: {
        return new String[] { pathToString(entry.getPath()) };
    }
    }
}