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

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

Introduction

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

Prototype

int CPE_PROJECT

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

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a required project.

Usage

From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceListLabelProvider.java

License:Open Source License

public String getCPListElementAttributeText(CPListElementAttribute attrib) {
    String notAvailable = NewWizardMessages.CPListLabelProvider_none;
    String key = attrib.getKey();
    if (key.equals(CPListElement.SOURCEATTACHMENT)) {
        String arg;//from  w  w w  .j  a  va2 s  . co  m
        IPath path = (IPath) attrib.getValue();
        if (path != null && !path.isEmpty()) {
            if (attrib.getParent().getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                arg = getVariableString(path);
            } else {
                arg = getPathString(path, path.getDevice() != null);
            }
        } else {
            arg = notAvailable;
        }
        return Messages.format(NewWizardMessages.CPListLabelProvider_source_attachment_label,
                new String[] { arg });
    } else if (key.equals(CPListElement.OUTPUT)) {
        String arg = null;
        IPath path = (IPath) attrib.getValue();
        if (path != null) {
            arg = BasicElementLabels.getPathLabel(path, false);
        } else {
            arg = NewWizardMessages.CPListLabelProvider_default_output_folder_label;
        }
        return Messages.format(NewWizardMessages.CPListLabelProvider_output_folder_label, new String[] { arg });
    } else if (key.equals(CPListElement.EXCLUSION)) {
        String arg = null;
        IPath[] patterns = (IPath[]) attrib.getValue();
        if (patterns != null && patterns.length > 0) {
            int patternsCount = 0;
            StringBuffer buf = new StringBuffer();
            for (int i = 0; i < patterns.length; i++) {
                if (patterns[i].segmentCount() > 0) {
                    String pattern = BasicElementLabels.getPathLabel(patterns[i], false);
                    if (patternsCount > 0) {
                        buf.append(NewWizardMessages.CPListLabelProvider_exclusion_filter_separator);
                    }
                    buf.append(pattern);
                    patternsCount++;
                }
            }
            if (patternsCount > 0) {
                arg = buf.toString();
            } else {
                arg = notAvailable;
            }
        } else {
            arg = notAvailable;
        }
        return Messages.format(NewWizardMessages.CPListLabelProvider_exclusion_filter_label,
                new String[] { arg });
    } else if (key.equals(CPListElement.INCLUSION)) {
        String arg = null;
        IPath[] patterns = (IPath[]) attrib.getValue();
        if (patterns != null && patterns.length > 0) {
            int patternsCount = 0;
            StringBuffer buf = new StringBuffer();
            for (int i = 0; i < patterns.length; i++) {
                if (patterns[i].segmentCount() > 0) {
                    String pattern = BasicElementLabels.getPathLabel(patterns[i], false);
                    if (patternsCount > 0) {
                        buf.append(NewWizardMessages.CPListLabelProvider_inclusion_filter_separator);
                    }
                    buf.append(pattern);
                    patternsCount++;
                }
            }
            if (patternsCount > 0) {
                arg = buf.toString();
            } else {
                arg = notAvailable;
            }
        } else {
            arg = NewWizardMessages.CPListLabelProvider_all;
        }
        return Messages.format(NewWizardMessages.CPListLabelProvider_inclusion_filter_label,
                new String[] { arg });
    } else if (key.equals(CPListElement.ACCESSRULES)) {
        IAccessRule[] rules = (IAccessRule[]) attrib.getValue();
        int nRules = rules != null ? rules.length : 0;

        int parentKind = attrib.getParent().getEntryKind();
        if (parentKind == IClasspathEntry.CPE_PROJECT) {
            Boolean combined = (Boolean) attrib.getParent().getAttribute(CPListElement.COMBINE_ACCESSRULES);
            if (nRules > 0) {
                if (combined.booleanValue()) {
                    if (nRules == 1) {
                        return NewWizardMessages.CPListLabelProvider_project_access_rules_combined_singular;
                    } else {
                        return Messages.format(
                                NewWizardMessages.CPListLabelProvider_project_access_rules_combined_plural,
                                String.valueOf(nRules));
                    }
                } else {
                    if (nRules == 1) {
                        return NewWizardMessages.CPListLabelProvider_project_access_rules_not_combined_singular;
                    } else {
                        return Messages.format(
                                NewWizardMessages.CPListLabelProvider_project_access_rules_not_combined_plural,
                                String.valueOf(nRules));
                    }
                }
            } else {
                return NewWizardMessages.CPListLabelProvider_project_access_rules_no_rules;
            }
        } else if (parentKind == IClasspathEntry.CPE_CONTAINER) {
            if (nRules > 1) {
                return Messages.format(NewWizardMessages.CPListLabelProvider_container_access_rules_plural,
                        String.valueOf(nRules));
            } else if (nRules == 1) {
                return NewWizardMessages.CPListLabelProvider_container_access_rules_singular;
            } else {
                return NewWizardMessages.CPListLabelProvider_container_no_access_rules;
            }
        } else {
            if (nRules > 1) {
                return Messages.format(NewWizardMessages.CPListLabelProvider_access_rules_enabled_plural,
                        String.valueOf(nRules));
            } else if (nRules == 1) {
                return NewWizardMessages.CPListLabelProvider_access_rules_enabled_singular;
            } else {
                return NewWizardMessages.CPListLabelProvider_access_rules_disabled;
            }
        }
    } else if (key.equals(CPListElement.IGNORE_OPTIONAL_PROBLEMS)) {
        String arg;
        if ("true".equals(attrib.getValue())) { //$NON-NLS-1$
            arg = NewWizardMessages.CPListLabelProvider_ignore_optional_problems_yes;
        } else {
            arg = NewWizardMessages.CPListLabelProvider_ignore_optional_problems_no;
        }
        return Messages.format(NewWizardMessages.CPListLabelProvider_ignore_optional_problems_label, arg);
    } else {
        ClasspathAttributeConfiguration config = fAttributeDescriptors.get(key);
        if (config != null) {
            ClasspathAttributeAccess access = attrib.getClasspathAttributeAccess();
            String nameLabel = config.getNameLabel(access);
            String valueLabel = config.getValueLabel(access); // should be LTR marked
            return Messages.format(NewWizardMessages.CPListLabelProvider_attribute_label,
                    new String[] { nameLabel, valueLabel });
        }
        String arg = (String) attrib.getValue();
        if (arg == null) {
            arg = notAvailable;
        }
        return Messages.format(NewWizardMessages.CPListLabelProvider_attribute_label,
                new String[] { key, arg });
    }
}

From source file:com.siteview.mde.internal.ui.wizards.plugin.NewLibraryPluginCreationOperation.java

License:Open Source License

private static boolean isPluginProjectEntry(IClasspathEntry entry) {
    if (IClasspathEntry.CPE_PROJECT != entry.getEntryKind())
        return false;
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject other = workspaceRoot.getProject(entry.getPath().segment(0));
    if (!MDE.hasPluginNature(other))
        return false;
    if (PDEProject.getFragmentXml(other).exists())
        return false;
    try {//from   www .  j  a  v a2s .co m
        InputStream is = PDEProject.getManifest(other).getContents();
        try {
            Manifest mf = new Manifest(is);
            if (mf.getMainAttributes().getValue(Constants.FRAGMENT_HOST) != null)
                return false;
        } finally {
            is.close();
        }
    } catch (IOException e) {
        // assume "not a fragment"
    } catch (CoreException e) {
        // assume "not a fragment"
    }
    return true;
}

From source file:com.sympedia.genfw.util.ClasspathHelper.java

License:Open Source License

public static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls) {
    try {/* ww w.j  ava 2 s. c  om*/
        collectClasspathUrlOutput(javaProject.getOutputLocation(), urls);

        IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : resolvedClasspath) {
            try {
                switch (entry.getEntryKind()) {
                case IClasspathEntry.CPE_SOURCE:
                    collectClasspathUrlOutput(entry.getOutputLocation(), urls);
                    break;

                case IClasspathEntry.CPE_LIBRARY:
                    File libFile = new File(entry.getPath().toString());
                    URL url = libFile.toURL();
                    if (!urls.contains(url)) {
                        //              System.out.println("LIB: " + url);
                        urls.add(url);
                    }
                    break;

                case IClasspathEntry.CPE_PROJECT:
                    String projectName = entry.getPath().segment(0);
                    IJavaProject requiredProject = getJavaProject(projectName);
                    collectClasspathURLs(requiredProject, urls);
                    break;

                default:
                    throw new RuntimeException();
                }
            } catch (MalformedURLException ex) {
                ex.printStackTrace();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java

License:Open Source License

private void addMavenClasspathEntries(Set<IRuntimeClasspathEntry> resolved,
        IRuntimeClasspathEntry runtimeClasspathEntry, ILaunchConfiguration configuration, int scope,
        IProgressMonitor monitor) throws CoreException {
    IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
    MavenJdtPlugin plugin = MavenJdtPlugin.getDefault();
    IClasspathManager buildpathManager = plugin.getBuildpathManager();
    IClasspathEntry[] cp = buildpathManager.getClasspath(javaProject.getProject(), scope, false, monitor);
    for (IClasspathEntry entry : cp) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_PROJECT:
            addProjectEntries(resolved, entry.getPath(), scope, getArtifactClassifier(entry), configuration,
                    monitor);//ww  w  .  j av  a  2 s .c  o m
            break;
        case IClasspathEntry.CPE_LIBRARY:
            resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()));
            break;
        default:
            break;
        }
    }
}

From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java

License:Open Source License

protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier,
        ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(path.segment(0));

    IMavenProjectFacade projectFacade = projectManager.create(project, monitor);
    if (projectFacade == null) {
        return;// ww w.j  ava 2s  .c o m
    }

    ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
    if (configuration == null) {
        return;
    }

    IJavaProject javaProject = JavaCore.create(project);

    boolean projectResolved = false;

    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
        IRuntimeClasspathEntry rce = null;
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!projectResolved) {

                IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault()
                        .getMavenClassifierManager();
                IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager
                        .getClassifierClasspathProvider(projectFacade, classifier);

                if (IClasspathManager.CLASSPATH_TEST == scope) {
                    classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor);
                } else {
                    classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor);
                }

                projectResolved = true;
            }
            break;
        case IClasspathEntry.CPE_CONTAINER:
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            if (container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) {
                switch (container.getKind()) {
                case IClasspathContainer.K_APPLICATION:
                    rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(),
                            IRuntimeClasspathEntry.USER_CLASSES, javaProject);
                    break;
                default:
                    break;
                }
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath());
            break;
        case IClasspathEntry.CPE_VARIABLE:
            if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) {
                rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath());
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            IProject res = root.getProject(entry.getPath().segment(0));
            if (res != null) {
                IJavaProject otherProject = JavaCore.create(res);
                if (otherProject != null) {
                    rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject);
                }
            }
            break;
        default:
            break;
        }
        if (rce != null) {
            addStandardClasspathEntries(resolved, rce, launchConfiguration);
        }
    }
}

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  w  w.j  a  v a 2  s  . c  o m*/
        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.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 ww  w  .  j  a  va  2s  .  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:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

private static void getClassURLs(IJavaProject javaProject, List<URL> urls) {
    IProject project = javaProject.getProject();
    IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();

    IClasspathEntry[] paths = null;// w w  w.ja v a 2s .c om
    IPath defaultOutputLocation = null;
    try {
        paths = javaProject.getResolvedClasspath(true);
        defaultOutputLocation = javaProject.getOutputLocation();
    } catch (JavaModelException e) {
        // don't show message to user neither log it
        // BytecodeOutlinePlugin.log(e, IStatus.ERROR);
    }
    if (paths != null) {
        IPath projectPath = javaProject.getProject().getLocation();
        for (int i = 0; i < paths.length; ++i) {
            IClasspathEntry cpEntry = paths[i];
            IPath p = null;
            if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                // filter out source container - there are unused for class
                // search - add bytecode output location instead
                p = cpEntry.getOutputLocation();
                if (p == null) {
                    // default output used:
                    p = defaultOutputLocation;
                }
            } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                String projName = cpEntry.getPath().toPortableString().substring(1);
                IProject proj = workspaceRoot.getProject(projName);
                IJavaProject projj = JavaCore.create(proj);
                getClassURLs(projj, urls);
                continue;
            } else {
                p = cpEntry.getPath();
            }

            if (p == null) {
                continue;
            }
            if (!p.toFile().exists()) {
                // removeFirstSegments: remove project from relative path
                p = projectPath.append(p.removeFirstSegments(1));
                if (!p.toFile().exists()) {
                    continue;
                }
            }
            try {
                urls.add(p.toFile().toURI().toURL());
            } catch (MalformedURLException e) {
                // don't show message to user
                BytecodeOutlinePlugin.log(e, IStatus.ERROR);
            }
        }
    }
}

From source file:de.tobject.findbugs.builder.PDEClassPathGenerator.java

License:Open Source License

private static void resolveInWorkspace(IClasspathEntry classpathEntry, Set<String> classPath,
        Set<IProject> projectOnCp) {
    int entryKind = classpathEntry.getEntryKind();
    switch (entryKind) {
    case IClasspathEntry.CPE_PROJECT:
        Set<String> cp = resolveProjectClassPath(classpathEntry.getPath(), projectOnCp);
        classPath.addAll(cp);// ww  w.j  a v  a2 s. c  o  m
        break;
    case IClasspathEntry.CPE_VARIABLE:
        classpathEntry = JavaCore.getResolvedClasspathEntry(classpathEntry);
        if (classpathEntry == null) {
            return;
        }
        //$FALL-THROUGH$
    case IClasspathEntry.CPE_LIBRARY:
        String lib = resolveLibrary(classpathEntry.getPath());
        if (lib != null) {
            classPath.add(lib);
        }
        break;
    case IClasspathEntry.CPE_SOURCE:
        // ???
        break;
    default:
        break;
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void addPath(IvyXmlWriter xw, IJavaProject jp, IClasspathEntry ent, boolean nest) {
    IPath p = ent.getPath();/*from   w  ww . j  a  v a  2  s .c  o m*/
    IPath op = ent.getOutputLocation();
    IPath sp = ent.getSourceAttachmentPath();
    IProject ip = jp.getProject();

    String jdp = null;
    boolean opt = false;
    IClasspathAttribute[] atts = ent.getExtraAttributes();
    for (IClasspathAttribute att : atts) {
        if (att.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME))
            jdp = att.getValue();
        else if (att.getName().equals(IClasspathAttribute.OPTIONAL)) {
            String v = att.getValue();
            if (v.equals("true"))
                opt = true;
        }
    }

    if (p == null && op == null)
        return;
    File f1 = null;
    if (p != null) {
        f1 = BedrockUtil.getFileForPath(p, ip);
        if (!f1.exists()) {
            BedrockPlugin.logD("Path file " + p + " not found as " + f1);
            // f1 = null;
        }
    }
    File f2 = null;
    if (op != null) {
        f2 = BedrockUtil.getFileForPath(op, ip);
        if (!f2.exists()) {
            BedrockPlugin.logD("Path file " + op + " not found");
            f2 = null;
        }
    }
    File f3 = null;
    if (sp != null) {
        f3 = BedrockUtil.getFileForPath(sp, ip);
        if (!f3.exists()) {
            BedrockPlugin.logD("Path file " + sp + " not found");
            f3 = null;
        }
    }
    if (f1 == null && f2 == null)
        return;

    // references to nested projects are handled in addClassPaths
    if (ent.getEntryKind() == IClasspathEntry.CPE_PROJECT)
        return;

    xw.begin("PATH");
    xw.field("ID", ent.hashCode());
    if (nest)
        xw.field("NESTED", "TRUE");

    switch (ent.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        xw.field("TYPE", "SOURCE");
        f3 = f1;
        f1 = null;
        break;
    case IClasspathEntry.CPE_PROJECT:
        xw.field("TYPE", "BINARY");
        break;
    case IClasspathEntry.CPE_LIBRARY:
        xw.field("TYPE", "LIBRARY");
        break;
    }
    if (ent.isExported())
        xw.field("EXPORTED", true);
    if (opt)
        xw.field("OPTIONAL", true);

    if (f1 != null)
        xw.textElement("BINARY", f1.getAbsolutePath());
    if (f2 != null)
        xw.textElement("OUTPUT", f2.getAbsolutePath());
    if (f3 != null)
        xw.textElement("SOURCE", f3.getAbsolutePath());
    if (jdp != null)
        xw.textElement("JAVADOC", jdp);

    IAccessRule[] rls = ent.getAccessRules();
    for (IAccessRule ar : rls) {
        xw.begin("ACCESS");
        xw.field("KIND", ar.getKind());
        xw.field("PATTERN", ar.getPattern().toString());
        xw.field("IGNOREIFBETTER", ar.ignoreIfBetter());
        xw.end("ACCESS");
    }

    xw.end("PATH");
}