aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Pospychala2012-09-10 06:27:34 (EDT)
committerJacek Pospychala2012-09-10 06:27:34 (EDT)
commit6c6d18bb5e878e680edc929cd926a1ffec45fafe (patch)
tree5e837cfd1b9cf82bc95023a41f1f3dcd63352dfc
parent9e31120a58fa9c588ce7bff10b92b0250df16df9 (diff)
downloadorg.eclipse.pdt-6c6d18bb5e878e680edc929cd926a1ffec45fafe.zip
org.eclipse.pdt-6c6d18bb5e878e680edc929cd926a1ffec45fafe.tar.gz
org.eclipse.pdt-6c6d18bb5e878e680edc929cd926a1ffec45fafe.tar.bz2
Bug 388972 - Support for FacetsR3_1_1
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java126
1 files changed, 100 insertions, 26 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java
index 40da395..0041ac0 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java
@@ -6,15 +6,111 @@ import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.php.internal.core.PHPVersion;
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 PHPFacets {
/**
+ * Returns true if the given project is a faceted project and the php core
+ * facet is installed
+ *
+ * @param project
+ * the project
+ * @return true if the php core facet is installed.
+ */
+ public static boolean isFacetedProject(IProject project) {
+ try {
+ final IFacetedProject faceted = ProjectFacetsManager
+ .create(project);
+ if (faceted != null) {
+ IProjectFacet coreFacet = ProjectFacetsManager
+ .getProjectFacet(PHPFacetsConstants.PHP_CORE_COMPONENT);
+ IProjectFacet phpFacet = ProjectFacetsManager
+ .getProjectFacet(PHPFacetsConstants.PHP_COMPONENT);
+ if (faceted.hasProjectFacet(coreFacet)
+ && faceted.hasProjectFacet(phpFacet)) {
+ return true;
+ }
+ }
+ } catch (CoreException ex) {
+ // silently ignore
+ }
+ return false;
+ }
+
+ /**
+ * Returns the php version from given faceted project; before invoking this
+ * method ensure that {@link #isFacetedProject(IProject)} return true.
+ *
+ * @param project
+ * the php faceted project
+ * @return the php version
+ */
+ public static PHPVersion getPhpVersionFromFacets(IProject project) {
+ try {
+ final IFacetedProject faceted = ProjectFacetsManager
+ .create(project);
+ if (faceted != null) {
+ IProjectFacet phpFacet = ProjectFacetsManager
+ .getProjectFacet(PHPFacetsConstants.PHP_COMPONENT);
+ final IProjectFacetVersion version = faceted
+ .getInstalledVersion(phpFacet);
+ if (PHPFacetsConstants.PHP_COMPONENT_VERSION_4.equals(version
+ .getVersionString())) {
+ return PHPVersion.PHP4;
+ }
+ if (PHPFacetsConstants.PHP_COMPONENT_VERSION_5.equals(version
+ .getVersionString())) {
+ return PHPVersion.PHP5;
+ }
+ if (PHPFacetsConstants.PHP_COMPONENT_VERSION_5_3.equals(version
+ .getVersionString())) {
+ return PHPVersion.PHP5_3;
+ }
+ if (PHPFacetsConstants.PHP_COMPONENT_VERSION_5_4.equals(version
+ .getVersionString())) {
+ return PHPVersion.PHP5_4;
+ }
+ }
+ } catch (CoreException ex) {
+ // silently ignore
+ }
+ // defaults to php 5.4
+ return PHPVersion.PHP5_4;
+ }
+
+ /**
+ * Returns the php facet version from given php version
+ *
+ * @param version
+ * php version
+ * @return the php facets version
+ */
+ public static IProjectFacetVersion convertToFacetVersion(PHPVersion version) {
+ IProjectFacet phpFacet = ProjectFacetsManager
+ .getProjectFacet(PHPFacetsConstants.PHP_COMPONENT);
+ switch (version) {
+ case PHP4:
+ return phpFacet
+ .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_4);
+ case PHP5:
+ return phpFacet
+ .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_5);
+ case PHP5_3:
+ return phpFacet
+ .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_5_3);
+ case PHP5_4:
+ default:
+ return phpFacet
+ .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_5_4);
+ }
+ }
+
+ /**
* Adds PHP facet for project
*
* @param project
@@ -44,30 +140,8 @@ public class PHPFacets {
// install the fixed facets
facetedProject.installProjectFacet(coreFacet.getDefaultVersion(), null,
- new NullProgressMonitor());
- // Fetch and activate the correct php version
- switch (phpVersion) {
- case PHP4:
- facetedProject.installProjectFacet(phpFacet
- .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_4),
- null, monitor);
- break;
- case PHP5:
- facetedProject.installProjectFacet(phpFacet
- .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_5),
- null, monitor);
- break;
- case PHP5_3:
- facetedProject.installProjectFacet(phpFacet
- .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_5_3),
- null, monitor);
- break;
- case PHP5_4:
- default:
- facetedProject.installProjectFacet(phpFacet
- .getVersion(PHPFacetsConstants.PHP_COMPONENT_VERSION_5_4),
- null, monitor);
- break;
- }
+ monitor);
+ facetedProject.installProjectFacet(convertToFacetVersion(phpVersion),
+ null, monitor);
}
}