Search in sources :

Example 6 with IProjectFacetVersion

use of org.eclipse.wst.common.project.facet.core.IProjectFacetVersion in project webtools.servertools by eclipse.

the class FacetUtil method verifyFacets.

/**
 * Tests whether the facets on a project are supported by a given server. Returns
 * an OK status if the server's runtime supports the project's facets, and an
 * ERROR status (with message) if it doesn't.
 *
 * @param project a project
 * @param server a server
 * @return OK status if the server's runtime supports the project's facets, and an
 *    ERROR status (with message) if it doesn't
 */
public static final IStatus verifyFacets(IProject project, IServer server) {
    if (server == null)
        return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorNoRuntime, null);
    IRuntime runtime = server.getRuntime();
    if (runtime == null)
        return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorNoRuntime, null);
    org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime2 = getRuntime(runtime);
    if (// bug 150194 - what do we do if the facet runtime doesn't exist yet
    runtime2 == null)
        return Status.OK_STATUS;
    try {
        IFacetedProject facetedProject = ProjectFacetsManager.create(project);
        Iterator iterator = facetedProject.getProjectFacets().iterator();
        while (iterator.hasNext()) {
            IProjectFacetVersion facet = (IProjectFacetVersion) iterator.next();
            if (!runtime2.supports(facet))
                return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorFacet, facet.getProjectFacet().getLabel(), facet.getVersionString()), null);
        }
    } catch (CoreException ce) {
        return ce.getStatus();
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) Iterator(java.util.Iterator) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 7 with IProjectFacetVersion

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

the class NewProjectDataModelFacetWizard method setRuntimeAndDefaultFacets.

protected void setRuntimeAndDefaultFacets(final IRuntime runtime) {
    final IFacetedProjectWorkingCopy dm = getFacetedProjectWorkingCopy();
    dm.setTargetedRuntimes(Collections.<IRuntime>emptySet());
    if (runtime != null) {
        final Set<IProjectFacetVersion> minFacets = new HashSet<IProjectFacetVersion>();
        try {
            for (IProjectFacet f : dm.getFixedProjectFacets()) {
                minFacets.add(f.getLatestSupportedVersion(runtime));
            }
        } catch (CoreException e) {
            throw new RuntimeException(e);
        }
        dm.setProjectFacets(minFacets);
        dm.setTargetedRuntimes(Collections.singleton(runtime));
    }
    dm.setSelectedPreset(FacetedProjectFramework.DEFAULT_CONFIGURATION_PRESET_ID);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) HashSet(java.util.HashSet)

Example 8 with IProjectFacetVersion

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

the class NewProjectDataModelFacetWizard method createPageControls.

@Override
public void createPageControls(Composite container) {
    super.createPageControls(container);
    final IPreset preset = this.template.getInitialPreset();
    final IRuntime runtime = (IRuntime) model.getProperty(FACET_RUNTIME);
    if (preset == null) {
        // If no preset is specified, select the runtime and it's default
        // facets.
        setRuntimeAndDefaultFacets(runtime);
    } else {
        // If preset is specified, select the runtime only if supports all
        // of the facets included in the preset.
        getFacetedProjectWorkingCopy().setSelectedPreset(preset.getId());
        boolean supports = false;
        if (runtime != null) {
            supports = true;
            for (Iterator itr = preset.getProjectFacets().iterator(); itr.hasNext(); ) {
                final IProjectFacetVersion fv = (IProjectFacetVersion) itr.next();
                if (!runtime.supports(fv)) {
                    supports = false;
                    break;
                }
            }
        }
        if (supports) {
            getFacetedProjectWorkingCopy().setTargetedRuntimes(Collections.singleton(runtime));
        } else {
            model.setProperty(FACET_RUNTIME, null);
        }
    }
    synchRuntimes();
}
Also used : IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) Iterator(java.util.Iterator) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Example 9 with IProjectFacetVersion

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

the class DataModelFacetCreationWizardPage method createPresetPanel.

protected void createPresetPanel(Composite top) {
    final IFacetedProjectWorkingCopy workingCopy = ((ModifyFacetedProjectWizard) getWizard()).getFacetedProjectWorkingCopy();
    final IFilter<IPreset> filter = new AbstractFilter<IPreset>() {

        {
            IFacetedProjectListener fpjwcListenerForPreset = new IFacetedProjectListener() {

                @Override
                public void handleEvent(final IFacetedProjectEvent event) {
                    handleProjectFacetsChangedEvent((IProjectFacetsChangedEvent) event);
                }
            };
            facetedProjectListeners.add(fpjwcListenerForPreset);
            workingCopy.addListener(fpjwcListenerForPreset, IFacetedProjectEvent.Type.PROJECT_FACETS_CHANGED);
        }

        @Override
        public boolean check(final IPreset preset) {
            final IProjectFacetVersion primaryFacetVersion = getPrimaryFacetVersion();
            return preset.getProjectFacets().contains(primaryFacetVersion);
        }

        private void handleProjectFacetsChangedEvent(final IProjectFacetsChangedEvent event) {
            for (IProjectFacetVersion fv : event.getFacetsWithChangedVersions()) {
                if (fv.getProjectFacet() == getPrimaryFacet()) {
                    final IFilterEvent<IPreset> filterEvent = new FilterEvent<IPreset>(this, IFilterEvent.Type.FILTER_CHANGED);
                    notifyListeners(filterEvent);
                }
            }
        }
    };
    final PresetSelectionPanel ppanel = new PresetSelectionPanel(top, workingCopy, filter);
    ppanel.setLayoutData(gdhfill());
}
Also used : IFacetedProjectListener(org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener) FilterEvent(org.eclipse.wst.common.project.facet.core.util.FilterEvent) AbstractFilter(org.eclipse.wst.common.project.facet.core.util.AbstractFilter) IFacetedProjectEvent(org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) ModifyFacetedProjectWizard(org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard) IProjectFacetsChangedEvent(org.eclipse.wst.common.project.facet.core.events.IProjectFacetsChangedEvent) PresetSelectionPanel(org.eclipse.wst.common.project.facet.ui.PresetSelectionPanel) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)

Example 10 with IProjectFacetVersion

use of org.eclipse.wst.common.project.facet.core.IProjectFacetVersion 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

IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)22 IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)10 CoreException (org.eclipse.core.runtime.CoreException)7 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)5 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)5 HashSet (java.util.HashSet)4 IPreset (org.eclipse.wst.common.project.facet.core.IPreset)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IDataModel (org.eclipse.wst.common.frameworks.datamodel.IDataModel)3 Action (org.eclipse.wst.common.project.facet.core.IFacetedProject.Action)3 Iterator (java.util.Iterator)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ILibraryProvider (org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider)2 LibraryInstallDelegate (org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate)2 IRuntime (org.eclipse.wst.common.project.facet.core.runtime.IRuntime)2 ModifyFacetedProjectWizard (org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard)2 MdwProgressMonitorDialog (com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog)1 ContainerType (com.centurylink.mdw.plugin.project.model.ServerSettings.ContainerType)1