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.eclipse.andmore.internal.resources.manager.ProjectClassLoader.java

License:Open Source License

/**
 * Returns an array of external jar files used by the project.
 * @return an array of OS-specific absolute file paths
 *///from w w  w.jav  a 2 s .  c  om
private final URL[] getExternalJars() {
    // get a java project from it
    IJavaProject javaProject = JavaCore.create(mJavaProject.getProject());

    ArrayList<URL> oslibraryList = new ArrayList<URL>();
    IClasspathEntry[] classpaths = javaProject.readRawClasspath();
    if (classpaths != null) {
        for (IClasspathEntry e : classpaths) {
            if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                    || e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                // if this is a classpath variable reference, we resolve it.
                if (e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                    e = JavaCore.getResolvedClasspathEntry(e);
                }

                handleClassPathEntry(e, oslibraryList);
            } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                // get the container.
                try {
                    IClasspathContainer container = JavaCore.getClasspathContainer(e.getPath(), javaProject);
                    // ignore the system and default_system types as they represent
                    // libraries that are part of the runtime.
                    if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
                        IClasspathEntry[] entries = container.getClasspathEntries();
                        for (IClasspathEntry entry : entries) {
                            // TODO: Xav -- is this necessary?
                            if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                                entry = JavaCore.getResolvedClasspathEntry(entry);
                            }

                            handleClassPathEntry(entry, oslibraryList);
                        }
                    }
                } catch (JavaModelException jme) {
                    // can't resolve the container? ignore it.
                    AndmoreAndroidPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", e.getPath());
                }
            }
        }
    }

    return oslibraryList.toArray(new URL[oslibraryList.size()]);
}

From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java

License:Open Source License

private void handleVariables(IClasspathEntry entry) {
    if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE
            && entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        // found variable
        String e = entry.getPath().toString();
        int index = e.indexOf('/');
        if (index == -1) {
            index = e.indexOf('\\');
        }//from  w w  w  .ja  v a 2 s. c  om
        String variable = e;
        String path = IAntCoreConstants.EMPTY_STRING;
        if (index != -1) {
            variable = e.substring(0, index);
            path = e.substring(index);
        }
        IPath value = JavaCore.getClasspathVariable(variable);
        if (value != null) {
            String projectRoot = ExportUtil.getProjectRoot(project);
            String relativePath = ExportUtil.getRelativePath(value.toString(), projectRoot);
            variable2valueMap.put(variable, relativePath);
        } else if (variable2valueMap.get(variable) == null) {
            // only add empty value, if variable is new
            variable2valueMap.put(variable, IAntCoreConstants.EMPTY_STRING);
        }
        rawClassPathEntriesAbsolute.add(value + path);
        rawClassPathEntries.add("${" + variable + "}" + path); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEClassPathBlock.java

License:Open Source License

private void editElementEntry(IDECPListElement elem) {
    IDECPListElement[] res = null;/*from  ww w  .  j a  va2 s .co m*/

    switch (elem.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY:
        IResource resource = elem.getResource();
        if (resource == null) {
            File file = elem.getPath().toFile();
            if (file.isDirectory()) {
                res = openExternalClassFolderDialog(elem);
            } else {
                res = openExtJarFileDialog(elem);
            }
        } else if (resource.getType() == IResource.FILE) {
            res = openJarFileDialog(elem);
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        res = openVariableSelectionDialog(elem);
        break;
    }
    if (res != null && res.length > 0) {
        IDECPListElement curr = res[0];
        curr.setExported(elem.isExported());
        // curr.setAttributesFromExisting(elem);
        fLibrariesList.replaceElement(elem, curr);
        if (elem.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            fLibrariesList.refresh();
        }
    }

}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEClassPathBlock.java

License:Open Source License

private static IDECPListElement createCPVariableElement(IPath path) {
    IDECPListElement elem = new IDECPListElement(IClasspathEntry.CPE_VARIABLE, path, null);
    IPath resolvedPath = JavaCore.getResolvedVariablePath(path);
    elem.setIsMissing((resolvedPath == null) || !resolvedPath.toFile().exists());
    return elem;/*from   w w  w .j a v a  2  s  . c o  m*/
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEClassPathBlock.java

License:Open Source License

public boolean isEntryKind(int kind) {
    return kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_PROJECT
            || kind == IClasspathEntry.CPE_VARIABLE || kind == IClasspathEntry.CPE_CONTAINER;
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEClassPathBlock.java

License:Open Source License

private IDECPListElement[] openVariableSelectionDialog(IDECPListElement existing) {
    List existingElements = fLibrariesList.getElements();
    ArrayList existingPaths = new ArrayList(existingElements.size());
    for (int i = 0; i < existingElements.size(); i++) {
        IDECPListElement elem = (IDECPListElement) existingElements.get(i);
        if (elem.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            existingPaths.add(elem.getPath());
        }/*from  ww w . j  a v  a2  s  . co  m*/
    }
    IPath[] existingPathsArray = (IPath[]) existingPaths.toArray(new IPath[existingPaths.size()]);

    if (existing == null) {
        IPath[] paths = BuildPathDialogAccess.chooseVariableEntries(getShell(), existingPathsArray);
        if (paths != null) {
            ArrayList result = new ArrayList();
            for (int i = 0; i < paths.length; i++) {
                IPath path = paths[i];
                IDECPListElement elem = createCPVariableElement(path);
                if (!existingElements.contains(elem)) {
                    result.add(elem);
                }
            }
            return (IDECPListElement[]) result.toArray(new IDECPListElement[result.size()]);
        }
    } else {
        IPath path = BuildPathDialogAccess.configureVariableEntry(getShell(), existing.getPath(),
                existingPathsArray);
        if (path != null) {
            return new IDECPListElement[] { createCPVariableElement(path) };
        }
    }
    return null;
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEClassPathBlock.java

License:Open Source License

private int getType(IDECPListElement element) {
    int kind = element.getEntryKind();
    if (kind == IClasspathEntry.CPE_VARIABLE) {
        return VAR_TYPE;
    } else if (kind == IClasspathEntry.CPE_PROJECT) {
        return PROJECT_TYPE;
    } else if (kind == IClasspathEntry.CPE_LIBRARY) {
        IResource resource = element.getResource();
        if (resource instanceof IFile) {
            return JAR_TYPE;
        }//from  ww w.jav  a 2 s  .  c  o  m
        if (resource instanceof IContainer) {
            return FOL_TYPE;
        }

        IPath path = element.getPath();

        File file = path.toFile();
        if (file.isFile()) {
            return EXTJAR_TYPE;
        } else {
            return ADDFOL_TYPE;
        }
    }

    return UNKNOW_TYPE;
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDECPListElement.java

License:Open Source License

private IClasspathEntry newClasspathEntry() {

    IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0];
    switch (fEntryKind) {
    case IClasspathEntry.CPE_SOURCE:
        return JavaCore.newSourceEntry(fPath, null, null, null, extraAttributes);
    case IClasspathEntry.CPE_LIBRARY: {
        return JavaCore.newLibraryEntry(fPath, null, null, null, extraAttributes, isExported());
    }// w  w w.  j  a  va2  s . c  om
    case IClasspathEntry.CPE_PROJECT: {
        return JavaCore.newProjectEntry(fPath, null, false, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_CONTAINER: {
        return JavaCore.newContainerEntry(fPath, null, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_VARIABLE: {
        return JavaCore.newVariableEntry(fPath, null, null, null, extraAttributes, isExported());
    }
    default:
        return null;
    }
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDECPListLabelProvider.java

License:Open Source License

public String getCPListElementText(IDECPListElement cpentry) {
    IPath path = cpentry.getPath();//  w  w w . j av  a  2 s .  c  o m
    switch (cpentry.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY: {
        IResource resource = cpentry.getResource();
        if (resource instanceof IContainer) {
            StringBuffer buf = new StringBuffer(getPathLabel(path, false));
            buf.append(' ');
            buf.append(fClassLabel);
            if (!resource.exists()) {
                buf.append(' ');
                if (cpentry.isMissing()) {
                    buf.append(fMissing);
                } else {
                    buf.append(fNewLabel);
                }
            }
            return buf.toString();
        } else {
            String label = getPathString(path, resource == null);
            if (cpentry.isMissing()) {
                label = label + ' ' + fMissing;
            }
            return label;
        }
    }
    case IClasspathEntry.CPE_VARIABLE: {
        String label = getVariableString(path);
        if (cpentry.isMissing()) {
            label = label + ' ' + fMissing;
        }
        return label;
    }
    case IClasspathEntry.CPE_PROJECT:
        String label = path.lastSegment();
        if (cpentry.isMissing()) {
            label = label + ' ' + fMissing;
        }
        return label;
    case IClasspathEntry.CPE_SOURCE: {
        String pathLabel = getPathLabel(path, false);
        StringBuffer buf = new StringBuffer(pathLabel);

        IResource resource = cpentry.getResource();
        if (resource != null && !resource.exists()) {
            buf.append(' ');
            if (cpentry.isMissing()) {
                buf.append(fMissing);
            } else {
                buf.append(fNewLabel);
            }
        } else if (cpentry.getOrginalPath() == null) {
            buf.append(' ');
            buf.append(fNewLabel);
        }
        return buf.toString();
    }
    default:
        // pass
    }
    return Messages.getString("IDECPListLabelProvider.unknown"); //$NON-NLS-1$
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDECPListLabelProvider.java

License:Open Source License

private Image getCPListElementBaseImage(IDECPListElement cpentry) {
    switch (cpentry.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY:
        IResource res = cpentry.getResource();
        if (res == null) {
            if (isArchivePath(cpentry.getPath(), false)) {
                return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_EXTJAR);
            } else {
                return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_EXTFOL);
            }/*  w  w  w. ja v a 2 s  .  c om*/
        } else if (res instanceof IFile) {
            return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_JAR);
        } else {
            return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_FOL);
        }
    case IClasspathEntry.CPE_PROJECT:
        return ReportPlugin.getDefault().getWorkbench().getSharedImages()
                .getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
    case IClasspathEntry.CPE_VARIABLE:
        return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_VARIABLE);
    default:
        return null;
    }
}