Search in sources :

Example 16 with IProjectFacet

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

Example 17 with IProjectFacet

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());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 18 with IProjectFacet

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);
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 19 with IProjectFacet

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());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 20 with IProjectFacet

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) Set(java.util.Set) HashSet(java.util.HashSet) 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) CoreException(org.eclipse.core.runtime.CoreException) HashSet(java.util.HashSet)

Aggregations

IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)28 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)17 CoreException (org.eclipse.core.runtime.CoreException)14 IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 HashSet (java.util.HashSet)6 IProject (org.eclipse.core.resources.IProject)6 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)5 IStatus (org.eclipse.core.runtime.IStatus)3 Action (org.eclipse.wst.common.project.facet.core.IFacetedProject.Action)3 IPluginPublisher (com.liferay.ide.server.core.IPluginPublisher)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ILibraryProvider (org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider)2 LibraryInstallDelegate (org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate)2 IDataModel (org.eclipse.wst.common.frameworks.datamodel.IDataModel)2 IRuntime (org.eclipse.wst.server.core.IRuntime)2 MdwProgressMonitorDialog (com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog)1 VcsRepository (com.centurylink.mdw.plugin.project.model.VcsRepository)1