Search in sources :

Example 21 with IProjectFacet

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

the class FacetModuleCoreSupportDelegate method isWebFragmentProject.

/**
 * @param project
 * @return
 * @throws CoreException
 */
static boolean isWebFragmentProject(IProject project) {
    if (project == null)
        return false;
    try {
        if (ProjectFacetsManager.isProjectFacetDefined(JST_WEBFRAGMENT_MODULE)) {
            IFacetedProject faceted = ProjectFacetsManager.create(project);
            IProjectFacet webModuleFacet = ProjectFacetsManager.getProjectFacet(JST_WEBFRAGMENT_MODULE);
            if (faceted != null && faceted.hasProjectFacet(webModuleFacet)) {
                return true;
            }
        }
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return false;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 22 with IProjectFacet

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

the class FacetModuleCoreSupportDelegate method isWebProject.

/**
 * @param project
 * @return
 * @throws CoreException
 */
static boolean isWebProject(IProject project) {
    boolean is = false;
    try {
        IFacetedProject faceted = ProjectFacetsManager.create(project);
        if (ProjectFacetsManager.isProjectFacetDefined(JST_WEB_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
        if (!is && ProjectFacetsManager.isProjectFacetDefined(WST_WEB_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(WST_WEB_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
        if (!is && ProjectFacetsManager.isProjectFacetDefined(JST_WEBFRAGMENT_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEBFRAGMENT_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return is;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 23 with IProjectFacet

use of org.eclipse.wst.common.project.facet.core.IProjectFacet in project liferay-ide by liferay.

the class LiferayProjectImportDataModelProvider method init.

@Override
public void init() {
    super.init();
    // set the project facets to get the runtime target dropdown to only show liferay runtimes
    IFacetedProjectWorkingCopy facetedProject = getFacetedProjectWorkingCopy();
    facetedProject.setSelectedPreset(IPluginFacetConstants.LIFERAY_PORTLET_PRESET);
    Set<IProjectFacet> fixedFacets = new HashSet<>();
    fixedFacets.add(ProjectFacetsManager.getProjectFacet(IPluginFacetConstants.LIFERAY_EXT_FACET_ID));
    facetedProject.setFixedProjectFacets(Collections.unmodifiableSet(fixedFacets));
    ProjectUtil.setDefaultRuntime(getDataModel());
}
Also used : IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) HashSet(java.util.HashSet)

Example 24 with IProjectFacet

use of org.eclipse.wst.common.project.facet.core.IProjectFacet in project liferay-ide by liferay.

the class LiferayFacetedProjectListener method handleEvent.

public void handleEvent(IFacetedProjectEvent event) {
    if (event.getType() != IFacetedProjectEvent.Type.POST_INSTALL) {
        return;
    }
    IProjectFacetActionEvent actionEvent = (IProjectFacetActionEvent) event;
    if (!JSDT_FACET.equals(actionEvent.getProjectFacet().getId())) {
        return;
    }
    Job uninstall = new WorkspaceJob("uninstall jsdt facet") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                IFacetedProject fProject = actionEvent.getProject();
                Set<IProjectFacet> fixedFacets = fProject.getFixedProjectFacets();
                Set<IProjectFacet> updatedFacets = new HashSet<>();
                for (IProjectFacet f : fixedFacets) {
                    if (!JSDT_FACET.equals(f.getId())) {
                        updatedFacets.add(f);
                    }
                }
                fProject.setFixedProjectFacets(updatedFacets);
            } catch (Exception e) {
                ProjectCore.logError("Unable to removed fixed jsdt facet", e);
            }
            try {
                Set<Action> actions = new HashSet<>();
                Type type = Type.valueOf("uninstall");
                Action uninstallJsdt = new Action(type, actionEvent.getProjectFacetVersion(), null);
                actions.add(uninstallJsdt);
                actionEvent.getProject().modify(actions, monitor);
                // try to remove unneeded jsdt files
                IProject project = actionEvent.getProject().getProject();
                IFile jsdtscope = project.getFile(".settings/.jsdtscope");
                if (FileUtil.exists(jsdtscope)) {
                    jsdtscope.delete(true, monitor);
                }
                IFile container = project.getFile(".settings/org.eclipse.wst.jsdt.ui.superType.container");
                if (FileUtil.exists(container)) {
                    container.delete(true, monitor);
                }
                IFile name = project.getFile(".settings/org.eclipse.wst.jsdt.ui.superType.name");
                if (FileUtil.exists(name)) {
                    name.delete(true, monitor);
                }
            } catch (CoreException ce) {
                ProjectCore.logError("Unable to uninstall jsdt facet", ce);
            }
            return Status.OK_STATUS;
        }
    };
    uninstall.schedule();
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) Action(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IProjectFacetActionEvent(org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Type(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action.Type) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) HashSet(java.util.HashSet)

Example 25 with IProjectFacet

use of org.eclipse.wst.common.project.facet.core.IProjectFacet in project liferay-ide by liferay.

the class SDKPluginFacetUtil method configureProjectAsSDKProject.

public static void configureProjectAsSDKProject(IFacetedProjectWorkingCopy fpjwc, String pluginType, String sdkLocation, ProjectRecord projectRecord) throws CoreException {
    IFacetedProjectTemplate template = getLiferayTemplateForProject(pluginType);
    IPreset preset = getLiferayPresetForProject(pluginType);
    if (preset == null) {
        throw new CoreException(ProjectCore.createErrorStatus(NLS.bind(Msgs.noFacetPreset, fpjwc.getProjectName())));
    }
    IRuntime primaryRuntime = fpjwc.getPrimaryRuntime();
    if (primaryRuntime != null) {
        fpjwc.removeTargetedRuntime(primaryRuntime);
    }
    Set<IProjectFacetVersion> currentProjectFacetVersions = fpjwc.getProjectFacets();
    Set<IProjectFacet> requiredFacets = template.getFixedProjectFacets();
    for (IProjectFacet requiredFacet : requiredFacets) {
        boolean hasRequiredFacet = false;
        for (IProjectFacetVersion currentFacetVersion : currentProjectFacetVersions) {
            if (currentFacetVersion.getProjectFacet().equals(requiredFacet)) {
                // TODO how to check the bundle support status?
                boolean requiredVersion = _isRequiredVersion(currentFacetVersion);
                if (requiredVersion) {
                    hasRequiredFacet = true;
                } else {
                    fpjwc.removeProjectFacet(currentFacetVersion);
                }
                break;
            }
        }
        if (!hasRequiredFacet) {
            IProjectFacetVersion requiredFacetVersion = _getRequiredFacetVersionFromPreset(requiredFacet, preset);
            if (requiredFacetVersion != null) {
                fpjwc.addProjectFacet(requiredFacetVersion);
                if (ProjectUtil.isJavaFacet(requiredFacetVersion)) {
                    configureJavaFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset, projectRecord);
                } else if (ProjectUtil.isDynamicWebFacet(requiredFacetVersion)) {
                    configureWebFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset);
                }
            }
        } else {
            if (ProjectUtil.isJavaFacet(requiredFacet)) {
                configureJavaFacet(fpjwc, requiredFacet, preset, projectRecord);
            } else if (ProjectUtil.isDynamicWebFacet(requiredFacet)) {
                configureWebFacet(fpjwc, requiredFacet, preset);
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IFacetedProjectTemplate(org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

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