use of org.eclipse.wst.common.project.facet.core.IProjectFacet 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);
}
}
}
use of org.eclipse.wst.common.project.facet.core.IProjectFacet in project sling by apache.
the class ProjectAdapter method installFacet.
public void installFacet(String facetId, String facetVersion) throws CoreException {
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
IProjectFacet slingBundleFacet = ProjectFacetsManager.getProjectFacet(facetId);
IProjectFacetVersion projectFacetVersion = slingBundleFacet.getVersion(facetVersion);
facetedProject.installProjectFacet(projectFacetVersion, null, new NullProgressMonitor());
}
use of org.eclipse.wst.common.project.facet.core.IProjectFacet in project sling by apache.
the class FacetHelper method containsFacet.
/**
* Checks if the specified project has the specified facet
*
* @param project the project, may be <code>null</code>
* @param facetId the facet to check for
* @return true if the specified <tt>project</tt> has the specified <tt>facetId</tt>
*/
public static boolean containsFacet(IProject project, String facetId) {
if (project == null) {
return false;
}
IFacetedProject facetedProject = (IFacetedProject) project.getAdapter(IFacetedProject.class);
if (facetedProject == null) {
return false;
}
IProjectFacet facet = ProjectFacetsManager.getProjectFacet(facetId);
return facetedProject.hasProjectFacet(facet);
}
use of org.eclipse.wst.common.project.facet.core.IProjectFacet in project sling by apache.
the class ConfigurationHelper method convertToContentPackageProject.
public static void convertToContentPackageProject(IProject project, IProgressMonitor monitor, IPath contentSyncRoot) throws CoreException {
IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, null);
// install content facet
IProjectFacet slingContentFacet = ProjectFacetsManager.getProjectFacet("sling.content");
facetedProject.installProjectFacet(slingContentFacet.getLatestVersion(), null, null);
ProjectUtil.setSyncDirectoryPath(project, contentSyncRoot);
// also install sightly facet 1.1 by default
IProjectFacet sightlyFacet = ProjectFacetsManager.getProjectFacet("sightly");
if (sightlyFacet != null) {
facetedProject.installProjectFacet(sightlyFacet.getLatestVersion(), null, null);
}
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
use of org.eclipse.wst.common.project.facet.core.IProjectFacet in project webtools.sourceediting by eclipse.
the class ConvertJob method runInWorkspace.
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(JSDT_FACET);
IFacetedProject facetedProject = ProjectFacetsManager.create(fProject);
if (facetedProject != null && fProject.isAccessible()) {
if (fInstall) {
IProjectFacetVersion latestVersion = projectFacet.getLatestVersion();
facetedProject.installProjectFacet(latestVersion, null, monitor);
}
if (fUseExplicitWorkingCopy) {
IFacetedProjectWorkingCopy copy = facetedProject.createWorkingCopy();
Set fixed = new HashSet(facetedProject.getFixedProjectFacets());
fixed.add(projectFacet);
copy.setFixedProjectFacets(fixed);
copy.commitChanges(new NullProgressMonitor());
copy.dispose();
} else {
Set fixed = new HashSet(facetedProject.getFixedProjectFacets());
if (!fixed.contains(projectFacet)) {
fixed.add(projectFacet);
facetedProject.setFixedProjectFacets(fixed);
}
}
}
} catch (IllegalArgumentException e) {
// unknown facet ID, bad installation configuration?
} catch (Exception e) {
Logger.logException(e);
}
return Status.OK_STATUS;
}
Aggregations