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:net.sourceforge.eclipsejetty.util.MavenDependencyInfo.java

License:Apache License

/**
 * Creates the info from the classpath entry
 * /* ww  w  . j  av  a2 s  . c  o  m*/
 * @param runtimeClasspathEntry the classpath entry
 * @return the info
 */
public static MavenDependencyInfo create(IRuntimeClasspathEntry runtimeClasspathEntry) {
    IClasspathEntry classpathEntry = runtimeClasspathEntry.getClasspathEntry();

    if (classpathEntry == null) {
        return null;
    }

    IClasspathAttribute[] extraAttributes = classpathEntry.getExtraAttributes();
    String groupId = null;
    String artifactId = null;
    String version = null;
    String classifier = null;
    MavenScope scope = null;

    for (IClasspathAttribute extraAttribute : extraAttributes) {
        if ("maven.groupId".equals(extraAttribute.getName())) //$NON-NLS-1$
        {
            groupId = extraAttribute.getValue();
        } else if ("maven.artifactId".equals(extraAttribute.getName())) //$NON-NLS-1$
        {
            artifactId = extraAttribute.getValue();
        } else if ("maven.version".equals(extraAttribute.getName())) //$NON-NLS-1$
        {
            version = extraAttribute.getValue();
        } else if ("maven.classifier".equals(extraAttribute.getName())) //$NON-NLS-1$
        {
            classifier = extraAttribute.getValue();
        } else if ("maven.scope".equals(extraAttribute.getName())) //$NON-NLS-1$
        {
            scope = MavenScope.to(extraAttribute.getValue());
        }
    }

    if (artifactId == null) {
        return null;
    }

    return new MavenDependencyInfo(groupId, artifactId, version, classifier, null, false, scope);
}

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

License:Apache License

public String getJavadocLocation(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (int j = 0; j < attributes.length; j++) {
        IClasspathAttribute attribute = attributes[j];
        if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attribute.getName())) {
            return attribute.getValue();
        }/*from ww  w.  j ava 2s  .  c o  m*/
    }
    return null;
}

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

License:Apache License

/**
 * Initialize the container with the "persisted" classpath entries, and then schedule the
 * refresh//from www  .  ja  va  2  s  .  c o m
 */
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
    if (IvyClasspathContainerHelper.isIvyClasspathContainer(containerPath)) {

        IvyDEMessage.info("Initializing container " + containerPath);

        // try to get an existing one
        IClasspathContainer container = null;
        try {
            container = JavaCore.getClasspathContainer(containerPath, project);
        } catch (JavaModelException ex) {
            // unless there are issues with the JDT, this should never happen
            IvyPlugin.logError("Unable to get container for " + containerPath.toString(), ex);
            return;
        }

        try {
            boolean refresh = false;
            IvyClasspathContainerImpl ivycp = null;
            IClasspathEntry entry = IvyClasspathContainerHelper.getEntry(containerPath, project);
            IClasspathAttribute[] attributes;
            boolean exported;
            if (entry != null) {
                attributes = entry.getExtraAttributes();
                exported = entry.isExported();
            } else {
                exported = false;
                attributes = new IClasspathAttribute[0];
            }

            if (container instanceof IvyClasspathContainerImpl) {
                IvyDEMessage.debug("Container already configured");
                ivycp = (IvyClasspathContainerImpl) container;
            } else {
                if (container == null) {
                    IvyDEMessage.debug("No saved container");
                    // try what the IvyDE plugin saved
                    IvyClasspathContainerSerializer serializer = IvyPlugin.getDefault()
                            .getIvyClasspathContainerSerializer();
                    Map ivycps = serializer.read(project);
                    if (ivycps != null) {
                        IvyDEMessage.debug("Found serialized containers");
                        ivycp = (IvyClasspathContainerImpl) ivycps.get(containerPath);
                    }
                    if (ivycp == null) {
                        IvyDEMessage.debug("No serialized containers match the expected container path");
                        // still bad luck or just a new classpath container
                        ivycp = new IvyClasspathContainerImpl(project, containerPath, new IClasspathEntry[0],
                                attributes);
                        // empty, so force refresh at least
                        refresh = true;
                    }
                } else {
                    IvyDEMessage.debug("Loading from a saved container");
                    // this might be the persisted one : reuse the persisted entries
                    ivycp = new IvyClasspathContainerImpl(project, containerPath,
                            container.getClasspathEntries(), attributes);
                }
            }

            // FIXME : container path upgrade removed since it seems to make some trouble:
            // containers get either uninitialized or initialized twice...

            // recompute the path as it may have been "upgraded"
            // IPath updatedPath = IvyClasspathContainerConfAdapter.getPath(ivycp.getConf());
            // if (!updatedPath.equals(containerPath)) {
            // IvyDEMessage.verbose("Upgrading container path from " + containerPath + " to " +
            // updatedPath);
            // updateIvyDEContainerPath(project, entry, attributes, exported, updatedPath);
            // return;
            // }

            IvyDEMessage.verbose("Setting container in JDT model");

            JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project },
                    new IClasspathContainer[] { ivycp }, null);

            int startupMode = IvyPlugin.getPreferenceStoreHelper().getResolveOnStartup();
            if (startupMode == ON_STARTUP_NOTHING) {
                if (!refresh) {
                    IvyDEMessage.verbose("Doing nothing on startup");
                    // unless we force a refresh, actually do nothing
                    return;
                }
            } else {
                refresh = startupMode == ON_STARTUP_REFRESH;
            }

            if (refresh) {
                IvyDEMessage.info("Scheduling a refresh of the container");
            } else {
                IvyDEMessage.info("Scheduling a resolve of the container");
            }
            // now refresh the container to be synchronized with the ivy.xml
            ivycp.launchResolve(refresh, null);
        } catch (Exception ex) {
            IStatus status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.OK,
                    "Unable to set container for " + containerPath.toString(), ex);
            throw new CoreException(status);
        }
    }
}

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 {/*from   w w  w.  j a  v  a  2 s . co  m*/
        conf = new IvyClasspathContainerConfiguration(project, entry.getPath(), true,
                entry.getExtraAttributes());
        exported = entry.isExported();
    }
    state = new IvyClasspathContainerState(conf);
    oldIvyFile = conf.getIvyXmlPath();
    oldConfs = conf.getConfs();
}

From source file:org.continuousassurance.swamp.eclipse.BuildfileGenerator.java

License:Apache License

/**
 * Gets the encoding of a classpath entry. Falls back to project encoding
 * if none found/*from   ww  w . j av  a  2s .c  o  m*/
 * @param entry the entry
 * @return the encoding or empty string if unspecified
 */
private static String getEncodingAttribute(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (IClasspathAttribute attr : attributes) {
        if (attr.getName().equals(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING)) {
            return attr.getValue();
        }
    }
    return "";
}

From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java

License:Open Source License

private static boolean matchEntry(IClasspathEntry entry, final String groupID, final String artifactID) {
    boolean matchGroup = false;
    boolean matchArtifact = false;
    for (IClasspathAttribute attr : entry.getExtraAttributes()) {
        if (attr.getName().equals("maven.groupId")) {
            if (groupID.equals(attr.getValue()) == false)
                return false;
            else/*from  ww w  . j a  v  a 2s. co m*/
                matchGroup = true;
        } else if (attr.getName().equals("maven.artifactId")) {
            if (artifactID.equals(attr.getValue()) == false)
                return false;
            else
                matchArtifact = true;
        }
        if (matchGroup && matchArtifact) {
            logger.info("Found classpath entry: ", entry);
            return true;
        }
    }
    return false;
}

From source file:org.eclim.plugin.jdt.project.JavaProjectManager.java

License:Open Source License

/**
 * Determines if the supplied entry contains attribute indicating that it
 * should not be removed./*w  w w .  java 2  s . com*/
 *
 * @param entry The IClasspathEntry
 * @return true to preserve the entry, false otherwise.
 */
protected boolean preserve(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (int ii = 0; ii < attributes.length; ii++) {
        String name = attributes[ii].getName();
        if (PRESERVE.equals(name)) {
            return Boolean.parseBoolean(attributes[ii].getValue());
        }
    }
    return false;
}

From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java

License:Open Source License

public static boolean isOnAspectpath(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (int j = 0; j < attributes.length; j++) {
        if (isAspectPathAttribute(attributes[j])) {
            return true;
        }/*www  . j  ava2 s  .c o m*/
    }
    return false;
}

From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java

License:Open Source License

public static List<IClasspathEntry> resolveDependentProjectClasspath(IClasspathEntry projEntry,
        IProject requiredProj) {// w  w  w  . j a va 2 s . co  m
    // add all output locations and exported classpath entities
    // AspectJ compiler doesn't understand the concept of a java project
    List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>();

    try {
        JavaProject requiredJavaProj = (JavaProject) JavaCore.create(requiredProj);
        // bug 288395 Do not use the default mechanism for resolving classpath here
        // this will look into jar files at the Classpath header in the jar's manifest
        // and include jar files that are potentially missing, but have no effect on
        // the build.
        Object resolvedClasspath = requiredJavaProj.resolveClasspath(requiredJavaProj.getRawClasspath(), true,
                false);
        IClasspathEntry[] requiredEntries = extractRequiredEntries(resolvedClasspath);
        for (int i = 0; i < requiredEntries.length; i++) {
            IClasspathEntry requiredEntry = requiredEntries[i];
            if (requiredEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {

                // always add source entries even if not explicitly exported
                // don't add the source folder itself, but instead add the outfolder
                IPath outputLocation = requiredEntry.getOutputLocation();
                if (outputLocation != null) {
                    IAccessRule[] rules = projEntry.getAccessRules();
                    IClasspathAttribute[] attributes = projEntry.getExtraAttributes();

                    // only add the out folder if it already exists
                    if (requiredProj.getFolder(outputLocation.removeFirstSegments(1)).exists()) {
                        IClasspathEntry outFolder = JavaCore.newLibraryEntry(outputLocation,
                                requiredEntry.getPath(), requiredProj.getFullPath(), rules, attributes,
                                projEntry.isExported());
                        actualEntries.add(outFolder);
                    }
                }
            } else if (requiredEntry.isExported()) {
                // must recur through this entry and add entries that it contains
                actualEntries.addAll(resolveClasspath(requiredEntry, requiredProj));

            }
        } // for (int i = 0; i < requiredEntries.length; i++)

        IPath outputLocation = requiredJavaProj.getOutputLocation();
        // Output location may not exist.  Do not put output location of required project
        // on path unless it exists
        boolean exists = false;
        // bug 244330 check to see if the project folder is also the output folder
        if (outputLocation.segmentCount() == 1) {
            exists = true;
        } else {
            if (requiredProj.getWorkspace().getRoot().getFolder(outputLocation).exists()) {
                exists = true;
            }
        }

        if (exists) {
            IClasspathEntry outFolder = JavaCore.newLibraryEntry(outputLocation, null,
                    requiredProj.getFullPath());
            actualEntries.add(outFolder);
        }
    } catch (JavaModelException e) {
    }
    return actualEntries;
}

From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java

License:Open Source License

public static boolean isOnInpath(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (int j = 0; j < attributes.length; j++) {
        if (isInPathAttribute(attributes[j])) {
            return true;
        }/* ww w.  j  a  v  a  2 s  .  c om*/
    }
    return false;
}