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.jboss.tools.ws.jaxrs.core.WorkbenchUtils.java

License:Open Source License

public static boolean removeReferencedLibrarySourceAttachment(IJavaProject javaProject, String name,
        IProgressMonitor progressMonitor)
        throws OperationCanceledException, CoreException, InterruptedException {
    IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
    boolean found = false;
    for (int i = 0; i < classpathEntries.length; i++) {
        IClasspathEntry classpathEntry = classpathEntries[i];
        IPath path = classpathEntry.getPath();
        if (path.toFile().getAbsolutePath().contains(name)) {
            if (!path.isAbsolute()) {
                path = JavaCore.getClasspathVariable("M2_REPO")
                        .append(path.makeRelativeTo(new Path("M2_REPO")));
            }/*from ww  w .j a  v  a2  s. c o  m*/
            classpathEntries[i] = JavaCore.newLibraryEntry(path, null, null, classpathEntry.getAccessRules(),
                    classpathEntry.getExtraAttributes(), classpathEntry.isExported());
            found = true;
        }
    }
    javaProject.setRawClasspath(classpathEntries, progressMonitor);
    // refresh/build project
    WorkbenchTasks.buildProject(javaProject.getProject(), progressMonitor);
    return found;
}

From source file:org.lwjgl.tools.LWJGLClasspathContainerPage.java

License:Open Source License

protected void update() {

    IStatus status = null;/*  ww w. j  ava 2s  . c om*/

    IClasspathEntry[] libEntries = BuildPathSupport.getLWJGLLibraryEntries();

    IPath containerPath = LWJGLClasspathContainerInitializer.LWJGL_LIBRARY_PATH;
    containerEntryResult = JavaCore.newContainerEntry(containerPath);

    if (libEntries == null) {
        status = new Status(ERROR, Activator.PLUGIN_ID, "No LWJGL library found");
    } else

    if (labelResolvedPath != null && !labelResolvedPath.isDisposed()) {
        // implies all other labels to be created and not yet disposed
        if (libEntries != null) {
            Set<String> setLines = new TreeSet<String>();
            IPath path;
            for (IClasspathEntry entry : libEntries) {
                path = entry.getPath();
                if (path != null) {
                    setLines.add(getPathLabel(path));
                }
            }
            setLabel(labelResolvedPath, setLines);

            setLines.clear();
            for (IClasspathEntry entry : libEntries) {
                path = entry.getSourceAttachmentPath();
                if (path != null) {
                    setLines.add(getPathLabel(path));
                }
            }
            setLabel(labelResolvedSourcePath, setLines);

            setLines.clear();
            for (IClasspathEntry entry : libEntries) {
                if (entry.getExtraAttributes() != null) {
                    for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                        if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attr.getName())) {
                            setLines.add(attr.getValue());
                            break;
                        }
                        if (JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY.equals(attr.getName())) {

                        }
                    }
                }
            }
            setLabel(labelResolvedDocPath, setLines);

            setLines.clear();
            for (IClasspathEntry entry : libEntries) {
                if (entry.getExtraAttributes() != null) {
                    for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                        if (JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY.equals(attr.getName())) {
                            setLines.add(attr.getValue());
                        }
                    }
                }
            }
            setLabel(labelNativePath, setLines);

        } else {
            labelResolvedPath.setText("not found");
            labelResolvedSourcePath.setText("not found");
            labelResolvedDocPath.setText("not found");
        }
    }
    if (status != null)
        updateStatus(status);
}

From source file:org.maven.ide.eclipse.scala.ScalaProjectConfigurator.java

License:Open Source License

private static void addDeployableAttribute(IJavaProject javaProject, IClasspathAttribute deployableAttribute,
        IProgressMonitor monitor) throws JavaModelException, CoreException {
    if (javaProject == null)
        return;/*  w w w  .j  av a  2  s .co  m*/
    ClasspathContainerInitializer scalaInitializer = JavaCore
            .getClasspathContainerInitializer(SCALA_CONTAINER_PATH);
    if (scalaInitializer == null)
        return;
    IPath scalaContainerPath = Path.fromPortableString(SCALA_CONTAINER_PATH);
    Boolean updateAble = scalaInitializer.canUpdateClasspathContainer(scalaContainerPath, javaProject);
    final IClasspathContainer scalaLibrary = JavaCore.getClasspathContainer(scalaContainerPath, javaProject);
    final IClasspathEntry[] cpEntries = scalaLibrary.getClasspathEntries();

    for (int i = 0; i < cpEntries.length; i++) {
        IClasspathEntry cpe = cpEntries[i];
        LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>();
        for (IClasspathAttribute attr : cpe.getExtraAttributes()) {
            //Keep all existing attributes except the non_deployable key
            if (!attr.getName().equals(NON_DEPLOYABLE_KEY)) {
                attrs.put(attr.getName(), attr);
            }
        }
        attrs.put(deployableAttribute.getName(), deployableAttribute);
        IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
        cpEntries[i] = JavaCore.newLibraryEntry(cpe.getPath(), cpe.getSourceAttachmentPath(),
                cpe.getSourceAttachmentRootPath(), cpe.getAccessRules(), newAttrs, cpe.isExported());
    }

    IClasspathContainer candidateScalaContainer = new IClasspathContainer() {
        public IPath getPath() {
            return scalaLibrary.getPath();
        }

        public IClasspathEntry[] getClasspathEntries() {
            return cpEntries;
        }

        public String getDescription() {
            return scalaLibrary.getDescription();
        }

        public int getKind() {
            return scalaLibrary.getKind();
        }
    };

    if (updateAble) {
        scalaInitializer.requestClasspathContainerUpdate(scalaContainerPath, javaProject,
                candidateScalaContainer);
    } else {
        IJavaProject[] jPArray = { javaProject };
        IClasspathContainer[] cpArray = { candidateScalaContainer };
        JavaCore.setClasspathContainer(scalaContainerPath, jPArray, cpArray, null);
    }
}

From source file:org.maven.ide.eclipse.scala.ScalaProjectConfigurator.java

License:Open Source License

private static IClasspathAttribute getDeployableAttribute(IClasspathEntry library) {
    if (library == null) {
        return null;
    }//from w ww.  j a  v a  2 s .  co m

    IClasspathAttribute[] attributes = library.getExtraAttributes();
    if (attributes == null || attributes.length == 0) {
        return null;
    }

    for (IClasspathAttribute attr : attributes) {
        if (DEPLOYABLE_KEY.equals(attr.getName())) {
            return new ClasspathAttribute(attr.getName(), attr.getValue());
        }
    }
    return null;
}

From source file:org.neuro4j.studio.core.buildpath.Neuro4jContainerInitializer.java

License:Apache License

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project,
        IClasspathContainer containerSuggestion) throws CoreException {
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode("org.neuro4j.workflow");

    IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
    if ((entries.length >= 1) && (isValidJUnitContainerPath(containerPath))) {
        String version = containerPath.segment(1);

        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            String preferenceKey = getPreferenceKey(entry, version);

            IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
            if (extraAttributes.length == 0) {
                String defaultValue = DefaultScope.INSTANCE.getNode("org.neuro4j.workflow").get(preferenceKey,
                        "");
                if (!defaultValue.equals(preferences.get(preferenceKey, defaultValue))) {
                    preferences.put(preferenceKey, defaultValue);
                }/*from   www.j  a  va 2 s.  c  o m*/

            } else {
                for (int j = 0; j < extraAttributes.length; j++) {
                    IClasspathAttribute attrib = extraAttributes[j];
                    if (attrib.getName().equals("javadoc_location")) {
                        if (preferenceKey == null)
                            break;
                        preferences.put(preferenceKey, attrib.getValue());

                        break;
                    }
                }
            }
        }
        rebindClasspathEntries(project.getJavaModel(), containerPath);
    }
}

From source file:org.org.eclipse.core.utils.jdt.tools.JavaProjectClasspathHelper.java

License:Open Source License

/**
 * This helper methods replaces a variable name with another in all matching entries of a project. If the target classpath variable doesn't exist, it is created on the fly.
 * //from   w w  w  .  j a v a2 s.  c  om
 * @param originalName
 * @param targetName
 * @param javaProject
 * @param monitor
 */
public static void changeClasspathVariable(String originalName, String targetName, IJavaProject javaProject,
        IProgressMonitor monitor) {
    try {
        if (javaProject == null) {
            throw new JavaProjectInteractionException("Project should not be null.");
        }
        if (JavaCore.getClasspathVariable(targetName) == null) {
            JavaCore.setClasspathVariable(targetName, JavaCore.getClasspathVariable(originalName), monitor);
        }

        IClasspathEntry[] classpathEntries = getRawClasspath(javaProject);
        List<IClasspathEntry> targetClasspathEntries = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry classpathEntry : classpathEntries) {
            if (!JavaProjectClasspathHelper.isVariableEntry(classpathEntry)) {
                targetClasspathEntries.add(classpathEntry);
            } else {
                IPath sourceAttachmentPath = classpathEntry.getSourceAttachmentPath();
                IClasspathAttribute javadocClasspathAttribute = null;
                for (IClasspathAttribute classpathAttribute : classpathEntry.getExtraAttributes()) {
                    if (classpathAttribute.getName()
                            .equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) {
                        javadocClasspathAttribute = classpathAttribute;
                    }
                }
                IPath javadocPath = null;
                if (javadocClasspathAttribute != null && javadocClasspathAttribute.getValue() != null) {
                    javadocPath = JavaProjectClasspathHelper
                            .pathFromJavadocAttributeValue(javadocClasspathAttribute);
                }
                ClasspathEntryDefinition classpathEntryWrapper = new ClasspathEntryDefinition(
                        classpathEntry.getPath(), sourceAttachmentPath, javadocPath, EntryType.VARIABLE);
                targetClasspathEntries.add(ClasspathHelper.createVariableEntryWithDifferentVariableName(
                        classpathEntryWrapper, targetName, monitor));
            }
        }
        JavaProjectClasspathHelper.updateRawClasspath(javaProject, targetClasspathEntries,
                new SubProgressMonitor(monitor, 1));
    } catch (Exception e) {
        throw new JavaProjectInteractionException(e);
    }
}

From source file:org.sonatype.m2e.plexus.annotations.internal.PlexusBuildParticipant.java

License:Open Source License

private boolean isTestEntry(IClasspathEntry cpe) {
    IClasspathAttribute[] attrs = cpe.getExtraAttributes();
    if (attrs != null) {
        for (IClasspathAttribute attr : attrs) {
            if (IClasspathManager.SCOPE_ATTRIBUTE.equals(attr.getName())) {
                return Artifact.SCOPE_TEST.equals(attr.getValue());
            }//from  w  ww .  j  av a  2  s .  co  m
        }
    }

    if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
        IProject project = getMavenProjectFacade().getProject();
        for (IPath testPath : getMavenProjectFacade().getTestCompileSourceLocations()) {
            if (project.getFolder(testPath).getFullPath().equals(cpe.getPath())) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyProjectConverter.java

License:Open Source License

private static void convertGradleProject(IProject project, SubMonitor sub) throws Exception {
    // nature//from  w  w w.j  a  v  a2 s . c  o m
    IProjectDescription description = project.getDescription();
    String[] ids = description.getNatureIds();
    List<String> newIds = new ArrayList<String>(ids.length);
    for (int i = 0; i < ids.length; i++) {
        if (!ids[i].equals(GRADLE_OLD_NATURE) && !ids[i].equals(GRADLE_NEW_NATURE)) {
            newIds.add(ids[i]);
        } else {
            newIds.add(GRADLE_NEW_NATURE);
        }
    }
    description.setNatureIds(newIds.toArray(new String[0]));
    project.setDescription(description, sub);

    // project preferences
    // DO NOTHING: gradle tooling handles these itself by reading in both old and new locations.

    // classpath container
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String path = entry.getPath().toString();
            if (path.contains(GRADLE_OLD_PREFIX)) {
                entry = JavaCore.newContainerEntry(new Path(path.replace(GRADLE_OLD_PREFIX, GRADLE_NEW_PREFIX)),
                        entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
            }
        }
        newClasspath.add(entry);
    }
    javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), sub);
}

From source file:org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyProjectConverter.java

License:Open Source License

private IClasspathAttribute[] convertGrailsClasspathAttributes(IClasspathEntry entry) {
    IClasspathAttribute[] oldAttributes = entry.getExtraAttributes();
    if (oldAttributes == null || oldAttributes.length == 0) {
        return new IClasspathAttribute[0];
    }//from  w  w  w.  ja v a 2  s .  c  o  m
    IClasspathAttribute[] newAttributes = new IClasspathAttribute[oldAttributes.length];
    for (int i = 0; i < oldAttributes.length; i++) {
        if (oldAttributes[i].getName().equals(GRAILS_OLD_ATTRIBUTE)) {
            newAttributes[i] = JavaCore.newClasspathAttribute(GRAILS_NEW_ATTRIBUTE,
                    oldAttributes[i].getValue());
        } else {
            newAttributes[i] = oldAttributes[i];
        }
    }

    return newAttributes;
}

From source file:org.springsource.ide.eclipse.gradle.core.GradleProject.java

License:Open Source License

/**
 * Create an Eclipse source classpath entry from a Gradle source entry. May return null
 * if the entry looks invalid (e.g. the corresponding folder doesn't exist in the project)
 * @param oldEntries old source entries indexed by path, used to copy over exclusions and inclusions so they don't get lost.
 *///from  w w w .j a  v  a2s .  co  m
private IClasspathEntry newSourceEntry(EclipseSourceDirectory gradleSourceDir,
        Map<IPath, IClasspathEntry> oldEntries) throws IllegalClassPathEntryException {
    Path gradleSourcePath = new Path(gradleSourceDir.getPath());
    try {
        IFolder srcFolder = getProject().getFolder(gradleSourcePath);
        if (!srcFolder.exists()) {
            throw new IllegalClassPathEntryException("non-existent source folder", this, gradleSourceDir);
        }
        IPath path = srcFolder.getFullPath();
        IClasspathEntry oldEntry = oldEntries.get(path);
        if (oldEntry == null) {
            return JavaCore.newSourceEntry(path);
        } else {
            return JavaCore.newSourceEntry(path, oldEntry.getInclusionPatterns(),
                    oldEntry.getExclusionPatterns(), oldEntry.getOutputLocation(),
                    oldEntry.getExtraAttributes());
        }
    } catch (IllegalClassPathEntryException e) {
        throw e;
    } catch (Throwable e) {
        throw new IllegalClassPathEntryException("illegal source folder", this, gradleSourceDir, e);
    }
}