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;
}
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);
}
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();
}
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());
}
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);
}
}
}
Aggregations