diff options
author | Pascal Rapicault (Ericsson) | 2013-03-04 20:02:57 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-03-04 20:03:52 +0000 |
commit | 3ad2f7c875e59e5f32ee3b537ae53a12a44091fe (patch) | |
tree | d62907149f29fc4a749eb2b37f402514a0884b70 | |
parent | eebd88c4be122c5f4c6e0f84c2c88a995a4f5d00 (diff) | |
download | rt.equinox.p2-20130304-200352.tar.gz rt.equinox.p2-20130304-200352.tar.xz rt.equinox.p2-20130304-200352.zip |
Persist completed migration in profile scopev20130304-200352
3 files changed, 58 insertions, 73 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java index c55d00019..9e99a42a1 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java @@ -19,6 +19,7 @@ import org.eclipse.equinox.p2.core.*; import org.eclipse.equinox.p2.engine.IProfileRegistry; import org.eclipse.equinox.p2.engine.ProfileScope; import org.eclipse.equinox.p2.operations.ProvisioningSession; +import org.eclipse.equinox.p2.ui.ProvisioningUI; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; @@ -190,4 +191,17 @@ public class AutomaticUpdatePlugin extends AbstractUIPlugin { getContext().ungetService(ref); return agentProvider; } + + //TODO Find a better place for these two methods + public void rememberMigrationCompleted(String profileId) { + IProfileRegistry registry = (IProfileRegistry) ProvisioningUI.getDefaultUI().getSession().getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME); + long[] history = registry.listProfileTimestamps(profileId); + AutomaticUpdatePlugin.getDefault().getPreferenceStore().setValue(AutomaticUpdateScheduler.MIGRATION_DIALOG_SHOWN, history[history.length - 1]); + AutomaticUpdatePlugin.getDefault().savePreferences(); + } + + //Get the timestamp that we migrated from. O if we have not migrated. + public long getLastMigration() { + return AutomaticUpdatePlugin.getDefault().getPreferenceStore().getLong(AutomaticUpdateScheduler.MIGRATION_DIALOG_SHOWN); + } } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java index 11b675675..58adf57a3 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java @@ -19,12 +19,10 @@ import java.net.URI; import java.util.Iterator; import java.util.Set; import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.preferences.ConfigurationScope; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.engine.EngineActivator; import org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector; import org.eclipse.equinox.internal.p2.metadata.query.UpdateQuery; -import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration.AbstractPage_c; import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration.ImportFromInstallationWizard_c; import org.eclipse.equinox.internal.provisional.p2.updatechecker.*; import org.eclipse.equinox.p2.core.IProvisioningAgent; @@ -44,7 +42,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.*; import org.eclipse.ui.statushandlers.StatusManager; -import org.osgi.service.prefs.Preferences; /** * This plug-in is loaded on startup to register with the update checker. @@ -54,7 +51,7 @@ import org.osgi.service.prefs.Preferences; public class AutomaticUpdateScheduler implements IStartup { private static final String ECLIPSE_P2_SKIP_MIGRATION_WIZARD = "eclipse.p2.skipMigrationWizard"; //$NON-NLS-1$ - // private static final String ECLIPSE_P2_SKIP_MOVED_INSTALL_DETECTION = "eclipse.p2.skipMovedInstallDetection"; //$NON-NLS-1$ + private static final String ECLIPSE_P2_SKIP_MOVED_INSTALL_DETECTION = "eclipse.p2.skipMovedInstallDetection"; //$NON-NLS-1$ public static final String MIGRATION_DIALOG_SHOWN = "migrationDialogShown"; //$NON-NLS-1$ // values are to be picked up from the arrays DAYS and HOURS @@ -135,9 +132,6 @@ public class AutomaticUpdateScheduler implements IStartup { return false; reposToMigrate = ((IMetadataRepositoryManager) otherConfigAgent.getService(IMetadataRepositoryManager.SERVICE_NAME)).getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_SYSTEM); - - //At this point we consider that the migration is done since we will present something to the user. - registry.setProfileStateProperty(currentProfile.getProfileId(), registry.listProfileTimestamps(currentProfile.getProfileId())[0], "INITIAL", "DONE"); } if (previousProfile == null && baseChangedSinceLastPresentationOfWizard(agent, registry, currentProfile)) @@ -146,22 +140,15 @@ public class AutomaticUpdateScheduler implements IStartup { if (previousProfile == null) return false; - if (!remindMeLater()) - return false; - if (needsMigration(previousProfile, currentProfile)) { openMigrationWizard(previousProfile); + } else { + //There is nothing to migrate, so we mark the migration complete + AutomaticUpdatePlugin.getDefault().rememberMigrationCompleted(currentProfile.getProfileId()); } return true; } - - private boolean remindMeLater() { - Preferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.equinox.p2.ui"); - return prefs.getBoolean(AbstractPage_c.REMIND_ME_LATER, true); - - } - private File getInstallFolder() { Location configurationLocation = (Location) ServiceHelper.getService(EngineActivator.getContext(), Location.class.getName(), Location.INSTALL_FILTER); return new File(configurationLocation.getURL().getPath()); @@ -191,15 +178,18 @@ public class AutomaticUpdateScheduler implements IStartup { } private boolean skipFirstTimeMigration() { - return true;//Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty(ECLIPSE_P2_SKIP_MOVED_INSTALL_DETECTION)); + return Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty(ECLIPSE_P2_SKIP_MOVED_INSTALL_DETECTION)); } private boolean isFirstTimeRunningThisSharedInstance(IProvisioningAgent agent, IProfileRegistry registry, IProfile currentProfile) { long[] history = registry.listProfileTimestamps(currentProfile.getProfileId()); boolean isInitial = IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL.equals(registry.getProfileStateProperties(currentProfile.getProfileId(), history[0]).get(IProfile.STATE_PROP_SHARED_INSTALL)); - if (isInitial) + if (isInitial) { + if (AutomaticUpdatePlugin.getDefault().getLastMigration() >= history[0]) + return false; return true; - return !"DONE".equals(registry.getProfileStateProperties(currentProfile.getProfileId(), history[0]).get("INITIAL")); + } + return false; } /** @@ -248,19 +238,13 @@ public class AutomaticUpdateScheduler implements IStartup { } private boolean baseChangedSinceLastPresentationOfWizard(IProvisioningAgent agent, IProfileRegistry registry, IProfile profile) { - long lastShownMigration = getLastShownMigration(); - IProfile lastReset = findMostRecentReset(registry, profile); - if (lastReset == null) - return false; - return lastShownMigration < lastReset.getTimestamp(); + long lastProfileMigrated = AutomaticUpdatePlugin.getDefault().getLastMigration(); + long lastResetTimestamp = findMostRecentResetTimestamp(registry, profile); + return lastProfileMigrated <= lastResetTimestamp; } - //Get the timestamp that we migrated from - private long getLastShownMigration() { - return AutomaticUpdatePlugin.getDefault().getPreferenceStore().getLong(MIGRATION_DIALOG_SHOWN); - } - - private IProfile findMostRecentReset(IProfileRegistry registry, IProfile profile) { + //The timestamp from which we migrated or -1 + private long findMostRecentResetTimestamp(IProfileRegistry registry, IProfile profile) { long[] history = registry.listProfileTimestamps(profile.getProfileId()); int index = history.length - 1; boolean found = false; @@ -268,8 +252,15 @@ public class AutomaticUpdateScheduler implements IStartup { index--; } if (!found) + return -1; + return history[index]; + } + + private IProfile findMostRecentReset(IProfileRegistry registry, IProfile profile) { + long ts = findMostRecentResetTimestamp(registry, profile); + if (ts == -1) return null; - return registry.getProfile(profile.getProfileId(), history[index]); + return registry.getProfile(profile.getProfileId(), ts); } /** diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java index e860d5887..90c7a9f16 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java @@ -12,14 +12,12 @@ package org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration; import java.util.Collection; -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; import org.eclipse.equinox.internal.p2.ui.dialogs.ISelectableIUsPage; import org.eclipse.equinox.internal.p2.ui.dialogs.InstallWizard; import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot; import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdatePlugin; -import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdateScheduler; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.engine.*; import org.eclipse.equinox.p2.metadata.IInstallableUnit; @@ -32,9 +30,6 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.statushandlers.StatusManager; -import org.osgi.service.prefs.BackingStoreException; -import org.osgi.service.prefs.Preferences; public class ImportFromInstallationWizard_c extends InstallWizard implements IImportWizard { private IProfile toImportFrom; @@ -80,20 +75,15 @@ public class ImportFromInstallationWizard_c extends InstallWizard implements IIm @Override public boolean performFinish() { cleanupProfileRegistry(); - rememberShownMigration(toImportFrom.getTimestamp()); - return super.performFinish(); + boolean finished = super.performFinish(); + if (finished) + rememberMigrationCompleted(); + return finished; } - //Remember the timestamp that we migrated from. - private void rememberShownMigration(long timestamp) { - AutomaticUpdatePlugin.getDefault().getPreferenceStore().setValue(AutomaticUpdateScheduler.MIGRATION_DIALOG_SHOWN, timestamp); - try { - Preferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.equinox.p2.ui"); //$NON-NLS-1$ - prefs.putBoolean(AbstractPage_c.REMIND_ME_LATER, true); - prefs.flush(); - } catch (BackingStoreException e) { - StatusManager.getManager().handle(new Status(IStatus.ERROR, AutomaticUpdatePlugin.PLUGIN_ID, 0, ProvUIMessages.ERROR_SAVING_PREFERENCES, e), StatusManager.LOG); - } + //Remember that we completed the migration + private void rememberMigrationCompleted() { + AutomaticUpdatePlugin.getDefault().rememberMigrationCompleted(toImportFrom.getProfileId()); } //Purge the profile registry from all the entries that are no longer relevant @@ -112,35 +102,25 @@ public class ImportFromInstallationWizard_c extends InstallWizard implements IIm } public boolean performCancel() { - - Preferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.equinox.p2.ui"); //$NON-NLS-1$ boolean result = false; MessageDialog dialog = new MessageDialog(getShell(), "Migration dialaog", null, ProvUIMessages.ImportFromInstallationPage_CONFIRMATION_DIALOG, MessageDialog.QUESTION, new String[] {"Yes", "Yes, but remind me later", "No"}, 2); int answer = dialog.open(); - try { - switch (answer) { - case -1 : // if the user closes the dialog without clicking any button. - break; - case 0 : - result = true; - prefs.putBoolean(AbstractPage_c.REMIND_ME_LATER, false); - prefs.flush(); - break; - case 1 : - result = true; - prefs.putBoolean(AbstractPage_c.REMIND_ME_LATER, true); - prefs.flush(); - break; - case 2 : - result = false; - break; - } - } catch (BackingStoreException e) { - StatusManager.getManager().handle(new Status(IStatus.ERROR, AutomaticUpdatePlugin.PLUGIN_ID, 0, ProvUIMessages.ERROR_SAVING_PREFERENCES, e), StatusManager.LOG); + switch (answer) { + case -1 : // if the user closes the dialog without clicking any button. + break; + case 0 : + result = true; + rememberMigrationCompleted(); + break; + case 1 : + result = true; + break; + case 2 : + result = false; + break; } return result; } - } |