Example usage for org.eclipse.jdt.core IClasspathAttribute OPTIONAL

List of usage examples for org.eclipse.jdt.core IClasspathAttribute OPTIONAL

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathAttribute OPTIONAL.

Prototype

String OPTIONAL

To view the source code for org.eclipse.jdt.core IClasspathAttribute OPTIONAL.

Click Source Link

Document

Constant for the name of the optional attribute.

Usage

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

License:Open Source License

public boolean isOptional() {
    for (int i = 0, length = this.extraAttributes.length; i < length; i++) {
        IClasspathAttribute attribute = this.extraAttributes[i];
        if (IClasspathAttribute.OPTIONAL.equals(attribute.getName()) && "true".equals(attribute.getValue())) //$NON-NLS-1$
            return true;
    }/*w  ww. ja  v a  2 s  .co  m*/
    return false;
}

From source file:com.google.gwt.eclipse.core.GWTProjectUtilities.java

License:Open Source License

private static boolean isOptional(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (IClasspathAttribute attribute : attributes) {
        if (IClasspathAttribute.OPTIONAL.equals(attribute.getName()) && "true".equals(attribute.getValue())) //$NON-NLS-1$
            return true;
    }/* ww  w  . jav a  2s.  c om*/
    return false;
}

From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java

License:Open Source License

public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, boolean isOptional)
        throws JavaModelException {
    checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$
    IClasspathAttribute[] attributes = isOptional
            ? new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, "true") }
            : new IClasspathAttribute[0];
    addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, null, true, attributes, false));
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void updatePathElement(List<IClasspathEntry> ents, Element xml) {
    IClasspathEntry oent = null;//from  w  ww. java2 s .c  o  m
    int id = IvyXml.getAttrInt(xml, "ID", 0);
    if (id != 0) {
        for (IClasspathEntry ent : ents) {
            if (ent.hashCode() == id) {
                oent = ent;
                break;
            }
        }
    }

    BedrockPlugin.logD("UPDATE PATH ELEMENT " + oent + " " + IvyXml.convertXmlToString(xml));

    if (IvyXml.getAttrString(xml, "TYPE").equals("LIBRARY")) {
        if (IvyXml.getAttrBool(xml, "DELETE")) {
            ents.remove(oent);
        } else if (IvyXml.getAttrBool(xml, "MODIFIED") || IvyXml.getAttrBool(xml, "NEW")) {
            String f = IvyXml.getTextElement(xml, "BINARY");
            IPath bin = (f == null ? null : Path.fromOSString(f));
            f = IvyXml.getTextElement(xml, "SOURCE");
            IPath src = (f == null ? null : Path.fromOSString(f));
            boolean optfg = IvyXml.getAttrBool(xml, "OPTIONAL");
            boolean export = IvyXml.getAttrBool(xml, "EXPORTED");
            IAccessRule[] rls = null;
            URL docu = null;
            String doc = IvyXml.getTextElement(xml, "JAVADOC");
            if (doc != null) {
                try {
                    docu = new URL(doc);
                } catch (MalformedURLException e) {
                }
                if (docu == null) {
                    try {
                        docu = new URL("file://" + doc);
                    } catch (MalformedURLException e) {
                    }
                }
            }
            if (oent != null) {
                rls = oent.getAccessRules();
            }

            IClasspathAttribute[] xatts = null;
            List<IClasspathAttribute> els = new ArrayList<IClasspathAttribute>();
            if (optfg)
                els.add(JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, "true"));
            if (docu != null) {
                els.add(JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        docu.toString()));
            }
            if (!els.isEmpty()) {
                xatts = new IClasspathAttribute[els.size()];
                xatts = els.toArray(xatts);
            }

            IClasspathEntry nent = null;
            if (bin != null)
                nent = JavaCore.newLibraryEntry(bin, src, null, rls, xatts, export);
            else
                nent = JavaCore.newSourceEntry(src, null, null, null, xatts);

            if (IvyXml.getAttrBool(xml, "MODIFIED") && oent != null) {
                int idx = ents.indexOf(oent);
                ents.set(idx, nent);
            } else {
                ents.add(nent);
            }
        }
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void addPath(IvyXmlWriter xw, IJavaProject jp, IClasspathEntry ent, boolean nest) {
    IPath p = ent.getPath();/*  www  .  j  a  va  2s .  co  m*/
    IPath op = ent.getOutputLocation();
    IPath sp = ent.getSourceAttachmentPath();
    IProject ip = jp.getProject();

    String jdp = null;
    boolean opt = false;
    IClasspathAttribute[] atts = ent.getExtraAttributes();
    for (IClasspathAttribute att : atts) {
        if (att.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME))
            jdp = att.getValue();
        else if (att.getName().equals(IClasspathAttribute.OPTIONAL)) {
            String v = att.getValue();
            if (v.equals("true"))
                opt = true;
        }
    }

    if (p == null && op == null)
        return;
    File f1 = null;
    if (p != null) {
        f1 = BedrockUtil.getFileForPath(p, ip);
        if (!f1.exists()) {
            BedrockPlugin.logD("Path file " + p + " not found as " + f1);
            // f1 = null;
        }
    }
    File f2 = null;
    if (op != null) {
        f2 = BedrockUtil.getFileForPath(op, ip);
        if (!f2.exists()) {
            BedrockPlugin.logD("Path file " + op + " not found");
            f2 = null;
        }
    }
    File f3 = null;
    if (sp != null) {
        f3 = BedrockUtil.getFileForPath(sp, ip);
        if (!f3.exists()) {
            BedrockPlugin.logD("Path file " + sp + " not found");
            f3 = null;
        }
    }
    if (f1 == null && f2 == null)
        return;

    // references to nested projects are handled in addClassPaths
    if (ent.getEntryKind() == IClasspathEntry.CPE_PROJECT)
        return;

    xw.begin("PATH");
    xw.field("ID", ent.hashCode());
    if (nest)
        xw.field("NESTED", "TRUE");

    switch (ent.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        xw.field("TYPE", "SOURCE");
        f3 = f1;
        f1 = null;
        break;
    case IClasspathEntry.CPE_PROJECT:
        xw.field("TYPE", "BINARY");
        break;
    case IClasspathEntry.CPE_LIBRARY:
        xw.field("TYPE", "LIBRARY");
        break;
    }
    if (ent.isExported())
        xw.field("EXPORTED", true);
    if (opt)
        xw.field("OPTIONAL", true);

    if (f1 != null)
        xw.textElement("BINARY", f1.getAbsolutePath());
    if (f2 != null)
        xw.textElement("OUTPUT", f2.getAbsolutePath());
    if (f3 != null)
        xw.textElement("SOURCE", f3.getAbsolutePath());
    if (jdp != null)
        xw.textElement("JAVADOC", jdp);

    IAccessRule[] rls = ent.getAccessRules();
    for (IAccessRule ar : rls) {
        xw.begin("ACCESS");
        xw.field("KIND", ar.getKind());
        xw.field("PATTERN", ar.getPattern().toString());
        xw.field("IGNOREIFBETTER", ar.ignoreIfBetter());
        xw.end("ACCESS");
    }

    xw.end("PATH");
}

From source file:org.eclipse.buildship.core.launch.internal.GradleClasspathProvider.java

License:Open Source License

private static boolean isOptional(IClasspathEntry entry) {
    for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
        if (IClasspathAttribute.OPTIONAL.equals(attribute.getName())
                && Boolean.parseBoolean(attribute.getValue())) {
            return true;
        }/*  w w w .j  a  v  a2  s.  c  o  m*/
    }
    return false;
}

From source file:org.eclipse.m2e.jdt.internal.ClasspathDescriptor.java

License:Open Source License

public ClasspathEntryDescriptor addSourceEntry(IPath sourcePath, IPath outputLocation, IPath[] inclusion,
        IPath[] exclusion, boolean generated) {
    //    IWorkspaceRoot workspaceRoot = project.getProject().getWorkspace().getRoot();
    ////from  ww w.  j a  v a  2  s.c  o m
    //    Util.createFolder(workspaceRoot.getFolder(sourcePath), generated);

    ClasspathEntryDescriptor descriptor = new ClasspathEntryDescriptor(IClasspathEntry.CPE_SOURCE, sourcePath);
    descriptor.setOutputLocation(outputLocation);
    descriptor.setInclusionPatterns(inclusion);
    descriptor.setExclusionPatterns(exclusion);
    if (generated) {
        descriptor.setClasspathAttribute(IClasspathAttribute.OPTIONAL, "true"); //$NON-NLS-1$
    }

    addEntryDescriptor(descriptor);

    return descriptor;
}

From source file:org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder.java

License:Open Source License

/**
 * Returns is the given classpath entry is optional or not
 * /*from ww  w .ja va 2 s  . c  o  m*/
 * @param entry
 * @return true if the specified {@link IClasspathEntry} is optional, false
 *         otherwise
 */
boolean isOptional(IClasspathEntry entry) {
    IClasspathAttribute[] attribs = entry.getExtraAttributes();
    for (int i = 0, length = attribs.length; i < length; i++) {
        IClasspathAttribute attribute = attribs[i];
        if (IClasspathAttribute.OPTIONAL.equals(attribute.getName()) && "true".equals(attribute.getValue())) { //$NON-NLS-1$
            return true;
        }
    }
    return false;
}