Example usage for org.eclipse.jdt.internal.core ClasspathAttribute ClasspathAttribute

List of usage examples for org.eclipse.jdt.internal.core ClasspathAttribute ClasspathAttribute

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core ClasspathAttribute ClasspathAttribute.

Prototype

public ClasspathAttribute(String name, String value) 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java

License:Open Source License

static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) {
    if (attributes == null)
        return NO_EXTRA_ATTRIBUTES;
    int length = attributes.getLength();
    if (length == 0)
        return NO_EXTRA_ATTRIBUTES;
    IClasspathAttribute[] result = new IClasspathAttribute[length];
    int index = 0;
    for (int i = 0; i < length; ++i) {
        Node node = attributes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element attribute = (Element) node;
            String name = attribute.getAttribute(TAG_ATTRIBUTE_NAME);
            if (name == null)
                continue;
            String value = attribute.getAttribute(TAG_ATTRIBUTE_VALUE);
            if (value == null)
                continue;
            result[index++] = new ClasspathAttribute(name, value);
        }//from   www.ja v  a 2  s  .  c o  m
    }
    if (index != length)
        System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index);
    return result;
}

From source file:com.google.gdt.eclipse.managedapis.impl.ClasspathEntryPrototype.java

License:Open Source License

/**
 * Produce a ClasspathEntry from this prototype.
 * /*from w  w  w .ja v a 2  s  .c o m*/
 * @param projectRoot The project root, used to determine relative paths.
 * @return The classpath entry or null if no class archive is defined.
 */
public IClasspathEntry createClasspathEntry(IPath projectRoot) {
    IPath libRelativePath = (classArchive == null) ? null
            : makeRelative(classArchive.getFullPath(), projectRoot);
    IPath srcPath = (sourceArchive == null) ? null : makeRelative(sourceArchive.getFullPath(), projectRoot);
    IPath javadocPath = (javadocArchive == null) ? null
            : makeRelative(javadocArchive.getFullPath(), projectRoot);

    IClasspathAttribute[] extraAttributes = (null == javadocPath) ? ClasspathEntry.NO_EXTRA_ATTRIBUTES
            : new IClasspathAttribute[] {
                    new ClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                            "jar:platform:/resource" + javadocPath.toString() + "!/") };

    // create a new CPE_LIBRARY type of cp entry with an attached source
    // archive if it exists
    return (libRelativePath == null) ? null
            : JavaCore.newLibraryEntry(libRelativePath, srcPath, srcPath == null ? null : new Path("/"),
                    ClasspathEntry.NO_ACCESS_RULES, extraAttributes, false);
}

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

@SuppressWarnings("checkstyle:innerassignment")
private static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) {
    if (attributes == null) {
        return ClasspathEntry.NO_EXTRA_ATTRIBUTES;
    }// ww w .  j av a  2s.c om
    final int length = attributes.getLength();
    if (length == 0) {
        return ClasspathEntry.NO_EXTRA_ATTRIBUTES;
    }
    IClasspathAttribute[] result = new IClasspathAttribute[length];
    int index = 0;
    for (int i = 0; i < length; ++i) {
        final Node node = attributes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            final Element attribute = (Element) node;
            final String name = attribute.getAttribute(ClasspathEntry.TAG_ATTRIBUTE_NAME);
            if (name == null) {
                continue;
            }
            final String value = attribute.getAttribute(ClasspathEntry.TAG_ATTRIBUTE_VALUE);
            if (value == null) {
                continue;
            }
            result[index++] = new ClasspathAttribute(name, value);
        }
    }
    if (index != length) {
        System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index);
    }
    return result;
}

From source file:org.codehaus.groovy.eclipse.core.builder.GroovyClasspathContainer.java

License:Apache License

private void updateEntries() {
    final List<IClasspathEntry> newEntries = newList();
    try {//w w w  .j  a v a 2 s.com
        URL groovyURL = CompilerUtils.getExportedGroovyAllJar();
        IPath runtimeJarPath = new Path(groovyURL.getPath());
        File srcJarFile = new File(groovyURL.getPath().replace(".jar", "-sources.jar"));
        IPath srcJarPath = srcJarFile.exists() ? new Path(srcJarFile.getAbsolutePath()) : null;

        File javadocJarFile = new File(groovyURL.getPath().replace(".jar", "-javadoc.jar"));
        IClasspathAttribute[] attrs;
        if (javadocJarFile.exists()) {
            String javadocJarPath = javadocJarFile.getAbsolutePath();
            final IClasspathAttribute cpattr = new ClasspathAttribute(
                    IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocJarPath);

            attrs = new IClasspathAttribute[] { cpattr };
        } else {
            attrs = new IClasspathAttribute[0];
        }
        IClasspathEntry entry = newLibraryEntry(runtimeJarPath, srcJarPath, null, null, attrs, true);
        newEntries.add(entry);

        URL[] extraJars = CompilerUtils.getExtraJarsForClasspath();
        for (URL jar : extraJars) {
            IPath jarPath = new Path(jar.getPath());
            newEntries.add(newLibraryEntry(jarPath, null, null));
        }

        if (useGroovyLibs()) {
            newEntries.addAll(getGroovyJarsInDotGroovyLib());
        }

        entries = newEntries.toArray(new IClasspathEntry[0]);
    } catch (Exception e) {
        GroovyCore.logException("Problem finding groovy runtime", e);
        entries = new IClasspathEntry[0];
    }
}

From source file:org.eclipse.ajdt.internal.ui.AspectJProjectPropertiesPage.java

License:Open Source License

private void addContainerToAttribute(IClasspathEntry classpathEntry, IClasspathAttribute attribute,
        IClasspathContainer container) {
    // find the attribute
    IClasspathAttribute[] attributes = classpathEntry.getExtraAttributes();
    for (int i = 0; i < attributes.length; i++) {
        if (attributes[i].getName().equals(attribute.getName())) {
            attributes[i] = new ClasspathAttribute(attribute.getName(), container.getPath().toPortableString());
        }//from   ww w.j av  a2  s  .c  o m
    }
}

From source file:org.eclipse.che.jdt.core.JavaCore.java

License:Open Source License

/**
 * Creates and returns a new classpath attribute with the given name and the given value.
 *
 * @return a new classpath attribute//from ww w .  ja v a 2 s. com
 */
public static IClasspathAttribute newClasspathAttribute(String name, String value) {
    return new ClasspathAttribute(name, value);
}

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;
    }// w ww  .  j  a v a2  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.springsource.ide.eclipse.gradle.core.classpathcontainer.GradleDependencyComputer.java

License:Open Source License

private void addJarEntry(IPath jarPath, ExternalDependency gEntry, boolean export) {
    // Get the location of a source jar, if any.
    IPath sourceJarPath = null;//from  w  w w  .j a  va 2 s. co  m
    File sourceJarFile = gEntry.getSource();
    if (sourceJarFile != null) {
        sourceJarPath = new Path(sourceJarFile.getAbsolutePath());
    }

    //Get the location of Java doc attachement, if any
    List<IClasspathAttribute> extraAttributes = new ArrayList<IClasspathAttribute>();
    File javaDoc = gEntry.getJavadoc();
    if (javaDoc != null) {
        //Example of what it looks like in the eclipse .classpath file:
        //<attributes>
        //  <attribute name="javadoc_location" value="jar:file:/tmp/workspace/repos/test-with-jdoc-1.0-javadoc.jar!/"/>
        //</attributes>
        String jdoc = javaDoc.toURI().toString();
        if (!javaDoc.isDirectory()) {
            //Assume its a jar or zip containing the docs
            jdoc = "jar:" + jdoc + "!/";
        }
        IClasspathAttribute javaDocAttribute = new ClasspathAttribute(
                IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, jdoc);
        extraAttributes.add(javaDocAttribute);
    }

    WTPUtil.excludeFromDeployment(project.getJavaProject(), jarPath, extraAttributes);

    //Create classpath entry with all this info
    IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(jarPath, sourceJarPath, null,
            ClasspathEntry.NO_ACCESS_RULES,
            extraAttributes.toArray(new IClasspathAttribute[extraAttributes.size()]), export);
    classpath.add(newLibraryEntry);
    if (newLibraryEntry.toString().contains("unresolved dependency")) {
        debug("entry: " + newLibraryEntry);
    }
}

From source file:org.talend.designer.maven.utils.MavenProjectUtils.java

License:Open Source License

public static void changeClasspath(IProgressMonitor monitor, IProject p, ProjectSystemFolder[] folders) {
    try {/* w w w. j  av a2 s.  c  o m*/
        if (!p.hasNature(JavaCore.NATURE_ID)) {
            JavaUtils.addJavaNature(p, monitor);
        }
        IJavaProject javaProject = JavaCore.create(p);
        IClasspathEntry[] rawClasspathEntries = javaProject.getRawClasspath();

        List<IClasspathEntry> list = new LinkedList<>();
        ClasspathAttribute attribute = new ClasspathAttribute("maven.pomderived", Boolean.TRUE.toString());
        for (ProjectSystemFolder psf : folders) {
            IFolder resources = p.getFolder(psf.getPath());
            if (resources.exists()) { // add the condition mostly for routines, since the resources folder might not exist
                IFolder output = p.getFolder(psf.getOutputPath());
                IClasspathEntry newEntry = JavaCore.newSourceEntry(resources.getFullPath(), new IPath[0],
                        new IPath[0], output.getFullPath(), new IClasspathAttribute[] { attribute });
                list.add(newEntry);
            }
        }
        IPath defaultJREContainerPath = JavaRuntime.newDefaultJREContainerPath();

        IClasspathEntry newEntry = JavaCore.newContainerEntry(defaultJREContainerPath, new IAccessRule[] {},
                new IClasspathAttribute[] { attribute }, false);
        list.add(newEntry);

        newEntry = JavaCore.newContainerEntry(new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"),
                newEntry.getAccessRules(), new IClasspathAttribute[] { attribute }, newEntry.isExported());
        list.add(newEntry);

        if (!Arrays.equals(rawClasspathEntries, list.toArray(new IClasspathEntry[] {}))
                || !p.getFile(".classpath").exists()) {
            rawClasspathEntries = list.toArray(new IClasspathEntry[] {});
            javaProject.setRawClasspath(rawClasspathEntries, monitor);
            javaProject.setOutputLocation(p.getFolder(MavenSystemFolders.JAVA.getOutputPath()).getFullPath(),
                    monitor);
        }
    } catch (

    CoreException e) {
        ExceptionHandler.process(e);
    }
}