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

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

Introduction

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

Prototype

IClasspathAttribute[] getExtraAttributes();

Source Link

Document

Returns the extra classpath attributes for this classpath entry.

Usage

From source file:org.eclipse.xtext.builder.JDTAwareEclipseResourceFileSystemAccess2.java

License:Open Source License

/**
 * @param prototype settings will be copied from the prototype and the new entry is inserted after that one.
 *//*from  w  w w . j av a  2 s. com*/
private void insertClasspathEntry(IContainer folder, IClasspathEntry prototype, IJavaProject project)
        throws JavaModelException {
    IClasspathEntry newEntry = JavaCore.newSourceEntry(folder.getFullPath(), prototype.getInclusionPatterns(),
            prototype.getExclusionPatterns(), prototype.getOutputLocation(), prototype.getExtraAttributes());
    IClasspathEntry[] classPath = project.getRawClasspath();
    IClasspathEntry[] newClassPath = new IClasspathEntry[classPath.length + 1];
    int i = 0;
    for (IClasspathEntry entry : classPath) {
        newClassPath[i++] = entry;
        if (entry.equals(prototype)) {
            newClassPath[i++] = newEntry;
        }
    }
    // should not happen, but to be sure
    if (i == newClassPath.length - 1 && newClassPath[i] == null) {
        LOG.warn("Cannot find classpath entry '" + prototype + "'");
        newClassPath[i] = newEntry;
    }
    project.setRawClasspath(newClassPath, getMonitor());
}

From source file:org.grails.ide.eclipse.core.internal.classpath.GrailsClasspathContainer.java

License:Open Source License

/**
 * Stores the configured source attachments paths in the projects settings area.
 * @param project the java project to store the preferences for
 * @param containerSuggestion the configured classpath container entries
 *///from ww  w  .j  a  v a2  s.  c o m
public static void storeSourceAttachments(IJavaProject project, IClasspathContainer containerSuggestion) {
    SpringCorePreferences prefs = SpringCorePreferences.getProjectPreferences(project.getProject(),
            GrailsCoreActivator.PLUGIN_ID);
    for (IClasspathEntry entry : containerSuggestion.getClasspathEntries()) {
        IPath path = entry.getPath();
        IPath sourcePath = entry.getSourceAttachmentPath();
        if (sourcePath != null) {
            prefs.putString("source.attachment-" + path.lastSegment().toString(), sourcePath.toString());
        }
        for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
            if (attribute.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) {
                String value = attribute.getValue();
                prefs.putString("javadoc.location-" + path.lastSegment().toString(), value);
            }
        }
    }
}

From source file:org.grails.ide.eclipse.core.internal.classpath.SourceFolderJob.java

License:Open Source License

/**
  * //from   w w  w.ja  v  a 2s  .  c om
  * @return all grails source class path entries. List may be empty or
  *         partial complete if error encountered.
  */
public static List<IClasspathEntry> getGrailsSourceClasspathEntries(IJavaProject javaProject) {
    List<IClasspathEntry> oldEntries = new ArrayList<IClasspathEntry>();
    try {
        for (IClasspathEntry entry : javaProject.getRawClasspath()) {
            // CPE_PROJECT is for in-place plugins that are present as
            // project entries, as opposed to CPE_SOURCE that are for source
            // folders
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                    || entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                    if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) {
                        oldEntries.add(entry);
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        GrailsCoreActivator.log(e);
    }
    return oldEntries;
}

From source file:org.grails.ide.eclipse.core.internal.GrailsResourceUtil.java

License:Open Source License

public static IPackageFragmentRoot[] getGrailsDependencyPackageFragmentRoots(IProject project, IPath path) {
    if (project == null) {
        return null;
    }/*  w ww .  j  av  a  2s  .  c o  m*/
    IJavaProject javaProject = JavaCore.create(project);
    try {

        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                    if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) {
                        IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath());
                        if (folder.getLocation().equals(path)) {
                            return javaProject.findPackageFragmentRoots(entry);
                        }
                    }
                }
            }
        }

    } catch (JavaModelException e) {
        GrailsCoreActivator.log(e);
    }
    return null;

}

From source file:org.grails.ide.eclipse.core.internal.GrailsResourceUtil.java

License:Open Source License

public static boolean hasClasspathAttribute(IClasspathEntry entry, String attributeName) {
    if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
        for (IClasspathAttribute attr : entry.getExtraAttributes()) {
            if (attr.getName().equals(attributeName)) {
                return true;
            }//from   w w w  .  j av a2 s  .  co m
        }
    }
    return false;
}

From source file:org.grails.ide.eclipse.core.workspace.GrailsClassPath.java

License:Open Source License

public static boolean isPluginSourceFolder(IClasspathEntry e) {
    if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
        for (IClasspathAttribute attr : e.getExtraAttributes()) {
            if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) {
                return true;
            }//from  ww w .  j ava2 s.  c om
        }
    }
    return false;
}

From source file:org.grails.ide.eclipse.ui.internal.filter.PackageExplorerFilter.java

License:Open Source License

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof IPackageFragmentRoot) {
        try {//from  w ww  . j a v  a  2 s . c o m
            IClasspathEntry entry = ((IPackageFragmentRoot) element).getRawClasspathEntry();
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                    if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) {
                        return false;
                    }
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
    }
    return true;
}

From source file:org.jboss.ide.eclipse.as.classpath.core.jee.AbstractClasspathContainerInitializer.java

License:Open Source License

public void requestClasspathContainerUpdate(final IPath containerPath, final IJavaProject project,
        final IClasspathContainer sg)

        throws CoreException

{
    String key = AbstractClasspathContainer.getDecorationManagerKey(containerPath.toString());

    IClasspathEntry[] entries = sg.getClasspathEntries();
    ClasspathDecorationsManager decorations = AbstractClasspathContainer.getDecorationsManager();
    decorations.clearAllDecorations(key);

    for (int i = 0; i < entries.length; i++) {
        final IClasspathEntry entry = entries[i];

        final IPath srcpath = entry.getSourceAttachmentPath();
        final IPath srcrootpath = entry.getSourceAttachmentRootPath();
        final IClasspathAttribute[] attrs = entry.getExtraAttributes();
        final String eid = entry.getPath().toString();
        final ClasspathDecorations dec = new ClasspathDecorations();

        dec.setSourceAttachmentPath(srcpath);
        dec.setSourceAttachmentRootPath(srcrootpath);
        dec.setExtraAttributes(attrs);//  ww w . j  a  v  a2  s.  c  o  m

        decorations.setDecorations(key, eid, dec);
    }
    decorations.save();
    final IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
    ((AbstractClasspathContainer) container).refresh();
}

From source file:org.jboss.tools.common.jdt.core.buildpath.MaterializeLibraryJob.java

License:Open Source License

private IClasspathEntry getNewClasspathEntry(IClasspathEntry entry, IPath destinationFilePath)
        throws CoreException {
    try {//from  w  ww  .j  a v  a  2s.  com
        return JavaCore.newLibraryEntry(destinationFilePath,
                (keepSourceAttachments) ? entry.getSourceAttachmentPath() : null,
                (keepSourceAttachments) ? entry.getSourceAttachmentRootPath() : null, entry.getAccessRules(),
                entry.getExtraAttributes(), entry.isExported());
    } catch (Exception e) {
        IStatus status = new Status(IStatus.ERROR, JDTExtActivator.PLUGIN_ID,
                NLS.bind(Messages.MaterializeLibraryJob_Error_creating_classpath_entry, e.getMessage()), e);
        throw new CoreException(status);
    }
}

From source file:org.jboss.tools.common.jdt.core.internal.buildpath.MavenLibraryMaterializationPostProcessor.java

License:Open Source License

private void removeExclusionPatterns(IJavaProject javaProject, IProgressMonitor monitor)
        throws JavaModelException {
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    ArrayList<IClasspathEntry> newEntriesList = new ArrayList<IClasspathEntry>(entries.length);
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath[] newExclusionPatterns = getExclusionPatterns(entry.getExclusionPatterns());
            IClasspathEntry newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                    newExclusionPatterns, entry.getOutputLocation(), entry.getExtraAttributes());
            newEntriesList.add(newEntry);
        } else {/*from  w w w .j  ava 2 s. co m*/
            newEntriesList.add(entry);
        }
    }

    IClasspathEntry[] newEntries = new IClasspathEntry[newEntriesList.size()];
    newEntriesList.toArray(newEntries);
    javaProject.setRawClasspath(newEntries, monitor);
}