| /******************************************************************************* |
| * Copyright (c) 2009 Red Hat and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Red Hat - Initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.wst.common.componentcore.internal.util; |
| |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.wst.common.project.facet.core.IFacetedProject; |
| import org.eclipse.wst.common.project.facet.core.IProjectFacet; |
| import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
| import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; |
| |
| public class FacetedProjectUtilities { |
| public static boolean isProjectOfType(IProject project, String typeID) { |
| return getProjectFacetVersion(project, typeID) != null; |
| } |
| |
| public static IProjectFacetVersion getProjectFacetVersion(IProject project, String typeID){ |
| IFacetedProject facetedProject = null; |
| try { |
| facetedProject = ProjectFacetsManager.create(project); |
| } catch (CoreException e) { |
| return null; |
| } |
| |
| if (facetedProject != null && ProjectFacetsManager.isProjectFacetDefined(typeID)) { |
| IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID); |
| if(projectFacet == null){ |
| return null; |
| } |
| return facetedProject.getProjectFacetVersion(projectFacet); |
| } |
| return null; |
| } |
| |
| public static boolean isProjectOfType(IFacetedProject facetedProject, String typeID) { |
| if (facetedProject != null && ProjectFacetsManager.isProjectFacetDefined(typeID)) { |
| IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID); |
| return projectFacet != null && facetedProject.hasProjectFacet(projectFacet); |
| } |
| return false; |
| } |
| } |