aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Pospychala2012-09-24 06:18:35 (EDT)
committerJacek Pospychala2012-09-24 06:18:35 (EDT)
commit3a71629d34e8a1a200ed7ba5a313c24fb8e09767 (patch)
tree30d09e30ace9f9becba62da27b2c95bdf819f898
parentf136b83ce938ca4690a2878b0291cb870d1ad98d (diff)
downloadorg.eclipse.pdt-3a71629d34e8a1a200ed7ba5a313c24fb8e09767.zip
org.eclipse.pdt-3a71629d34e8a1a200ed7ba5a313c24fb8e09767.tar.gz
org.eclipse.pdt-3a71629d34e8a1a200ed7ba5a313c24fb8e09767.tar.bz2
Bug 389036 - Update PHP facet version accordingly to project PHP version
-rw-r--r--plugins/org.eclipse.php.core/plugin.xml22
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/InstallActionDelegate.java (renamed from plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/DummyActionDelegate.java)2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/Messages.java15
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java37
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/VersionChangeActionDelegate.java19
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/messages.properties1
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/OptionsConfigurationBlock.java24
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPCoreOptionsConfigurationBlock.java24
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.java2
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.properties2
10 files changed, 136 insertions, 12 deletions
diff --git a/plugins/org.eclipse.php.core/plugin.xml b/plugins/org.eclipse.php.core/plugin.xml
index c69e14b..7f62bc5 100644
--- a/plugins/org.eclipse.php.core/plugin.xml
+++ b/plugins/org.eclipse.php.core/plugin.xml
@@ -361,19 +361,31 @@
</project-facet-version>
<action facet="php.core.component" version="1" type="install">
- <delegate class="org.eclipse.php.internal.core.facet.DummyActionDelegate" />
+ <delegate class="org.eclipse.php.internal.core.facet.InstallActionDelegate" />
</action>
<action facet="php.component" version="4" type="install">
- <delegate class="org.eclipse.php.internal.core.facet.DummyActionDelegate" />
+ <delegate class="org.eclipse.php.internal.core.facet.InstallActionDelegate" />
</action>
<action facet="php.component" version="5" type="install">
- <delegate class="org.eclipse.php.internal.core.facet.DummyActionDelegate" />
+ <delegate class="org.eclipse.php.internal.core.facet.InstallActionDelegate" />
</action>
<action facet="php.component" version="5.3" type="install">
- <delegate class="org.eclipse.php.internal.core.facet.DummyActionDelegate" />
+ <delegate class="org.eclipse.php.internal.core.facet.InstallActionDelegate" />
</action>
<action facet="php.component" version="5.4" type="install">
- <delegate class="org.eclipse.php.internal.core.facet.DummyActionDelegate" />
+ <delegate class="org.eclipse.php.internal.core.facet.InstallActionDelegate" />
+ </action>
+ <action facet="php.component" version="4" type="version-change">
+ <delegate class="org.eclipse.php.internal.core.facet.VersionChangeActionDelegate" />
+ </action>
+ <action facet="php.component" version="5" type="version-change">
+ <delegate class="org.eclipse.php.internal.core.facet.VersionChangeActionDelegate" />
+ </action>
+ <action facet="php.component" version="5.3" type="version-change">
+ <delegate class="org.eclipse.php.internal.core.facet.VersionChangeActionDelegate" />
+ </action>
+ <action facet="php.component" version="5.4" type="version-change">
+ <delegate class="org.eclipse.php.internal.core.facet.VersionChangeActionDelegate" />
</action>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/DummyActionDelegate.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/InstallActionDelegate.java
index 3ab7588..7342281 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/DummyActionDelegate.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/InstallActionDelegate.java
@@ -6,7 +6,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-public class DummyActionDelegate implements IDelegate {
+public class InstallActionDelegate implements IDelegate {
public void execute(IProject arg0, IProjectFacetVersion arg1, Object arg2,
IProgressMonitor arg3) throws CoreException {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/Messages.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/Messages.java
new file mode 100644
index 0000000..6c000c7
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/Messages.java
@@ -0,0 +1,15 @@
+package org.eclipse.php.internal.core.facet;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.php.internal.core.facet.messages"; //$NON-NLS-1$
+ public static String PHPFacets_SettingVersionFailed;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
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 0041ac0..c880ead 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
@@ -4,8 +4,8 @@ import java.util.HashSet;
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.*;
+import org.eclipse.php.internal.core.PHPCorePlugin;
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;
@@ -15,6 +15,39 @@ import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
public class PHPFacets {
/**
+ * Synchronizes the php version for facets
+ *
+ * @param project
+ * @return the status of setting the version
+ */
+ public static IStatus setFacetedVersion(IProject project, PHPVersion version) {
+ if (isFacetedProject(project)) {
+ try {
+ final IProjectFacetVersion facetedVersion = convertToFacetVersion(version);
+ final IProjectFacet phpFacet = ProjectFacetsManager
+ .getProjectFacet(PHPFacetsConstants.PHP_COMPONENT);
+ final IFacetedProject faceted = ProjectFacetsManager
+ .create(project);
+ if (!facetedVersion.equals(faceted
+ .getInstalledVersion(phpFacet))) {
+ final Set<IFacetedProject.Action> actions = new HashSet<IFacetedProject.Action>();
+ actions.add(new IFacetedProject.Action(
+ IFacetedProject.Action.Type.VERSION_CHANGE,
+ facetedVersion, null));
+ faceted.modify(actions, new NullProgressMonitor());
+ }
+ } catch (CoreException ex) {
+ return new Status(IStatus.ERROR, PHPCorePlugin.ID,
+ Messages.PHPFacets_SettingVersionFailed, ex);
+ } catch (IllegalArgumentException ex) {
+ return new Status(IStatus.ERROR, PHPCorePlugin.ID,
+ Messages.PHPFacets_SettingVersionFailed, ex);
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
* Returns true if the given project is a faceted project and the php core
* facet is installed
*
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/VersionChangeActionDelegate.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/VersionChangeActionDelegate.java
new file mode 100644
index 0000000..dfdc159
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/VersionChangeActionDelegate.java
@@ -0,0 +1,19 @@
+package org.eclipse.php.internal.core.facet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+
+public class VersionChangeActionDelegate implements IDelegate {
+
+ public void execute(IProject arg0, IProjectFacetVersion arg1, Object arg2,
+ IProgressMonitor arg3) throws CoreException {
+ // sync php version of the project
+ // check if there is any change to prevent endless loops
+ // (php options upgrade will invoke a version change and lead to this)
+ // TODO
+ }
+
+}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/messages.properties b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/messages.properties
new file mode 100644
index 0000000..bb6b854
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/messages.properties
@@ -0,0 +1 @@
+PHPFacets_SettingVersionFailed=Changing the version failed because of unsatisfied constraints. Check your activated project facets.
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/OptionsConfigurationBlock.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/OptionsConfigurationBlock.java
index 43644b8..dc14d48 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/OptionsConfigurationBlock.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/OptionsConfigurationBlock.java
@@ -142,8 +142,8 @@ public abstract class OptionsConfigurationBlock {
fDisabledProjectSettings = new IdentityHashMap();
for (int i = 0; i < allKeys.length; i++) {
Key curr = allKeys[i];
- fDisabledProjectSettings.put(curr, curr.getStoredValue(
- fLookupOrder, false, fManager));
+ fDisabledProjectSettings.put(curr,
+ curr.getStoredValue(fLookupOrder, false, fManager));
}
}
@@ -439,8 +439,8 @@ public abstract class OptionsConfigurationBlock {
for (int i = 0; i < fExpandedComposites.size(); i++) {
ExpandableComposite curr = (ExpandableComposite) fExpandedComposites
.get(i);
- settings.put(SETTINGS_EXPANDED + String.valueOf(i), curr
- .isExpanded());
+ settings.put(SETTINGS_EXPANDED + String.valueOf(i),
+ curr.isExpanded());
}
}
@@ -615,6 +615,11 @@ public abstract class OptionsConfigurationBlock {
hasChanges = true;
}
+ if (!this.checkChanges(currContext)) {
+ // check failed
+ return false;
+ }
+
boolean doBuild = false;
if (needsBuild) {
String[] strings = getFullBuildDialogStrings(fProject == null);
@@ -657,6 +662,17 @@ public abstract class OptionsConfigurationBlock {
return true;
}
+ /**
+ * Default implementation returns true. Override and return false if the
+ * changes are incompatible to the underlying project
+ *
+ * @param currContext
+ * @return false to deny the changes.
+ */
+ protected boolean checkChanges(IScopeContext currContext) {
+ return true;
+ }
+
protected void prepareForBuild() {
// implement this method for any actions that need to be taken before
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPCoreOptionsConfigurationBlock.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPCoreOptionsConfigurationBlock.java
index bfae90e..313d2e7 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPCoreOptionsConfigurationBlock.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPCoreOptionsConfigurationBlock.java
@@ -12,7 +12,14 @@
package org.eclipse.php.internal.ui.preferences;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.php.internal.core.PHPCorePlugin;
+import org.eclipse.php.internal.core.PHPVersion;
+import org.eclipse.php.internal.core.facet.PHPFacets;
+import org.eclipse.php.internal.core.preferences.CorePreferenceConstants.Keys;
import org.eclipse.php.internal.ui.preferences.util.Key;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -39,4 +46,21 @@ public abstract class PHPCoreOptionsConfigurationBlock extends
return getKey(PHPCorePlugin.ID, key);
}
+ protected boolean checkChanges(IScopeContext currContext) {
+ final Key versionKey = getPHPCoreKey(Keys.PHP_VERSION);
+ // synch the php facets version if needed
+ final String newVersion = versionKey.getStoredValue(currContext,
+ fManager);
+ final IStatus status = PHPFacets.setFacetedVersion(fProject,
+ PHPVersion.byAlias(newVersion));
+ if (!status.isOK()) {
+ MessageDialog dialog = new MessageDialog(
+ getShell(),
+ PreferencesMessages.PHPCoreOptionsConfigurationBlock_SettingVersionFailed_Title,
+ null, status.getMessage(), MessageDialog.ERROR,
+ new String[] { IDialogConstants.CANCEL_LABEL }, 0);
+ dialog.open();
+ }
+ return status.isOK();
+ }
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.java
index 3c12bfe..23fcc53 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.java
@@ -802,4 +802,6 @@ public final class PreferencesMessages extends NLS {
public static String FavoriteStaticMemberInputDialog_error_invalidTypeName;
public static String FavoriteStaticMemberInputDialog_error_entryExists;
+ public static String PHPCoreOptionsConfigurationBlock_SettingVersionFailed_Title;
+
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.properties b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.properties
index c47cac2..4ac1ff2 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.properties
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PreferencesMessages.properties
@@ -936,3 +936,5 @@ NativeLibrariesPropertyPage_read_only=The current class path entry belongs to co
CleanUpPreferencePage_Description=A&ctive profile:
CleanUpPreferencePage_Title=Code Clean Up
+
+PHPCoreOptionsConfigurationBlock_SettingVersionFailed_Title=Failed setting php version \ No newline at end of file