Search in sources :

Example 6 with IAccessRule

use of org.eclipse.jdt.core.IAccessRule in project lwjgl by LWJGL.

the class BuildPathSupport method getLWJGLLibraryEntries.

public static IClasspathEntry[] getLWJGLLibraryEntries() {
    IPath bundleBase = getBundleLocation(LWJGL_PLUGIN);
    if (bundleBase != null) {
        IClasspathEntry[] entries = new IClasspathEntry[JAR_FILES.length];
        for (int i = 0; i < JAR_FILES.length; i++) {
            //$NON-NLS-1$
            IPath jarLocation = bundleBase.append(JAR_FILES[i]);
            IPath srcLocation = getSourceLocation(SRC_FILES[i]);
            String nativeLocation = getNativeLocation();
            String javadocLocation = getJavadocLocation(DOC_FILES[i]);
            IAccessRule[] accessRules = {};
            IClasspathAttribute[] attributes = { // 
            JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation), JavaCore.newClasspathAttribute(JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY, nativeLocation) };
            // return JavaCore.newClasspathAttribute(JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY, dialog.getNativeLibraryPath());
            entries[i] = JavaCore.newLibraryEntry(jarLocation, srcLocation, null, accessRules, attributes, false);
        }
        return entries;
    }
    return null;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 7 with IAccessRule

use of org.eclipse.jdt.core.IAccessRule in project che by eclipse.

the class ClasspathEntry method elementDecode.

public static IClasspathEntry elementDecode(Element element, IJavaProject project, Map unknownElements) {
    IPath projectPath = project.getProject().getFullPath();
    NamedNodeMap attributes = element.getAttributes();
    NodeList children = element.getChildNodes();
    boolean[] foundChildren = new boolean[children.getLength()];
    String kindAttr = removeAttribute(TAG_KIND, attributes);
    String pathAttr = removeAttribute(TAG_PATH, attributes);
    // ensure path is absolute
    IPath path = new Path(pathAttr);
    int kind = kindFromString(kindAttr);
    if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) {
        if (!(path.segmentCount() > 0 && path.segment(0).equals(org.eclipse.jdt.internal.core.ClasspathEntry.DOT_DOT))) {
            path = projectPath.append(path);
        }
    }
    // source attachment info (optional)
    IPath sourceAttachmentPath = element.hasAttribute(TAG_SOURCEPATH) ? new Path(removeAttribute(TAG_SOURCEPATH, attributes)) : null;
    if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null && !sourceAttachmentPath.isAbsolute()) {
        sourceAttachmentPath = projectPath.append(sourceAttachmentPath);
    }
    IPath sourceAttachmentRootPath = element.hasAttribute(TAG_ROOTPATH) ? new Path(removeAttribute(TAG_ROOTPATH, attributes)) : null;
    // exported flag (optional)
    //$NON-NLS-1$
    boolean isExported = removeAttribute(TAG_EXPORTED, attributes).equals("true");
    // inclusion patterns (optional)
    IPath[] inclusionPatterns = decodePatterns(attributes, TAG_INCLUDING);
    if (inclusionPatterns == null)
        inclusionPatterns = INCLUDE_ALL;
    // exclusion patterns (optional)
    IPath[] exclusionPatterns = decodePatterns(attributes, TAG_EXCLUDING);
    if (exclusionPatterns == null)
        exclusionPatterns = EXCLUDE_NONE;
    // access rules (optional)
    NodeList attributeList = getChildAttributes(TAG_ACCESS_RULES, children, foundChildren);
    IAccessRule[] accessRules = decodeAccessRules(attributeList);
    // backward compatibility
    if (accessRules == null) {
        accessRules = getAccessRules(inclusionPatterns, exclusionPatterns);
    }
    // combine access rules (optional)
    //$NON-NLS-1$
    boolean combineAccessRestrictions = !removeAttribute(TAG_COMBINE_ACCESS_RULES, attributes).equals("false");
    // extra attributes (optional)
    attributeList = getChildAttributes(TAG_ATTRIBUTES, children, foundChildren);
    IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList);
    // custom output location
    IPath outputLocation = element.hasAttribute(TAG_OUTPUT) ? projectPath.append(removeAttribute(TAG_OUTPUT, attributes)) : null;
    String[] unknownAttributes = null;
    ArrayList unknownChildren = null;
    if (unknownElements != null) {
        // unknown attributes
        int unknownAttributeLength = attributes.getLength();
        if (unknownAttributeLength != 0) {
            unknownAttributes = new String[unknownAttributeLength * 2];
            for (int i = 0; i < unknownAttributeLength; i++) {
                Node attribute = attributes.item(i);
                unknownAttributes[i * 2] = attribute.getNodeName();
                unknownAttributes[i * 2 + 1] = attribute.getNodeValue();
            }
        }
        // unknown children
        for (int i = 0, length = foundChildren.length; i < length; i++) {
            if (!foundChildren[i]) {
                Node node = children.item(i);
                if (node.getNodeType() != Node.ELEMENT_NODE)
                    continue;
                if (unknownChildren == null)
                    unknownChildren = new ArrayList();
                StringBuffer buffer = new StringBuffer();
                decodeUnknownNode(node, buffer, project);
                unknownChildren.add(buffer.toString());
            }
        }
    }
    // recreate the CP entry
    IClasspathEntry entry = null;
    switch(kind) {
        case IClasspathEntry.CPE_PROJECT:
            entry = new org.eclipse.jdt.internal.core.ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, // inclusion patterns
            org.eclipse.jdt.internal.core.ClasspathEntry.INCLUDE_ALL, // exclusion patterns
            org.eclipse.jdt.internal.core.ClasspathEntry.EXCLUDE_NONE, // source attachment
            null, // source attachment root
            null, // specific output folder
            null, isExported, accessRules, combineAccessRestrictions, extraAttributes);
            break;
        case IClasspathEntry.CPE_LIBRARY:
            entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported);
            break;
        case IClasspathEntry.CPE_SOURCE:
            // must be an entry in this project or specify another project
            String projSegment = path.segment(0);
            if (projSegment != null && path.toOSString().startsWith(project.getProject().getFullPath().toOSString())) {
                // this project
                entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes);
            } else {
                if (path.segmentCount() == 1 || path.segment(0).equals(project.getProject().getFullPath().segment(0))) {
                    // another project
                    entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes, isExported);
                } else {
                    // an invalid source folder
                    entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes);
                }
            }
            break;
        case IClasspathEntry.CPE_VARIABLE:
            entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported);
            break;
        case IClasspathEntry.CPE_CONTAINER:
            entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported);
            break;
        case org.eclipse.jdt.internal.core.ClasspathEntry.K_OUTPUT:
            if (!path.isAbsolute())
                return null;
            entry = new org.eclipse.jdt.internal.core.ClasspathEntry(org.eclipse.jdt.internal.core.ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path, INCLUDE_ALL, EXCLUDE_NONE, // source attachment
            null, // source attachment root
            null, // custom output location
            null, false, // no access rules
            null, // no accessible files to combine
            false, NO_EXTRA_ATTRIBUTES);
            break;
        default:
            throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr));
    }
    if (unknownAttributes != null || unknownChildren != null) {
        UnknownXmlElements unknownXmlElements = new UnknownXmlElements();
        unknownXmlElements.attributes = unknownAttributes;
        unknownXmlElements.children = unknownChildren;
        unknownElements.put(path, unknownXmlElements);
    }
    return entry;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NamedNodeMap(org.w3c.dom.NamedNodeMap) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Aggregations

IAccessRule (org.eclipse.jdt.core.IAccessRule)7 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)5 IPath (org.eclipse.core.runtime.IPath)4 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)4 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 Node (org.w3c.dom.Node)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IExecutionEnvironment (org.eclipse.che.jdt.core.launching.environments.IExecutionEnvironment)1 MavenArtifactKey (org.eclipse.che.maven.data.MavenArtifactKey)1 Element (org.w3c.dom.Element)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 NodeList (org.w3c.dom.NodeList)1