Search in sources :

Example 1 with IRuntimeComponentType

use of org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType in project webtools.sourceediting by eclipse.

the class RuntimePresetMappingRegistry method readDescriptors.

private void readDescriptors() {
    descriptors = new ArrayList<MappingDescriptor>();
    IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(WSTWebPlugin.PLUGIN_ID, EXTENSION_POINT);
    if (point == null)
        return;
    IConfigurationElement[] elements = point.getConfigurationElements();
    for (int i = 0; i < elements.length; i++) {
        IConfigurationElement element = elements[i];
        if (ELEMENT_MAPPING.equals(element.getName())) {
            String id = element.getAttribute(ATTRIBUTE_ID);
            if (null == id || id.trim().length() == 0) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " is missing attribute " + ATTRIBUTE_ID);
                continue;
            }
            String runtimeID = element.getAttribute(ATTRIBUTE_FACET_RUNTIME_TYPE_ID);
            if (null == runtimeID || runtimeID.trim().length() == 0) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " is missing attribute " + ATTRIBUTE_FACET_RUNTIME_TYPE_ID);
                continue;
            }
            List<String> staticRuntimeIDs = getStaticTokens(runtimeID);
            List<IRuntimeComponentType> staticRuntimeTypes = new ArrayList<IRuntimeComponentType>();
            for (String staticRuntimeID : staticRuntimeIDs) {
                try {
                    IRuntimeComponentType runtimeType = RuntimeManager.getRuntimeComponentType(staticRuntimeID);
                    if (runtimeType != null) {
                        staticRuntimeTypes.add(runtimeType);
                    }
                } catch (IllegalArgumentException e) {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                    WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " defined invalid attribute " + ATTRIBUTE_FACET_RUNTIME_TYPE_ID + ": " + runtimeID + " unable to resolve runtime: " + staticRuntimeID, e);
                }
            }
            String runtimeVersionStr = element.getAttribute(ATTRIBUTE_FACET_RUNTIME_VERSION);
            if (null == runtimeVersionStr || runtimeVersionStr.trim().length() == 0) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " is missing attribute " + ATTRIBUTE_FACET_RUNTIME_VERSION);
                continue;
            }
            if (!staticRuntimeTypes.isEmpty()) {
                List<String> staticRuntimeVersions = getStaticTokens(runtimeVersionStr);
                for (String staticVersion : staticRuntimeVersions) {
                    boolean foundVersion = false;
                    for (int k = 0; k < staticRuntimeTypes.size() && !foundVersion; k++) {
                        IRuntimeComponentType runtimeType = staticRuntimeTypes.get(k);
                        try {
                            runtimeType.getVersion(staticVersion);
                            foundVersion = true;
                        } catch (IllegalArgumentException e) {
                        // eat it
                        }
                    }
                    if (!foundVersion) {
                        // $NON-NLS-1$
                        StringBuffer validVersions = new StringBuffer(" valid versions include: ");
                        for (IRuntimeComponentType runtimeType : staticRuntimeTypes) {
                            // $NON-NLS-1$
                            validVersions.append("\n");
                            validVersions.append(runtimeType.getId());
                            // $NON-NLS-1$
                            validVersions.append(": ");
                            for (Iterator<IRuntimeComponentVersion> iterator = runtimeType.getVersions().iterator(); iterator.hasNext(); ) {
                                validVersions.append(iterator.next().getVersionString());
                                if (iterator.hasNext()) {
                                    // $NON-NLS-1$
                                    validVersions.append(" ");
                                }
                            }
                        }
                        WSTWebPlugin.logError(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                        "Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " defined invalid attribute " + ATTRIBUTE_FACET_RUNTIME_VERSION + ": " + staticVersion + validVersions);
                    }
                }
            }
            String facetID = element.getAttribute(ATTRIBUTE_FACET_ID);
            if (null == facetID || facetID.trim().length() == 0) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " is missing attribute " + ATTRIBUTE_FACET_ID);
                continue;
            }
            List<String> staticFacetIDs = getStaticTokens(facetID);
            List<IProjectFacet> staticFacets = new ArrayList<IProjectFacet>();
            for (String staticFacetID : staticFacetIDs) {
                try {
                    IProjectFacet facet = ProjectFacetsManager.getProjectFacet(staticFacetID);
                    if (null != facet) {
                        staticFacets.add(facet);
                    }
                } catch (IllegalArgumentException e) {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " defined invalid attribute " + ATTRIBUTE_FACET_ID + ": " + staticFacetID, e);
                }
            }
            String facetVersionStr = element.getAttribute(ATTRIBUTE_FACET_VERSION);
            if (null == facetVersionStr || facetVersionStr.trim().length() == 0) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " is missing attribute " + ATTRIBUTE_FACET_VERSION);
                continue;
            }
            List<String> staticFacetVersionStrs = getStaticTokens(facetVersionStr);
            if (!staticFacets.isEmpty() && !staticFacetVersionStrs.isEmpty()) {
                for (String staticFacetVersion : staticFacetVersionStrs) {
                    boolean foundFacetVersion = false;
                    for (int k = 0; k < staticFacets.size() && !foundFacetVersion; k++) {
                        IProjectFacet staticFacet = staticFacets.get(k);
                        try {
                            IProjectFacetVersion staticVersion = staticFacet.getVersion(staticFacetVersion);
                            if (staticVersion != null) {
                                foundFacetVersion = true;
                            }
                        } catch (IllegalArgumentException e) {
                        // eat it
                        }
                    }
                    if (!foundFacetVersion) {
                        // $NON-NLS-1$
                        StringBuffer validVersions = new StringBuffer(" valid versions include: ");
                        for (IProjectFacet staticFacet : staticFacets) {
                            // $NON-NLS-1$
                            validVersions.append("\n");
                            validVersions.append(staticFacet.getId());
                            // $NON-NLS-1$
                            validVersions.append(": ");
                            for (Iterator<IProjectFacetVersion> iterator = staticFacet.getVersions().iterator(); iterator.hasNext(); ) {
                                validVersions.append(iterator.next().getVersionString());
                                if (iterator.hasNext()) {
                                    // $NON-NLS-1$
                                    validVersions.append(" ");
                                }
                            }
                        }
                        WSTWebPlugin.logError(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                        "Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " defined invalid attribute " + ATTRIBUTE_FACET_VERSION + ": " + staticFacetVersion + validVersions);
                        continue;
                    }
                }
            }
            String presetID = element.getAttribute(ATTRIBUTE_PRESET_ID);
            if (null == presetID || presetID.trim().length() == 0) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " is missing attribute " + ATTRIBUTE_PRESET_ID);
                continue;
            }
            try {
                ProjectFacetsManager.getPreset(presetID);
            } catch (IllegalArgumentException e) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                WSTWebPlugin.logError("Extension: " + EXTENSION_POINT + " Element: " + ELEMENT_MAPPING + " defined invalid attribute " + ATTRIBUTE_PRESET_ID + ": " + presetID, e);
                continue;
            }
            MappingDescriptor descriptor = new MappingDescriptor(element);
            descriptors.add(descriptor);
        } else {
            // $NON-NLS-1$ //$NON-NLS-2$
            WSTWebPlugin.logError("Elements must be named: " + ELEMENT_MAPPING + " within the extension: " + EXTENSION_POINT);
            // $NON-NLS-1$ //$NON-NLS-2$
            WSTWebPlugin.logError("Element: " + element.getName() + " is invalid within the extension: " + EXTENSION_POINT);
        }
    }
}
Also used : IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IRuntimeComponentVersion(org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IRuntimeComponentType(org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType)

Aggregations

ArrayList (java.util.ArrayList)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)1 IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)1 IRuntimeComponentType (org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType)1 IRuntimeComponentVersion (org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion)1