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

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

Introduction

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

Prototype

int CPE_CONTAINER

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

Click Source Link

Document

Entry kind constant describing a classpath entry representing a name classpath container.

Usage

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

License:Open Source License

private void extractDependencies(IJavaProject javaProject, IClasspathEntry[] classpath,
        List<ProjectDependency> classpathDependencies) throws JavaModelException {
    for (IClasspathEntry cpe : classpath) {
        if (!isValid(cpe)) {
            continue;
        }/*from   w  w w. j  a v a  2s.  co  m*/
        if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), javaProject);
            if (container != null) {
                IClasspathEntry[] cpes = container.getClasspathEntries();
                if (cpes != null && cpes.length > 0) {
                    extractDependencies(javaProject, cpes, classpathDependencies);
                }
            }
        } else {
            classpathDependencies.add(new JavaDependency(cpe));
        }
    }
}

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

License:Open Source License

private boolean isValid(IClasspathEntry cpe) {

    if (IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind()
            && ("org.eclipse.jdt.launching.JRE_CONTAINER".equals(cpe.getPath().segment(0))
                    || MavenClasspathHelpers.isMaven2ClasspathContainer(cpe.getPath()))) {
        return false;
    }//  w ww.j  a va  2s  . c o m
    if (IClasspathEntry.CPE_SOURCE == cpe.getEntryKind()) {
        return false;
    }
    return true;
}

From source file:org.jboss.tools.maven.conversion.ui.internal.jobs.DeleteExistingClasspathEntriesJob.java

License:Open Source License

private boolean isKept(IClasspathEntry cpe) {
    if (IClasspathEntry.CPE_SOURCE == cpe.getEntryKind() || (IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind()
            && ("org.eclipse.jdt.launching.JRE_CONTAINER".equals(cpe.getPath().segment(0))
                    || MavenClasspathHelpers.isMaven2ClasspathContainer(cpe.getPath())))) {
        return true;
    }/* www .j ava 2s  . co m*/
    return false;
}

From source file:org.jboss.tools.maven.core.MavenCoreActivator.java

License:Open Source License

public static void addClasspathAttribute(IJavaProject javaProject, IClasspathAttribute attribute,
        IProgressMonitor monitor) throws JavaModelException {
    if (javaProject == null || !javaProject.exists()) {
        return;/*  w  w w.  j a v a 2 s.c o m*/
    }

    IClasspathEntry[] cp = javaProject.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        if (IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind() && cp[i].getPath() != null
                && cp[i].getPath().segmentCount() > 0
                && IClasspathManager.CONTAINER_ID.equals(cp[i].getPath().segment(0))) {
            LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>();
            for (IClasspathAttribute attr : cp[i].getExtraAttributes()) {
                attrs.put(attr.getName(), attr);
            }
            attrs.put(attribute.getName(), attribute);
            IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
            cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newAttrs,
                    cp[i].isExported());
            break;
        }
    }
    javaProject.setRawClasspath(cp, monitor);

}

From source file:org.jboss.tools.maven.jbosspackaging.configurators.SarProjectConfigurator.java

License:Open Source License

protected void updateContainerAttributes(IProject project, IClasspathAttribute attributeToAdd,
        String attributeToDelete, IProgressMonitor monitor) throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null)
        return;//from   ww  w. j  a  v a  2s  .  c  om
    IClasspathEntry[] cp = javaProject.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        if (IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind()
                && MavenClasspathHelpers.isMaven2ClasspathContainer(cp[i].getPath())) {
            LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>();
            for (IClasspathAttribute attr : cp[i].getExtraAttributes()) {
                if (!attr.getName().equals(attributeToDelete)) {
                    attrs.put(attr.getName(), attr);
                }
            }
            attrs.put(attributeToAdd.getName(), attributeToAdd);
            IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
            cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newAttrs,
                    cp[i].isExported());
            break;
        }
    }
    javaProject.setRawClasspath(cp, monitor);
}

From source file:org.jboss.tools.maven.jdt.utils.ClasspathHelpers.java

License:Open Source License

public static IClasspathContainer getEndorsedDirsClasspathContainer(IJavaProject project)
        throws JavaModelException {
    IClasspathEntry[] entries = project.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && isEndorsedDirsClasspathContainer(entry.getPath())) {
            return JavaCore.getClasspathContainer(entry.getPath(), project);
        }/*from  w  ww . ja  v  a 2s  .c o m*/
    }
    return null;
}

From source file:org.jboss.tools.maven.sourcelookup.ui.internal.util.SourceLookupUtil.java

License:Open Source License

public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath,
        boolean displayDialog) {
    try {// w  w w .  j  a v  a2s. co  m
        if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) {
            return;
        }
        String value = SourceLookupActivator.getDefault().getAutoAddSourceAttachment();
        if (SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_ATTACHMENT_NEVER.equals(value)) {
            return;
        }
        if (displayDialog && SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_ATTACHMENT_PROMPT.equals(value)) {
            final boolean[] attach = new boolean[1];
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    attach[0] = promptToAddSourceAttachment(fragment.getElementName(),
                            newSourcePath.toString());
                }
            });
            if (!attach[0]) {
                return;
            }
            ;
        }
        IPath containerPath = null;
        IJavaProject jproject = fragment.getJavaProject();
        IClasspathEntry entry = fragment.getRawClasspathEntry();
        if (entry == null) {
            entry = JavaCore.newLibraryEntry(fragment.getPath(), null, null);
        } else {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                containerPath = entry.getPath();
                ClasspathContainerInitializer initializer = JavaCore
                        .getClasspathContainerInitializer(containerPath.segment(0));
                IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject);
                if (initializer == null || container == null) {
                    return;
                }
                IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject);
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
                    return;
                }
                if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
                    return;
                }
                entry = JavaModelUtil.findEntryInContainer(container, fragment.getPath());
                if (entry == null) {
                    return;
                }
            }
        }
        IClasspathEntry entry1;
        CPListElement elem = CPListElement.createFromExisting(entry, null);
        elem.setAttribute(CPListElement.SOURCEATTACHMENT, newSourcePath);
        entry1 = elem.getClasspathEntry();
        if (entry1.equals(entry)) {
            return;
        }
        IClasspathEntry newEntry = entry1;
        String[] changedAttributes = { CPListElement.SOURCEATTACHMENT };
        BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, jproject, containerPath,
                newEntry.getReferencingEntry() != null, new NullProgressMonitor());
    } catch (CoreException e) {
        // ignore
    }
}

From source file:org.jboss.tools.portlet.core.internal.project.facet.PortletFacetUninstallDelegate.java

License:Open Source License

public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
        throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null && javaProject.exists()) {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        IPath containerPath = new Path(IPortletConstants.PORTLET_RUNTIME_CONTAINER_ID);
        List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (containerPath.equals(path)) {
                    continue;
                }//from   w  w w  . j a  v  a2s . com
            }
            newEntries.add(entry);
        }
        if (newEntries.size() != entries.length) {
            javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor);
        }
    }
}

From source file:org.jboss.tools.project.examples.fixes.WTPRuntimeFix.java

License:Open Source License

private void fixEsb(IProject eclipseProject, ProjectFix fix, IRuntime runtime) throws JavaModelException {
    String required_components = fix.getProperties().get(REQUIRED_COMPONENTS);
    if (required_components == null) {
        return;//  w  w  w  .j  a  v  a  2s  .  c  om
    }
    List<String> components = tokenize(required_components);
    if (components == null) {
        return;
    }
    boolean esbRequired = false;
    for (String component : components) {
        if (ESB.equals(component)) {
            esbRequired = true;
            break;
        }
    }
    if (esbRequired) {
        IJavaProject javaProject = JavaCore.create(eclipseProject);
        if (javaProject != null) {
            if (!javaProject.isOpen()) {
                javaProject.open(null);
            }
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            IClasspathEntry[] newEntries = new IClasspathEntry[entries.length];
            boolean changed = false;
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    IPath path = entry.getPath();
                    if (new Path(RuntimeClasspathContainer.SERVER_CONTAINER).isPrefixOf(path)) {
                        RuntimeClasspathProviderWrapper rcpw = JavaServerPlugin
                                .findRuntimeClasspathProvider(runtime.getRuntimeType());
                        IPath serverContainerPath = new Path(RuntimeClasspathContainer.SERVER_CONTAINER)
                                .append(rcpw.getId()).append(runtime.getId());
                        newEntries[i] = JavaCore.newContainerEntry(serverContainerPath);
                        changed = true;
                    } else if (ESB_SERVER_SUPPLIED_CONTAINER_PATH.isPrefixOf(path)) {
                        IPath esbContainerPath = ESB_SERVER_SUPPLIED_CONTAINER_PATH.append(runtime.getId());
                        newEntries[i] = JavaCore.newContainerEntry(esbContainerPath);
                        changed = true;
                    } else {
                        newEntries[i] = entry;
                    }
                } else {
                    newEntries[i] = entry;
                }
            }
            if (changed) {
                javaProject.setRawClasspath(newEntries, new NullProgressMonitor());
            }
        }
    }
}

From source file:org.jboss.tools.project.examples.internal.fixes.WTPRuntimeFix.java

License:Open Source License

private void fixEsb(IProject eclipseProject, RequirementModel fix, IRuntime runtime) throws JavaModelException {
    Collection<String> components = splitProperty(REQUIRED_COMPONENTS);
    if (components.isEmpty()) {
        return;//from w  w w  .  j  a va2 s  .  co m
    }
    boolean esbRequired = false;
    for (String component : components) {
        if (ESB.equals(component)) {
            esbRequired = true;
            break;
        }
    }
    if (esbRequired) {
        IJavaProject javaProject = JavaCore.create(eclipseProject);
        if (javaProject != null) {
            if (!javaProject.isOpen()) {
                javaProject.open(null);
            }
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            IClasspathEntry[] newEntries = new IClasspathEntry[entries.length];
            boolean changed = false;
            IRuntimeType rt = runtime.getRuntimeType();
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    IPath path = entry.getPath();
                    if (rt != null && new Path(RuntimeClasspathContainer.SERVER_CONTAINER).isPrefixOf(path)) {
                        RuntimeClasspathProviderWrapper rcpw = JavaServerPlugin
                                .findRuntimeClasspathProvider(rt);
                        IPath serverContainerPath = new Path(RuntimeClasspathContainer.SERVER_CONTAINER)
                                .append(rcpw.getId()).append(runtime.getId());
                        newEntries[i] = JavaCore.newContainerEntry(serverContainerPath);
                        changed = true;
                    } else if (ESB_SERVER_SUPPLIED_CONTAINER_PATH.isPrefixOf(path)) {
                        IPath esbContainerPath = ESB_SERVER_SUPPLIED_CONTAINER_PATH.append(runtime.getId());
                        newEntries[i] = JavaCore.newContainerEntry(esbContainerPath);
                        changed = true;
                    } else {
                        newEntries[i] = entry;
                    }
                } else {
                    newEntries[i] = entry;
                }
            }
            if (changed) {
                javaProject.setRawClasspath(newEntries, new NullProgressMonitor());
            }
        }
    }
}