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

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

Introduction

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

Prototype

IPath getPath();

Source Link

Document

Returns the path of this classpath entry.

Usage

From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ProjectLabelProvider.java

License:Apache License

public String getText(Object element) {
    if (element instanceof ISigilBundle) {
        ISigilBundle bundle = (ISigilBundle) element;
        return bundle.getBundleInfo().getSymbolicName();
    }//www  . j  a v a  2s.  c  o  m

    if (element instanceof IRequiredBundle) {
        IRequiredBundle req = (IRequiredBundle) element;
        return req.getSymbolicName() + " " + req.getVersions();
    }

    if (element instanceof IPackageImport) {
        IPackageImport req = (IPackageImport) element;
        return req.getPackageName() + " " + req.getVersions();
    }

    if (element instanceof IPackageExport) {
        IPackageExport pe = (IPackageExport) element;
        return pe.getPackageName() + " " + pe.getVersion();
    }

    if (element instanceof IResource) {
        IResource resource = (IResource) element;
        return resource.getName();
    }

    if (element instanceof IPackageFragment) {
        IPackageFragment f = (IPackageFragment) element;
        return f.getElementName();
    }

    if (element instanceof IPackageFragmentRoot) {
        IPackageFragmentRoot f = (IPackageFragmentRoot) element;
        try {
            return f.getUnderlyingResource().getName();
        } catch (JavaModelException e) {
            return "unknown";
        }
    }

    if (element instanceof IClasspathEntry) {
        IClasspathEntry cp = (IClasspathEntry) element;
        return cp.getPath().toString();
    }

    return element.toString();
}

From source file:org.apache.felix.sigil.eclipse.ui.util.ModelLabelProvider.java

License:Apache License

public String getText(Object element) {
    if (element instanceof ISigilBundle) {
        ISigilBundle bundle = (ISigilBundle) element;
        return bundle.getBundleInfo().getSymbolicName() + " " + bundle.getBundleInfo().getVersion();
    }/* w w w. j  a v a  2  s. co m*/
    if (element instanceof IBundleModelElement) {
        IBundleModelElement bundle = (IBundleModelElement) element;
        return bundle.getSymbolicName();
    }
    if (element instanceof IRequiredBundle) {
        IRequiredBundle req = (IRequiredBundle) element;
        return req.getSymbolicName() + " " + req.getVersions();
    }

    if (element instanceof IPackageImport) {
        IPackageImport req = (IPackageImport) element;
        return req.getPackageName() + " " + req.getVersions();
    }

    if (element instanceof IPackageExport) {
        IPackageExport pe = (IPackageExport) element;
        Version rawVersion = pe.getRawVersion();
        return rawVersion != null ? pe.getPackageName() + " " + rawVersion : pe.getPackageName();
    }

    if (element instanceof IResource) {
        IResource resource = (IResource) element;
        return resource.getName();
    }

    if (element instanceof IPackageFragment) {
        IPackageFragment f = (IPackageFragment) element;
        return f.getElementName();
    }

    if (element instanceof IPackageFragmentRoot) {
        IPackageFragmentRoot f = (IPackageFragmentRoot) element;
        try {
            return f.getUnderlyingResource().getName();
        } catch (JavaModelException e) {
            return "unknown";
        }
    }

    if (element instanceof IClasspathEntry) {
        IClasspathEntry cp = (IClasspathEntry) element;
        return cp.getPath().toString();
    }

    if (element instanceof IBundleRepository) {
        IBundleRepository rep = (IBundleRepository) element;
        IRepositoryModel config = SigilCore.getRepositoryModel(rep);
        return config.getName();
    }

    if (element instanceof Throwable) {
        Throwable t = (Throwable) element;
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        PrintStream print = new PrintStream(buf);
        t.printStackTrace(print);
        print.flush();
        return buf.toString();
    }

    return element.toString();
}

From source file:org.apache.felix.sigil.ui.eclipse.ui.util.ModelLabelProvider.java

License:Apache License

public String getText(Object element) {
    if (element instanceof ISigilBundle) {
        ISigilBundle bundle = (ISigilBundle) element;
        return bundle.getBundleInfo().getSymbolicName() + " " + bundle.getBundleInfo().getVersion();
    }//w  w w .  j  av  a 2s  .  c  om
    if (element instanceof IBundleModelElement) {
        IBundleModelElement bundle = (IBundleModelElement) element;
        return bundle.getSymbolicName();
    }
    if (element instanceof IRequiredBundle) {
        IRequiredBundle req = (IRequiredBundle) element;
        return req.getSymbolicName() + " " + req.getVersions();
    }

    if (element instanceof IPackageImport) {
        IPackageImport req = (IPackageImport) element;
        return req.getPackageName() + " " + req.getVersions();
    }

    if (element instanceof IPackageExport) {
        IPackageExport pe = (IPackageExport) element;
        Version rawVersion = pe.getRawVersion();
        return rawVersion != null ? pe.getPackageName() + " " + rawVersion : pe.getPackageName();
    }

    if (element instanceof IResource) {
        IResource resource = (IResource) element;
        return resource.getName();
    }

    if (element instanceof IPackageFragment) {
        IPackageFragment f = (IPackageFragment) element;
        return f.getElementName();
    }

    if (element instanceof IPackageFragmentRoot) {
        IPackageFragmentRoot f = (IPackageFragmentRoot) element;
        try {
            return f.getUnderlyingResource().getName();
        } catch (JavaModelException e) {
            return "unknown";
        }
    }

    if (element instanceof IClasspathEntry) {
        IClasspathEntry cp = (IClasspathEntry) element;
        return cp.getPath().toString();
    }

    if (element instanceof IBundleRepository) {
        IBundleRepository rep = (IBundleRepository) element;
        IRepositoryModel config = SigilCore.getRepositoryConfiguration().findRepository(rep.getId());
        return config.getName();
    }

    return element.toString();
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

/**
 * Search the Ivy classpath containers within the specified Java project
 * //from w w  w .  j av  a 2s .c  o m
 * @param javaProject
 *            the project to search into
 * @return the Ivy classpath container if found
 */
public static List<IvyClasspathContainer> getContainers(IJavaProject javaProject) {
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainer) {
                        containers.add((IvyClasspathContainer) cp);
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

public static List<IvyClasspathContainer> getContainersFromIvyFile(IFile ivyfile) {
    IJavaProject javaProject = JavaCore.create(ivyfile.getProject());
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }/*from   w  ww.j  a  va  2s .co m*/
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainerImpl) {
                        IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) cp;
                        if (ivycp.getConf().getIvyXmlPath()
                                .equals(ivyfile.getProjectRelativePath().toString())) {
                            containers.add(ivycp);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

public static List<IvyClasspathContainer> getContainersFromIvySettings(IFile ivySettings) {
    IJavaProject javaProject = JavaCore.create(ivySettings.getProject());
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }//from w ww  .  ja va2 s  . c o m
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainerImpl) {
                        IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) cp;
                        ResolvedPath settingsPath;
                        try {
                            settingsPath = ivycp.getConf().getInheritedSettingsSetup()
                                    .getResolvedIvySettingsPath(ivycp.getConf().getProject());
                        } catch (IvyDEException e) {
                            // cannot resolve the ivy settings so just ignore
                            continue;
                        }
                        if (settingsPath.getResolvedPath()
                                .equals(ivySettings.getProjectRelativePath().toString())) {
                            containers.add(ivycp);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

/**
 * Search the Ivy classpath entry within the specified Java project with the specific path
 * //www  .  jav a  2 s .c om
 * @param containerPath
 *            the path of the container
 * @param javaProject
 *            the project to search into
 * @return the Ivy classpath container if found, otherwise return <code>null</code>
 */
public static IClasspathEntry getEntry(IPath containerPath, IJavaProject javaProject) {
    if (javaProject == null || !javaProject.exists()) {
        return null;
    }
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (containerPath.equals(entry.getPath())) {
                    return entry;
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return null;
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyAttachementManager.java

License:Apache License

public void updateAttchements(IJavaProject project, IPath containerPath,
        IClasspathContainer containerSuggestion) {
    IvyDEMessage.verbose("Updating attachements on the container " + containerPath);

    Properties newProps = new Properties();

    IClasspathEntry[] newEntries = containerSuggestion.getClasspathEntries();
    for (int i = 0; i < newEntries.length; i++) {
        IClasspathEntry entry = newEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            if (entry.getSourceAttachmentPath() != null) {
                newProps.put(path + SRC_SUFFIX, entry.getSourceAttachmentPath().toPortableString());
            }// w ww .  j av a  2s  .  c o m
            if (entry.getSourceAttachmentRootPath() != null) {
                newProps.put(path + SRCROOT_SUFFIX, entry.getSourceAttachmentRootPath().toPortableString());
            }
            String javadocUrl = getJavadocLocation(entry);
            if (javadocUrl != null) {
                newProps.put(path + DOC_SUFFIX, javadocUrl);
            }
        }
    }

    IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) IvyClasspathContainerHelper
            .getContainer(containerPath, project);
    if (ivycp == null) {
        IvyDEMessage.error("The IvyDE container could not be found. Aborting updating attachements.");
        // something wrong happened, give up
        return;
    }
    IClasspathEntry[] existingEntries = ivycp.getClasspathEntries();
    for (int i = 0; i < existingEntries.length; i++) {
        IClasspathEntry entry = existingEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            String value = (String) prop.get(path + SRC_SUFFIX);
            if (value != null && entry.getSourceAttachmentPath() != null
                    && value.equals(entry.getSourceAttachmentPath().toPortableString())) {
                newProps.remove(path + SRC_SUFFIX);
            }
            value = (String) prop.get(path + SRCROOT_SUFFIX);
            if (value != null && entry.getSourceAttachmentRootPath() != null
                    && value.equals(entry.getSourceAttachmentRootPath().toPortableString())) {
                newProps.remove(path + SRCROOT_SUFFIX);
            }
        }
    }

    // copy the actually new overrided properties
    prop.putAll(newProps);

    // now update the ivyde container for real
    ivycp.updateClasspathEntries(newEntries);

    // store the global result
    IvyDEMessage.verbose("Saving attachement properties");
    try {
        FileOutputStream out = new FileOutputStream(containersAttachementFile);
        try {
            prop.store(out, "");
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                // don't care
            }
        }
    } catch (IOException ioe) {
        IvyPlugin.logWarn("IvyDE attachement properties could not be saved", ioe);
    }
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyClasspathUtil.java

License:Apache License

/**
 * Work around the non adaptability of ClassPathContainer
 * /*from w w w.jav  a  2  s.  co m*/
 * @param cpc
 *            the container to transform into an IvyClasspathContainer
 * @return the IvyClasspathContainer is such, null, if not
 */
public static IvyClasspathContainerImpl jdt2IvyCPC(ClassPathContainer cpc) {
    IClasspathEntry entry = cpc.getClasspathEntry();
    try {
        IClasspathContainer icp = JavaCore.getClasspathContainer(entry.getPath(), cpc.getJavaProject());
        if (icp instanceof IvyClasspathContainerImpl) {
            return (IvyClasspathContainerImpl) icp;
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return null;
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvydeContainerPage.java

License:Apache License

public void setSelection(IClasspathEntry entry) {
    if (entry == null) {
        conf = new IvyClasspathContainerConfiguration(project, "ivy.xml", true);
    } else {/* w  w  w  .  ja v a  2s. c om*/
        conf = new IvyClasspathContainerConfiguration(project, entry.getPath(), true,
                entry.getExtraAttributes());
        exported = entry.isExported();
    }
    state = new IvyClasspathContainerState(conf);
    oldIvyFile = conf.getIvyXmlPath();
    oldConfs = conf.getConfs();
}